]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/lib/apps/rpp-test-suite/src/din.c
fc2407dda9042612ae421d422c652a232eb7dc9b
[pes-rpp/rpp-simulink.git] / rpp / lib / apps / rpp-test-suite / src / din.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 : din.c
20  * Abstract:
21  *     RPP test suite - module for testing DIN.
22  *
23  * References:
24  *     test.h
25  */
26
27
28 #include "rpp/rpp.h"
29 #include "test.h"
30
31 #define FREQ_MILLIS      100
32
33
34 // Task control
35 static boolean_t stop_tasks = FALSE;
36 static uint8_t tasks_running = 0;
37
38
39 /**
40  * FreeRTOS Task that read digital inputs and prints them on the SCI.
41  */
42 void din_test_task(void* par)
43 {
44     rpp_sci_printf((const char*)
45             "Digital Inputs Test [1-16]:\r\n"
46         );
47     rpp_sci_printf((const char*)
48             "===========================================================\r\n"
49         );
50     rpp_sci_printf((const char*)
51             "01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16\r\n"
52           //  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
53         );
54
55     // Calculate wait time in OS ticks
56     static const portTickType freq_ticks = FREQ_MILLIS / portTICK_RATE_MS;
57     portTickType last_wake_time = xTaskGetTickCount();
58
59     while(!stop_tasks) {
60
61         // Update inputs
62         rpp_din_update();
63
64         // Print inputs
65         // Terminal needs to be at least 47 chars long
66         if(stop_tasks) {
67             continue;
68         }
69         rpp_sci_printf((const char*)
70                 "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
71                 "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
72             );
73
74         rpp_sci_printf((const char*)
75                 " %d  %d  %d  %d  %d  %d  %d  %d  %d  %d  %d  %d  %d  %d  %d  %d",
76                 rpp_din_get( 1, FALSE),
77                 rpp_din_get( 2, FALSE),
78                 rpp_din_get( 3, FALSE),
79                 rpp_din_get( 4, FALSE),
80                 rpp_din_get( 5, FALSE),
81                 rpp_din_get( 6, FALSE),
82                 rpp_din_get( 7, FALSE),
83                 rpp_din_get( 8, FALSE),
84                 rpp_din_get( 9, FALSE),
85                 rpp_din_get(10, FALSE),
86                 rpp_din_get(11, FALSE),
87                 rpp_din_get(12, FALSE),
88                 rpp_din_get(13, FALSE),
89                 rpp_din_get(14, FALSE),
90                 rpp_din_get(15, FALSE),
91                 rpp_din_get(16, FALSE)
92             );
93
94         // Wait until next step
95         if(!stop_tasks) {
96             vTaskDelayUntil(&last_wake_time, freq_ticks);
97         }
98     }
99
100     // Delete myself
101     tasks_running--;
102     vTaskDelete(NULL);
103 }
104
105
106 /**
107  * DIN Test entry point.
108  */
109 void test_din()
110 {
111     /// Configure module
112     // Configure pins
113     int pin = 1;
114     for(pin = 1; pin <= 16; pin++) {
115         // Configure pin as pull-down, active, non-wake up
116         rpp_din_setup(pin, FALSE, TRUE, FALSE);
117     }
118     rpp_din_update();
119
120
121     /// Spawn tasks
122     xTaskHandle test_task_handle;
123
124     portBASE_TYPE task_created = xTaskCreate(din_test_task,
125                     (const signed char*)"din_test_task",
126                     TEST_TASK_STACK, NULL, TEST_TASK_PRIORITY,
127                     &test_task_handle
128             );
129
130     if(task_created != pdPASS) {
131
132         rpp_sci_printf((const char*)
133                 "ERROR: Problem spawning the test task. "
134                 "Error code: %d\r\n", (uint32_t)task_created
135             );
136         wait_for_quit();
137         return;
138     }
139     tasks_running++;
140
141
142     // Wait for user exit
143     wait_for_quit();
144     stop_tasks = TRUE;
145     while(tasks_running > 0) {
146         taskYIELD();
147     }
148     stop_tasks = FALSE;
149
150
151     /// Reset module configuration
152     // - Not required
153
154
155     rpp_sci_printf((const char*)"\r\n");
156
157     return;
158 }
159
160