]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - apps/rpp-test-suite/src/din.c
25ce2edc03071de784215343d26ece79ec7b1ec4
[pes-rpp/rpp-lib.git] / 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     1000
32
33
34 /**
35  * FreeRTOS Task that read digital inputs and prints them on the SCI.
36  */
37 void din_test_task(void* par)
38 {
39     rpp_sci_printf((const char*)"Digital Inputs Test [1-16]:\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     // Configure pins
47     int pin = 1;
48     for(pin = 1; pin <= 16; pin++) {
49         rpp_din_setup(pin, FALSE, TRUE, FALSE);
50     }
51     rpp_din_update();
52
53     while(TRUE) {
54
55         // Wait until next step
56         vTaskDelayUntil(&last_wake_time, freq_ticks);
57
58         // Update inputs
59         rpp_din_update();
60
61         // Print inputs
62         // Terminal needs to be at least 31 chars long
63         rpp_sci_printf((const char*)
64                 "\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\b"
65             );
66
67         rpp_sci_printf((const char*)
68                 "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
69                 rpp_din_get( 1, FALSE),
70                 rpp_din_get( 2, FALSE),
71                 rpp_din_get( 3, FALSE),
72                 rpp_din_get( 4, FALSE),
73                 rpp_din_get( 5, FALSE),
74                 rpp_din_get( 6, FALSE),
75                 rpp_din_get( 7, FALSE),
76                 rpp_din_get( 8, FALSE),
77                 rpp_din_get( 9, FALSE),
78                 rpp_din_get(10, FALSE),
79                 rpp_din_get(11, FALSE),
80                 rpp_din_get(12, FALSE),
81                 rpp_din_get(13, FALSE),
82                 rpp_din_get(14, FALSE),
83                 rpp_din_get(15, FALSE),
84                 rpp_din_get(16, FALSE)
85             );
86     }
87 }
88
89
90 /**
91  * DIN Test entry point.
92  */
93 void test_din(void)
94 {
95     xTaskHandle test_task_handle;
96
97     portBASE_TYPE task_created = xTaskCreate(din_test_task,
98                     (const signed char*)"din_test_task",
99                     TEST_TASK_TASK, NULL, TEST_TASK_PRIORITY,
100                     &test_task_handle
101             );
102
103     if(task_created != pdPASS) {
104
105         rpp_sci_printf((const char*)
106                 "ERROR: Problem spawning the test task. "
107                 "Error code: %d\r\n", (uint32_t)task_created
108             );
109         wait_for_quit();
110         return;
111     }
112
113     wait_for_quit();
114     vTaskDelete(test_task_handle);
115
116     // Reset module
117     // - Not required
118
119     return;
120 }
121
122