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 - module for testing AIN.
23 #define FREQ_MILLIS 100
27 static boolean_t stop_tasks = FALSE;
28 static uint8_t tasks_running = 0;
31 * FreeRTOS Task that read analog inputs and prints them on the SCI.
33 void adc_test_task(void *par)
35 rpp_sci_printf((const char *)
36 "Analog Inputs Test [1-12]:\r\n"
38 rpp_sci_printf((const char *)
39 "===========================================================\r\n"
41 rpp_sci_printf((const char *)
42 " 1 2 3 4 5 6 7 8 9 10 11 12\r\n"
43 // 4095 4095 4095 4095 4095 4095 4095 4095 4095 4095 4095 4095
46 // Calculate wait time in OS ticks
47 static const portTickType freq_ticks = FREQ_MILLIS / portTICK_RATE_MS;
48 portTickType last_wake_time = xTaskGetTickCount();
55 if (stop_tasks) // This printfs are really expensive, avoid
56 continue; // to run them if application is requested to stop.
59 // Terminal needs to be at least 59 chars long
60 rpp_sci_printf((const char *)
61 "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
62 "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
65 rpp_sci_printf((const char *)
66 "%4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d",
81 // Wait until next step
83 vTaskDelayUntil(&last_wake_time, freq_ticks);
85 #endif /* TARGET_POSIX */
94 * ADC Test entry point.
103 xTaskHandle test_task_handle;
105 portBASE_TYPE task_created = xTaskCreate(adc_test_task,
107 TEST_TASK_STACK, NULL, TEST_TASK_PRIORITY,
111 if (task_created != pdPASS) {
113 rpp_sci_printf((const char *)
114 "ERROR: Problem spawning the test task. "
115 "Error code: %d\r\n", (uint32_t)task_created
124 // Wait for user exit
125 // Note: Not an easy task. If we preempt delete the task from this context
126 // using vTaskDelete and the task is holding a semaphore, like in the middle
127 // of a SCI send, printf, or similar, the semaphore will never be released
128 // and the application will deadlock in the next call to that function.
129 // As a general rule of thumb just allow vTaskDelete on the tasks themselves
130 // and implement a synchronization mecanism. Here we set flag to notify them
131 // that they should stop and then force change context each time this gets
132 // executed until all the tasks deleted themselves.
135 while (tasks_running > 0)
140 /// Reset module configuration
144 rpp_sci_printf((const char *)"\r\n");