]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - apps/rpp-test-suite/mout.c
Allow using GIOs NHET106 and NHET116 on HDK-like boards
[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  * 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.
10  *
11  * File : mout.c
12  * Abstract:
13  *     RPP test suite - module for testing MOUT.
14  *
15  * References:
16  *     test.h
17  */
18
19
20 #include "rpp/rpp.h"
21 #include "test.h"
22
23 #define FREQ_MILLIS     1000
24
25
26 // Task control
27 static boolean_t stop_tasks = FALSE;
28 static uint8_t tasks_running = 0;
29
30 /**
31  * FreeRTOS Task that toggle the MOUT outputs, then reads the diagnostics and
32  * compare.
33  */
34 void mout_test_task(void *par)
35 {
36         rpp_sci_printf((const char *)
37                                    "Power Output Test:\r\n"
38                                    );
39         rpp_sci_printf((const char *)
40                                    "===========================================================\r\n"
41                                    );
42         rpp_sci_printf((const char *)
43                                    "1     2     3     4     5     6\r\n"
44                        // 1:BAD 1:BAD 1:BAD 1:BAD 1:BAD 1:BAD
45                        // 1: OK 1: OK 1: OK 1: OK 1: OK 1: OK
46                                    );
47
48         // Calculate wait time in OS ticks
49         static const portTickType freq_ticks = FREQ_MILLIS / portTICK_RATE_MS;
50         portTickType last_wake_time = xTaskGetTickCount();
51
52         uint8_t i;
53         uint8_t tmp;
54         uint8_t pin;
55         boolean_t state = TRUE;
56         while (!stop_tasks) {
57
58                 // Toggle state one by one slowly
59                 for (pin = 1; pin <= 6; pin++) {
60
61                         // Change pin
62                         rpp_mout_set(pin, state);
63
64                         // Reprint values
65                         rpp_sci_printf((const char *)
66                                                    "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
67                                                    "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
68                                                    );
69
70                         tmp = pin;
71                         for (pin = 1; pin <= 6; pin++) {
72                                 rpp_sci_printf((const char *)
73                                                            "%d:    ", rpp_mout_get(pin)
74                                                            );
75                         }
76                         pin = tmp;
77
78                         // Wait for next change
79                         if (!stop_tasks)
80                                 vTaskDelayUntil(&last_wake_time, freq_ticks);
81                         else
82                                 break;
83
84                 }
85                 state = !state;
86
87                 if (!stop_tasks)
88                         rpp_sci_printf((const char *)
89                                                    "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
90                                                    "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
91                                                    );
92
93                 for (i = 0; i < 10; i++) {
94
95                         // Wait until next step
96                         if (!stop_tasks)
97                                 vTaskDelayUntil(&last_wake_time, freq_ticks);
98                         else
99                                 break;
100
101                         rpp_sci_printf((const char *)
102                                                    "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
103                                                    "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
104                                                    );
105
106                         for (pin = 1; pin <= 6; pin++) {
107                                 rpp_sci_printf((const char *)
108                                                            "%d:%s ", rpp_mout_get(pin),
109                                                            (rpp_mout_diag(pin) == SUCCESS) ? " OK" : "BAD"
110                                                            );
111                         }
112
113                 }
114         }
115
116         // Delete myself
117         tasks_running--;
118         vTaskDelete(NULL);
119 }
120
121
122 /**
123  * MOUT Test entry point.
124  */
125 void test_mout()
126 {
127         /// Configure module
128         // - Not needed
129
130
131         /// Spawn tasks
132         xTaskHandle test_task_handle;
133
134         portBASE_TYPE task_created = xTaskCreate(mout_test_task,
135                                                                                          (const signed char *)"mout_test_task",
136                                                                                          TEST_TASK_STACK, NULL, TEST_TASK_PRIORITY,
137                                                                                          &test_task_handle
138                                                                                          );
139
140         if (task_created != pdPASS) {
141
142                 rpp_sci_printf((const char *)
143                                            "ERROR: Problem spawning the test task. "
144                                            "Error code: %d\r\n", (uint32_t)task_created
145                                            );
146                 wait_for_quit();
147                 return;
148         }
149         tasks_running++;
150
151
152         // Wait for user exit
153         wait_for_quit();
154         stop_tasks = TRUE;
155         while (tasks_running > 0)
156                 taskYIELD();
157         stop_tasks = FALSE;
158
159
160         /// Reset module configuration
161         uint8_t pin;
162         for (pin = 1; pin <= 6; pin++) {
163                 rpp_mout_set(pin, LOW);
164         }
165
166
167         rpp_sci_printf((const char *)"\r\n");
168
169         return;
170 }