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)
40 if ( strncmp(string, "adc", BUF_SIZE) == 0)
42 else if (strncmp(string, "dac", BUF_SIZE) == 0)
44 else if (strncmp(string, "can", BUF_SIZE) == 0)
46 else if (strncmp(string, "din", 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, "hbr", BUF_SIZE) == 0)
54 else if (strncmp(string, "hout", BUF_SIZE) == 0)
56 else if (strncmp(string, "lin", BUF_SIZE) == 0)
58 else if (strncmp(string, "lout", BUF_SIZE) == 0)
60 else if (strncmp(string, "mout", BUF_SIZE) == 0)
62 else if (strncmp(string, "sci", BUF_SIZE) == 0)
64 else if (strncmp(string, "sdc", BUF_SIZE) == 0)
66 else if (strncmp(string, "sdr", BUF_SIZE) == 0)
68 else if (strncmp(string, "help", BUF_SIZE) == 0) {
69 rpp_sci_printf((const char *)"Available commands:\r\n");
70 rpp_sci_printf((const char *)"\thelp - Display this help.\r\n");
71 rpp_sci_printf((const char *)"\tain - Test Analog Input.\r\n");
72 rpp_sci_printf((const char *)"\taout - Test Analog Output.\r\n");
73 rpp_sci_printf((const char *)"\tcan - Test CAN communication.\r\n");
74 rpp_sci_printf((const char *)"\tdin - Test Digital Inputs.\r\n");
75 rpp_sci_printf((const char *)"\teth - Test Ethernet communication.\r\n");
76 rpp_sci_printf((const char *)"\tfr - Test FlexRay communication.\r\n");
77 rpp_sci_printf((const char *)"\thbr - Test H-Bridge.\r\n");
78 rpp_sci_printf((const char *)"\thout - Test High Power Output.\r\n");
79 rpp_sci_printf((const char *)"\tlin - Test LIN communication.\r\n");
80 rpp_sci_printf((const char *)"\tlout - Test Digital Outputs.\r\n");
81 rpp_sci_printf((const char *)"\tmout - Test Power Outputs.\r\n");
82 rpp_sci_printf((const char *)"\tsci - Test Serial Communication Interface.\r\n");
83 rpp_sci_printf((const char *)"\tsdc - Test SD-Card.\r\n");
84 rpp_sci_printf((const char *)"\tsdr - Test SD-RAM.\r\n");
87 // Unknown command, print buffer back
88 rpp_sci_printf((const char *)
89 "ERROR: Unknown command \"%s\"\r\n", string
95 * Test suite command processor.
97 void test_cmdproc(void *par)
100 rpp_sci_printf((const char *)
101 "RPP Library Test Suite.\r\n"
103 rpp_sci_printf((const char *)
104 "===========================================================\r\n"
106 rpp_sci_printf((const char *)
107 "[Type a module to test or 'help']\r\n"
110 rpp_sci_printf((const char *)"%s", prompt);
113 uint8_t buff_index = 0;
114 boolean_t flush = FALSE;
117 // Get one character from the user
118 if (rpp_sci_read_nb(1, &input) != SUCCESS) {
119 vTaskDelay(INPUT_IDLE / portTICK_RATE_MS);
123 // Backspace and Delete
124 if (input == 8 || input == 127) {
125 if (buff_index > 0) {
133 else if (input == 10 || input == 13) {
134 // Line feed or Carriage return
139 else if (isprint(input)) {
140 // If is any printable character
142 // Store character and increment buffer index
143 in_buffer[buff_index] = input;
147 // Check if buffer is full and force flush
148 if (buff_index == BUF_SIZE - 1)
151 // All other character are ignored
158 in_buffer[buff_index] = '\0';
162 execute_cmd((char *)&in_buffer);
163 rpp_sci_printf((const char *)"%s", newline);
164 rpp_sci_printf((const char *)"%s", prompt);
176 /// Utilities ------------------------------------------------------------------
178 * Wait for user input "q" to quit the loop.
182 while (rpp_sci_getc() < 0)
183 vTaskDelay(INPUT_IDLE / portTICK_RATE_MS);
188 * Infinite busy loop.
190 * This function is called after an error has being detected to "stop"
193 void busy_infinite_loop()
201 /// Main functions -------------------------------------------------------------
203 * Application main function
205 * This function is called after startup.
209 // Initialize library
213 rpp_sci_setup(115200);
216 portBASE_TYPE task_created =
217 xTaskCreate(test_cmdproc,
218 (const signed char *)"test_cmdproc",
219 1024, NULL, TEST_TASK_PRIORITY, NULL
222 if (task_created != pdPASS) {
223 rpp_sci_printf((const char *)
224 "ERROR: Problem allocating memory for command processor to "
225 "start. Error code: %d\r\n", (uint32_t)task_created
227 busy_infinite_loop();
231 vTaskStartScheduler();
233 // Catch memory problems
234 rpp_sci_printf((const char *)
235 "ERROR: Problem allocating memory for scheduler to start.\r\n"
237 busy_infinite_loop();
244 * FreeRTOS malloc() failed hook.
246 void vApplicationMallocFailedHook(void)
248 rpp_sci_printf((const char *)
249 "ERROR: Manual memory allocation failed.\r\n"
255 * FreeRTOS stack overflow hook.
257 void vApplicationStackOverflowHook(xTaskHandle xTask,
258 signed portCHAR *pcTaskName)
260 rpp_sci_printf((const char *)
261 "ERROR: Stack overflow : \"%s\".\r\n", pcTaskName