Statistics
| Branch: | Tag: | Revision:

amiro-os / core / src / aos_main.cpp @ 891fd122

History | View | Annotate | Download (51.986 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 7de0cc90 Thomas Schöpping
#endif /* defined(AMIROOS_CFG_MAIN_EXTRA_INCLUDE_HEADER) */
37 b6b45e4c Thomas Schöpping
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 891fd122 Julian Leichert
/**
68
 * @brief Event mask to identify rtcan message events.
69
 */
70
#define RTCANEVENT_MASK                         EVENT_MASK(5)
71
72 75c1f470 Thomas Schöpping
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (HAL_USE_CAN == TRUE)) || defined(__DOXYGEN__)
73
#define SSSP_STAGE3_ENABLE                      true
74
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) && (HAL_USE_CAN == TRUE) */
75
#define SSSP_STAGE3_ENABLE                      false
76
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (HAL_USE_CAN == TRUE) */
77
78
#if (SSSP_STAGE3_ENABLE == true) || defined(__DOXYGEN__)
79 9ebb11a9 Thomas Schöpping
80 933df08e Thomas Schöpping
/**
81
 * @brief   CAN message identifier for initialization of the SSSP stack initialization sequence.
82
 */
83
#define SSSP_STACKINIT_CANMSGID_INIT            0x003
84
85
/**
86
 * @brief   CAN message identifier for transmitting module IDs during the SSSP stack initialization sequence.
87
 */
88
#define SSSP_STACKINIT_CANMSGID_MODULEID        0x002
89
90
/**
91
 * @brief   CAN message identifier for abortion of the SSSP stack initialization sequence.
92
 */
93
#define SSSP_STACKINIT_CANMSGID_ABORT           0x001
94
95 75c1f470 Thomas Schöpping
#endif /* (SSSP_STAGE3_ENABLE == true) */
96 1d3e002f Thomas Schöpping
97 75c1f470 Thomas Schöpping
#if (AMIROOS_CFG_SSSP_ENABLE != true) || defined(__DOXYGEN__)
98 1d3e002f Thomas Schöpping
/**
99
 * @brief   Default shutdown mode if SSSP is unavailable.
100
 */
101
#define AOS_SHUTDOWN_DEFAULT                    AOS_SHUTDOWN_DEEPSLEEP
102 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
103 9ebb11a9 Thomas Schöpping
104 75c1f470 Thomas Schöpping
#if (HAL_USE_CAN == TRUE) || defined(__DOXYGEN__)
105 933df08e Thomas Schöpping
/**
106 9461fadc Thomas Schöpping
 * @brief   CAN message identifier for calender synchronization message.
107
 */
108
#define CALENDERSYNC_CANMSGID                   0x004
109 75c1f470 Thomas Schöpping
#endif /* (HAL_USE_CAN == TRUE) */
110 9461fadc Thomas Schöpping
111 f3ac1c96 Thomas Schöpping
/******************************************************************************/
112
/* EXPORTED VARIABLES                                                         */
113
/******************************************************************************/
114
115
/******************************************************************************/
116
/* LOCAL TYPES                                                                */
117
/******************************************************************************/
118
119
/******************************************************************************/
120
/* LOCAL VARIABLES                                                            */
121
/******************************************************************************/
122
123 9461fadc Thomas Schöpping
/**
124 e545e620 Thomas Schöpping
 * @brief   Listener object for I/O events.
125
 */
126
static event_listener_t _eventListenerIO;
127
128
/**
129
 * @brief   Listener object for OS events.
130
 */
131
static event_listener_t _eventListenerOS;
132
133
#if defined(MODULE_HAL_PROGIF) || defined(__DOXYGEN__)
134
/**
135 ba516b61 Thomas Schöpping
 * @brief   I/O channel for the programmer interface.
136 e545e620 Thomas Schöpping
 */
137 ba516b61 Thomas Schöpping
static AosIOChannel _stdiochannel;
138
139 2dd2e257 Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
140 ba516b61 Thomas Schöpping
/**
141
 * @brief   I/O shell channel for the programmer interface.
142
 */
143
static AosShellChannel _stdshellchannel;
144 2dd2e257 Thomas Schöpping
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true)*/
145 1d3e002f Thomas Schöpping
#endif /* defined(MODULE_HAL_PROGIF) */
146 e545e620 Thomas Schöpping
147 b6b45e4c Thomas Schöpping
/*
148
 * hook to add further static variables
149
 */
150
#if defined(AMIROOS_CFG_MAIN_EXTRA_STATIC_VARIABLES)
151
AMIROOS_CFG_MAIN_EXTRA_STATIC_VARIABLES
152 7de0cc90 Thomas Schöpping
#endif /* defined(AMIROOS_CFG_MAIN_EXTRA_STATIC_VARIABLES) */
153 b6b45e4c Thomas Schöpping
154 f3ac1c96 Thomas Schöpping
/******************************************************************************/
155
/* LOCAL FUNCTIONS                                                            */
156
/******************************************************************************/
157
158 e545e620 Thomas Schöpping
/**
159
 * @brief   Prints an error message about an unexpected event.
160
 *
161
 * @param[in] mask    The event mask.
162
 * @param[in] flags   The event flags.
163
 */
164 933df08e Thomas Schöpping
static inline void _unexpectedEventError(const eventmask_t mask, const eventflags_t flags)
165 e545e620 Thomas Schöpping
{
166 6b53f6bf Thomas Schöpping
#if (AMIROOS_CFG_DBG == true)
167 1e5f7648 Thomas Schöpping
  aosprintf("CTRL: unexpected/unknown event received. mask: 0x%08X; flags: 0x%08X\n", mask, flags);
168 7de0cc90 Thomas Schöpping
#else /* (AMIROOS_CFG_DBG == true) */
169 933df08e Thomas Schöpping
  (void)(mask);
170
  (void)(flags);
171 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_DBG == true) */
172 3e1a9c79 Thomas Schöpping
  return;
173 933df08e Thomas Schöpping
}
174
175 75c1f470 Thomas Schöpping
#if (SSSP_STAGE3_ENABLE == true) || defined(__DOXYGEN__)
176 933df08e Thomas Schöpping
/**
177
 * @brief   Callback function to be used during SSSP stack initialization sequence.
178
 *
179
 * @param[in] par   A pointer to an @p event_source_t to be fired.
180
 */
181
static void _ssspTimerCallback(void* par)
182
{
183
  aosDbgCheck(par != NULL);
184
185
  chSysLockFromISR();
186
  chEvtBroadcastI((event_source_t*)par);
187
  chSysUnlockFromISR();
188
189 e545e620 Thomas Schöpping
  return;
190
}
191 75c1f470 Thomas Schöpping
#endif /* (SSSP_STAGE3_ENABLE == true) */
192 e545e620 Thomas Schöpping
193
/**
194 9461fadc Thomas Schöpping
 * @brief   Helper function to serialize data.
195 933df08e Thomas Schöpping
 *
196
 * @param[out]  dst   Pointer to the output buffer.
197 9461fadc Thomas Schöpping
 * @param[in]   src   Data to be serialized.
198
 * @param[in]   n     Number of bytes to serialize.
199 933df08e Thomas Schöpping
 */
200 9461fadc Thomas Schöpping
inline void _serialize(uint8_t* dst, const uint64_t src, const uint8_t n)
201 933df08e Thomas Schöpping
{
202
  aosDbgCheck(dst != NULL);
203 9461fadc Thomas Schöpping
  aosDbgCheck(n > 0 && n <= 8);
204 933df08e Thomas Schöpping
205 9461fadc Thomas Schöpping
  for (uint8_t byte = 0; byte < n; ++byte) {
206 933df08e Thomas Schöpping
    dst[byte] = (uint8_t)((src >> (byte * 8)) & 0xFF);
207
  }