]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - apps/rpp-test-suite/src/ain.c
Fixed some minor and other mayor bugs. Changes simulation to static memory to avoid...
[pes-rpp/rpp-lib.git] / apps / rpp-test-suite / src / ain.c
1 /* Copyright (C) 2013 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Carlos Jenkins <carlos@jenkins.co.cr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  * File : ain.c
20  * Abstract:
21  *     RPP test suite - module for testing AIN.
22  *
23  * References:
24  *     test.h
25  */
26
27
28 #include "rpp/rpp.h"
29 #include "test.h"
30
31 #define FREQ_MILLIS     1000
32
33
34 /**
35  * FreeRTOS Task that read analog inputs and prints them on the SCI.
36  */
37 void ain_test_task(void* par)
38 {
39     rpp_sci_printf((const char*)"Analog Inputs Test [1-12]:\r\n");
40     rpp_sci_printf((const char*)"================================\r\n");
41
42     // Calculate wait time in OS ticks
43     static const portTickType freq_ticks = FREQ_MILLIS / portTICK_RATE_MS;
44     portTickType last_wake_time = xTaskGetTickCount();
45
46     while(TRUE) {
47
48         // Update inputs
49         rpp_ain_update();
50
51         // Print inputs
52         // Terminal needs to be at least 59 chars long
53         rpp_sci_printf((const char*)
54                 "\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"
55                 "\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"
56             );
57         rpp_sci_printf((const char*)
58                 "%4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d",
59                 rpp_ain_get(1),
60                 rpp_ain_get(2),
61                 rpp_ain_get(3),
62                 rpp_ain_get(4),
63                 rpp_ain_get(5),
64                 rpp_ain_get(6),
65                 rpp_ain_get(7),
66                 rpp_ain_get(8),
67                 rpp_ain_get(9),
68                 rpp_ain_get(10),
69                 rpp_ain_get(11),
70                 rpp_ain_get(12)
71             );
72
73         // Wait until next step
74         vTaskDelayUntil(&last_wake_time, freq_ticks);
75     }
76 }
77
78
79 /**
80  * AIN Test entry point.
81  */
82 void test_ain(void)
83 {
84     xTaskHandle test_task_handle;
85
86     rpp_sci_printf((const char*)"Try to create task.\r\n");
87     portBASE_TYPE task_created = xTaskCreate(ain_test_task,
88                     (const signed char*)"ain_test_task",
89                     TEST_TASK_STACK, NULL, TEST_TASK_PRIORITY,
90                     &test_task_handle
91             );
92     rpp_sci_printf((const char*)"After try to create task.\r\n");
93
94     if(task_created != pdPASS) {
95
96         rpp_sci_printf((const char*)
97                 "ERROR: Problem spawning the test task. "
98                 "Error code: %d\r\n", (uint32_t)task_created
99             );
100         wait_for_quit();
101         return;
102
103     }
104
105     wait_for_quit();
106     vTaskDelete(test_task_handle);
107     vTaskDelay(4); // Allow the idle task to free memory
108
109     // Reset module
110     // - Not required
111
112     return;
113 }
114
115