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";
34 #warning TODO: Merge into ../_linux/main.c -MS
37 * Compare user string and execute command.
39 void execute_cmd(char *string)
41 if ( strncmp(string, "adc", BUF_SIZE) == 0)
43 else if (strncmp(string, "dac", BUF_SIZE) == 0)
45 else if (strncmp(string, "can", BUF_SIZE) == 0)
47 else if (strncmp(string, "din", BUF_SIZE) == 0)
49 else if (strncmp(string, "eth", BUF_SIZE) == 0)
51 else if (strncmp(string, "fr", BUF_SIZE) == 0)
53 else if (strncmp(string, "hbr", BUF_SIZE) == 0)
55 else if (strncmp(string, "hout", BUF_SIZE) == 0)
57 else if (strncmp(string, "lin", BUF_SIZE) == 0)
59 else if (strncmp(string, "lout", BUF_SIZE) == 0)
61 else if (strncmp(string, "mout", BUF_SIZE) == 0)
63 else if (strncmp(string, "sci", BUF_SIZE) == 0)
65 else if (strncmp(string, "sdc", BUF_SIZE) == 0)
67 else if (strncmp(string, "sdr", BUF_SIZE) == 0)
69 else if (strncmp(string, "help", BUF_SIZE) == 0) {
70 rpp_sci_printf((const char *)"Available commands:\r\n");
71 rpp_sci_printf((const char *)"\thelp - Display this help.\r\n");
72 rpp_sci_printf((const char *)"\tain - Test Analog Input.\r\n");
73 rpp_sci_printf((const char *)"\taout - Test Analog Output.\r\n");
74 rpp_sci_printf((const char *)"\tcan - Test CAN communication.\r\n");
75 rpp_sci_printf((const char *)"\tdin - Test Digital Inputs.\r\n");
76 rpp_sci_printf((const char *)"\teth - Test Ethernet communication.\r\n");
77 rpp_sci_printf((const char *)"\tfr - Test FlexRay communication.\r\n");
78 rpp_sci_printf((const char *)"\thbr - Test H-Bridge.\r\n");
79 rpp_sci_printf((const char *)"\thout - Test High Power Output.\r\n");
80 rpp_sci_printf((const char *)"\tlin - Test LIN communication.\r\n");
81 rpp_sci_printf((const char *)"\tlout - Test Digital Outputs.\r\n");
82 rpp_sci_printf((const char *)"\tmout - Test Power Outputs.\r\n");
83 rpp_sci_printf((const char *)"\tsci - Test Serial Communication Interface.\r\n");
84 rpp_sci_printf((const char *)"\tsdc - Test SD-Card.\r\n");
85 rpp_sci_printf((const char *)"\tsdr - Test SD-RAM.\r\n");
88 // Unknown command, print buffer back
89 rpp_sci_printf((const char *)
90 "ERROR: Unknown command \"%s\"\r\n", string
96 * Test suite command processor.
98 void test_cmdproc(void *par)
101 rpp_sci_printf((const char *)
102 "RPP Library Test Suite.\r\n"
104 rpp_sci_printf((const char *)
105 "===========================================================\r\n"
107 rpp_sci_printf((const char *)
108 "[Type a module to test or 'help']\r\n"
111 rpp_sci_printf((const char *)"%s", prompt);
114 uint8_t buff_index = 0;
115 boolean_t flush = FALSE;
118 // Get one character from the user
119 if (rpp_sci_read_nb(1, &input) != SUCCESS) {
120 vTaskDelay(INPUT_IDLE / portTICK_RATE_MS);
124 // Backspace and Delete
125 if (input == 8 || input == 127) {
126 if (buff_index > 0) {
134 else if (input == 10 || input == 13) {
135 // Line feed or Carriage return
140 else if (isprint(input)) {
141 // If is any printable character
143 // Store character and increment buffer index
144 in_buffer[buff_index] = input;
148 // Check if buffer is full and force flush
149 if (buff_index == BUF_SIZE - 1)
152 // All other character are ignored
159 in_buffer[buff_index] = '\0';
163 execute_cmd((char *)&in_buffer);
164 rpp_sci_printf((const char *)"%s", newline);
165 rpp_sci_printf((const char *)"%s", prompt);
177 /// Utilities ------------------------------------------------------------------
179 * Wait for user input "q" to quit the loop.
183 while (rpp_sci_getc() < 0)
184 vTaskDelay(INPUT_IDLE / portTICK_RATE_MS);
189 * Infinite busy loop.
191 * This function is called after an error has being detected to "stop"
194 void busy_infinite_loop()
202 /// Main functions -------------------------------------------------------------
204 * Application main function
206 * This function is called after startup.
210 // Initialize library
214 rpp_sci_setup(115200);
217 portBASE_TYPE task_created =
218 xTaskCreate(test_cmdproc,
219 (const signed char *)"test_cmdproc",
220 1024, NULL, TEST_TASK_PRIORITY, NULL
223 if (task_created != pdPASS) {
224 rpp_sci_printf((const char *)
225 "ERROR: Problem allocating memory for command processor to "
226 "start. Error code: %d\r\n", (uint32_t)task_created
228 busy_infinite_loop();
232 vTaskStartScheduler();
234 // Catch memory problems
235 rpp_sci_printf((const char *)
236 "ERROR: Problem allocating memory for scheduler to start.\r\n"
238 busy_infinite_loop();
245 * FreeRTOS malloc() failed hook.
247 void vApplicationMallocFailedHook(void)
249 rpp_sci_printf((const char *)
250 "ERROR: Manual memory allocation failed.\r\n"
256 * FreeRTOS stack overflow hook.
258 void vApplicationStackOverflowHook(xTaskHandle xTask,
259 signed portCHAR *pcTaskName)
261 rpp_sci_printf((const char *)
262 "ERROR: Stack overflow : \"%s\".\r\n", pcTaskName