amiro-os / core / src / aos_main.cpp @ 23437e98
History | View | Annotate | Download (46.587 KB)
| 1 | e545e620 | Thomas Schöpping | /*
|
|---|---|---|---|
| 2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
| 3 | 84f0ce9e | Thomas Schöpping | Copyright (C) 2016..2019 Thomas Schöpping et al.
|
| 4 | e545e620 | Thomas Schöpping | |
| 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 | 3940ba8a | Thomas Schöpping | #include <amiroos.h> |
| 30 | e545e620 | Thomas Schöpping | |
| 31 | b6b45e4c | Thomas Schöpping | /*
|
| 32 | * hook to add further includes
|
||
| 33 | */
|
||
| 34 | 512abac1 | Thomas Schöpping | #if defined(AMIROOS_CFG_MAIN_EXTRA_INCLUDE_HEADER)
|
| 35 | #include AMIROOS_CFG_MAIN_EXTRA_INCLUDE_HEADER
|
||
| 36 | b6b45e4c | Thomas Schöpping | #endif
|
| 37 | |||
| 38 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
| 39 | /* LOCAL DEFINITIONS */
|
||
| 40 | /******************************************************************************/
|
||
| 41 | |||
| 42 | e545e620 | Thomas Schöpping | /**
|
| 43 | * @brief Event mask to identify I/O events.
|
||
| 44 | */
|
||
| 45 | 6b53f6bf | Thomas Schöpping | #define IOEVENT_MASK EVENT_MASK(0) |
| 46 | e545e620 | Thomas Schöpping | |
| 47 | /**
|
||
| 48 | * @brief Event mask to identify OS events.
|
||
| 49 | */
|
||
| 50 | 6b53f6bf | Thomas Schöpping | #define OSEVENT_MASK EVENT_MASK(1) |
| 51 | e545e620 | Thomas Schöpping | |
| 52 | /**
|
||
| 53 | 933df08e | Thomas Schöpping | * @brief Event mask to idetify CAN events.
|
| 54 | */
|
||
| 55 | #define CANEVENT_MASK EVENT_MASK(2) |
||
| 56 | |||
| 57 | /**
|
||
| 58 | * @brief Event mask to idetify timeout events.
|
||
| 59 | */
|
||
| 60 | #define TIMEOUTEVENT_MASK EVENT_MASK(3) |
||
| 61 | |||
| 62 | /**
|
||
| 63 | * @brief Event mask to idetify signal delay events.
|
||
| 64 | */
|
||
| 65 | #define DELAYEVENT_MASK EVENT_MASK(4) |
||
| 66 | |||
| 67 | 9ebb11a9 | Thomas Schöpping | #if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
| 68 | |||
| 69 | 933df08e | Thomas Schöpping | /**
|
| 70 | * @brief CAN message identifier for initialization of the SSSP stack initialization sequence.
|
||
| 71 | */
|
||
| 72 | #define SSSP_STACKINIT_CANMSGID_INIT 0x003 |
||
| 73 | |||
| 74 | /**
|
||
| 75 | * @brief CAN message identifier for transmitting module IDs during the SSSP stack initialization sequence.
|
||
| 76 | */
|
||
| 77 | #define SSSP_STACKINIT_CANMSGID_MODULEID 0x002 |
||
| 78 | |||
| 79 | /**
|
||
| 80 | * @brief CAN message identifier for abortion of the SSSP stack initialization sequence.
|
||
| 81 | */
|
||
| 82 | #define SSSP_STACKINIT_CANMSGID_ABORT 0x001 |
||
| 83 | |||
| 84 | 1d3e002f | Thomas Schöpping | #else /* AMIROOS_CFG_SSSP_ENABLE == false */ |
| 85 | |||
| 86 | /**
|
||
| 87 | * @brief Default shutdown mode if SSSP is unavailable.
|
||
| 88 | */
|
||
| 89 | #define AOS_SHUTDOWN_DEFAULT AOS_SHUTDOWN_DEEPSLEEP
|
||
| 90 | |||
| 91 | #endif /* AMIROOS_CFG_SSSP_ENABLE */ |
||
| 92 | 9ebb11a9 | Thomas Schöpping | |
| 93 | 933df08e | Thomas Schöpping | /**
|
| 94 | 9461fadc | Thomas Schöpping | * @brief CAN message identifier for calender synchronization message.
|
| 95 | */
|
||
| 96 | #define CALENDERSYNC_CANMSGID 0x004 |
||
| 97 | |||
| 98 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
| 99 | /* EXPORTED VARIABLES */
|
||
| 100 | /******************************************************************************/
|
||
| 101 | |||
| 102 | /******************************************************************************/
|
||
| 103 | /* LOCAL TYPES */
|
||
| 104 | /******************************************************************************/
|
||
| 105 | |||
| 106 | /******************************************************************************/
|
||
| 107 | /* LOCAL VARIABLES */
|
||
| 108 | /******************************************************************************/
|
||
| 109 | |||
| 110 | 9461fadc | Thomas Schöpping | /**
|
| 111 | e545e620 | Thomas Schöpping | * @brief Listener object for I/O events.
|
| 112 | */
|
||
| 113 | static event_listener_t _eventListenerIO;
|
||
| 114 | |||
| 115 | /**
|
||
| 116 | * @brief Listener object for OS events.
|
||
| 117 | */
|
||
| 118 | static event_listener_t _eventListenerOS;
|
||
| 119 | |||
| 120 | #if defined(MODULE_HAL_PROGIF) || defined(__DOXYGEN__)
|
||
| 121 | /**
|
||
| 122 | ba516b61 | Thomas Schöpping | * @brief I/O channel for the programmer interface.
|
| 123 | e545e620 | Thomas Schöpping | */
|
| 124 | ba516b61 | Thomas Schöpping | static AosIOChannel _stdiochannel;
|
| 125 | |||
| 126 | 2dd2e257 | Thomas Schöpping | #if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
| 127 | ba516b61 | Thomas Schöpping | /**
|
| 128 | * @brief I/O shell channel for the programmer interface.
|
||
| 129 | */
|
||
| 130 | static AosShellChannel _stdshellchannel;
|
||
| 131 | 2dd2e257 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true)*/ |
| 132 | 1d3e002f | Thomas Schöpping | #endif /* defined(MODULE_HAL_PROGIF) */ |
| 133 | e545e620 | Thomas Schöpping | |
| 134 | b6b45e4c | Thomas Schöpping | /*
|
| 135 | * hook to add further static variables
|
||
| 136 | */
|
||
| 137 | #if defined(AMIROOS_CFG_MAIN_EXTRA_STATIC_VARIABLES)
|
||
| 138 | AMIROOS_CFG_MAIN_EXTRA_STATIC_VARIABLES |
||
| 139 | #endif
|
||
| 140 | |||
| 141 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
| 142 | /* LOCAL FUNCTIONS */
|
||
| 143 | /******************************************************************************/
|
||
| 144 | |||
| 145 | e545e620 | Thomas Schöpping | /**
|
| 146 | * @brief Prints an error message about an unexpected event.
|
||
| 147 | *
|
||
| 148 | * @param[in] mask The event mask.
|
||
| 149 | * @param[in] flags The event flags.
|
||
| 150 | */
|
||
| 151 | 933df08e | Thomas Schöpping | static inline void _unexpectedEventError(const eventmask_t mask, const eventflags_t flags) |
| 152 | e545e620 | Thomas Schöpping | {
|
| 153 | 6b53f6bf | Thomas Schöpping | #if (AMIROOS_CFG_DBG == true) |
| 154 | 1e5f7648 | Thomas Schöpping | aosprintf("CTRL: unexpected/unknown event received. mask: 0x%08X; flags: 0x%08X\n", mask, flags);
|
| 155 | 6b53f6bf | Thomas Schöpping | #else
|
| 156 | 933df08e | Thomas Schöpping | (void)(mask);
|
| 157 | (void)(flags);
|
||
| 158 | 6b53f6bf | Thomas Schöpping | #endif
|
| 159 | 3e1a9c79 | Thomas Schöpping | return;
|
| 160 | 933df08e | Thomas Schöpping | } |
| 161 | |||
| 162 | 9ebb11a9 | Thomas Schöpping | #if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
| 163 | 933df08e | Thomas Schöpping | /**
|
| 164 | * @brief Callback function to be used during SSSP stack initialization sequence.
|
||
| 165 | *
|
||
| 166 | * @param[in] par A pointer to an @p event_source_t to be fired.
|
||
| 167 | */
|
||
| 168 | static void _ssspTimerCallback(void* par) |
||
| 169 | {
|
||
| 170 | aosDbgCheck(par != NULL);
|
||
| 171 | |||
| 172 | chSysLockFromISR(); |
||
| 173 | chEvtBroadcastI((event_source_t*)par); |
||
| 174 | chSysUnlockFromISR(); |
||
| 175 | |||
| 176 | e545e620 | Thomas Schöpping | return;
|
| 177 | } |
||
| 178 | 9ebb11a9 | Thomas Schöpping | #endif /* AMIROOS_CFG_SSSP_ENABLE == true */ |
| 179 | e545e620 | Thomas Schöpping | |
| 180 | /**
|
||
| 181 | 9461fadc | Thomas Schöpping | * @brief Helper function to serialize data.
|
| 182 | 933df08e | Thomas Schöpping | *
|
| 183 | * @param[out] dst Pointer to the output buffer.
|
||
| 184 | 9461fadc | Thomas Schöpping | * @param[in] src Data to be serialized.
|
| 185 | * @param[in] n Number of bytes to serialize.
|
||
| 186 | 933df08e | Thomas Schöpping | */
|
| 187 | 9461fadc | Thomas Schöpping | inline void _serialize(uint8_t* dst, const uint64_t src, const uint8_t n) |
| 188 | 933df08e | Thomas Schöpping | {
|
| 189 | aosDbgCheck(dst != NULL);
|
||
| 190 | 9461fadc | Thomas Schöpping | aosDbgCheck(n > 0 && n <= 8); |
| 191 | 933df08e | Thomas Schöpping | |
| 192 | 9461fadc | Thomas Schöpping | for (uint8_t byte = 0; byte < n; ++byte) { |
| 193 | 933df08e | Thomas Schöpping | dst[byte] = (uint8_t)((src >> (byte * 8)) & 0xFF); |
| 194 | } |
||
| 195 | |||
| 196 | return;
|
||
| 197 | } |
||
| 198 | |||
| 199 | /**
|
||
| 200 | 9461fadc | Thomas Schöpping | * @brief Helper function to deserialize data.
|
| 201 | 933df08e | Thomas Schöpping | *
|
| 202 | * @param[in] src Pointer to the buffer of data to be deserialzed.
|
||
| 203 | 9461fadc | Thomas Schöpping | * @param[in] n Number of bytes to deserialize.
|
| 204 | 933df08e | Thomas Schöpping | *
|
| 205 | * @return The deserialized 32 bit data.
|
||
| 206 | */
|
||
| 207 | 9461fadc | Thomas Schöpping | inline uint64_t _deserialize(uint8_t* src, const uint8_t n) |
| 208 | 933df08e | Thomas Schöpping | {
|
| 209 | aosDbgCheck(src != NULL);
|
||
| 210 | 9461fadc | Thomas Schöpping | aosDbgCheck(n > 0 && n <= 8); |
| 211 | 933df08e | Thomas Schöpping | |
| 212 | 9461fadc | Thomas Schöpping | uint64_t result = 0;
|
| 213 | for (uint8_t byte = 0; byte < n |