amiro-os / core / src / aos_main.cpp @ 11adbe34
History | View | Annotate | Download (43.687 KB)
1 | e545e620 | Thomas Schöpping | /*
|
---|---|---|---|
2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | Copyright (C) 2016..2018 Thomas Schöpping et al.
|
||
4 | |||
5 | This program is free software: you can redistribute it and/or modify
|
||
6 | it under the terms of the GNU General Public License as published by
|
||
7 | the Free Software Foundation, either version 3 of the License, or
|
||
8 | (at your option) any later version.
|
||
9 | |||
10 | This program is distributed in the hope that it will be useful,
|
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | GNU General Public License for more details.
|
||
14 | |||
15 | You should have received a copy of the GNU General Public License
|
||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
17 | */
|
||
18 | |||
19 | 53710ca3 | Marc Rothmann | /**
|
20 | * @file aos_main.cpp
|
||
21 | * @brief Main function.
|
||
22 | * @details Main function with SSSP and initialization,
|
||
23 | * extendable via hooks.
|
||
24 | *
|
||
25 | * @addtogroup aos_system
|
||
26 | * @{
|
||
27 | */
|
||
28 | |||
29 | e545e620 | Thomas Schöpping | #include <amiroos.h> |
30 | cb835a3e | Thomas Schöpping | #include <module.h> |
31 | e545e620 | Thomas Schöpping | |
32 | b6b45e4c | Thomas Schöpping | /*
|
33 | * hook to add further includes
|
||
34 | */
|
||
35 | 512abac1 | Thomas Schöpping | #if defined(AMIROOS_CFG_MAIN_EXTRA_INCLUDE_HEADER)
|
36 | #include AMIROOS_CFG_MAIN_EXTRA_INCLUDE_HEADER
|
||
37 | b6b45e4c | Thomas Schöpping | #endif
|
38 | |||
39 | e545e620 | Thomas Schöpping | /**
|
40 | * @brief Event mask to identify I/O events.
|
||
41 | */
|
||
42 | 6b53f6bf | Thomas Schöpping | #define IOEVENT_MASK EVENT_MASK(0) |
43 | e545e620 | Thomas Schöpping | |
44 | /**
|
||
45 | * @brief Event mask to identify OS events.
|
||
46 | */
|
||
47 | 6b53f6bf | Thomas Schöpping | #define OSEVENT_MASK EVENT_MASK(1) |
48 | e545e620 | Thomas Schöpping | |
49 | /**
|
||
50 | 933df08e | Thomas Schöpping | * @brief Event mask to idetify CAN events.
|
51 | */
|
||
52 | #define CANEVENT_MASK EVENT_MASK(2) |
||
53 | |||
54 | /**
|
||
55 | * @brief Event mask to idetify timeout events.
|
||
56 | */
|
||
57 | #define TIMEOUTEVENT_MASK EVENT_MASK(3) |
||
58 | |||
59 | /**
|
||
60 | * @brief Event mask to idetify signal delay events.
|
||
61 | */
|
||
62 | #define DELAYEVENT_MASK EVENT_MASK(4) |
||
63 | |||
64 | 9ebb11a9 | Thomas Schöpping | #if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
65 | |||
66 | 933df08e | Thomas Schöpping | /**
|
67 | * @brief CAN message identifier for initialization of the SSSP stack initialization sequence.
|
||
68 | */
|
||
69 | #define SSSP_STACKINIT_CANMSGID_INIT 0x003 |
||
70 | |||
71 | /**
|
||
72 | * @brief CAN message identifier for transmitting module IDs during the SSSP stack initialization sequence.
|
||
73 | */
|
||
74 | #define SSSP_STACKINIT_CANMSGID_MODULEID 0x002 |
||
75 | |||
76 | /**
|
||
77 | * @brief CAN message identifier for abortion of the SSSP stack initialization sequence.
|
||
78 | */
|
||
79 | #define SSSP_STACKINIT_CANMSGID_ABORT 0x001 |
||
80 | |||
81 | 9ebb11a9 | Thomas Schöpping | #endif /* AMIROOS_CFG_SSSP_ENABLE == true */ |
82 | |||
83 | 933df08e | Thomas Schöpping | /**
|
84 | 9461fadc | Thomas Schöpping | * @brief CAN message identifier for calender synchronization message.
|
85 | */
|
||
86 | #define CALENDERSYNC_CANMSGID 0x004 |
||
87 | |||
88 | /**
|
||
89 | e545e620 | Thomas Schöpping | * @brief Listener object for I/O events.
|
90 | */
|
||
91 | static event_listener_t _eventListenerIO;
|
||
92 | |||
93 | /**
|
||
94 | * @brief Listener object for OS events.
|
||
95 | */
|
||
96 | static event_listener_t _eventListenerOS;
|
||
97 | |||
98 | #if defined(MODULE_HAL_PROGIF) || defined(__DOXYGEN__)
|
||
99 | /**
|
||
100 | ba516b61 | Thomas Schöpping | * @brief I/O channel for the programmer interface.
|
101 | e545e620 | Thomas Schöpping | */
|
102 | ba516b61 | Thomas Schöpping | static AosIOChannel _stdiochannel;
|
103 | |||
104 | b8268050 | Thomas Schöpping | #if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
105 | ba516b61 | Thomas Schöpping | /**
|
106 | * @brief I/O shell channel for the programmer interface.
|
||
107 | */
|
||
108 | static AosShellChannel _stdshellchannel;
|
||
109 | e545e620 | Thomas Schöpping | #endif
|
110 | b8268050 | Thomas Schöpping | #endif
|
111 | e545e620 | Thomas Schöpping | |
112 | b6b45e4c | Thomas Schöpping | /*
|
113 | * hook to add further static variables
|
||
114 | */
|
||
115 | #if defined(AMIROOS_CFG_MAIN_EXTRA_STATIC_VARIABLES)
|
||
116 | AMIROOS_CFG_MAIN_EXTRA_STATIC_VARIABLES |
||
117 | #endif
|
||
118 | |||
119 | e545e620 | Thomas Schöpping | /**
|
120 | * @brief Prints an error message about an unexpected event.
|
||
121 | *
|
||
122 | * @param[in] mask The event mask.
|
||
123 | * @param[in] flags The event flags.
|
||
124 | */
|
||
125 | 933df08e | Thomas Schöpping | static inline void _unexpectedEventError(const eventmask_t mask, const eventflags_t flags) |
126 | e545e620 | Thomas Schöpping | { |
127 | 6b53f6bf | Thomas Schöpping | #if (AMIROOS_CFG_DBG == true) |
128 | 1e5f7648 | Thomas Schöpping | aosprintf("CTRL: unexpected/unknown event received. mask: 0x%08X; flags: 0x%08X\n", mask, flags);
|
129 | 6b53f6bf | Thomas Schöpping | #else
|
130 | 933df08e | Thomas Schöpping | (void)(mask);
|
131 | (void)(flags);
|
||
132 | 6b53f6bf | Thomas Schöpping | #endif
|
133 | 3e1a9c79 | Thomas Schöpping | return;
|
134 | 933df08e | Thomas Schöpping | } |
135 | |||
136 | 9ebb11a9 | Thomas Schöpping | #if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
137 | 933df08e | Thomas Schöpping | /**
|
138 | * @brief Callback function to be used during SSSP stack initialization sequence.
|
||
139 | *
|
||
140 | * @param[in] par A pointer to an @p event_source_t to be fired.
|
||
141 | */
|
||
142 | static void _ssspTimerCallback(void* par) |
||
143 | { |
||
144 | aosDbgCheck(par != NULL);
|
||
145 | |||
146 | chSysLockFromISR(); |
||
147 | chEvtBroadcastI((event_source_t*)par); |
||
148 | chSysUnlockFromISR(); |
||
149 | |||
150 | e545e620 | Thomas Schöpping | return;
|
151 | } |
||
152 | 9ebb11a9 | Thomas Schöpping | #endif /* AMIROOS_CFG_SSSP_ENABLE == true */ |
153 | e545e620 | Thomas Schöpping | |
154 | /**
|
||
155 | 9461fadc | Thomas Schöpping | * @brief Helper function to serialize data.
|
156 | 933df08e | Thomas Schöpping | *
|
157 | * @param[out] dst Pointer to the output buffer.
|
||
158 | 9461fadc | Thomas Schöpping | * @param[in] src Data to be serialized.
|
159 | * @param[in] n Number of bytes to serialize.
|
||
160 | 933df08e | Thomas Schöpping | */
|
161 | 9461fadc | Thomas Schöpping | inline void _serialize(uint8_t* dst, const uint64_t src, const uint8_t n) |
162 | 933df08e | Thomas Schöpping | { |
163 | aosDbgCheck(dst != NULL);
|
||
164 | 9461fadc | Thomas Schöpping | aosDbgCheck(n > 0 && n <= 8); |
165 | 933df08e | Thomas Schöpping | |
166 | 9461fadc | Thomas Schöpping | for (uint8_t byte = 0; byte < n; ++byte) { |
167 | 933df08e | Thomas Schöpping | dst[byte] = (uint8_t)((src >> (byte * 8)) & 0xFF); |
168 | } |
||
169 | |||
170 | return;
|
||
171 | } |
||
172 | |||
173 | /**
|
||
174 | 9461fadc | Thomas Schöpping | * @brief Helper function to deserialize data.
|
175 | 933df08e | Thomas Schöpping | *
|
176 | * @param[in] src Pointer to the buffer of data to be deserialzed.
|
||
177 | 9461fadc | Thomas Schöpping | * @param[in] n Number of bytes to deserialize.
|
178 | 933df08e | Thomas Schöpping | *
|
179 | * @return The deserialized 32 bit data.
|
||
180 | */
|
||
181 | 9461fadc | Thomas Schöpping | inline uint64_t _deserialize(uint8_t* src, const uint8_t n) |
182 | 933df08e | Thomas Schöpping | { |
183 | aosDbgCheck(src != NULL);
|
||
184 | 9461fadc | Thomas Schöpping | aosDbgCheck(n > 0 && n <= 8); |
185 | 933df08e | Thomas Schöpping | |
186 | 9461fadc | Thomas Schöpping | uint64_t result = 0;
|
187 | for (uint8_t byte = 0; byte < n; ++byte) { |
||
188 | result |= ((uint64_t)src[byte]) << (byte * 8);
|
||
189 | } |
||
190 | |||
191 | return result;
|
||
192 | } |
||
193 | |||
194 | /**
|
||
195 | * @brief Converter function to encode a TM value to a single unsigned 64 bit integer.
|
||
196 | *
|
||
197 | * @details Contents of the TM struct are mapped as follows:
|
||
198 | * bits |63 62|61 53|52 50|49 26|25 22|21 17|16 12|11 6|5 0|
|
||
199 | * #bits | 2 | 9 | 3 | 24 | 4 | 5 | 5 | 6 | 6 |
|
||
200 | * value | isdst | yday | wday | year | mon | mday | hour | min | sec |
|
||
201 | * range | special | [0, 365] | [0, 6] | [1900, ...] | [0, 11] | [1, 31] | [0, 23] | [0, 59] | [0, 61] |
|
||
202 | * The Daylight Saving Time Flag (isdsst) is encoded as follows:
|
||
203 | * DST not in effect -> 0
|
||
204 | * DST in effect -> 1
|
||
205 | * no information available -> 2
|
||
206 | *
|
||
207 | * @param[in] src Pointer to the TM struct to encode.
|
||
208 | *
|
||
209 | * @return An unsigned 64 bit integer, which holds the encoded time value.
|
||
210 | */
|
||
211 | inline uint64_t _TM2U64(struct tm* src) |
||
212 | { |
||
213 | aosDbgCheck(src != NULL);
|
||
214 | |||
215 | return (((uint64_t)(src->tm_sec & 0x0000003F) << (0)) | |
||
216 | ((uint64_t)(src->tm_min & 0x0000003F) << (6)) | |
||
217 | ((uint64_t)(src->tm_hour & 0x0000001F) << (12)) | |