1 /* Copyright (C) 2013, 2014 Czech Technical University in Prague
4 * - Carlos Jenkins <carlos@jenkins.co.cr>
6 * This document contains proprietary information belonging to Czech
7 * Technical University in Prague. Passing on and copying of this
8 * document, and communication of its contents is not permitted
9 * without prior written authorization.
13 * RPP test suite command processor.
20 #include <ctype.h> // isprint()
21 #include <string.h> // strncmp()
27 /// Command processor task -----------------------------------------------------
30 static char in_buffer[BUF_SIZE];
31 static const char *prompt = "--> ";
32 static const char *newline = "\r\n";
36 * Compare user string and execute command.
38 void execute_cmd(char *string)
41 if ( strncmp(string, "adc", BUF_SIZE) == 0)
43 else if (strncmp(string, "can", BUF_SIZE) == 0)
44 #else /* TARGET_POSIX */
45 if (strncmp(string, "can", BUF_SIZE) == 0)
46 #endif /* TARGET_POSIX */
49 else if (strncmp(string, "eth", BUF_SIZE) == 0)
51 else if (strncmp(string, "fr", BUF_SIZE) == 0)
53 else if (strncmp(string, "lin", BUF_SIZE) == 0)
55 #endif /* TARGET_POSIX */
56 else if (strncmp(string, "sci", BUF_SIZE) == 0)
58 else if (strncmp(string, "help", BUF_SIZE) == 0) {
59 rpp_sci_printf((const char *)"Available commands:\r\n");
60 rpp_sci_printf((const char *)"\thelp - Display this help.\r\n");
62 rpp_sci_printf((const char *)"\tain - Test Analog Input.\r\n");
63 #endif /* ! TARGET_POSIX */
64 rpp_sci_printf((const char *)"\tcan - Test CAN communication.\r\n");
66 rpp_sci_printf((const char *)"\teth - Test Ethernet communication.\r\n");
67 rpp_sci_printf((const char *)"\tfr - Test FlexRay communication.\r\n");
68 rpp_sci_printf((const char *)"\tlin - Test LIN communication.\r\n");
69 #endif /* TARGET_POSIX */
70 rpp_sci_printf((const char *)"\tsci - Test Serial Communication Interface.\r\n");
73 // Unknown command, print buffer back
74 rpp_sci_printf((const char *)
75 "ERROR: Unknown command \"%s\"\r\n", string
81 * Test suite command processor.
83 void test_cmdproc(void *par)
86 rpp_sci_printf((const char *)
87 "RPP Library Test Suite.\r\n"
89 rpp_sci_printf((const char *)
90 "===========================================================\r\n"
92 rpp_sci_printf((const char *)
93 "[Type a module to test or 'help']\r\n"
96 rpp_sci_printf((const char *)"%s", prompt);
99 uint8_t buff_index = 0;
100 boolean_t flush = FALSE;
103 // Get one character from the user
104 if (rpp_sci_read_nb(1, &input) != SUCCESS) {
105 vTaskDelay(INPUT_IDLE / portTICK_RATE_MS);
109 // Backspace and Delete
110 if (input == 8 || input == 127) {
111 if (buff_index > 0) {
119 else if (input == 10 || input == 13) {
120 // Line feed or Carriage return
125 else if (isprint(input)) {
126 // If is any printable character
128 // Store character and increment buffer index
129 in_buffer[buff_index] = input;
133 // Check if buffer is full and force flush
134 if (buff_index == BUF_SIZE - 1)
137 // All other character are ignored
144 in_buffer[buff_index] = '\0';
148 execute_cmd((char *)&in_buffer);
149 rpp_sci_printf((const char *)"%s", newline);
150 rpp_sci_printf((const char *)"%s", prompt);
162 /// Utilities ------------------------------------------------------------------
164 * Wait for user input "q" to quit the loop.
168 while (rpp_sci_getc() < 0)
169 vTaskDelay(INPUT_IDLE / portTICK_RATE_MS);
174 * Infinite busy loop.
176 * This function is called after an error has being detected to "stop"
179 void busy_infinite_loop()
187 /// Main functions -------------------------------------------------------------
189 * Application main function
191 * This function is called after startup.
196 // Initialize library
200 rpp_sci_setup(115200);
201 #endif /* ! TARGET_POSIX */
203 portBASE_TYPE task_created =
204 xTaskCreate(test_cmdproc,
205 (const signed char *)"test_cmdproc",
206 1024, NULL, TEST_TASK_PRIORITY, NULL
209 if (task_created != pdPASS) {
210 rpp_sci_printf((const char *)
211 "ERROR: Problem allocating memory for command processor to "
212 "start. Error code: %d\r\n", (uint32_t)task_created
214 busy_infinite_loop();
218 vTaskStartScheduler();
220 // Catch memory problems
221 rpp_sci_printf((const char *)
222 "ERROR: Problem allocating memory for scheduler to start.\r\n"
224 busy_infinite_loop();
231 * FreeRTOS malloc() failed hook.
233 void vApplicationMallocFailedHook(void)
235 rpp_sci_printf((const char *)
236 "ERROR: Manual memory allocation failed.\r\n"
242 * FreeRTOS stack overflow hook.
244 void vApplicationStackOverflowHook(xTaskHandle xTask,
245 signed portCHAR *pcTaskName)
247 rpp_sci_printf((const char *)
248 "ERROR: Stack overflow : \"%s\".\r\n", pcTaskName