]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - apps/rpp-test-suite/mout.c
Change license to MIT
[pes-rpp/rpp-lib.git] / apps / rpp-test-suite / mout.c
1 /* Copyright (C) 2013 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Carlos Jenkins <carlos@jenkins.co.cr>
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use,
10  * copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following
13  * conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  *
27  * File : mout.c
28  * Abstract:
29  *     RPP test suite - module for testing MOUT.
30  *
31  * References:
32  *     test.h
33  */
34
35
36 #include "rpp/rpp.h"
37 #include "test.h"
38
39 #define FREQ_MILLIS     1000
40
41
42 // Task control
43 static boolean_t stop_tasks = FALSE;
44 static uint8_t tasks_running = 0;
45
46 /**
47  * FreeRTOS Task that toggle the MOUT outputs, then reads the diagnostics and
48  * compare.
49  */
50 void mout_test_task(void *par)
51 {
52         rpp_sci_printf((const char *)
53                                    "Power Output Test:\r\n"
54                                    );
55         rpp_sci_printf((const char *)
56                                    "===========================================================\r\n"
57                                    );
58         rpp_sci_printf((const char *)
59                                    "1     2     3     4     5     6\r\n"
60                        // 1:BAD 1:BAD 1:BAD 1:BAD 1:BAD 1:BAD
61                        // 1: OK 1: OK 1: OK 1: OK 1: OK 1: OK
62                                    );
63
64         // Calculate wait time in OS ticks
65         static const portTickType freq_ticks = FREQ_MILLIS / portTICK_RATE_MS;
66         portTickType last_wake_time = xTaskGetTickCount();
67
68         uint8_t i;
69         uint8_t tmp;
70         uint8_t pin;
71         boolean_t state = TRUE;
72         while (!stop_tasks) {
73
74                 // Toggle state one by one slowly
75                 for (pin = 1; pin <= 6; pin++) {
76
77                         // Change pin
78                         rpp_mout_set(pin, state);
79
80                         // Reprint values
81                         rpp_sci_printf((const char *)
82                                                    "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
83                                                    "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
84                                                    );
85
86                         tmp = pin;
87                         for (pin = 1; pin <= 6; pin++) {
88                                 rpp_sci_printf((const char *)
89                                                            "%d:    ", rpp_mout_get(pin)
90                                                            );
91                         }
92                         pin = tmp;
93
94                         // Wait for next change
95                         if (!stop_tasks)
96                                 vTaskDelayUntil(&last_wake_time, freq_ticks);
97                         else
98                                 break;
99
100                 }
101                 state = !state;
102
103                 if (!stop_tasks)
104                         rpp_sci_printf((const char *)
105                                                    "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
106                                                    "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
107                                                    );
108
109                 for (i = 0; i < 10; i++) {
110
111                         // Wait until next step
112                         if (!stop_tasks)
113                                 vTaskDelayUntil(&last_wake_time, freq_ticks);
114                         else
115                                 break;
116
117                         rpp_sci_printf((const char *)
118                                                    "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
119                                                    "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
120                                                    );
121
122                         for (pin = 1; pin <= 6; pin++) {
123                                 rpp_sci_printf((const char *)
124                                                            "%d:%s ", rpp_mout_get(pin),
125                                                            (rpp_mout_diag(pin) == SUCCESS) ? " OK" : "BAD"
126                                                            );
127                         }
128
129                 }
130         }
131
132         // Delete myself
133         tasks_running--;
134         vTaskDelete(NULL);
135 }
136
137
138 /**
139  * MOUT Test entry point.
140  */
141 void test_mout()
142 {
143         /// Configure module
144         // - Not needed
145
146
147         /// Spawn tasks
148         xTaskHandle test_task_handle;
149
150         portBASE_TYPE task_created = xTaskCreate(mout_test_task,
151                                                                                          (const signed char *)"mout_test_task",
152                                                                                          TEST_TASK_STACK, NULL, TEST_TASK_PRIORITY,
153                                                                                          &test_task_handle
154                                                                                          );
155
156         if (task_created != pdPASS) {
157
158                 rpp_sci_printf((const char *)
159                                            "ERROR: Problem spawning the test task. "
160                                            "Error code: %d\r\n", (uint32_t)task_created
161                                            );
162                 wait_for_quit();
163                 return;
164         }
165         tasks_running++;
166
167
168         // Wait for user exit
169         wait_for_quit();
170         stop_tasks = TRUE;
171         while (tasks_running > 0)
172                 taskYIELD();
173         stop_tasks = FALSE;
174
175
176         /// Reset module configuration
177         uint8_t pin;
178         for (pin = 1; pin <= 6; pin++) {
179                 rpp_mout_set(pin, LOW);
180         }
181
182
183         rpp_sci_printf((const char *)"\r\n");
184
185         return;
186 }