Revision cda14729
README.txt | ||
---|---|---|
300 | 300 |
Next, you have to configure the main thread to whitelist the event flag (all I/O |
301 | 301 |
events are blacklisted by default). While system relevant events like power down |
302 | 302 |
are whitelisted by the OS, any custom events need to be added exl´plicitely. |
303 |
This is done via the optional AMIROOS_CFG_MAIN_LOOP_IOEVENT_MASK macro, which
|
|
304 |
should be defined in the module.h file. Example: |
|
305 |
|
|
306 |
#define AMIROOS_CFG_MAIN_LOOP_IOEVENT_MASK \
|
|
307 |
(AOS_IOEVENT_FLAG(padX) | AOS_IOEVENT_FLAG(padY) | AOS_IOEVENT_FLAG(padZ))
|
|
308 |
|
|
309 |
When AMIROOS_CFG_MAIN_LOOP_IOEVENT_MASK has been defined correctly, the main
|
|
310 |
thread will be notified by the according events and execute its event handling
|
|
311 |
routine. Hence you have to implement another macro in module.h to handle the
|
|
312 |
custom event(s) appropriately: MODULE_MAIN_LOOP_IO_EVENT(eventflags). As you can
|
|
313 |
see, the variable 'eventflags' is propagated to the hook. This variable is a
|
|
314 |
mask, that allows to identify the GPIO pad(s), which caused the event, by the
|
|
315 |
bits set. Following the example above, you can check which GPIOs have caused
|
|
316 |
events by using if-clauses in the implementation of the hook: |
|
317 |
|
|
318 |
#define MODULE_MAIN_LOOP_IO_EVENT(eventflags) { \
|
|
319 |
if (eventflags & AOS_IOEVENT_FLAG(padX)) { \
|
|
303 |
This is done via the optional AMIROOS_CFG_MAIN_LOOP_GPIOEVENT_FLAGSMASK macro,
|
|
304 |
which should be defined in the module.h file. Example:
|
|
305 |
|
|
306 |
#define AMIROOS_CFG_MAIN_LOOP_GPIOEVENT_FLAGSMASK \
|
|
307 |
(AOS_GPIOEVENT_FLAG(padX) | AOS_GPIOEVENT_FLAG(padY) | AOS_GPIOEVENT_FLAG(padZ))
|
|
308 |
|
|
309 |
When AMIROOS_CFG_MAIN_LOOP_GPIOEVENT_FLAGSMASK has been defined correctly, the
|
|
310 |
main thread will be notified by the according events and execute its event
|
|
311 |
handling routine. Hence you have to implement another macro in module.h to
|
|
312 |
handle the custom event(s) appropriately: MODULE_MAIN_LOOP_GPIOEVENT(eventflags).
|
|
313 |
As you can see, the variable 'eventflags' is propagated to the hook. This
|
|
314 |
variable is a mask, that allows to identify the GPIO pad(s), which caused the
|
|
315 |
event, by the bits set. Following the example above, you can check which GPIOs
|
|
316 |
have caused events by using if-clauses in the implementation of the hook:
|
|
317 |
|
|
318 |
#define MODULE_MAIN_LOOP_GPIOEVENT(eventflags) { \
|
|
319 |
if (eventflags & AOS_GPIOEVENT_FLAG(padX)) { \
|
|
320 | 320 |
/* handle event */ \ |
321 | 321 |
} \ |
322 | 322 |
if (eventflags & (AOS_IOEVENT_FLAG(padY) | \ |
323 |
AOS_IOEVENT_FLAG(padZ))) { \
|
|
323 |
AOS_GPIOEVENT_FLAG(padZ))) { \
|
|
324 | 324 |
/* handle combined event */ \ |
325 | 325 |
} \ |
326 | 326 |
} |
327 | 327 |
|
328 | 328 |
Summing up, you have to |
329 | 329 |
1) configure and enable the GPIO interrupt. |
330 |
2) define the AMIROOS_CFG_MAIN_LOOP_IOEVENT_MASK macro.
|
|
331 |
3) implement the MODULE_MAIN_LOOP_IO_EVENT(eventflags) hook.
|
|
330 |
2) define the AMIROOS_CFG_MAIN_LOOP_GPIOEVENT_FLAGSMASK macro.
|
|
331 |
3) implement the MODULE_MAIN_LOOP_GPIOEVENT(eventflags) hook.
|
|
332 | 332 |
|
333 | 333 |
|
334 | 334 |
4.3 Implementing a New Low-Level Driver |
amiroos.h | ||
---|---|---|
45 | 45 |
* @brief The operating system minor version. |
46 | 46 |
* @note A higher minor version implies new functionalty, but all old interfaces are still available. |
47 | 47 |
*/ |
48 |
#define AMIROOS_VERSION_MINOR 0
|
|
48 |
#define AMIROOS_VERSION_MINOR 1
|
|
49 | 49 |
|
50 | 50 |
/** |
51 | 51 |
* @brief The operating system patch level. |
52 | 52 |
*/ |
53 |
#define AMIROOS_VERSION_PATCH 1
|
|
53 |
#define AMIROOS_VERSION_PATCH 0
|
|
54 | 54 |
|
55 | 55 |
/** @} */ |
56 | 56 |
|
57 | 57 |
/******************************************************************************/ |
58 |
/* CONFIGURATION */ |
|
59 |
/******************************************************************************/ |
|
60 |
|
|
61 |
#include <aosconf.h> |
|
62 |
#if !defined(_AMIRO_OS_CFG_) |
|
63 |
#error "invalid AMiRo-OS configuration file" |
|
64 |
#elif (AMIRO_OS_CFG_VERSION_MAJOR != AMIROOS_VERSION_MAJOR) || (AMIRO_OS_CFG_VERSION_MINOR < AMIROOS_VERSION_MINOR) |
|
65 |
#error "incompatible AMiRo-OS configuration file" |
|
66 |
#endif |
|
67 |
|
|
68 |
/******************************************************************************/ |
|
58 | 69 |
/* SUBSYSTEMS */ |
59 | 70 |
/******************************************************************************/ |
60 | 71 |
|
61 |
/* Bootloader (AMiRo-BLT) */
|
|
62 |
#include <amiroblt.h>
|
|
72 |
/* Bootloader */ |
|
73 |
#include <aos_bootloader.h>
|
|
63 | 74 |
|
64 | 75 |
/* System Kerne (ChibiOS)l */ |
65 | 76 |
#include <hal.h> |
... | ... | |
72 | 83 |
/* AMiRo-OS CORE */ |
73 | 84 |
/******************************************************************************/ |
74 | 85 |
|
75 |
/* configuration */ |
|
76 |
#include <aosconf.h> |
|
77 |
#if !defined(_AMIRO_OS_CFG_) |
|
78 |
#error "invalid AMiRo-OS configuration file" |
|
79 |
#elif (AMIRO_OS_CFG_VERSION_MAJOR != AMIROOS_VERSION_MAJOR) || (AMIRO_OS_CFG_VERSION_MINOR < AMIROOS_VERSION_MINOR) |
|
80 |
#error "incompatible AMiRo-OS configuration file" |
|
81 |
#endif |
|
82 | 86 |
#include "core/inc/aos_confcheck.h" |
83 | 87 |
|
84 |
/* core headers */ |
|
85 | 88 |
#include "core/inc/aos_types.h" |
86 | 89 |
#include "core/inc/aos_debug.h" |
87 | 90 |
#include "core/inc/aos_time.h" |
88 | 91 |
#include "core/inc/aos_timer.h" |
89 | 92 |
#include "core/inc/aos_iostream.h" |
90 | 93 |
#include "core/inc/aos_shell.h" |
94 |
#include "core/inc/aos_sssp.h" |
|
91 | 95 |
#include "core/inc/aos_system.h" |
92 | 96 |
#include "core/inc/aos_thread.h" |
93 | 97 |
#include "core/inc/aos_test.h" |
94 | 98 |
|
95 |
/* module specifications */ |
|
99 |
/******************************************************************************/ |
|
100 |
/* MODULE */ |
|
101 |
/******************************************************************************/ |
|
102 |
|
|
96 | 103 |
#include <module.h> |
97 | 104 |
|
98 | 105 |
#endif /* AMIROOS_H */ |
bootloader/aos_bootloader.h | ||
---|---|---|
1 |
/* |
|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
3 |
Copyright (C) 2016..2019 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 |
/** |
|
20 |
* @file aos_bootloader.h |
|
21 |
* @brief Bootloader wrapper header. |
|
22 |
* |
|
23 |
* @addtogroup aos_bootloader |
|
24 |
* @{ |
|
25 |
*/ |
|
26 |
|
|
27 |
#ifndef AMIROOS_BOOTLOADER_H |
|
28 |
#define AMIROOS_BOOTLOADER_H |
|
29 |
|
|
30 |
#include <amiroos.h> |
|
31 |
|
|
32 |
/******************************************************************************/ |
|
33 |
/* CONSTANTS */ |
|
34 |
/******************************************************************************/ |
|
35 |
|
|
36 |
/** |
|
37 |
* @brief Identifier for the case that no bootloader is installed/available. |
|
38 |
*/ |
|
39 |
#define AOS_BOOTLOADER_NONE 0 |
|
40 |
|
|
41 |
/** |
|
42 |
* @brief Identifier for AMiRo-BLT |
|
43 |
* @note The version of the installed AMiRo-BLT can be retreived via the AMiRo-BLT interface. |
|
44 |
*/ |
|
45 |
#define AOS_BOOTLOADER_AMiRoBLT 1 |
|
46 |
|
|
47 |
/******************************************************************************/ |
|
48 |
/* SETTINGS */ |
|
49 |
/******************************************************************************/ |
|
50 |
|
|
51 |
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT) |
|
52 |
#include <amiroblt.h> |
|
53 |
#endif |
|
54 |
|
|
55 |
/******************************************************************************/ |
|
56 |
/* CHECKS */ |
|
57 |
/******************************************************************************/ |
|
58 |
|
|
59 |
#if (AMIROOS_CFG_BOOTLOADER != AOS_BOOTLOADER_NONE) && \ |
|
60 |
(AMIROOS_CFG_BOOTLOADER != AOS_BOOTLOADER_AMiRoBLT) |
|
61 |
#error "AMIROOS_CFG_BOOTLOADER set to invalid value in aosconf.h" |
|
62 |
#endif |
|
63 |
|
|
64 |
/******************************************************************************/ |
|
65 |
/* DATA STRUCTURES AND TYPES */ |
|
66 |
/******************************************************************************/ |
|
67 |
|
|
68 |
/******************************************************************************/ |
|
69 |
/* MACROS */ |
|
70 |
/******************************************************************************/ |
|
71 |
|
|
72 |
/******************************************************************************/ |
|
73 |
/* EXTERN DECLARATIONS */ |
|
74 |
/******************************************************************************/ |
|
75 |
|
|
76 |
/******************************************************************************/ |
|
77 |
/* INLINE FUNCTIONS */ |
|
78 |
/******************************************************************************/ |
|
79 |
|
|
80 |
#endif /* AMIROOS_BOOTLOADER_H */ |
|
81 |
|
|
82 |
/** @} */ |
bootloader/bootloader.mk | ||
---|---|---|
30 | 30 |
AMIROBLT := $(AMIROOS_BOOTLOADER_DIR)AMiRo-BLT |
31 | 31 |
|
32 | 32 |
# include paths |
33 |
AMIROOS_BOOTLOADER_INC = $(AMIROBLT)/Target/Source/AMiRo |
|
33 |
AMIROOS_BOOTLOADER_INC = $(AMIROOS_BOOTLOADER_DIR) \ |
|
34 |
$(AMIROBLT)/Target/Source/AMiRo |
|
34 | 35 |
|
35 | 36 |
# load module ID constants |
36 | 37 |
include $(AMIROBLT)/Target/Modules/moduleids.mk |
core/inc/aos_confcheck.h | ||
---|---|---|
59 | 59 |
#error "AMIROOS_CFG_MAIN_LOOP_TIMEOUT not defined in aosconf.h" |
60 | 60 |
#endif /* !defined(AMIROOS_CFG_MAIN_LOOP_TIMEOUT) */ |
61 | 61 |
|
62 |
/* bootloader parameters and options */ |
|
63 |
|
|
64 |
#if !defined(AMIROOS_CFG_BOOTLOADER) |
|
65 |
#error "AMIROOS_CFG_BOOTLOADER not defined in aosconf.h" |
|
66 |
#endif /* !defined(AMIROOS_CFG_BOOTLOADER)*/ |
|
67 |
|
|
62 | 68 |
/* SSSP parameters and options */ |
63 | 69 |
|
64 | 70 |
#if !defined(AMIROOS_CFG_SSSP_ENABLE) |
65 | 71 |
#error "AMIROOS_CFG_SSSP_ENABLE not defined in aosconf.h" |
66 | 72 |
#endif /* !defined(AMIROOS_CFG_SSSP_ENABLE) */ |
67 | 73 |
|
68 |
# if (AMIROOS_CFG_SSSP_ENABLE == true) |
|
74 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) |
|
75 |
|
|
76 |
#if !defined(AMIROOS_CFG_SSSP_STARTUP) |
|
77 |
#error "AMIROOS_CFG_SSSP_STARTUP not defined in aosconf.h" |
|
78 |
#else /* !defined(AMIROOS_CFG_SSSP_STARTUP) */ |
|
79 |
#if (AMIROOS_CFG_SSSP_STARTUP == true) |
|
80 |
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT) |
|
81 |
#error "AMIROOS_CFG_SSSP_STARTUP is enabled in aosconf.h, but SSSP startup phase is already handled by AMiRo-BLT." |
|
82 |
#endif /* (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT) */ |
|
83 |
#else /* (AMIROOS_CFG_SSSP_STARTUP == true) */ |
|
84 |
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE) |
|
85 |
#error "AMIROOS_CFG_SSSP_STARTUP is disabled in aosconf.h, but no bootloader is defined to handle SSSP startup phase instead." |
|
86 |
#endif /* (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE) */ |
|
87 |
#endif /* (AMIROOS_CFG_SSSP_STARTUP == true) */ |
|
88 |
#endif /* !defined(AMIROOS_CFG_SSSP_STARTUP) */ |
|
89 |
|
|
90 |
#if !defined(AMIROOS_CFG_SSSP_SHUTDOWN) |
|
91 |
#error "AMIROOS_CFG_SSSP_SHUTDOWN not defined in aosconf.h" |
|
92 |
#else /* !defined(AMIROOS_CFG_SSSP_SHUTDOWN) */ |
|
93 |
#if (AMIROOS_CFG_SSSP_SHUTDOWN != true) |
|
94 |
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE) |
|
95 |
#error "AMIROOS_CFG_SSSP_SHUTDOWN is disabled in aosconf.h, but no bootloader is defined to handle SSSP shutdown phase instead." |
|
96 |
#endif /* (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE) */ |
|
97 |
#endif /* (AMIROOS_CFG_SSSP_SHUTDOWN != true) && (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE) */ |
|
98 |
#endif /* !defined(AMIROOS_CFG_SSSP_SHUTDOWN) */ |
|
99 |
|
|
100 |
#if !defined(AMIROOS_CFG_SSSP_MSI) |
|
101 |
#error "AMIROOS_CFG_SSSP_MSI not defined in aosconf.h" |
|
102 |
#endif /* !defined(AMIROOS_CFG_SSSP_MSI) */ |
|
103 |
|
|
104 |
#if !defined(AMIROOS_CFG_SSSP_MODULEIDWIDTH) |
|
105 |
#error "AMIROOS_CFG_SSSP_MODULEIDWIDTH not defined in aosconf.h" |
|
106 |
#endif /* !defined(AMIROOS_CFG_SSSP_MODULEIDWIDTH) */ |
|
69 | 107 |
|
70 | 108 |
#if !defined(AMIROOS_CFG_SSSP_MASTER) |
71 | 109 |
#error "AMIROOS_CFG_SSSP_MASTER not defined in aosconf.h" |
... | ... | |
94 | 132 |
#error "AMIROOS_CFG_SSSP_SYSSYNCPERIOD not defined in aosconf.h" |
95 | 133 |
#endif /* !defined(AMIROOS_CFG_SSSP_SYSSYNCPERIOD) */ |
96 | 134 |
|
135 |
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
|
136 |
|
|
137 |
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT) |
|
138 |
#warning "SSSP is disabled in aosconf.h, but AMiRo-BLT implements it nevertheless." |
|
139 |
#endif /* (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT) */ |
|
140 |
|
|
97 | 141 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
98 | 142 |
|
99 | 143 |
/* system shell options */ |
... | ... | |
123 | 167 |
#else /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
124 | 168 |
|
125 | 169 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) |
126 |
#pragma message "AMiRo-OS shell enabled implicitely via AMIROOS_CFG_TESTS_ENABLE"
|
|
170 |
#error "Enabling AMIROOS_CFG_TESTS_ENABLE in aosconf.h requires AMIROOS_CFG_SHELL_ENABLE to be enabled as well."
|
|
127 | 171 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
128 | 172 |
|
129 | 173 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
core/inc/aos_shell.h | ||
---|---|---|
29 | 29 |
|
30 | 30 |
#include <amiroos.h> |
31 | 31 |
|
32 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true)
|
|
32 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
|
|
33 | 33 |
|
34 | 34 |
/******************************************************************************/ |
35 | 35 |
/* CONSTANTS */ |
... | ... | |
418 | 418 |
/* INLINE FUNCTIONS */ |
419 | 419 |
/******************************************************************************/ |
420 | 420 |
|
421 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
|
|
421 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
|
422 | 422 |
|
423 | 423 |
#endif /* AMIROOS_SHELL_H */ |
424 | 424 |
|
core/inc/aos_sssp.h | ||
---|---|---|
1 |
/* |
|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
3 |
Copyright (C) 2016..2019 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 |
/** |
|
20 |
* @file aos_sssp.h |
|
21 |
* @brief SSSP related macros, structures and functions. |
|
22 |
* |
|
23 |
* @addtogroup aos_sssp |
|
24 |
* @{ |
|
25 |
*/ |
|
26 |
|
|
27 |
#ifndef AMIROOS_SSSP_H |
|
28 |
#define AMIROOS_SSSP_H |
|
29 |
|
|
30 |
#include <amiroos.h> |
|
31 |
|
|
32 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
|
33 |
|
|
34 |
/******************************************************************************/ |
|
35 |
/* CONSTANTS */ |
|
36 |
/******************************************************************************/ |
|
37 |
|
|
38 |
/** |
|
39 |
* @brief Major version of the implemented SSSP. |
|
40 |
*/ |
|
41 |
#define AOS_SSSP_VERSION_MAJOR 1 |
|
42 |
|
|
43 |
/** |
|
44 |
* @brief Minor version of the implemented SSSP. |
|
45 |
*/ |
|
46 |
#define AOS_SSSP_VERSION_MINOR 4 |
|
47 |
|
|
48 |
/** |
|
49 |
* @brief Time of delays in microseconds. |
|
50 |
*/ |
|
51 |
#define AOS_SSSP_DELAY AMIROOS_CFG_SSSP_SIGNALDELAY |
|
52 |
|
|
53 |
/** |
|
54 |
* @brief Timeout delay in microseconds according to SSSP. |
|
55 |
* @details SSSP 1.x defines timeouts to be ten times longer than the signal delay time. |
|
56 |
*/ |
|
57 |
#define AOS_SSSP_TIMEOUT (10 * AOS_SSSP_DELAY) |
|
58 |
|
|
59 |
/** |
|
60 |
* @brief Value to indicate an invalid module ID. |
|
61 |
*/ |
|
62 |
#define AOS_SSSP_MODULEID_INVALID ((aos_ssspmoduleid_t)0) |
|
63 |
|
|
64 |
/** |
|
65 |
* @brief Value for broadcasting, adressing all modules. |
|
66 |
* @note This value is identical to @p AOS_SSSP_MODULEID_INVALID since in the case that no module IDs were applied, addressing of specific modules is not possible, thus every communication would be a broadcast. |
|
67 |
*/ |
|
68 |
#define AOS_SSSP_MODULEID_BROADCAST ((aos_ssspmoduleid_t)0) |
|
69 |
|
|
70 |
/******************************************************************************/ |
|
71 |
/* SETTINGS */ |
|
72 |
/******************************************************************************/ |
|
73 |
|
|
74 |
/******************************************************************************/ |
|
75 |
/* CHECKS */ |
|
76 |
/******************************************************************************/ |
|
77 |
|
|
78 |
#if (AMIROOS_CFG_SSSP_MSI == true) |
|
79 |
#error "SSSP module stack initialization (MSI not implemented yet" |
|
80 |
#endif |
|
81 |
|
|
82 |
/******************************************************************************/ |
|
83 |
/* DATA STRUCTURES AND TYPES */ |
|
84 |
/******************************************************************************/ |
|
85 |
|
|
86 |
/** |
|
87 |
* @brief Enumeration of the several stages of SSSP. |
|
88 |
*/ |
|
89 |
typedef enum { |
|
90 |
AOS_SSSP_STAGE_UNDEFINED = 0x0000, /**< Identifier of yet undefined stage variable. */ |
|
91 |
AOS_SSSP_STAGE_STARTUP = 0x1000, /**< Identifier of SSSP startup phase. */ |
|
92 |
AOS_SSSP_STAGE_STARTUP_1 = 0x1100, /**< Identifier of SSSP startup phase stage 1. */ |
|
93 |
AOS_SSSP_STAGE_STARTUP_1_1 = 0x1110, /**< Identifier of SSSP startup phase stage 1-1. */ |
|
94 |
AOS_SSSP_STAGE_STARTUP_1_2 = 0x1120, /**< Identifier of SSSP startup phase stage 1-2. */ |
|
95 |
AOS_SSSP_STAGE_STARTUP_1_3 = 0x1130, /**< Identifier of SSSP startup phase stage 1-3. */ |
|
96 |
AOS_SSSP_STAGE_STARTUP_2 = 0x1200, /**< Identifier of SSSP startup phase stage 2. */ |
|
97 |
AOS_SSSP_STAGE_STARTUP_2_1 = 0x1210, /**< Identifier of SSSP startup phase stage 2-1. */ |
|
98 |
AOS_SSSP_STAGE_STARTUP_2_2 = 0x1220, /**< Identifier of SSSP startup phase stage 2-2. */ |
|
99 |
AOS_SSSP_STAGE_STARTUP_3 = 0x1300, /**< Identifier of SSSP startup phase stage 3. */ |
|
100 |
AOS_SSSP_STAGE_STARTUP_3_1 = 0x1310, /**< Identifier of SSSP startup phase stage 3-1. */ |
|
101 |
AOS_SSSP_STAGE_STARTUP_3_2 = 0x1320, /**< Identifier of SSSP startup phase stage 3-2. */ |
|
102 |
AOS_SSSP_STAGE_STARTUP_3_3 = 0x1330, /**< Identifier of SSSP startup phase stage 3-3. */ |
|
103 |
AOS_SSSP_STAGE_STARTUP_3_4 = 0x1340, /**< Identifier of SSSP startup phase stage 3-4. */ |
|
104 |
AOS_SSSP_STAGE_OPERATION = 0x2000, /**< Identifier of SSSP operation pahse. */ |
|
105 |
AOS_SSSP_STAGE_SHUTDOWN = 0x3000, /**< Identifier of SSSP shutdown phase. */ |
|
106 |
AOS_SSSP_STAGE_SHUTDOWN_1 = 0x3100, /**< Identifier of SSSP shutdown phase stage 1. */ |
|
107 |
AOS_SSSP_STAGE_SHUTDOWN_1_1 = 0x3110, /**< Identifier of SSSP shutdown phase stage 1-1. */ |
|
108 |
AOS_SSSP_STAGE_SHUTDOWN_1_2 = 0x3120, /**< Identifier of SSSP shutdown phase stage 1-2. */ |
|
109 |
AOS_SSSP_STAGE_SHUTDOWN_1_3 = 0x3130, /**< Identifier of SSSP shutdown phase stage 1-3. */ |
|
110 |
AOS_SSSP_STAGE_SHUTDOWN_2 = 0x3200, /**< Identifier of SSSP shutdown phase stage 2. */ |
|
111 |
AOS_SSSP_STAGE_SHUTDOWN_2_1 = 0x3210, /**< Identifier of SSSP shutdown phase stage 2-1. */ |
|
112 |
AOS_SSSP_STAGE_SHUTDOWN_2_2 = 0x3220, /**< Identifier of SSSP shutdown phase stage 2-2. */ |
|
113 |
AOS_SSSP_STAGE_SHUTDOWN_2_3 = 0x3230, /**< Identifier of SSSP shutdown phase stage 2-3. */ |
|
114 |
} aos_ssspstage_t; |
|
115 |
|
|
116 |
/** |
|
117 |
* @brief Type to represent module IDs. |
|
118 |
*/ |
|
119 |
#if (AMIROOS_CFG_SSSP_MODULEIDWIDTH == 8) |
|
120 |
typedef uint8_t aos_ssspmoduleid_t; |
|
121 |
#elif (AMIROOS_CFG_SSSP_MODULEIDWIDTH == 16) || defined(__DOXYGEN__) |
|
122 |
typedef uint16_t aos_ssspmoduleid_t; |
|
123 |
#elif (AMIROOS_CFG_SSSP_MODULEIDWIDTH == 32) |
|
124 |
typedef uint32_t aos_ssspmoduleid_t; |
|
125 |
#else |
|
126 |
#error "AMIROOS_CFG_SSSP_MODULEIDWIDTH set to an invalid value." |
|
127 |
#endif |
|
128 |
|
|
129 |
/** |
|
130 |
* @brief Data structure holding module-wide SSSP information. |
|
131 |
*/ |
|
132 |
typedef struct { |
|
133 |
/** |
|
134 |
* @brief Current execution stage of SSSP. |
|
135 |
*/ |
|
136 |
aos_ssspstage_t stage; |
|
137 |
|
|
138 |
#if (AMIROOS_CFG_SSSP_MSI == true) || defined(__DOXYGEN__) |
|
139 |
|
|
140 |
/** |
|
141 |
* @brief Module identifier. |
|
142 |
* @details A value of @p AOS_SSSP_MODULEID_INVALID indicates an uninitialized ID. |
|
143 |
* The values @p AOS_SSSP_MODULEID_INVALID and @p AOS_SSSP_MODULEID_ALL are reserved and must not be set. |
|
144 |
*/ |
|
145 |
aos_ssspmoduleid_t moduleId; |
|
146 |
|
|
147 |
#endif /* (AMIROOS_CFG_SSSP_MSI == true) */ |
|
148 |
|
|
149 |
} aos_ssspdata_t; |
|
150 |
|
|
151 |
/******************************************************************************/ |
|
152 |
/* MACROS */ |
|
153 |
/******************************************************************************/ |
|
154 |
|
|
155 |
/******************************************************************************/ |
|
156 |
/* EXTERN DECLARATIONS */ |
|
157 |
/******************************************************************************/ |
|
158 |
|
|
159 |
#if defined(__cplusplus) |
|
160 |
extern "C" { |
|
161 |
#endif /* defined(__cplusplus) */ |
|
162 |
void aosSsspInit(void); |
|
163 |
aos_status_t aosSsspProceed(event_listener_t* listener, eventflags_t flags, eventmask_t mask, eventmask_t* received); |
|
164 |
void aosSsspShutdownInit(void); |
|
165 |
#if (AMIROOS_CFG_SSSP_SHUTDOWN == true) || defined(__DOXYGEN__) |
|
166 |
void aosSsspShutdownBroadcastIdentifier(unsigned int identifier); |
|
167 |
eventmask_t aosSsspShutdownWaitForIdentifierPulse(event_listener_t* gpiolistener, eventflags_t sflags, eventmask_t timermask, unsigned int* identifier); |
|
168 |
#endif /* (AMIROOS_CFG_SSSP_SHUTDOWN == true) */ |
|
169 |
#if defined(__cplusplus) |
|
170 |
} |
|
171 |
#endif /* defined(__cplusplus) */ |
|
172 |
|
|
173 |
/******************************************************************************/ |
|
174 |
/* INLINE FUNCTIONS */ |
|
175 |
/******************************************************************************/ |
|
176 |
|
|
177 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
|
178 |
|
|
179 |
#endif /* AMIROOS_SSSP_H */ |
|
180 |
|
|
181 |
/** @} */ |
core/inc/aos_system.h | ||
---|---|---|
40 | 40 |
#define AOS_SYSTEM_TIME_RESOLUTION ((MICROSECONDS_PER_SECOND + CH_CFG_ST_FREQUENCY - 1) / CH_CFG_ST_FREQUENCY) |
41 | 41 |
|
42 | 42 |
/** |
43 |
* @brief System event flag which is emitted when a shutdown was initiated.
|
|
43 |
* @brief System event flag mask for shutdown related events.
|
|
44 | 44 |
*/ |
45 |
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN (eventflags_t)(1 << 0) |
|
45 |
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_MASK ((eventflags_t)0x1F) |
|
46 |
|
|
47 |
/** |
|
48 |
* @brief System event flag which is emitted when a passive shutdown was initiated. |
|
49 |
*/ |
|
50 |
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_PASSIVE ((eventflags_t)(1 << 0)) |
|
46 | 51 |
|
47 | 52 |
/** |
48 | 53 |
* @brief System event flag which is emitted when a shutdown to transportation mode was initiated. |
49 | 54 |
*/ |
50 |
#define AOS_SYSTEM_EVENTFLAGS_TRANSPORTATION (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 1))
|
|
55 |
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_TRANSPORTATION ((eventflags_t)(1 << 1))
|
|
51 | 56 |
|
52 | 57 |
/** |
53 | 58 |
* @brief System event flag which is emitted when a shutdown to deepsleep mode was initiated. |
54 | 59 |
*/ |
55 |
#define AOS_SYSTEM_EVENTFLAGS_DEEPSLEEP (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 2))
|
|
60 |
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_DEEPSLEEP ((eventflags_t)(1 << 2))
|
|
56 | 61 |
|
57 | 62 |
/** |
58 | 63 |
* @brief System event flag which is emitted when a shutdown to hibernate mode was initiated. |
59 | 64 |
*/ |
60 |
#define AOS_SYSTEM_EVENTFLAGS_HIBERNATE (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 3))
|
|
65 |
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_HIBERNATE ((eventflags_t)(1 << 3))
|
|
61 | 66 |
|
62 | 67 |
/** |
63 | 68 |
* @brief System event flag which is emitted when a system restart was initiated. |
64 | 69 |
*/ |
65 |
#define AOS_SYSTEM_EVENTFLAGS_RESTART (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 4)) |
|
66 |
|
|
67 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
|
68 |
|
|
69 |
/** |
|
70 |
* @brief Major version of the implemented SSSP. |
|
71 |
*/ |
|
72 |
#define AOS_SYSTEM_SSSP_VERSION_MAJOR 1 |
|
73 |
|
|
74 |
/** |
|
75 |
* @brief Minor version of the implemented SSSP. |
|
76 |
*/ |
|
77 |
#define AOS_SYSTEM_SSSP_VERSION_MINOR 4 |
|
78 |
|
|
79 |
/** |
|
80 |
* @brief Timeout delay according to SSSP. |
|
81 |
* @details SSSP defines timeouts to be ten times longer than the signal delay time. |
|
82 |
*/ |
|
83 |
#define AOS_SYSTEM_SSSP_TIMEOUT (10 * AMIROOS_CFG_SSSP_SIGNALDELAY) |
|
84 |
|
|
85 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
|
70 |
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_RESTART ((eventflags_t)(1 << 4)) |
|
86 | 71 |
|
87 | 72 |
/******************************************************************************/ |
88 | 73 |
/* SETTINGS */ |
... | ... | |
101 | 86 |
*/ |
102 | 87 |
typedef enum aos_shutdown { |
103 | 88 |
AOS_SHUTDOWN_NONE, /**< Default value if no shutdown action was initiated */ |
89 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
|
104 | 90 |
AOS_SHUTDOWN_PASSIVE, /**< Passive shutdown (initiated by another module). */ |
91 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
|
92 |
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE) || defined (__DOXYGEN__) |
|
93 |
AOS_SHUTDOWN_ACTIVE, /**< Active shutdown. */ |
|
94 |
#endif /* (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE) */ |
|
95 |
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT) || defined (__DOXYGEN__) |
|
105 | 96 |
AOS_SHUTDOWN_HIBERNATE, /**< Active shutdown to hibernate mode. */ |
106 | 97 |
AOS_SHUTDOWN_DEEPSLEEP, /**< Active shutdown to deepsleep mode. */ |
107 | 98 |
AOS_SHUTDOWN_TRANSPORTATION, /**< Active shutdown to transportation mode. */ |
108 | 99 |
AOS_SHUTDOWN_RESTART, /**< Active saystem restart request. */ |
100 |
#endif /* (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT) */ |
|
109 | 101 |
} aos_shutdown_t; |
110 | 102 |
|
111 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
|
112 |
|
|
113 |
/** |
|
114 |
* @brief Enumerator of the several stages of SSSP. |
|
115 |
*/ |
|
116 |
typedef enum aos_ssspstage { |
|
117 |
AOS_SSSP_STARTUP_1_1 = 0x10, /**< Identifier of SSSP startup phase stage 1-1. */ |
|
118 |
AOS_SSSP_STARTUP_1_2 = 0x11, /**< Identifier of SSSP startup phase stage 1-2. */ |
|
119 |
AOS_SSSP_STARTUP_1_3 = 0x12, /**< Identifier of SSSP startup phase stage 1-3. */ |
|
120 |
AOS_SSSP_STARTUP_2_1 = 0x14, /**< Identifier of SSSP startup phase stage 2-1. */ |
|
121 |
AOS_SSSP_STARTUP_2_2 = 0x15, /**< Identifier of SSSP startup phase stage 2-2. */ |
|
122 |
AOS_SSSP_STARTUP_3_1 = 0x18, /**< Identifier of SSSP startup phase stage 3-1. */ |
|
123 |
AOS_SSSP_STARTUP_3_2 = 0x19, /**< Identifier of SSSP startup phase stage 3-2. */ |
|
124 |
AOS_SSSP_STARTUP_3_3 = 0x1A, /**< Identifier of SSSP startup phase stage 3-3. */ |
|
125 |
AOS_SSSP_STARTUP_3_4 = 0x1B, /**< Identifier of SSSP startup phase stage 3-4. */ |
|
126 |
AOS_SSSP_OPERATION = 0x20, /**< Identifier of SSSP operation pahse. */ |
|
127 |
AOS_SSSP_SHUTDOWN_1_1 = 0x30, /**< Identifier of SSSP shutdown phase stage 1-1. */ |
|
128 |
AOS_SSSP_SHUTDOWN_1_2 = 0x31, /**< Identifier of SSSP shutdown phase stage 1-2. */ |
|
129 |
AOS_SSSP_SHUTDOWN_1_3 = 0x32, /**< Identifier of SSSP shutdown phase stage 1-3. */ |
|
130 |
AOS_SSSP_SHUTDOWN_2_1 = 0x34, /**< Identifier of SSSP shutdown phase stage 2-1. */ |
|
131 |
AOS_SSSP_SHUTDOWN_2_2 = 0x35, /**< Identifier of SSSP shutdown phase stage 2-2. */ |
|
132 |
AOS_SSSP_SHUTDOWN_3 = 0x38, /**< Identifier of SSSP shutdown phase stage 3. */ |
|
133 |
} aos_ssspstage_t; |
|
134 |
|
|
135 |
/** |
|
136 |
* @brief Type to represent module IDs. |
|
137 |
*/ |
|
138 |
typedef uint16_t aos_ssspmoduleid_t; |
|
139 |
|
|
140 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
|
141 |
|
|
142 | 103 |
/** |
143 | 104 |
* @brief AMiRo-OS base system structure. |
144 | 105 |
*/ |
145 | 106 |
typedef struct aos_system { |
146 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
|
147 |
/** |
|
148 |
* @brief SSSP relevant data. |
|
149 |
*/ |
|
150 |
struct { |
|
151 |
/** |
|
152 |
* @brief Current SSSP stage of the system. |
|
153 |
*/ |
|
154 |
aos_ssspstage_t stage; |
|
155 |
|
|
156 |
/** |
|
157 |
* @brief Module identifier. |
|
158 |
* @details A value of 0 indicates an uninitialized ID. |
|
159 |
* The vlaues 0 and ~0 are reserved und must not be set. |
|
160 |
*/ |
|
161 |
aos_ssspmoduleid_t moduleId; |
|
162 |
} sssp; |
|
163 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
|
164 | 107 |
|
165 | 108 |
/** |
166 | 109 |
* @brief System I/O stream. |
... | ... | |
173 | 116 |
struct { |
174 | 117 |
|
175 | 118 |
/** |
176 |
* @brief I/O event source.
|
|
119 |
* @brief GPIO event source.
|
|
177 | 120 |
*/ |
178 |
event_source_t io; |
|
121 |
event_source_t gpio;
|
|
179 | 122 |
|
180 | 123 |
/** |
181 | 124 |
* @brief OS event source. |
... | ... | |
183 | 126 |
event_source_t os; |
184 | 127 |
} events; |
185 | 128 |
|
186 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
|
|
129 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
|
187 | 130 |
|
188 | 131 |
/** |
189 | 132 |
* @brief Pointer to the shell object. |
190 | 133 |
*/ |
191 | 134 |
aos_shell_t shell; |
192 | 135 |
|
193 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */ |
|
136 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
|
137 |
|
|
138 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
|
139 |
|
|
140 |
/** |
|
141 |
* @brief SSSP relevant data. |
|
142 |
*/ |
|
143 |
aos_ssspdata_t sssp; |
|
144 |
|
|
145 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
|
194 | 146 |
|
195 | 147 |
} aos_system_t; |
196 | 148 |
|
... | ... | |
217 | 169 |
#if defined(__cplusplus) |
218 | 170 |
extern "C" { |
219 | 171 |
#endif /* defined(__cplusplus) */ |
220 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true)
|
|
172 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
|
|
221 | 173 |
void aosSysInit(const char* shellPrompt); |
222 |
#else /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
|
|
174 |
#else /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
|
223 | 175 |
void aosSysInit(void); |
224 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
|
|
176 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
|
225 | 177 |
void aosSysStart(void); |
226 | 178 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined (__DOXYGEN__) |
227 |
eventmask_t aosSysSsspStartupOsInitSyncCheck(event_listener_t* syncEvtListener);
|
|
179 |
void aosSysStartUptime(void);
|
|
228 | 180 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
229 | 181 |
void aosSysGetUptimeX(aos_timestamp_t* ut); |
230 |
#if (HAL_USE_RTC == TRUE) |
|
182 |
#if (HAL_USE_RTC == TRUE) || defined(__DOXYGEN__)
|
|
231 | 183 |
void aosSysGetDateTime(struct tm* dt); |
232 | 184 |
void aosSysSetDateTime(struct tm* dt); |
233 | 185 |
#endif /* (HAL_USE_RTC == TRUE) */ |
234 | 186 |
void aosSysShutdownInit(aos_shutdown_t shutdown); |
235 | 187 |
void aosSysStop(void); |
236 | 188 |
void aosSysDeinit(void); |
237 |
void aosSysShutdownFinal(aos_shutdown_t shutdown); |
|
238 |
palcallback_t aosSysGetStdExtiCallback(void); |
|
189 |
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_SHUTDOWN != true)) || \ |
|
190 |
((AMIROOS_CFG_SSSP_ENABLE != true) && (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)) || \ |
|
191 |
defined(__DOXYGEN__) |
|
192 |
void aosSysShutdownToBootloader(aos_shutdown_t shutdown); |
|
193 |
#endif /* ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_SHUTDOWN != true)) || ((AMIROOS_CFG_SSSP_ENABLE != true) && (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)) */ |
|
194 |
palcallback_t aosSysGetStdGpioCallback(void); |
|
239 | 195 |
#if defined(__cplusplus) |
240 | 196 |
} |
241 | 197 |
#endif /* defined(__cplusplus) */ |
core/inc/aos_thread.h | ||
---|---|---|
122 | 122 |
extern "C" { |
123 | 123 |
#endif /* defined(_cplusplus) */ |
124 | 124 |
void aosThdSleepUntilS(const aos_timestamp_t t); |
125 |
#if (AMIROOS_CFG_DBG == true) && (CH_DBG_FILL_THREADS == TRUE)
|
|
125 |
#if ((AMIROOS_CFG_DBG == true) && (CH_DBG_FILL_THREADS == TRUE)) || defined(__DOXYGEN__)
|
|
126 | 126 |
size_t aosThdGetStackPeakUtilization(thread_t* thread); |
127 | 127 |
#endif /* (AMIROOS_CFG_DBG == true) && (CH_DBG_FILL_THREADS == TRUE) */ |
128 | 128 |
#if defined(__cplusplus) |
core/inc/aos_types.h | ||
---|---|---|
87 | 87 |
/** |
88 | 88 |
* @brief Converts a GPIO pad number to a unique event flag. |
89 | 89 |
*/ |
90 |
#define AOS_IOEVENT_FLAG(pad) ((eventflags_t)1 << pad)
|
|
90 |
#define AOS_GPIOEVENT_FLAG(pad) ((eventflags_t)1 << pad)
|
|
91 | 91 |
|
92 | 92 |
/******************************************************************************/ |
93 | 93 |
/* EXTERN DECLARATIONS */ |
core/src/aos_main.cpp | ||
---|---|---|
19 | 19 |
/** |
20 | 20 |
* @file aos_main.cpp |
21 | 21 |
* @brief Main function. |
22 |
* @details Main function with SSSP and initialization, |
|
23 |
* extendable via hooks. |
|
24 | 22 |
* |
25 | 23 |
* @addtogroup aos_system |
26 | 24 |
* @{ |
... | ... | |
40 | 38 |
/******************************************************************************/ |
41 | 39 |
|
42 | 40 |
/** |
43 |
* @brief Event mask to identify I/O events.
|
|
41 |
* @brief Event mask to identify GPIO events.
|
|
44 | 42 |
*/ |
45 |
#define IOEVENT_MASK EVENT_MASK(0)
|
|
43 |
#define EVENTMASK_GPIO EVENT_MASK(0)
|
|
46 | 44 |
|
47 | 45 |
/** |
48 | 46 |
* @brief Event mask to identify OS events. |
49 | 47 |
*/ |
50 |
#define OSEVENT_MASK EVENT_MASK(1)
|
|
48 |
#define EVENTMASK_OS EVENT_MASK(1)
|
|
51 | 49 |
|
52 |
/** |
|
53 |
* @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 |
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (HAL_USE_CAN == TRUE)) || defined(__DOXYGEN__) |
|
68 |
#define SSSP_STAGE3_ENABLE true |
|
69 |
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) && (HAL_USE_CAN == TRUE) */ |
|
70 |
#define SSSP_STAGE3_ENABLE false |
|
71 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (HAL_USE_CAN == TRUE) */ |
|
72 |
|
|
73 |
#if (SSSP_STAGE3_ENABLE == true) || defined(__DOXYGEN__) |
|
74 |
|
|
75 |
/** |
|
76 |
* @brief CAN message identifier for initialization of the SSSP stack initialization sequence. |
|
77 |
*/ |
|
78 |
#define SSSP_STACKINIT_CANMSGID_INIT 0x003 |
|
79 |
|
|
80 |
/** |
|
81 |
* @brief CAN message identifier for transmitting module IDs during the SSSP stack initialization sequence. |
|
82 |
*/ |
|
83 |
#define SSSP_STACKINIT_CANMSGID_MODULEID 0x002 |
|
50 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
|
84 | 51 |
|
85 | 52 |
/** |
86 |
* @brief CAN message identifier for abortion of the SSSP stack initialization sequence.
|
|
53 |
* @brief Event mask to identify SSSP timer events.
|
|
87 | 54 |
*/ |
88 |
#define SSSP_STACKINIT_CANMSGID_ABORT 0x001
|
|
55 |
#define EVENTMASK_SSSPTIMER EVENT_MASK(2)
|
|
89 | 56 |
|
90 |
#endif /* (SSSP_STAGE3_ENABLE == true) */ |
|
91 |
|
|
92 |
#if (AMIROOS_CFG_SSSP_ENABLE != true) || defined(__DOXYGEN__) |
|
93 |
/** |
|
94 |
* @brief Default shutdown mode if SSSP is unavailable. |
|
95 |
*/ |
|
96 |
#define AOS_SHUTDOWN_DEFAULT AOS_SHUTDOWN_DEEPSLEEP |
|
97 | 57 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
98 | 58 |
|
99 |
#if (HAL_USE_CAN == TRUE) || defined(__DOXYGEN__) |
|
100 |
/** |
|
101 |
* @brief CAN message identifier for calender synchronization message. |
|
102 |
*/ |
|
103 |
#define CALENDERSYNC_CANMSGID 0x004 |
|
104 |
#endif /* (HAL_USE_CAN == TRUE) */ |
|
105 |
|
|
106 | 59 |
/******************************************************************************/ |
107 | 60 |
/* EXPORTED VARIABLES */ |
108 | 61 |
/******************************************************************************/ |
... | ... | |
116 | 69 |
/******************************************************************************/ |
117 | 70 |
|
118 | 71 |
/** |
119 |
* @brief Listener object for I/O events.
|
|
72 |
* @brief Listener object for GPIO events.
|
|
120 | 73 |
*/ |
121 |
static event_listener_t _eventListenerIO; |
|
74 |
static event_listener_t _eventListenerGPIO;
|
|
122 | 75 |
|
123 | 76 |
/** |
124 | 77 |
* @brief Listener object for OS events. |
... | ... | |
126 | 79 |
static event_listener_t _eventListenerOS; |
127 | 80 |
|
128 | 81 |
#if defined(MODULE_HAL_PROGIF) || defined(__DOXYGEN__) |
82 |
|
|
129 | 83 |
/** |
130 | 84 |
* @brief I/O channel for the programmer interface. |
131 | 85 |
*/ |
132 | 86 |
static AosIOChannel _stdiochannel; |
133 | 87 |
|
134 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
|
88 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
|
89 |
|
|
90 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
|
91 |
|
|
135 | 92 |
/** |
136 | 93 |
* @brief I/O shell channel for the programmer interface. |
137 | 94 |
*/ |
138 | 95 |
static AosShellChannel _stdshellchannel; |
139 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true)*/ |
|
96 |
|
|
140 | 97 |
#endif /* defined(MODULE_HAL_PROGIF) */ |
141 | 98 |
|
142 | 99 |
/* |
... | ... | |
167 | 124 |
return; |
168 | 125 |
} |
169 | 126 |
|
170 |
#if (SSSP_STAGE3_ENABLE == true) || defined(__DOXYGEN__) |
|
171 |
/** |
|
172 |
* @brief Callback function to be used during SSSP stack initialization sequence. |
|
173 |
* |
|
174 |
* @param[in] par A pointer to an @p event_source_t to be fired. |
|
175 |
*/ |
|
176 |
static void _ssspTimerCallback(void* par) |
|
177 |
{ |
|
178 |
aosDbgCheck(par != NULL); |
|
179 |
|
|
180 |
chSysLockFromISR(); |
|
181 |
chEvtBroadcastI((event_source_t*)par); |
|
182 |
chSysUnlockFromISR(); |
|
183 |
|
|
184 |
return; |
|
185 |
} |
|
186 |
#endif /* (SSSP_STAGE3_ENABLE == true) */ |
|
187 |
|
|
188 | 127 |
/** |
189 | 128 |
* @brief Helper function to serialize data. |
190 | 129 |
* |
... | ... | |
286 | 225 |
|
287 | 226 |
#endif /* (HAL_USE_RTC == TRUE) */ |
288 | 227 |
|
289 |
#if (SSSP_STAGE3_ENABLE) || defined(__DOXYGEN__) |
|
290 |
/** |
|
291 |
* @brief Implementation of the SSSP module stack initialization sequence (startup phase 3). |
|
292 |
* |
|
293 |
* @return Shutdown value. |
|
294 |
* @retval AOS_SHUTDOWN_NONE No shutdown signal received |
|
295 |
* @retval AOS_SHUTDOWN_PASSIVE Shutdown signal received. |
|
296 |
*/ |
|
297 |
aos_shutdown_t _ssspModuleStackInitialization(void) |
|
298 |
{ |
|
299 |
// local types |
|
300 |
/** |
|
301 |
* @brief States for the internal state machine to implement SSSP startup stage 3. |
|
302 |
*/ |
|
303 |
typedef enum { |
|
304 |
STAGE_3_1, /**< Initiation of SSSP startup stage 3. */ |
|
305 |
STAGE_3_2, /**< Starting the sequence and broadcasting the first ID. */ |
|
306 |
STAGE_3_3_WAITFORFIRSTID, /**< Waiting for first ID after initiation. */ |
|
307 |
STAGE_3_3_WAITFORIDORSIG, /**< Waiting for next ID or activation of neighbor signal. */ |
|
308 |
STAGE_3_3_WAITFORID, /**< Waiting for next ID (after the module has set its own ID). */ |
|
309 |
STAGE_3_4_FINISH, /**< Successful finish of stage 3. */ |
|
310 |
STAGE_3_4_ABORT_ACTIVE, /**< Aborting stage 3 (active). */ |
|
311 |
STAGE_3_4_ABORT, /**< Aborting stage 3 (passive). */ |
|
312 |
} sssp_modulestackinitstage_t; |
|
313 |
|
|
314 |
typedef struct { |
|
315 |
bool loop : 1; |
|
316 |
bool wfe : 1; |
|
317 |
bool wfe_next : 1; |
|
318 |
} flags_t; |
|
319 |
|
|
320 |
// local variables |
|
321 |
aos_shutdown_t shutdown = AOS_SHUTDOWN_NONE; |
|
322 |
sssp_modulestackinitstage_t stage = STAGE_3_1; |
|
323 |
eventmask_t eventmask = 0; |
|
324 |
eventflags_t ioflags = 0; |
|
325 |
event_source_t eventSourceTimeout; |
|
326 |
event_source_t eventSourceDelay; |
|
327 |
event_listener_t eventListenerTimeout; |
|
328 |
event_listener_t eventListenerDelay; |
|
329 |
event_listener_t eventListenerCan; |
|
330 |
virtual_timer_t timerTimeout; |
|
331 |
virtual_timer_t timerDelay; |
|
332 |
CANTxFrame canTxFrame; |
|
333 |
CANRxFrame canRxFrame; |
|
334 |
#if (AMIROOS_CFG_SSSP_STACK_START != true) || (AMIROOS_CFG_DBG == true) |
|
335 |
aos_ssspmoduleid_t lastid = 0; |
|
336 |
#endif /* (AMIROOS_CFG_SSSP_STACK_START != true) || (AMIROOS_CFG_DBG == true) */ |
|
337 |
flags_t flags; |
|
338 |
aos_timestamp_t uptime; |
|
339 |
|
|
340 |
// initialize local varibles |
|
341 |
chEvtObjectInit(&eventSourceTimeout); |
|
342 |
chEvtObjectInit(&eventSourceDelay); |
|
343 |
chVTObjectInit(&timerTimeout); |
|
344 |
chVTObjectInit(&timerDelay); |
|
345 |
canTxFrame.RTR = CAN_RTR_DATA; |
|
346 |
canTxFrame.IDE = CAN_IDE_STD; |
|
347 |
flags.loop = true; |
|
348 |
flags.wfe = false; // do not wait for events in the initial iteration of the FSM loop |
|
349 |
flags.wfe_next = true; |
|
350 |
|
|
351 |
// initialize system variables |
|
352 |
aos.sssp.stage = AOS_SSSP_STARTUP_3_1; |
|
353 |
aos.sssp.moduleId = 0; |
|
354 |
|
|
355 |
// listen to events (timout, delay, CAN receive) |
|
356 |
chEvtRegisterMask(&eventSourceTimeout, &eventListenerTimeout, TIMEOUTEVENT_MASK); |
|
357 |
chEvtRegisterMask(&eventSourceDelay, &eventListenerDelay, DELAYEVENT_MASK); |
|
358 |
chEvtRegisterMask(&MODULE_HAL_CAN.rxfull_event, &eventListenerCan, CANEVENT_MASK); |
|
359 |
|
|
360 |
/* |
|
361 |
* FSM in a loop. |
|
362 |
* |
|
363 |
* This is a fully event-based FSM for the module stack initialization |
|
364 |
* sequence, defined by SSSP as startup stage 3. There are five different |
|
365 |
* events that can occur at this point: |
|
366 |
* I/O events: The input level of an input pin has changed. Such events must |
|
367 |
* be handled differently depending on the current state. Most |
|
368 |
* of the time, however, such events can be ignored. |
|
369 |
* OS events: Such events are only available after this stage completed and |
|
370 |
* thus should never occur. However, there is an optional hook |
|
371 |
* to handle such events, nevertheless. |
|
372 |
* CAN events: At least one CAN message was received. Note that this event |
|
373 |
* will only fire again if all input buffers have been cleared. |
|
374 |
* timeouts: If some module does not support the sequence of there is any |
|
375 |
* issue, such a case is detected via timeouts and must be |
|
376 |
* handled accordingly (see abort state). In some cases, it is |
|
377 |
* possible that a timeout event occurres 'simultaneously' with |
|
378 |
* some other event. This can be caused by several timing issues |
|
379 |
* and is a valid situation. As a result, any other events |
|
380 |
* should be handled before the timeout event. If the other |
|
381 |
* events are expected and valid, this implementation requires |
|
382 |
* the timeout event flag to be cleared explicitely. Otherwise |
|
383 |
* it is evaluated at the end of each iteration of the loop. |
|
384 |
* delays: Depending on the current state, delays are required by SSSP |
|
385 |
* for timing of the sequential activation of signals. |
|
386 |
*/ |
|
387 |
aosDbgPrintf("SSSP stack initialization sequence:\n"); |
|
388 |
while (flags.loop) { |
|
389 |
#if (AMIROOS_CFG_DBG == true) |
|
390 |
switch (stage) { |
|
391 |
case STAGE_3_1: |
|
392 |
aosDbgPrintf(">>> 3-1\n"); |
|
393 |
break; |
|
394 |
case STAGE_3_2: |
|
395 |
aosDbgPrintf(">>> 3-2\n"); |
|
396 |
break; |
|
397 |
case STAGE_3_3_WAITFORFIRSTID: |
|
398 |
aosDbgPrintf(">>> 3-3 (1st ID)\n"); |
|
399 |
break; |
|
400 |
case STAGE_3_3_WAITFORIDORSIG: |
|
401 |
aosDbgPrintf(">>> 3-3 (ID/sig)\n"); |
|
402 |
break; |
|
403 |
case STAGE_3_3_WAITFORID: |
|
404 |
aosDbgPrintf(">>> 3-3 (ID)\n"); |
|
405 |
break; |
|
406 |
case STAGE_3_4_FINISH: |
|
407 |
aosDbgPrintf(">>> 3-4 (finish)\n"); |
|
408 |
break; |
|
409 |
case STAGE_3_4_ABORT_ACTIVE: |
|
410 |
aosDbgPrintf(">>> 3-4 (active abort)\n"); |
|
411 |
break; |
|
412 |
case STAGE_3_4_ABORT: |
|
413 |
aosDbgPrintf(">>> 3-4 (abort)\n"); |
|
414 |
break; |
|
415 |
} |
|
416 |
#endif /* (AMIROOS_CFG_DBG == true) */ |
|
417 |
|
|
418 |
// reset wfe flag for the next iteration |
|
419 |
flags.wfe_next = true; |
|
420 |
|
|
421 |
// waiting for events (may be skipped) |
|
422 |
if (flags.wfe) { |
|
423 |
// wait for any event to occur |
|
424 |
aosDbgPrintf("WFE..."); |
|
425 |
eventmask = chEvtWaitAnyTimeout(ALL_EVENTS, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT)); |
|
426 |
aosDbgPrintf("\t0x%08X", eventmask); |
|
427 |
} else { |
|
428 |
aosDbgPrintf("WFE skipped"); |
|
429 |
eventmask = 0; |
|
430 |
} |
|
431 |
aosSysGetUptime(&uptime); |
|
432 |
aosDbgPrintf("\t%04ums\n", (uint32_t)(uptime / MICROSECONDS_PER_MILLISECOND)); |
|
433 |
|
|
434 |
/* |
|
435 |
* execute some general tasks and high priority events |
|
436 |
*/ |
|
437 |
// no event occurred at all |
|
438 |
if ((flags.wfe) && (eventmask == 0)) { |
|
439 |
aosDbgPrintf("ERR: no evt\n"); |
|
440 |
// enforce timeout event |
|
441 |
chEvtBroadcast(&eventSourceTimeout); |
|
442 |
continue; |
|
443 |
} |
|
444 |
// if an IO event occurred |
|
445 |
if (eventmask & _eventListenerIO.events) { |
|
446 |
ioflags = chEvtGetAndClearFlags(&_eventListenerIO); |
|
447 |
aosDbgPrintf("INFO: IO evt (0x%08X)\n", ioflags); |
|
448 |
// a power-down event occurred |
|
449 |
if (ioflags & MODULE_SSSP_EVENTFLAGS_PD) { |
|
450 |
aosDbgPrintf("PD evt\n"); |
|
451 |
// deactivate S and UP |
|
452 |
aosDbgPrintf("disabling S\n"); |
|
453 |
apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF); |
|
454 |
#if (AMIROOS_CFG_SSSP_STACK_END != true) |
|
455 |
aosDbgPrintf("disabling UP\n"); |
|
456 |
apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_OFF); |
|
457 |
#endif /* (AMIROOS_CFG_SSSP_STACK_END != true) */ |
|
458 |
// set shutdown flag and exit the loop |
|
459 |
shutdown = AOS_SHUTDOWN_PASSIVE; |
|
460 |
break; |
|
461 |
} |
|
462 |
// the S signal was deactivated |
|
463 |
if (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC) { |
|
464 |
apalControlGpioState_t sstate; |
|
465 |
apalControlGpioGet(&moduleSsspGpioSync, &sstate); |
|
466 |
if (sstate == APAL_GPIO_ON) { |
|
467 |
aosDbgPrintf("S evt (enabled)\n"); |
|
468 |
} else { |
|
469 |
aosDbgPrintf("S evt (disabled)\n"); |
|
470 |
// either finish or abort |
|
471 |
if ((stage == STAGE_3_3_WAITFORID) && (aos.sssp.moduleId != 0)) { |
|
472 |
stage = STAGE_3_4_FINISH; |
|
473 |
} else if (stage != STAGE_3_4_ABORT) { |
|
474 |
stage = STAGE_3_4_ABORT_ACTIVE; |
|
475 |
} |
|
476 |
} |
|
477 |
} |
|
478 |
} |
|
479 |
// an OS event occurred |
|
480 |
if (eventmask & _eventListenerOS.events) { |
|
481 |
aosDbgPrintf("WARN: OS evt\n"); |
|
482 |
// get the flags |
|
483 |
eventflags_t oseventflags = chEvtGetAndClearFlags(&_eventListenerOS); |
|
484 |
// there should be no OS events at this point |
|
485 |
#if defined(MODULE_SSSP_STARTUP_3_OSEVENT_HOOK) |
|
486 |
MODULE_SSSP_STARTUP_3_OSEVENT_HOOK(eventmask, eventflags); |
|
487 |
#else /* defined(MODULE_SSSP_STARTUP_3_OSEVENT_HOOK) */ |
|
488 |
_unexpectedEventError(eventmask, oseventflags); |
|
489 |
#endif /* defined(MODULE_SSSP_STARTUP_3_OSEVENT_HOOK) */ |
|
490 |
} |
|
491 |
// if a CAN event occurred |
|
492 |
if ((eventmask & eventListenerCan.events)) { |
|
493 |
aosDbgPrintf("CAN evt\n"); |
|
494 |
// fetch message |
|
495 |
if (flags.wfe) { |
|
496 |
canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canRxFrame, TIME_IMMEDIATE); |
|
497 |
aosDbgPrintf("CAN <- 0x%03X\n", canRxFrame.SID); |
|
498 |
} |
|
499 |
// identify and handle abort messgaes |
|
500 |
if (canRxFrame.SID == SSSP_STACKINIT_CANMSGID_ABORT) { |
|
501 |
stage = STAGE_3_4_ABORT; |
|
502 |
} |
|
503 |
// warn if a unexpected message was received |
|
504 |
else if ((canRxFrame.SID != SSSP_STACKINIT_CANMSGID_INIT) && |
|
505 |
(canRxFrame.SID != SSSP_STACKINIT_CANMSGID_MODULEID)) { |
|
506 |
aosDbgPrintf("WARN: unknown msg\n"); |
|
507 |
} |
|
508 |
// any further pending messages are fetched at the end of the loop |
|
509 |
} |
|
510 |
// if a timeout event occurred |
|
511 |
if (eventmask & eventListenerTimeout.events) { |
|
512 |
aosDbgPrintf("timeout evt\n"); |
|
513 |
// is handled at the end of the loop (or must be cleared by FSM) |
|
514 |
} |
|
515 |
// if a delay event occurred |
|
516 |
if (eventmask & eventListenerDelay.events) { |
|
517 |
aosDbgPrintf("delay evt\n"); |
|
518 |
// is handled by FSM |
|
519 |
} |
|
520 |
|
|
521 |
/* |
|
522 |
* this is the actual FSM |
|
523 |
*/ |
|
524 |
switch (stage) { |
|
525 |
case STAGE_3_1: |
|
526 |
{ |
|
527 |
aos.sssp.stage = AOS_SSSP_STARTUP_3_1; |
|
528 |
|
|
529 |
// there was no event at all (skipped wfe) |
|
530 |
if (eventmask == 0 && flags.wfe == false) { |
|
531 |
#if (AMIROOS_CFG_SSSP_MASTER == true) |
|
532 |
// initialize the stage by transmitting an according CAN message |
|
533 |
aosDbgPrintf("CAN -> init\n"); |
|
534 |
canTxFrame.DLC = 0; |
|
535 |
canTxFrame.SID = SSSP_STACKINIT_CANMSGID_INIT; |
|
536 |
if (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_IMMEDIATE) != MSG_OK) { |
|
537 |
chEvtBroadcast(&eventSourceTimeout); |
|
538 |
break; |
|
539 |
} |
|
540 |
// activate S |
|
541 |
aosDbgPrintf("enabling S\n"); |
|
542 |
apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_ON); |
|
543 |
#if (AMIROOS_CFG_SSSP_STACK_START == true) |
|
544 |
// proceed immediately |
|
545 |
stage = STAGE_3_2; |
|
546 |
flags.wfe_next = false; |
|
547 |
#else /* (AMIROOS_CFG_SSSP_STACK_START == true) */ |
|
548 |
// set the timeout timer |
|
549 |
chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout); |
|
550 |
// proceed |
|
551 |
stage = STAGE_3_3_WAITFORFIRSTID; |
|
552 |
#endif /* (AMIROOS_CFG_SSSP_STACK_START == true) */ |
|
553 |
#else /* (AMIROOS_CFG_SSSP_MASTER == true) */ |
|
554 |
// set the timeout timer |
|
555 |
chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout); |
|
556 |
#endif /* (AMIROOS_CFG_SSSP_MASTER == true) */ |
|
557 |
} |
|
558 |
|
|
559 |
#if (AMIROOS_CFG_SSSP_MASTER != true) |
|
560 |
// a CAN message was received |
|
561 |
else if (eventmask & eventListenerCan.events) { |
|
562 |
// if an initiation message was received |
|
563 |
if (canRxFrame.DLC == 0 && |
|
564 |
canRxFrame.RTR == CAN_RTR_DATA && |
|
565 |
canRxFrame.IDE == CAN_IDE_STD && |
|
566 |
canRxFrame.SID == SSSP_STACKINIT_CANMSGID_INIT) { |
|
567 |
aosDbgPrintf("init msg\n"); |
|
568 |
// reset the timeout timer and clear pending flags |
|
569 |
chVTReset(&timerTimeout); |
|
570 |
chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE); |
|
571 |
eventmask &= ~(eventListenerTimeout.events); |
|
572 |
// activate S |
|
573 |
aosDbgPrintf("enabling S\n"); |
|
574 |
apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_ON); |
|
575 |
#if (AMIROOS_CFG_SSSP_STACK_START == true) |
|
576 |
// proceed |
|
577 |
stage = STAGE_3_2; |
|
578 |
flags.wfe_next = false; |
|
579 |
#else /* (AMIROOS_CFG_SSSP_STACK_START == true) */ |
|
580 |
// set the timeout timer |
|
581 |
chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout); |
|
582 |
// proceed |
|
583 |
stage = STAGE_3_3_WAITFORFIRSTID; |
|
584 |
#endif /* (AMIROOS_CFG_SSSP_STACK_START == true) */ |
|
585 |
} |
|
586 |
} |
|
587 |
#endif /* (AMIROOS_CFG_SSSP_MASTER != true) */ |
|
588 |
|
|
589 |
break; |
|
590 |
} /* end of STAGE_3_1 */ |
|
591 |
|
|
592 |
case STAGE_3_2: |
|
593 |
{ |
|
594 |
#if (AMIROOS_CFG_SSSP_STACK_START == true) |
|
595 |
aos.sssp.stage = AOS_SSSP_STARTUP_3_2; |
|
596 |
|
|
597 |
// if this stage was just entered |
|
598 |
if (flags.wfe == false) { |
|
599 |
// set the module ID |
|
600 |
aos.sssp.moduleId = 1; |
|
601 |
// broadcast module ID |
|
602 |
aosDbgPrintf("CAN -> ID (%u)\n", aos.sssp.moduleId); |
|
603 |
canTxFrame.DLC = 4; |
|
604 |
canTxFrame.SID = SSSP_STACKINIT_CANMSGID_MODULEID; |
|
605 |
_serialize(canTxFrame.data8, aos.sssp.moduleId, 4); |
|
606 |
if (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_IMMEDIATE) != MSG_OK) { |
|
607 |
chEvtBroadcast(&eventSourceTimeout); |
|
608 |
break; |
|
609 |
} |
|
610 |
#if (AMIROOS_CFG_DBG == true) |
|
611 |
lastid = aos.sssp.moduleId; |
|
612 |
#endif /* (AMIROOS_CFG_DBG == true) */ |
|
613 |
#if (AMIROOS_CFG_SSSP_STACK_END == true) |
|
614 |
// sequence is already over |
|
615 |
// deactivate S |
|
616 |
aosDbgPrintf("disabling S\n"); |
|
617 |
apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF); |
|
618 |
// proceed |
|
619 |
stage = STAGE_3_3_WAITFORID; |
|
620 |
#else /* (AMIROOS_CFG_SSSP_STACK_END == true) */ |
|
621 |
// set the delay timer so the UP signal is activated later |
|
622 |
chVTSet(&timerDelay, chTimeUS2I(AMIROOS_CFG_SSSP_SIGNALDELAY), _ssspTimerCallback, &eventSourceDelay); |
|
623 |
#endif /* (AMIROOS_CFG_SSSP_STACK_END == true) */ |
|
624 |
} |
|
625 |
|
|
626 |
// if a delay event occurred |
|
627 |
if (eventmask & eventListenerDelay.events) { |
|
628 |
// activate UP |
|
629 |
aosDbgPrintf("enabling UP\n"); |
|
630 |
apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_ON); |
|
631 |
// deactivate S |
|
632 |
aosDbgPrintf("disabling S\n"); |
|
633 |
apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF); |
|
634 |
// explicitely clear timeout event flag |
|
635 |
chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE); |
|
636 |
eventmask &= ~(eventListenerTimeout.events); |
|
637 |
// proceed |
|
638 |
stage = STAGE_3_3_WAITFORID; |
|
639 |
} |
|
640 |
#endif /* (AMIROOS_CFG_SSSP_STACK_START == true) */ |
|
641 |
|
|
642 |
break; |
|
643 |
} /* end of STAGE_3_2 */ |
|
644 |
|
|
645 |
case STAGE_3_3_WAITFORFIRSTID: |
|
646 |
{ |
|
647 |
#if (AMIROOS_CFG_SSSP_STACK_START != true) |
|
648 |
aos.sssp.stage = AOS_SSSP_STARTUP_3_3; |
|
649 |
|
|
650 |
// a CAN message was received |
|
651 |
if (eventmask & eventListenerCan.events) { |
|
652 |
// if an ID message was received |
|
653 |
if (canRxFrame.DLC == 4 && |
|
654 |
canRxFrame.RTR == CAN_RTR_DATA && |
|
655 |
canRxFrame.IDE == CAN_IDE_STD && |
|
656 |
canRxFrame.SID == SSSP_STACKINIT_CANMSGID_MODULEID) { |
|
657 |
aosDbgPrintf("ID (%u)\n", (uint32_t)_deserialize(canRxFrame.data8, 4)); |
|
658 |
// validate received ID |
|
659 |
if (lastid < _deserialize(canRxFrame.data8, 4)) { |
|
660 |
// store received ID |
|
661 |
lastid = _deserialize(canRxFrame.data8, 4); |
|
662 |
// restart timeout timer |
|
663 |
chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout); |
|
664 |
// proceed |
|
665 |
stage = STAGE_3_3_WAITFORIDORSIG; |
|
666 |
} else { |
|
667 |
aosDbgPrintf("ERR: invalid ID\n"); |
|
668 |
// abort |
|
669 |
stage = STAGE_3_4_ABORT_ACTIVE; |
|
670 |
flags.wfe_next = false; |
|
671 |
} |
|
672 |
// explicitely clear timeout event flag |
|
673 |
chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE); |
|
674 |
eventmask &= ~(eventListenerTimeout.events); |
|
675 |
} |
|
676 |
} |
|
677 |
#endif /* (AMIROOS_CFG_SSSP_STACK_START != true) */ |
|
678 |
break; |
|
679 |
} /* end of STAGE_3_3_WAITFORFIRSTID */ |
|
680 |
|
|
681 |
case STAGE_3_3_WAITFORIDORSIG: |
|
682 |
{ |
|
683 |
#if (AMIROOS_CFG_SSSP_STACK_START != true) |
|
684 |
aos.sssp.stage = AOS_SSSP_STARTUP_3_3; |
|
685 |
|
|
686 |
// a CAN message was received |
|
687 |
if (eventmask & eventListenerCan.events) { |
|
688 |
// if an ID message was received |
|
689 |
if (canRxFrame.DLC == 4 && |
|
690 |
canRxFrame.RTR == CAN_RTR_DATA && |
|
691 |
canRxFrame.IDE == CAN_IDE_STD && |
|
692 |
canRxFrame.SID == SSSP_STACKINIT_CANMSGID_MODULEID) { |
|
693 |
aosDbgPrintf("ID (%u)\n", (uint32_t)_deserialize(canRxFrame.data8, 4)); |
|
694 |
// validate received ID |
|
695 |
if (lastid < _deserialize(canRxFrame.data8, 4)) { |
|
696 |
// store received ID |
|
697 |
lastid = _deserialize(canRxFrame.data8, 4); |
|
698 |
// restart timeout timer |
|
699 |
chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout); |
|
700 |
} else { |
|
701 |
aosDbgPrintf("ERR: invalid ID\n"); |
|
702 |
// abort |
|
703 |
stage = STAGE_3_4_ABORT_ACTIVE; |
|
704 |
flags.wfe_next = false; |
|
705 |
} |
|
706 |
// explicitely clear timeout event flag |
|
707 |
chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE); |
|
708 |
eventmask &= ~(eventListenerTimeout.events); |
|
709 |
} |
|
710 |
} |
|
711 |
|
|
712 |
// if an IO event was received (DN signal) |
|
713 |
if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_DN)) { |
|
714 |
aosDbgPrintf("DN evt\n"); |
|
715 |
// reset timeout timer |
|
716 |
chVTReset(&timerTimeout); |
|
717 |
chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE); |
|
718 |
eventmask &= ~(eventListenerTimeout.events); |
|
719 |
// increment and broadcast ID |
|
720 |
aos.sssp.moduleId = lastid + 1; |
|
721 |
aosDbgPrintf("CAN -> ID (%u)\n", aos.sssp.moduleId); |
|
722 |
canTxFrame.DLC = 4; |
|
723 |
canTxFrame.SID = SSSP_STACKINIT_CANMSGID_MODULEID; |
|
724 |
_serialize(canTxFrame.data8, aos.sssp.moduleId, 4); |
|
725 |
if (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_IMMEDIATE) != MSG_OK) { |
|
726 |
chEvtBroadcast(&eventSourceTimeout); |
|
727 |
break; |
|
728 |
} |
|
729 |
// set delay timer |
|
730 |
chVTSet(&timerDelay, chTimeUS2I(AMIROOS_CFG_SSSP_SIGNALDELAY), _ssspTimerCallback, &eventSourceDelay); |
|
731 |
} |
|
732 |
|
|
733 |
// if a delay event occurred |
|
734 |
if (eventmask & eventListenerDelay.events) { |
|
735 |
#if (AMIROOS_CFG_SSSP_STACK_END != true) |
|
736 |
// activate UP |
|
737 |
aosDbgPrintf("enabling UP\n"); |
|
738 |
apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_ON); |
|
739 |
#endif /* (AMIROOS_CFG_SSSP_STACK_END != true) */ |
|
740 |
// deactivate S |
|
741 |
aosDbgPrintf("disabling S\n"); |
|
742 |
apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF); |
|
743 |
// reset the timeout timer |
|
744 |
chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout); |
|
745 |
chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE); |
|
746 |
eventmask &= ~(eventListenerTimeout.events); |
|
747 |
// proceed |
|
748 |
stage = STAGE_3_3_WAITFORID; |
|
749 |
} |
|
750 |
#endif /* (AMIROOS_CFG_SSSP_STACK_START != true) */ |
|
751 |
|
|
752 |
break; |
|
753 |
} /* end of STAGE_3_3_WAITFORIDORSIG */ |
|
754 |
|
|
755 |
case STAGE_3_3_WAITFORID: |
|
756 |
{ |
|
757 |
aos.sssp.stage = AOS_SSSP_STARTUP_3_3; |
|
758 |
|
|
759 |
#if (AMIROOS_CFG_SSSP_STACK_END != true) |
|
760 |
// a CAN message was received |
|
761 |
if (eventmask & eventListenerCan.events) { |
|
762 |
// if an ID message was received |
|
763 |
if (canRxFrame.DLC == 4 && |
|
764 |
canRxFrame.RTR == CAN_RTR_DATA && |
|
765 |
canRxFrame.IDE == CAN_IDE_STD && |
|
766 |
canRxFrame.SID == SSSP_STACKINIT_CANMSGID_MODULEID) { |
|
767 |
#if (AMIROOS_CFG_SSSP_STACK_START != true) || (AMIROOS_CFG_DBG == true) |
|
768 |
// Plausibility of the received ID is not checked at this point but is done by other modules still in a previous stage. |
|
769 |
lastid = _deserialize(canRxFrame.data8, 4); |
|
770 |
aosDbgPrintf("ID (%u)\n", lastid); |
|
771 |
#endif /* (AMIROOS_CFG_SSSP_STACK_START != true) || (AMIROOS_CFG_DBG == true) */ |
|
772 |
// restart timeout timer |
|
773 |
chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout); |
|
774 |
chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE); |
|
775 |
eventmask &= ~(eventListenerTimeout.events); |
|
776 |
} |
|
777 |
} |
|
778 |
#endif /* (AMIROOS_CFG_SSSP_STACK_END != true) */ |
|
779 |
|
|
780 |
break; |
|
781 |
} /* end of STAGE_3_3_WAITFORID */ |
|
782 |
|
|
783 |
case STAGE_3_4_FINISH: |
|
784 |
{ |
|
785 |
aos.sssp.stage = AOS_SSSP_STARTUP_3_4; |
|
786 |
|
|
787 |
// if an IO event was received (S signal) |
|
788 |
if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC)) { |
|
789 |
// reset the timeout timer |
|
790 |
chVTReset(&timerTimeout); |
|
791 |
chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE); |
|
792 |
eventmask &= ~(eventListenerTimeout.events); |
|
793 |
//set the delay timer |
|
794 |
chVTSet(&timerDelay, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceDelay); |
|
795 |
} |
|
796 |
|
|
797 |
// if a CAN event was received |
|
798 |
if (eventmask & eventListenerCan.events) { |
|
799 |
// if an abort message was received |
|
800 |
if (canRxFrame.SID == SSSP_STACKINIT_CANMSGID_ABORT) { |
|
801 |
aosDbgPrintf("abort msg\n"); |
|
802 |
// reset the delay timer |
|
803 |
chVTReset(&timerDelay); |
|
804 |
chEvtWaitAnyTimeout(eventListenerDelay.events, TIME_IMMEDIATE); |
|
805 |
eventmask &= ~(eventListenerDelay.events); |
|
806 |
// proceed |
|
807 |
stage = STAGE_3_4_ABORT; |
|
808 |
} |
|
809 |
} |
|
810 |
|
|
811 |
// if a delay timer event occurred |
|
812 |
if (eventmask & eventListenerDelay.events) { |
|
813 |
aosDbgPrintf("sequence sucessful\n"); |
|
814 |
// sequence finished sucessfully |
|
815 |
flags.loop = false; |
|
816 |
} |
|
817 |
|
|
818 |
break; |
|
819 |
} /* end of STAGE_3_4_FINISH */ |
|
820 |
|
|
821 |
case STAGE_3_4_ABORT_ACTIVE: |
|
822 |
{ |
|
823 |
aos.sssp.stage = AOS_SSSP_STARTUP_3_4; |
|
824 |
|
|
825 |
// emit abort message |
|
826 |
canTxFrame.DLC = 0; |
|
827 |
canTxFrame.SID = SSSP_STACKINIT_CANMSGID_ABORT; |
|
828 |
canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canTxFrame, TIME_INFINITE); |
|
829 |
aosDbgPrintf("CAN -> abort\n"); |
|
830 |
// clear timeout flag |
|
831 |
eventmask &= ~(eventListenerTimeout.events); |
|
832 |
// proceed immediately |
|
833 |
stage = STAGE_3_4_ABORT; |
|
834 |
flags.wfe_next = false; |
|
835 |
break; |
|
836 |
} /* end of STAGE_3_4_ABORT_ACTIVE */ |
|
837 |
|
|
838 |
case STAGE_3_4_ABORT: |
|
839 |
{ |
|
840 |
aos.sssp.stage = AOS_SSSP_STARTUP_3_4; |
|
841 |
|
|
842 |
// deactivate S |
|
843 |
aosDbgPrintf("disabling SYNC\n"); |
|
844 |
apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF); |
|
845 |
// invalidate module ID |
|
846 |
aos.sssp.moduleId = 0; |
|
847 |
|
|
848 |
// if an IO event was received (S signal) |
|
849 |
if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC)) { |
|
850 |
aosDbgPrintf("sequence aborted\n"); |
|
851 |
// exit the sequence |
|
852 |
flags.loop = false; |
|
853 |
} |
|
854 |
|
|
855 |
break; |
|
856 |
} /* end of STAGE_3_4_ABORT */ |
|
857 |
} /* end of switch(stage) */ |
|
858 |
|
|
859 |
// fetch pending CAN message (if any) |
|
860 |
if ((eventmask & eventListenerCan.events) && (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canRxFrame, TIME_IMMEDIATE) == MSG_OK)) { |
|
861 |
aosDbgPrintf("CAN <- 0x%03X\n", canRxFrame.SID); |
|
862 |
flags.wfe_next = false; |
Also available in: Unified diff