amiro-os / core / src / aos_main.cpp @ 849b383a
History | View | Annotate | Download (38.637 KB)
| 1 | e545e620 | Thomas Schöpping | /*
|
|---|---|---|---|
| 2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
| 3 | 96621a83 | Thomas Schöpping | Copyright (C) 2016..2020 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 | *
|
||
| 23 | * @addtogroup aos_system
|
||
| 24 | * @{
|
||
| 25 | */
|
||
| 26 | |||
| 27 | 3940ba8a | Thomas Schöpping | #include <amiroos.h> |
| 28 | e545e620 | Thomas Schöpping | |
| 29 | b6b45e4c | Thomas Schöpping | /*
|
| 30 | * hook to add further includes
|
||
| 31 | */
|
||
| 32 | 512abac1 | Thomas Schöpping | #if defined(AMIROOS_CFG_MAIN_EXTRA_INCLUDE_HEADER)
|
| 33 | #include AMIROOS_CFG_MAIN_EXTRA_INCLUDE_HEADER
|
||
| 34 | 7de0cc90 | Thomas Schöpping | #endif /* defined(AMIROOS_CFG_MAIN_EXTRA_INCLUDE_HEADER) */ |
| 35 | b6b45e4c | Thomas Schöpping | |
| 36 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
| 37 | /* LOCAL DEFINITIONS */
|
||
| 38 | /******************************************************************************/
|
||
| 39 | |||
| 40 | e545e620 | Thomas Schöpping | /**
|
| 41 | cda14729 | Thomas Schöpping | * @brief Event mask to identify GPIO events.
|
| 42 | e545e620 | Thomas Schöpping | */
|
| 43 | cda14729 | Thomas Schöpping | #define EVENTMASK_GPIO EVENT_MASK(0) |
| 44 | e545e620 | Thomas Schöpping | |
| 45 | /**
|
||
| 46 | * @brief Event mask to identify OS events.
|
||
| 47 | */
|
||
| 48 | cda14729 | Thomas Schöpping | #define EVENTMASK_OS EVENT_MASK(1) |
| 49 | e545e620 | Thomas Schöpping | |
| 50 | cda14729 | Thomas Schöpping | #if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
| 51 | 933df08e | Thomas Schöpping | |
| 52 | c53ef0b1 | Thomas Schöpping | |
| 53 | #if (AMIROOS_CFG_SSSP_MSI == true) || defined(__DOXYGEN__) |
||
| 54 | |||
| 55 | /**
|
||
| 56 | * @brief Event mask to identify SSSP timeout events (MSI only).
|
||
| 57 | */
|
||
| 58 | #define EVENTMASK_SSSPTIMEOUT EVENT_MASK(2) |
||
| 59 | |||
| 60 | #endif /* (AMIROOS_CFG_SSSP_MSI == true) */ |
||
| 61 | |||
| 62 | 933df08e | Thomas Schöpping | /**
|
| 63 | c53ef0b1 | Thomas Schöpping | * @brief Event mask to identify SSSP delay events.
|
| 64 | 933df08e | Thomas Schöpping | */
|
| 65 | c53ef0b1 | Thomas Schöpping | #define EVENTMASK_SSSPDELAY EVENT_MASK(3) |
| 66 | 933df08e | Thomas Schöpping | |
| 67 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
| 68 | 9ebb11a9 | Thomas Schöpping | |
| 69 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
| 70 | /* EXPORTED VARIABLES */
|
||
| 71 | /******************************************************************************/
|
||
| 72 | |||
| 73 | /******************************************************************************/
|
||
| 74 | /* LOCAL TYPES */
|
||
| 75 | /******************************************************************************/
|
||
| 76 | |||
| 77 | /******************************************************************************/
|
||
| 78 | /* LOCAL VARIABLES */
|
||
| 79 | /******************************************************************************/
|
||
| 80 | |||
| 81 | 9461fadc | Thomas Schöpping | /**
|
| 82 | cda14729 | Thomas Schöpping | * @brief Listener object for GPIO events.
|
| 83 | e545e620 | Thomas Schöpping | */
|
| 84 | cda14729 | Thomas Schöpping | static event_listener_t _eventListenerGPIO;
|
| 85 | e545e620 | Thomas Schöpping | |
| 86 | /**
|
||
| 87 | * @brief Listener object for OS events.
|
||
| 88 | */
|
||
| 89 | static event_listener_t _eventListenerOS;
|
||
| 90 | |||
| 91 | #if defined(MODULE_HAL_PROGIF) || defined(__DOXYGEN__)
|
||
| 92 | cda14729 | Thomas Schöpping | |
| 93 | e545e620 | Thomas Schöpping | /**
|
| 94 | ba516b61 | Thomas Schöpping | * @brief I/O channel for the programmer interface.
|
| 95 | e545e620 | Thomas Schöpping | */
|
| 96 | ba516b61 | Thomas Schöpping | static AosIOChannel _stdiochannel;
|
| 97 | |||
| 98 | afcf6d89 | Thomas Schöpping | #endif /* defined(MODULE_HAL_PROGIF) */ |
| 99 | cda14729 | Thomas Schöpping | |
| 100 | #if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
||
| 101 | |||
| 102 | ba516b61 | Thomas Schöpping | /**
|
| 103 | * @brief I/O shell channel for the programmer interface.
|
||
| 104 | */
|
||
| 105 | static AosShellChannel _stdshellchannel;
|
||
| 106 | cda14729 | Thomas Schöpping | |
| 107 | 47e89ebf | Thomas Schöpping | #endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
| 108 | e545e620 | Thomas Schöpping | |
| 109 | b6b45e4c | Thomas Schöpping | /*
|
| 110 | * hook to add further static variables
|
||
| 111 | */
|
||
| 112 | #if defined(AMIROOS_CFG_MAIN_EXTRA_STATIC_VARIABLES)
|
||
| 113 | AMIROOS_CFG_MAIN_EXTRA_STATIC_VARIABLES |
||
| 114 | 7de0cc90 | Thomas Schöpping | #endif /* defined(AMIROOS_CFG_MAIN_EXTRA_STATIC_VARIABLES) */ |
| 115 | b6b45e4c | Thomas Schöpping | |
| 116 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
| 117 | /* LOCAL FUNCTIONS */
|
||
| 118 | /******************************************************************************/
|
||
| 119 | |||
| 120 | e545e620 | Thomas Schöpping | /**
|
| 121 | * @brief Prints an error message about an unexpected event.
|
||
| 122 | *
|
||
| 123 | * @param[in] mask The event mask.
|
||
| 124 | * @param[in] flags The event flags.
|
||
| 125 | */
|
||
| 126 | 88c47fd9 | Thomas Schöpping | static inline void _unexpectedEventError(const eventmask_t mask, const eventflags_t flags) |
| 127 | e545e620 | Thomas Schöpping | {
|
| 128 | 6b53f6bf | Thomas Schöpping | #if (AMIROOS_CFG_DBG == true) |
| 129 | bc7aed20 | Thomas Schöpping | aosDbgPrintf("CTRL: unexpected/unknown event received. mask: 0x%08X; flags: 0x%08X\n", mask, flags);
|
| 130 | 7de0cc90 | Thomas Schöpping | #else /* (AMIROOS_CFG_DBG == true) */ |
| 131 | 933df08e | Thomas Schöpping | (void)(mask);
|
| 132 | (void)(flags);
|
||
| 133 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_DBG == true) */ |
| 134 | 3e1a9c79 | Thomas Schöpping | return;
|
| 135 | 933df08e | Thomas Schöpping | } |
| 136 | |||
| 137 | bc7aed20 | Thomas Schöpping | #if ((AMIROOS_CFG_SSSP_ENABLE == true) && (HAL_USE_RTC == TRUE)) || defined(__DOXYGEN__) |
| 138 | #if (AMIROOS_CFG_SSSP_MASTER == true) || defined(__DOXYGEN__) |
||
| 139 | 23437e98 | Thomas Schöpping | |
| 140 | 9461fadc | Thomas Schöpping | /**
|
| 141 | * @brief Converter function to encode a TM value to a single unsigned 64 bit integer.
|
||
| 142 | *
|
||
| 143 | * @details Contents of the TM struct are mapped as follows:
|
||
| 144 | * bits |63 62|61 53|52 50|49 26|25 22|21 17|16 12|11 6|5 0|
|
||
| 145 | * #bits | 2 | 9 | 3 | 24 | 4 | 5 | 5 | 6 | 6 |
|
||
| 146 | * value | isdst | yday | wday | year | mon | mday | hour | min | sec |
|
||
| 147 | * range | special | [0, 365] | [0, 6] | [1900, ...] | [0, 11] | [1, 31] | [0, 23] | [0, 59] | [0, 61] |
|
||
| 148 | * The Daylight Saving Time Flag (isdsst) is encoded as follows:
|
||
| 149 | * DST not in effect -> 0
|
||
| 150 | * DST in effect -> 1
|
||
| 151 | * no information available -> 2
|
||
| 152 | *
|
||
| 153 | * @param[in] src Pointer to the TM struct to encode.
|
||
| 154 | *
|
||
| 155 | * @return An unsigned 64 bit integer, which holds the encoded time value.
|
||
| 156 | */
|
||
| 157 | 88c47fd9 | Thomas Schöpping | static inline uint64_t _TM2U64(struct tm* src) |
| 158 | 9461fadc | Thomas Schöpping | {
|
| 159 | aosDbgCheck(src != NULL);
|
||
| 160 | |||
| 161 | return (((uint64_t)(src->tm_sec & 0x0000003F) << (0)) | |
||
| 162 | ((uint64_t)(src->tm_min & 0x0000003F) << (6)) | |
||
| 163 | ((uint64_t)(src->tm_hour & 0x0000001F) << (12)) | |
||
| 164 | ((uint64_t)(src->tm_mday & 0x0000001F) << (17)) | |
||
| 165 | ((uint64_t)(src->tm_mon & 0x0000000F) << (22)) | |
||
| 166 | ((uint64_t)(src->tm_year & 0x00FFFFFF) << (26)) | |
||
| 167 | ((uint64_t)(src->tm_wday & 0x00000007) << (50)) | |
||
| 168 | ((uint64_t)(src->tm_yday & 0x000001FF) << (53)) | |
||
| 169 | ((uint64_t)((src->tm_isdst == 0) ? 0 : (src->tm_isdst > 0) ? 1 : 2) << (62))); |
||
| 170 | } |
||
| 171 | |||
| 172 | /**
|
||
| 173 | bc7aed20 | Thomas Schöpping | * @brief Serializes 64 bit unsigned integer input and stores it in a byte array.
|
| 174 | * @details Serialization is performed in big-endian fashion.
|
||
| 175 | *
|
||
| 176 | * @param[out] dst Pointer to the output buffer.
|
||
| 177 | * @param[in] src Data to be serialized.
|
||
| 178 | */
|
||
| 179 | 88c47fd9 | Thomas Schöpping | static inline void _serializeU64(uint8_t* dst, const uint64_t src) |
| 180 | bc7aed20 | Thomas Schöpping | {
|
| 181 | aosDbgCheck(dst != NULL);
|
||
| 182 | |||
| 183 | for (uint8_t byte = 0; byte < sizeof(uint64_t); ++byte) { |
||
| 184 | dst[byte] = ((src >> ((sizeof(uint64_t) - (byte+1)) * 8)) & 0xFF); |
||
| 185 | } |
||
| 186 | |||
| 187 | return;
|
||
| 188 | } |
||
| 189 | |||
| 190 | #endif /* (AMIROOS_CFG_SSSP_MASTER == true) */ |
||
| 191 | #if (AMIROOS_CFG_SSSP_MASTER != true) || defined(__DOXYGEN__) |
||
| 192 | |||
| 193 | /**
|
||
| 194 | * @brief Deserialize 64 bit unsigned integer data from a buffer.
|
||
| 195 | * @details Data is assumed to be serialized in big-endian fashion.
|
||
| 196 | *
|
||
| 197 | * @param[in] src Pointer to the buffer of data to be deserialzed.
|
||
| 198 | *
|
||
| 199 | * @return Deserialized 64 bit data.
|
||
| 200 | */
|
||
| 201 | 88c47fd9 | Thomas Schöpping | static inline uint64_t _deserializeU64(uint8_t* src) |
| 202 | bc7aed20 | Thomas Schöpping | {
|
| 203 | aosDbgCheck(src != NULL);
|
||
| 204 | |||
| 205 | uint64_t result = 0;
|
||
| 206 | for (uint8_t byte = 0; byte < sizeof(uint64_t); ++byte) { |
||
| 207 |