1 /* Copyright (C) 2013, 2014, 2015 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)
44 #endif /* TARGET_POSIX */
45 if ( strncmp(string, "can", BUF_SIZE) == 0)
48 else if (strncmp(string, "eth", BUF_SIZE) == 0)
50 else if (strncmp(string, "fr", BUF_SIZE) == 0)
52 else if (strncmp(string, "lin", BUF_SIZE) == 0)
54 #endif /* TARGET_POSIX */
55 else if (strncmp(string, "sci", BUF_SIZE) == 0)
57 else if (strncmp(string, "help", BUF_SIZE) == 0) {
58 rpp_sci_printf((const char *)"Available commands:\r\n");
59 rpp_sci_printf((const char *)"\thelp - Display this help.\r\n");
61 rpp_sci_printf((const char *)"\tain - Test Analog Input.\r\n");
62 #endif /* ! TARGET_POSIX */
63 rpp_sci_printf((const char *)"\tcan - Test CAN communication.\r\n");
65 rpp_sci_printf((const char *)"\teth - Test Ethernet communication.\r\n");
66 rpp_sci_printf((const char *)"\tfr - Test FlexRay communication.\r\n");
67 rpp_sci_printf((const char *)"\tlin - Test LIN communication.\r\n");
68 #endif /* TARGET_POSIX */
69 rpp_sci_printf((const char *)"\tsci - Test Serial Communication Interface.\r\n");
72 // Unknown command, print buffer back
73 rpp_sci_printf((const char *)
74 "ERROR: Unknown command \"%s\"\r\n", string
80 * Test suite command processor.
82 void test_cmdproc(void *par)
85 rpp_sci_printf((const char *)
86 "RPP Library Test Suite.\r\n"
88 rpp_sci_printf((const char *)
89 "===========================================================\r\n"
91 rpp_sci_printf((const char *)
92 "[Type a module to test or 'help']\r\n"
95 rpp_sci_printf((const char *)"%s", prompt);
98 uint8_t buff_index = 0;
99 boolean_t flush = FALSE;
102 // Get one character from the user
103 if (rpp_sci_read_nb(1, &input) != SUCCESS) {
104 vTaskDelay(INPUT_IDLE / portTICK_RATE_MS);
108 // Backspace and Delete
109 if (input == 8 || input == 127) {
110 if (buff_index > 0) {
118 else if (input == 10 || input == 13) {
119 // Line feed or Carriage return
124 else if (isprint(input)) {
125 // If is any printable character
127 // Store character and increment buffer index
128 in_buffer[buff_index] = input;
132 // Check if buffer is full and force flush
133 if (buff_index == BUF_SIZE - 1)
136 // All other character are ignored
143 in_buffer[buff_index] = '\0';
147 execute_cmd((char *)&in_buffer);
148 rpp_sci_printf((const char *)"%s", newline);
149 rpp_sci_printf((const char *)"%s", prompt);
161 /// Utilities ------------------------------------------------------------------
163 * Wait for user input "q" to quit the loop.
167 while (rpp_sci_getc() < 0)
168 vTaskDelay(INPUT_IDLE / portTICK_RATE_MS);
173 * Infinite busy loop.
175 * This function is called after an error has being detected to "stop"
178 void busy_infinite_loop()
186 /// Main functions -------------------------------------------------------------
188 * Application main function
190 * This function is called after startup.
194 // Initialize library
199 rpp_sci_setup(115200);
200 #endif /* ! TARGET_POSIX */
202 portBASE_TYPE task_created =
203 xTaskCreate(test_cmdproc,
204 (const signed char *)"test_cmdproc",
205 1024, NULL, TEST_TASK_PRIORITY, NULL
208 if (task_created != pdPASS) {
209 rpp_sci_printf((const char *)
210 "ERROR: Problem allocating memory for command processor to "
211 "start. Error code: %d\r\n", (uint32_t)task_created
213 busy_infinite_loop();
217 vTaskStartScheduler();
219 // Catch memory problems
220 rpp_sci_printf((const char *)
221 "ERROR: Problem allocating memory for scheduler to start.\r\n"
223 busy_infinite_loop();
230 * FreeRTOS malloc() failed hook.
232 void vApplicationMallocFailedHook(void)
234 rpp_sci_printf((const char *)
235 "ERROR: Manual memory allocation failed.\r\n"
241 * FreeRTOS stack overflow hook.
243 void vApplicationStackOverflowHook(xTaskHandle xTask,
244 signed portCHAR *pcTaskName)
246 rpp_sci_printf((const char *)
247 "ERROR: Stack overflow : \"%s\".\r\n", pcTaskName