Revision b309b751
amiroos.h | ||
---|---|---|
1 |
/* |
|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
3 |
Copyright (C) 2016..2018 Thomas Schöpping et al. |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU General Public License as published by |
|
7 |
the Free Software Foundation, either version 3 of the License, or |
|
8 |
(at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU General Public License |
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
|
|
19 |
#ifndef _AMIROOS_H_ |
|
20 |
#define _AMIROOS_H_ |
|
21 |
|
|
22 |
/** |
|
23 |
* @brief AMiRo-OS identification macro. |
|
24 |
*/ |
|
25 |
#define _AMIRO_OS_ |
|
26 |
|
|
27 |
/** |
|
28 |
* @name AMiRo-OS version and relase information. |
|
29 |
* @{ |
|
30 |
*/ |
|
31 |
|
|
32 |
/** |
|
33 |
* @brief The type of this version. |
|
34 |
* @note Is one of "pre-alpha", "alpha", "beta", "release candidate", "release". |
|
35 |
*/ |
|
36 |
#define AMIROOS_RELEASE_TYPE "beta" |
|
37 |
|
|
38 |
/** |
|
39 |
* @brief The operating system major version. |
|
40 |
* @note Changes of the major version imply incompatibilities. |
|
41 |
*/ |
|
42 |
#define AMIROOS_VERSION_MAJOR 2 |
|
43 |
|
|
44 |
/** |
|
45 |
* @brief The operating system minor version. |
|
46 |
* @note A higher minor version implies new functionalty, but all old interfaces are still available. |
|
47 |
*/ |
|
48 |
#define AMIROOS_VERSION_MINOR 0 |
|
49 |
|
|
50 |
/** |
|
51 |
* @brief The operating system patch level. |
|
52 |
*/ |
|
53 |
#define AMIROOS_VERSION_PATCH 0 |
|
54 |
|
|
55 |
/** @} */ |
|
56 |
|
|
57 |
/* subsystems headers */ |
|
58 |
#include <aosconf.h> |
|
59 |
#include <hal.h> |
|
60 |
#if defined(HAL_USE_QEI) && (HAL_USE_QEI == TRUE) |
|
61 |
#include <hal_qei.h> |
|
62 |
#endif |
|
63 |
#include <ch.h> |
|
64 |
|
|
65 |
/* configuration check */ |
|
66 |
#if !defined(_AMIRO_OS_CFG_) |
|
67 |
#error "invalid AMiRo-OS configuration file" |
|
68 |
#endif |
|
69 |
#if (_AMIRO_OS_CFG_VERSION_MAJOR_ != AMIROOS_VERSION_MAJOR) || (_AMIRO_OS_CFG_VERSION_MINOR_ < AMIROOS_VERSION_MINOR) |
|
70 |
#error "incompatible AMiRo-OS configuration file" |
|
71 |
#endif |
|
72 |
#include "core/inc/aos_confcheck.h" |
|
73 |
|
|
74 |
/* core headers */ |
|
75 |
#include "core/inc/aos_debug.h" |
|
76 |
#include <core/inc/aos_iostream.h> |
|
77 |
#include "core/inc/aos_shell.h" |
|
78 |
#include "core/inc/aos_system.h" |
|
79 |
#include "core/inc/aos_thread.h" |
|
80 |
#include "core/inc/aos_time.h" |
|
81 |
#include "core/inc/aos_timer.h" |
|
82 |
#include "core/inc/aos_types.h" |
|
83 |
#include "core/inc/aos_unittest.h" |
|
84 |
|
|
85 |
#endif /* _AMIROOS_H_ */ |
core/core.mk | ||
---|---|---|
1 |
################################################################################ |
|
2 |
# AMiRo-OS is an operating system designed for the Autonomous Mini Robot # |
|
3 |
# (AMiRo) platform. # |
|
4 |
# Copyright (C) 2016..2018 Thomas Schöpping et al. # |
|
5 |
# # |
|
6 |
# This program is free software: you can redistribute it and/or modify # |
|
7 |
# it under the terms of the GNU General Public License as published by # |
|
8 |
# the Free Software Foundation, either version 3 of the License, or # |
|
9 |
# (at your option) any later version. # |
|
10 |
# # |
|
11 |
# This program is distributed in the hope that it will be useful, # |
|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
|
14 |
# GNU General Public License for more details. # |
|
15 |
# # |
|
16 |
# You should have received a copy of the GNU General Public License # |
|
17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
|
18 |
# # |
|
19 |
# This research/work was supported by the Cluster of Excellence Cognitive # |
|
20 |
# Interaction Technology 'CITEC' (EXC 277) at Bielefeld University, which is # |
|
21 |
# funded by the German Research Foundation (DFG). # |
|
22 |
################################################################################ |
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
# absolute path to this directory |
|
27 |
AMIROOS_CORE_DIR := $(dir $(lastword $(MAKEFILE_LIST))) |
|
28 |
|
|
29 |
# include paths |
|
30 |
AMIROOSCOREINC = $(AMIROOS_CORE_DIR)inc |
|
31 |
|
|
32 |
# C source files |
|
33 |
AMIROOSCORECSRC = $(AMIROOS_CORE_DIR)src/aos_debug.c \ |
|
34 |
$(AMIROOS_CORE_DIR)src/aos_iostream.c \ |
|
35 |
$(AMIROOS_CORE_DIR)src/aos_shell.c \ |
|
36 |
$(AMIROOS_CORE_DIR)src/aos_system.c \ |
|
37 |
$(AMIROOS_CORE_DIR)src/aos_thread.c \ |
|
38 |
$(AMIROOS_CORE_DIR)src/aos_time.c \ |
|
39 |
$(AMIROOS_CORE_DIR)src/aos_timer.c \ |
|
40 |
$(AMIROOS_CORE_DIR)src/aos_unittest.c |
|
41 |
|
|
42 |
# C++ source files |
|
43 |
AMIROOSCORECPPSRC = $(AMIROOS_CORE_DIR)src/aos_main.cpp |
|
44 |
|
core/inc/aos_confcheck.h | ||
---|---|---|
1 |
/* |
|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
3 |
Copyright (C) 2016..2018 Thomas Schöpping et al. |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU General Public License as published by |
|
7 |
the Free Software Foundation, either version 3 of the License, or |
|
8 |
(at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU General Public License |
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
|
|
19 |
/** |
|
20 |
* @file aos_confcheck.h |
|
21 |
* @brief Header that checks whether all necessary configurations are correct. |
|
22 |
* |
|
23 |
* @addtogroup aos_system |
|
24 |
* @{ |
|
25 |
*/ |
|
26 |
|
|
27 |
#ifndef _AMIROOS_CONFCHECK_H_ |
|
28 |
#define _AMIROOS_CONFCHECK_H_ |
|
29 |
|
|
30 |
#include <aosconf.h> |
|
31 |
|
|
32 |
/* |
|
33 |
* Kernel parameters and options |
|
34 |
*/ |
|
35 |
|
|
36 |
#ifndef AMIROOS_CFG_DBG |
|
37 |
#error "AMIROOS_CFG_DBG not defined in aosconf.h" |
|
38 |
#endif |
|
39 |
|
|
40 |
#ifndef AMIROOS_CFG_TESTS_ENABLE |
|
41 |
#error "AMIROOS_CFG_TESTS_ENABLE not defined in aosconf.h" |
|
42 |
#endif |
|
43 |
|
|
44 |
#ifndef AMIROOS_CFG_PROFILE |
|
45 |
#error "AMIROOS_CFG_PROFILE not defined in aosconf.h" |
|
46 |
#endif |
|
47 |
|
|
48 |
#ifndef AMIROOS_CFG_MAIN_LOOP_TIMEOUT |
|
49 |
#error "AMIROOS_CFG_MAIN_LOOP_TIMEOUT not defined in aosconf.h" |
|
50 |
#endif |
|
51 |
|
|
52 |
/* |
|
53 |
* SSSP parameters and options |
|
54 |
*/ |
|
55 |
|
|
56 |
#ifndef AMIROOS_CFG_SSSP_MASTER |
|
57 |
#error "AMIROOS_CFG_SSSP_MASTER not defined in aosconf.h" |
|
58 |
#endif |
|
59 |
|
|
60 |
#ifndef AMIROOS_CFG_SSSP_STACK_START |
|
61 |
#error "AMIROOS_CFG_SSSP_STACK_START not defined in aosconf.h" |
|
62 |
#endif |
|
63 |
|
|
64 |
#ifndef AMIROOS_CFG_SSSP_STACK_END |
|
65 |
#error "AMIROOS_CFG_SSSP_STACK_END not defined in aosconf.h" |
|
66 |
#endif |
|
67 |
|
|
68 |
#if (AMIROOS_CFG_SSSP_STACK_START == true) && (AMIROOS_CFG_SSSP_STACK_END == true) |
|
69 |
#warning "AMIROOS_CFG_SSSP_STACK_START and AMIROOS_CFG_SSSP_STACK_END both enabled in aosconf.h" |
|
70 |
#if (AMIROOS_CFG_SSSP_MASTER != true) |
|
71 |
#error "AMIROOS_CFG_SSSP_MASTER must be enabled in this case" |
|
72 |
#endif |
|
73 |
#endif |
|
74 |
|
|
75 |
#ifndef AMIROOS_CFG_SSSP_SIGNALDELAY |
|
76 |
#error "AMIROOS_CFG_SSSP_SIGNALDELAY not defined in aosconf.h" |
|
77 |
#endif |
|
78 |
|
|
79 |
#ifndef AMIROOS_CFG_SSSP_SYSSYNCPERIOD |
|
80 |
#error "AMIROOS_CFG_SSSP_SYSSYNCPERIOD not defined in aosconf.h" |
|
81 |
#endif |
|
82 |
|
|
83 |
/* |
|
84 |
* System shell options |
|
85 |
*/ |
|
86 |
|
|
87 |
#ifndef AMIROOS_CFG_SHELL_ENABLE |
|
88 |
#error "AMIROOS_CFG_SHELL_ENABLE not defined in aosconf.h" |
|
89 |
#endif |
|
90 |
|
|
91 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) |
|
92 |
|
|
93 |
#ifndef AMIROOS_CFG_SHELL_STACKSIZE |
|
94 |
#error "AMIROOS_CFG_SHELL_STACKSIZE not defined in aosconf.h" |
|
95 |
#endif |
|
96 |
|
|
97 |
#ifndef AMIROOS_CFG_SHELL_THREADPRIO |
|
98 |
#error "AMIROOS_CFG_SHELL_THREADPRIO not defined in aosconf.h" |
|
99 |
#endif |
|
100 |
|
|
101 |
#ifndef AMIROOS_CFG_SHELL_LINEWIDTH |
|
102 |
#error "AMIROOS_CFG_SHELL_LINEWIDTH not defined in aosconf.h" |
|
103 |
#endif |
|
104 |
|
|
105 |
#ifndef AMIROOS_CFG_SHELL_MAXARGS |
|
106 |
#error "AMIROOS_CFG_SHELL_MAXARGS not defined in aosconf.h" |
|
107 |
#endif |
|
108 |
|
|
109 |
#endif /* AMIROOS_CFG_SHELL_ENABLE == true */ |
|
110 |
|
|
111 |
#endif /* _AMIROOS_CONFCHECK_H_ */ |
|
112 |
|
|
113 |
/** @} */ |
core/inc/aos_debug.h | ||
---|---|---|
1 |
/* |
|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
3 |
Copyright (C) 2016..2018 Thomas Schöpping et al. |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU General Public License as published by |
|
7 |
the Free Software Foundation, either version 3 of the License, or |
|
8 |
(at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU General Public License |
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
|
|
19 |
/** |
|
20 |
* @file aos_debug.h |
|
21 |
* @brief Macros used for debugging. |
|
22 |
* |
|
23 |
* @addtogroup aos_debug |
|
24 |
* @{ |
|
25 |
*/ |
|
26 |
|
|
27 |
#ifndef _AMIROOS_DEBUG_H_ |
|
28 |
#define _AMIROOS_DEBUG_H_ |
|
29 |
|
|
30 |
#include <aosconf.h> |
|
31 |
#include <ch.h> |
|
32 |
|
|
33 |
#if (AMIROOS_CFG_DBG == true) || defined(__DOXYGEN__) |
|
34 |
|
|
35 |
/** |
|
36 |
* @brief Function parameters check. |
|
37 |
* @details If the condition check fails, the kernel panics and halts. |
|
38 |
* |
|
39 |
* @param[in] c The condition to be verified to be true. |
|
40 |
*/ |
|
41 |
#define aosDbgCheck(c) chDbgCheck(c) |
|
42 |
|
|
43 |
/** |
|
44 |
* @brief Condition assertion. |
|
45 |
* @details If the condition check fails, the kernel panics with a message and halts. |
|
46 |
* @note As a limitation of ChibiOS, the remark string is not currently used. |
|
47 |
* |
|
48 |
* @param[in] c The condition to be verified to be true. |
|
49 |
*/ |
|
50 |
#define aosDbgAssert(c) chDbgAssert(c, "__FILE__(__LINE__): aosDbgAssert failed") |
|
51 |
|
|
52 |
/** |
|
53 |
* @brief Condition assertion. |
|
54 |
* @details If the condition check fails, the kernel panics with a message and halts. |
|
55 |
* @note As a limitation of ChibiOS, the remark string is not currently used. |
|
56 |
* |
|
57 |
* @param[in] c The condition to be verified to be true. |
|
58 |
* @param[in] r A custom remark string. |
|
59 |
*/ |
|
60 |
#define aosDbgAssertMsg(c, r) { \ |
|
61 |
(void)r; \ |
|
62 |
chDbgAssert(c, r); \ |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* @brief Printf function for messages only printed in debug builds. |
|
67 |
* |
|
68 |
* @param[in] fmt Formatted string to print. |
|
69 |
*/ |
|
70 |
#define aosDbgPrintf(fmt, ...) chprintf((BaseSequentialStream*)&aos.iostream, fmt, ##__VA_ARGS__) |
|
71 |
|
|
72 |
#else /* (AMIROOS_CFG_DBG != true) */ |
|
73 |
|
|
74 |
#define aosDbgCheck(c) { \ |
|
75 |
(void)(c); \ |
|
76 |
} |
|
77 |
|
|
78 |
#define aosDbgAssert(c) { \ |
|
79 |
(void)(c); \ |
|
80 |
} |
|
81 |
|
|
82 |
#define aosDbgAssertMsg(c, r) { \ |
|
83 |
(void)(c); \ |
|
84 |
(void)(r); \ |
|
85 |
} |
|
86 |
|
|
87 |
#define aosDbgPrintf(fmt, ...) { \ |
|
88 |
(void)(fmt); \ |
|
89 |
} |
|
90 |
|
|
91 |
#endif |
|
92 |
|
|
93 |
#ifdef __cplusplus |
|
94 |
extern "C" { |
|
95 |
#endif |
|
96 |
void aosPrintHaltErrorCode(const char* reason); |
|
97 |
#ifdef __cplusplus |
|
98 |
} |
|
99 |
#endif |
|
100 |
|
|
101 |
#endif /* _AMIROOS_DEBUG_H_ */ |
|
102 |
|
|
103 |
/** @} */ |
core/inc/aos_iostream.h | ||
---|---|---|
1 |
/* |
|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
3 |
Copyright (C) 2016..2018 Thomas Schöpping et al. |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU General Public License as published by |
|
7 |
the Free Software Foundation, either version 3 of the License, or |
|
8 |
(at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU General Public License |
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
|
|
19 |
/** |
|
20 |
* @file aos_iostream.h |
|
21 |
* @brief Stream and channel macros and structures. |
|
22 |
* |
|
23 |
* @addtogroup aos_stream |
|
24 |
* @{ |
|
25 |
*/ |
|
26 |
|
|
27 |
#ifndef _AMIROOS_IOSTREAM_H_ |
|
28 |
#define _AMIROOS_IOSTREAM_H_ |
|
29 |
|
|
30 |
#include <hal.h> |
|
31 |
#include <aos_types.h> |
|
32 |
#include <stdarg.h> |
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
/** |
|
37 |
* @brief Channel flag to indicate whether the channel is attached to a stream. |
|
38 |
*/ |
|
39 |
#define AOS_IOCHANNEL_ATTACHED (1 << 0) |
|
40 |
|
|
41 |
/** |
|
42 |
* @brief Channel flag to indicate whether the channel is set as input. |
|
43 |
*/ |
|
44 |
#define AOS_IOCHANNEL_INPUT_ENABLE (1 << 1) |
|
45 |
|
|
46 |
/** |
|
47 |
* @brief Channel flag to indicate whether the channel is set as output. |
|
48 |
*/ |
|
49 |
#define AOS_IOCHANNEL_OUTPUT_ENABLE (1 << 2) |
|
50 |
|
|
51 |
/* |
|
52 |
* forward definitions |
|
53 |
*/ |
|
54 |
typedef struct aos_iochannel AosIOChannel; |
|
55 |
typedef struct aos_ostream AosIOStream; |
|
56 |
|
|
57 |
/** |
|
58 |
* @brief AosI=Channel specific methods. |
|
59 |
*/ |
|
60 |
#define _aos_iochannel_methods \ |
|
61 |
_base_asynchronous_channel_methods |
|
62 |
|
|
63 |
/** |
|
64 |
* @brief AosIOChannel specific data. |
|
65 |
*/ |
|
66 |
#define _aos_iochannel_data \ |
|
67 |
/* pointer to a BaseAsynchronousChannel object */ \ |
|
68 |
BaseAsynchronousChannel* asyncchannel; \ |
|
69 |
/* pointer to the next channel in a AosIOStream */ \ |
|
70 |
AosIOChannel* next; \ |
|
71 |
/* flags related to the channel */ \ |
|
72 |
uint8_t flags; |
|
73 |
|
|
74 |
/** |
|
75 |
* @extends BaseAsynchronousChannelVMT |
|
76 |
* |
|
77 |
* @brief AosIOChannel virtual methods table. |
|
78 |
*/ |
|
79 |
struct AosIOChannelVMT { |
|
80 |
_aos_iochannel_methods |
|
81 |
}; |
|
82 |
|
|
83 |
/** |
|
84 |
* @extends BaseAsynchronousChannel |
|
85 |
* |
|
86 |
* @brief I/O Channel class. |
|
87 |
* @details This class implements an asynchronous I/O channel. |
|
88 |
*/ |
|
89 |
struct aos_iochannel { |
|
90 |
/** @brief Virtual Methods Table. */ |
|
91 |
const struct AosIOChannelVMT* vmt; |
|
92 |
_aos_iochannel_data |
|
93 |
}; |
|
94 |
|
|
95 |
/** |
|
96 |
* @brief AosIOStream methods. |
|
97 |
*/ |
|
98 |
#define _aos_iostream_methods \ |
|
99 |
_base_sequential_stream_methods |
|
100 |
|
|
101 |
/** |
|
102 |
* @brief AosIOStream data. |
|
103 |
*/ |
|
104 |
#define _aos_iostream_data \ |
|
105 |
/* Pointer to the first channel in a list. */ \ |
|
106 |
AosIOChannel* channel; |
|
107 |
|
|
108 |
/** |
|
109 |
* @extends BaseSequentialStream |
|
110 |
* |
|
111 |
* @brief AosIOStream virtual methods table. |
|
112 |
*/ |
|
113 |
struct AosIOStreamVMT { |
|
114 |
_aos_iostream_methods |
|
115 |
}; |
|
116 |
|
|
117 |
/** |
|
118 |
* @extends BaseSequentialStream |
|
119 |
* |
|
120 |
* @brief I/O Stream class. |
|
121 |
* @details This class implements an base sequential stream. |
|
122 |
* @todo So far only output but no input is supported. |
|
123 |
*/ |
|
124 |
struct aos_ostream { |
|
125 |
const struct AosIOStreamVMT* vmt; |
|
126 |
_aos_iostream_data |
|
127 |
}; |
|
128 |
|
|
129 |
#ifdef __cplusplus |
|
130 |
extern "C" { |
|
131 |
#endif |
|
132 |
void aosIOStreamInit(AosIOStream* stream); |
|
133 |
void aosIOChannelInit(AosIOChannel* channel, BaseAsynchronousChannel* asyncchannel); |
|
134 |
void aosIOStreamAddChannel(AosIOStream* stream, AosIOChannel* channel); |
|
135 |
aos_status_t aosIOStreamRemoveChannel(AosIOStream* stream, AosIOChannel* channel); |
|
136 |
void aosIOChannelInputEnable(AosIOChannel* channel); |
|
137 |
void aosIOChannelInputDisable(AosIOChannel* channel); |
|
138 |
void aosIOChannelOutputEnable(AosIOChannel* channel); |
|
139 |
void aosIOChannelOutputDisable(AosIOChannel* channel); |
|
140 |
#ifdef __cplusplus |
|
141 |
} |
|
142 |
#endif |
|
143 |
|
|
144 |
#endif /* _AMIROOS_IOSTREAM_H_ */ |
|
145 |
|
|
146 |
/** @} */ |
core/inc/aos_shell.h | ||
---|---|---|
1 |
/* |
|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
3 |
Copyright (C) 2016..2018 Thomas Schöpping et al. |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU General Public License as published by |
|
7 |
the Free Software Foundation, either version 3 of the License, or |
|
8 |
(at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU General Public License |
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
|
|
19 |
/** |
|
20 |
* @file aos_shell.h |
|
21 |
* @brief Shell macros and structures. |
|
22 |
* |
|
23 |
* @addtogroup aos_shell |
|
24 |
* @{ |
|
25 |
*/ |
|
26 |
|
|
27 |
#ifndef _AMIROOS_SHELL_H_ |
|
28 |
#define _AMIROOS_SHELL_H_ |
|
29 |
|
|
30 |
#include <aosconf.h> |
|
31 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) |
|
32 |
#include <hal.h> |
|
33 |
#include <aos_types.h> |
|
34 |
|
|
35 |
/** |
|
36 |
* @brief Shell event flag that is emitted when the thread starts. |
|
37 |
*/ |
|
38 |
#define AOS_SHELL_EVTFLAG_START ((eventflags_t)(1 << 0)) |
|
39 |
|
|
40 |
/** |
|
41 |
* @brief Shell event flag that is emitted when a command is executed. |
|
42 |
*/ |
|
43 |
#define AOS_SHELL_EVTFLAG_EXEC ((eventflags_t)(1 << 1)) |
|
44 |
|
|
45 |
/** |
|
46 |
* @brief Shell event flag that is emitted when a command execution finished. |
|
47 |
*/ |
|
48 |
#define AOS_SHELL_EVTFLAG_DONE ((eventflags_t)(1 << 2)) |
|
49 |
|
|
50 |
/** |
|
51 |
* @brief Shell event flag that is emitted when the shread stops. |
|
52 |
*/ |
|
53 |
#define AOS_SHELL_EVTFLAG_EXIT ((eventflags_t)(1 << 3)) |
|
54 |
|
|
55 |
/** |
|
56 |
* @brief Shell event flag that is emitted when an I/O error occurred. |
|
57 |
*/ |
|
58 |
#define AOS_SHELL_EVTFLAG_IOERROR ((eventflags_t)(1 << 4)) |
|
59 |
|
|
60 |
/** |
|
61 |
* @brief Shell input configuration for replacing content by user input. |
|
62 |
*/ |
|
63 |
#define AOS_SHELL_CONFIG_INPUT_OVERWRITE (1 << 0) |
|
64 |
|
|
65 |
/** |
|
66 |
* @brief Shell prompt configuration print a minimalistic prompt. |
|
67 |
*/ |
|
68 |
#define AOS_SHELL_CONFIG_PROMPT_MINIMAL (1 << 1) |
|
69 |
|
|
70 |
/** |
|
71 |
* @brief Shell prompt configuration to additionally print the system uptime with the prompt. |
|
72 |
*/ |
|
73 |
#define AOS_SHELL_CONFIG_PROMPT_UPTIME (1 << 2) |
|
74 |
|
|
75 |
/** |
|
76 |
* @brief Shell prompt configuration to additionally print the date and time with the prompt. |
|
77 |
*/ |
|
78 |
#define AOS_SHELL_CONFIG_PROMPT_DATETIME (2 << 2) |
|
79 |
|
|
80 |
/** |
|
81 |
* @brief Shell prompt configuration to additionally print the system uptime with the prompt. |
|
82 |
*/ |
|
83 |
#define AOS_SHELL_CONFIG_MATCH_CASE (1 << 4) |
|
84 |
|
|
85 |
/** |
|
86 |
* @brief Shell I/O channel flag whether the channel is attached to a list. |
|
87 |
*/ |
|
88 |
#define AOS_SHELLCHANNEL_ATTACHED (1 << 0) |
|
89 |
|
|
90 |
/** |
|
91 |
* @brief Shell I/O channel flag whether the channel is enabled as input. |
|
92 |
*/ |
|
93 |
#define AOS_SHELLCHANNEL_INPUT_ENABLED (1 << 1) |
|
94 |
|
|
95 |
/** |
|
96 |
* @brief Shell I/O channel flag whether the channel is enabled as output. |
|
97 |
*/ |
|
98 |
#define AOS_SHELLCHANNEL_OUTPUT_ENABLED (1 << 2) |
|
99 |
|
|
100 |
/* |
|
101 |
* forward definitions |
|
102 |
*/ |
|
103 |
typedef struct aos_shellchannel AosShellChannel; |
|
104 |
typedef struct aos_shellstream AosShellStream; |
|
105 |
|
|
106 |
/** |
|
107 |
* @brief AosShellChannel specific methods. |
|
108 |
*/ |
|
109 |
#define _aos_shell_channel_methods \ |
|
110 |
_base_asynchronous_channel_methods |
|
111 |
|
|
112 |
/** |
|
113 |
* @brief AosShellChannel specific data. |
|
114 |
*/ |
|
115 |
#define _aos_shell_channel_data \ |
|
116 |
/* pointer to a BaseAsynchronousChannel object */ \ |
|
117 |
BaseAsynchronousChannel* asyncchannel; \ |
|
118 |
/* event listener for the associated BaseAsynchronousChannel */ \ |
|
119 |
event_listener_t listener; \ |
|
120 |
/* pointer to the next chennal in a AosShellStream */ \ |
|
121 |
AosShellChannel* next; \ |
|
122 |
/* flags related to the channel */ \ |
|
123 |
uint8_t flags; |
|
124 |
|
|
125 |
/** |
|
126 |
* @extends BaseAsynchronousChannelVMT |
|
127 |
* |
|
128 |
* @brief AosShellChannel virtual methods table. |
|
129 |
*/ |
|
130 |
struct AosShellChannelVMT { |
|
131 |
_aos_shell_channel_methods |
|
132 |
}; |
|
133 |
|
|
134 |
/** |
|
135 |
* @extends BaseAsynchronousChannel |
|
136 |
* |
|
137 |
* @brief Shell channel class. |
|
138 |
* @details This class implements an asynchronous I/O channel. |
|
139 |
*/ |
|
140 |
struct aos_shellchannel { |
|
141 |
/** @brief Virtual Methods Table. */ |
|
142 |
const struct AosShellChannelVMT* vmt; |
|
143 |
_aos_shell_channel_data |
|
144 |
}; |
|
145 |
|
|
146 |
/** |
|
147 |
* @brief AosShellStream methods. |
|
148 |
*/ |
|
149 |
#define _aos_shellstream_methods \ |
|
150 |
_base_sequential_stream_methods |
|
151 |
|
|
152 |
/** |
|
153 |
* @brief AosShellStream data. |
|
154 |
*/ |
|
155 |
#define _aos_shellstream_data \ |
|
156 |
/* Pointer to the first channel in a list. */ \ |
|
157 |
AosShellChannel* channel; |
|
158 |
|
|
159 |
/** |
|
160 |
* @extends BaseSequentialStream |
|
161 |
* |
|
162 |
* @brief AosShellStream virtual methods table. |
|
163 |
*/ |
|
164 |
struct AosShellStreamVMT { |
|
165 |
_aos_shellstream_methods |
|
166 |
}; |
|
167 |
|
|
168 |
/** |
|
169 |
* @extends BaseSequentialStream |
|
170 |
* |
|
171 |
* @brief Shell Stream class. |
|
172 |
* @details This class implements an base sequential stream. |
|
173 |
* @todo So far only output but no input is supported. |
|
174 |
*/ |
|
175 |
struct aos_shellstream { |
|
176 |
const struct AosShellStreamVMT* vmt; |
|
177 |
_aos_shellstream_data |
|
178 |
}; |
|
179 |
|
|
180 |
/** |
|
181 |
* @brief Shell command calback type. |
|
182 |
*/ |
|
183 |
typedef int (*aos_shellcmdcb_t)(BaseSequentialStream* stream, int argc, char* argv[]); |
|
184 |
|
|
185 |
/** |
|
186 |
* @brief Shell command structure. |
|
187 |
*/ |
|
188 |
typedef struct aos_shellcommand { |
|
189 |
/** |
|
190 |
* @brief Command name. |
|
191 |
*/ |
|
192 |
const char* name; |
|
193 |
|
|
194 |
/** |
|
195 |
* @brief Callback function. |
|
196 |
*/ |
|
197 |
aos_shellcmdcb_t callback; |
|
198 |
|
|
199 |
/** |
|
200 |
* @brief Pointer to next command in a singly linked list. |
|
201 |
*/ |
|
202 |
struct aos_shellcommand* next; |
|
203 |
|
|
204 |
} aos_shellcommand_t; |
|
205 |
|
|
206 |
/** |
|
207 |
* @brief Execution status of a shell command. |
|
208 |
*/ |
|
209 |
typedef struct aos_shellexecstatus { |
|
210 |
/** |
|
211 |
* @brief Pointer to the command that was executed. |
|
212 |
*/ |
|
213 |
aos_shellcommand_t* command; |
|
214 |
|
|
215 |
/** |
|
216 |
* @brief Return value of the executed command. |
|
217 |
*/ |
|
218 |
int retval; |
|
219 |
} aos_shellexecstatus_t; |
|
220 |
|
|
221 |
/** |
|
222 |
* @brief Enumerator to encode shell actions. |
|
223 |
*/ |
|
224 |
typedef enum aos_shellaction { |
|
225 |
AOS_SHELL_ACTION_NONE, |
|
226 |
AOS_SHELL_ACTION_READCHAR, |
|
227 |
AOS_SHELL_ACTION_AUTOFILL, |
|
228 |
AOS_SHELL_ACTION_SUGGEST, |
|
229 |
AOS_SHELL_ACTION_INSERTTOGGLE, |
|
230 |
AOS_SHELL_ACTION_DELETEFORWARD, |
|
231 |
AOS_SHELL_ACTION_DELETEBACKWARD, |
|
232 |
AOS_SHELL_ACTION_RECALLLAST, |
|
233 |
AOS_SHELL_ACTION_CLEAR, |
|
234 |
AOS_SHELL_ACTION_CURSOR2START, |
|
235 |
AOS_SHELL_ACTION_CURSOR2END, |
|
236 |
AOS_SHELL_ACTION_CURSORLEFT, |
|
237 |
AOS_SHELL_ACTION_CURSORRIGHT, |
|
238 |
AOS_SHELL_ACTION_EXECUTE, |
|
239 |
AOS_SHELL_ACTION_ESCSTART, |
|
240 |
} aos_shellaction_t; |
|
241 |
|
|
242 |
/** |
|
243 |
* @brief Shell structure. |
|
244 |
*/ |
|
245 |
typedef struct aos_shell { |
|
246 |
/** |
|
247 |
* @brief Pointer to the thread object. |
|
248 |
*/ |
|
249 |
thread_t* thread; |
|
250 |
|
|
251 |
/** |
|
252 |
* @brief Event source. |
|
253 |
*/ |
|
254 |
event_source_t eventSource; |
|
255 |
|
|
256 |
/** |
|
257 |
* @brief Struct for OS related events |
|
258 |
*/ |
|
259 |
struct { |
|
260 |
/** |
|
261 |
* @brief Pointer to the OS' event source. |
|
262 |
*/ |
|
263 |
event_source_t* eventSource; |
|
264 |
|
|
265 |
/** |
|
266 |
* @brief Listener for OS related events. |
|
267 |
*/ |
|
268 |
event_listener_t eventListener; |
|
269 |
} os; |
|
270 |
|
|
271 |
/** |
|
272 |
* @brief Pointer to the first I/O channel. |
|
273 |
*/ |
|
274 |
AosShellStream stream; |
|
275 |
|
|
276 |
/** |
|
277 |
* @brief String to printed as prompt. |
|
278 |
*/ |
|
279 |
const char* prompt; |
|
280 |
|
|
281 |
/** |
|
282 |
* @brief Pointer to the first element of the singly linked list of commands. |
|
283 |
* @details Commands are ordered alphabetically in the list. |
|
284 |
*/ |
|
285 |
aos_shellcommand_t* commands; |
|
286 |
|
|
287 |
/** |
|
288 |
* @brief Execution status of the most recent command. |
|
289 |
*/ |
|
290 |
aos_shellexecstatus_t execstatus; |
|
291 |
|
|
292 |
/** |
|
293 |
* @brief Input buffer. |
|
294 |
*/ |
|
295 |
char* line; |
|
296 |
|
|
297 |
/** |
|
298 |
* @brief Size of the input buffer. |
|
299 |
*/ |
|
300 |
size_t linesize; |
|
301 |
|
|
302 |
/** |
|
303 |
* @brief Structure containing data for internal input parsing. |
|
304 |
*/ |
|
305 |
struct { |
|
306 |
/** |
|
307 |
* @brief The last action executed by the shell. |
|
308 |
*/ |
|
309 |
aos_shellaction_t lastaction; |
|
310 |
|
|
311 |
/** |
|
312 |
* @brief Number of character in the current escape sequence. |
|
313 |
*/ |
|
314 |
uint8_t escp; |
|
315 |
|
|
316 |
/** |
|
317 |
* @brief Buffer to store an escape sequence. |
|
318 |
*/ |
|
319 |
char escseq[5]; |
|
320 |
|
|
321 |
/** |
|
322 |
* @brief Current curso position. |
|
323 |
*/ |
|
324 |
size_t cursorpos; |
|
325 |
|
|
326 |
/** |
|
327 |
* @brief Current line width. |
|
328 |
*/ |
|
329 |
size_t lineend; |
|
330 |
|
|
331 |
/** |
|
332 |
* @brief Flag whether there was input since the prompt was printed the last time. |
|
333 |
*/ |
|
334 |
bool noinput; |
|
335 |
} inputdata; |
|
336 |
|
|
337 |
/** |
|
338 |
* @brief Argument buffer. |
|
339 |
*/ |
|
340 |
char** arglist; |
|
341 |
|
|
342 |
/** |
|
343 |
* @brief Size of the argument buffer. |
|
344 |
*/ |
|
345 |
size_t arglistsize; |
|
346 |
|
|
347 |
/** |
|
348 |
* @brief Configuration flags. |
|
349 |
*/ |
|
350 |
uint8_t config; |
|
351 |
} aos_shell_t; |
|
352 |
|
|
353 |
#ifdef __cplusplus |
|
354 |
extern "C" { |
|
355 |
#endif |
|
356 |
void aosShellInit(aos_shell_t* shell, event_source_t* oseventsource, const char* prompt, char* line, size_t linesize, char** arglist, size_t arglistsize); |
|
357 |
void aosShellStreamInit(AosShellStream* stream); |
|
358 |
void aosShellChannelInit(AosShellChannel* channel, BaseAsynchronousChannel* asyncchannel); |
|
359 |
aos_status_t aosShellAddCommand(aos_shell_t* shell, aos_shellcommand_t* cmd); |
|
360 |
aos_status_t aosShellRemoveCommand(aos_shell_t* shell, char* cmd, aos_shellcommand_t** removed); |
|
361 |
void aosShellStreamAddChannel(AosShellStream* stream, AosShellChannel* channel); |
|
362 |
aos_status_t aosShellStreamRemoveChannel(AosShellStream* stream, AosShellChannel* channel); |
|
363 |
void aosShellChannelInputEnable(AosShellChannel* channel); |
|
364 |
void aosShellChannelInputDisable( AosShellChannel* channel); |
|
365 |
void aosShellChannelOutputEnable(AosShellChannel* channel); |
|
366 |
void aosShellChannelOutputDisable(AosShellChannel* channel); |
|
367 |
THD_FUNCTION(aosShellThread, shell); |
|
368 |
#ifdef __cplusplus |
|
369 |
} |
|
370 |
#endif |
|
371 |
|
|
372 |
#endif /* AMIROOS_CFG_SHELL_ENABLE == true */ |
|
373 |
|
|
374 |
#endif /* _AMIROOS_SHELL_H_ */ |
|
375 |
|
|
376 |
/** @} */ |
core/inc/aos_system.h | ||
---|---|---|
1 |
/* |
|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
3 |
Copyright (C) 2016..2018 Thomas Schöpping et al. |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU General Public License as published by |
|
7 |
the Free Software Foundation, either version 3 of the License, or |
|
8 |
(at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU General Public License |
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
|
|
19 |
/** |
|
20 |
* @file aos_system.h |
|
21 |
* @brief System macros and structures. |
|
22 |
* |
|
23 |
* @addtogroup aos_system |
|
24 |
* @{ |
|
25 |
*/ |
|
26 |
|
|
27 |
#ifndef _AMIROOS_SYSTEM_H_ |
|
28 |
#define _AMIROOS_SYSTEM_H_ |
|
29 |
|
|
30 |
#include <aos_iostream.h> |
|
31 |
#include <amiro-lld.h> |
|
32 |
#include <aos_shell.h> |
|
33 |
#include <aos_time.h> |
|
34 |
#include <chprintf.h> |
|
35 |
|
|
36 |
/** |
|
37 |
* @brief Resolution of the system time measurement. |
|
38 |
*/ |
|
39 |
#define AOS_SYSTEM_TIME_RESOLUTION ((MICROSECONDS_PER_SECOND + CH_CFG_ST_FREQUENCY - 1) / CH_CFG_ST_FREQUENCY) |
|
40 |
|
|
41 |
/** |
|
42 |
* @brief System event flag which is emitted when a shutdown was initiated. |
|
43 |
*/ |
|
44 |
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN (eventflags_t)(1 << 0) |
|
45 |
|
|
46 |
/** |
|
47 |
* @brief System event flag which is emitted when a shutdown to transportation mode was initiated. |
|
48 |
*/ |
|
49 |
#define AOS_SYSTEM_EVENTFLAGS_TRANSPORTATION (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 1)) |
|
50 |
|
|
51 |
/** |
|
52 |
* @brief System event flag which is emitted when a shutdown to deepsleep mode was initiated. |
|
53 |
*/ |
|
54 |
#define AOS_SYSTEM_EVENTFLAGS_DEEPSLEEP (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 2)) |
|
55 |
|
|
56 |
/** |
|
57 |
* @brief System event flag which is emitted when a shutdown to hibernate mode was initiated. |
|
58 |
*/ |
|
59 |
#define AOS_SYSTEM_EVENTFLAGS_HIBERNATE (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 3)) |
|
60 |
|
|
61 |
/** |
|
62 |
* @brief System event flag which is emitted when a system restart was initiated. |
|
63 |
*/ |
|
64 |
#define AOS_SYSTEM_EVENTFLAGS_RESTART (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 4)) |
|
65 |
|
|
66 |
/** |
|
67 |
* @brief Major version of the implemented SSSP. |
|
68 |
*/ |
|
69 |
#define AOS_SYSTEM_SSSP_VERSION_MAJOR 1 |
|
70 |
|
|
71 |
/** |
|
72 |
* @brief Minor version of the implemented SSSP. |
|
73 |
*/ |
|
74 |
#define AOS_SYSTEM_SSSP_VERSION_MINOR 4 |
|
75 |
|
|
76 |
/** |
|
77 |
* @brief Timeout delay according to SSSP. |
|
78 |
* @details SSSP defines timeouts to be ten times longer than the signal delay time. |
|
79 |
*/ |
|
80 |
#define AOS_SYSTEM_SSSP_TIMEOUT (10 * AMIROOS_CFG_SSSP_SIGNALDELAY) |
|
81 |
|
|
82 |
/** |
|
83 |
* @brief Enumerator to identify shutdown types. |
|
84 |
*/ |
|
85 |
typedef enum aos_shutdown { |
|
86 |
AOS_SHUTDOWN_NONE, /**< Default value if no shutdown action was initiated */ |
|
87 |
AOS_SHUTDOWN_PASSIVE, /**< Passive shutdown (initiated by another module). */ |
|
88 |
AOS_SHUTDOWN_HIBERNATE, /**< Active shutdown to hibernate mode. */ |
|
89 |
AOS_SHUTDOWN_DEEPSLEEP, /**< Active shutdown to deepsleep mode. */ |
|
90 |
AOS_SHUTDOWN_TRANSPORTATION, /**< Active shutdown to transportation mode. */ |
|
91 |
AOS_SHUTDOWN_RESTART, /**< Active saystem restart request. */ |
|
92 |
} aos_shutdown_t; |
|
93 |
|
|
94 |
/** |
|
95 |
* @brief Enumerator of the several stages of SSSP. |
|
96 |
*/ |
|
97 |
typedef enum aos_ssspstage { |
|
98 |
AOS_SSSP_STARTUP_1_1 = 0x10, /**< Identifier of SSSP startup phase stage 1-1. */ |
|
99 |
AOS_SSSP_STARTUP_1_2 = 0x11, /**< Identifier of SSSP startup phase stage 1-2. */ |
|
100 |
AOS_SSSP_STARTUP_1_3 = 0x12, /**< Identifier of SSSP startup phase stage 1-3. */ |
|
101 |
AOS_SSSP_STARTUP_2_1 = 0x14, /**< Identifier of SSSP startup phase stage 2-1. */ |
|
102 |
AOS_SSSP_STARTUP_2_2 = 0x15, /**< Identifier of SSSP startup phase stage 2-2. */ |
|
103 |
AOS_SSSP_STARTUP_3_1 = 0x18, /**< Identifier of SSSP startup phase stage 3-1. */ |
|
104 |
AOS_SSSP_STARTUP_3_2 = 0x19, /**< Identifier of SSSP startup phase stage 3-2. */ |
|
105 |
AOS_SSSP_STARTUP_3_3 = 0x1A, /**< Identifier of SSSP startup phase stage 3-3. */ |
|
106 |
AOS_SSSP_STARTUP_3_4 = 0x1B, /**< Identifier of SSSP startup phase stage 3-4. */ |
|
107 |
AOS_SSSP_OPERATION = 0x20, /**< Identifier of SSSP operation pahse. */ |
|
108 |
AOS_SSSP_SHUTDOWN_1_1 = 0x30, /**< Identifier of SSSP shutdown phase stage 1-1. */ |
|
109 |
AOS_SSSP_SHUTDOWN_1_2 = 0x31, /**< Identifier of SSSP shutdown phase stage 1-2. */ |
|
110 |
AOS_SSSP_SHUTDOWN_1_3 = 0x32, /**< Identifier of SSSP shutdown phase stage 1-3. */ |
|
111 |
AOS_SSSP_SHUTDOWN_2_1 = 0x34, /**< Identifier of SSSP shutdown phase stage 2-1. */ |
|
112 |
AOS_SSSP_SHUTDOWN_2_2 = 0x35, /**< Identifier of SSSP shutdown phase stage 2-2. */ |
|
113 |
AOS_SSSP_SHUTDOWN_3 = 0x38, /**< Identifier of SSSP shutdown phase stage 3. */ |
|
114 |
} aos_ssspstage_t; |
|
115 |
|
|
116 |
/** |
|
117 |
* @brief Type to represent module IDs. |
|
118 |
*/ |
|
119 |
typedef uint16_t aos_ssspmoduleid_t; |
|
120 |
|
|
121 |
/** |
|
122 |
* @brief AMiRo-OS base system structure. |
|
123 |
*/ |
|
124 |
typedef struct aos_system { |
|
125 |
|
|
126 |
/** |
|
127 |
* @brief SSSP relevant data. |
|
128 |
*/ |
|
129 |
struct { |
|
130 |
/** |
|
131 |
* @brief Current SSSP stage of the system. |
|
132 |
*/ |
|
133 |
aos_ssspstage_t stage; |
|
134 |
|
|
135 |
/** |
|
136 |
* @brief Module identifier. |
|
137 |
* @details A value of 0 indicates an uninitialized ID. |
|
138 |
* The vlaues 0 and ~0 are reserved und must not be set. |
|
139 |
*/ |
|
140 |
aos_ssspmoduleid_t moduleId; |
|
141 |
} sssp; |
|
142 |
|
|
143 |
/** |
|
144 |
* @brief System I/O stream. |
|
145 |
*/ |
|
146 |
AosIOStream iostream; |
|
147 |
|
|
148 |
/** |
|
149 |
* @brief Event structure. |
|
150 |
*/ |
|
151 |
struct { |
|
152 |
|
|
153 |
/** |
|
154 |
* @brief I/O event source. |
|
155 |
*/ |
|
156 |
event_source_t io; |
|
157 |
|
|
158 |
/** |
|
159 |
* @brief OS event source. |
|
160 |
*/ |
|
161 |
event_source_t os; |
|
162 |
} events; |
|
163 |
|
|
164 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
|
165 |
/** |
|
166 |
* @brief Pointer to the shell object. |
|
167 |
*/ |
|
168 |
aos_shell_t shell; |
|
169 |
#endif |
|
170 |
|
|
171 |
} aos_system_t; |
|
172 |
|
|
173 |
/** |
|
174 |
* @brief Global system object. |
|
175 |
*/ |
|
176 |
extern aos_system_t aos; |
|
177 |
|
|
178 |
/** |
|
179 |
* @brief Printf function that uses the default system I/O stream. |
|
180 |
* |
|
181 |
* @param[in] fmt Formatted string to print. |
|
182 |
*/ |
|
183 |
#define aosprintf(fmt, ...) chprintf((BaseSequentialStream*)&aos.iostream, fmt, ##__VA_ARGS__) |
|
184 |
|
|
185 |
#ifdef __cplusplus |
|
186 |
extern "C" { |
|
187 |
#endif |
|
188 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) |
|
189 |
void aosSysInit(const char* shellPrompt); |
|
190 |
#else |
|
191 |
void aosSysInit(void); |
|
192 |
#endif |
|
193 |
void aosSysStart(void); |
|
194 |
eventmask_t aosSysSsspStartupOsInitSyncCheck(event_listener_t* syncEvtListener); |
|
195 |
void aosSysGetUptimeX(aos_timestamp_t* ut); |
|
196 |
void aosSysGetDateTime(struct tm* dt); |
|
197 |
void aosSysSetDateTime(struct tm* dt); |
|
198 |
void aosSysShutdownInit(aos_shutdown_t shutdown); |
|
199 |
void aosSysStop(void); |
|
200 |
void aosSysDeinit(void); |
|
201 |
void aosSysShutdownFinal(aos_shutdown_t shutdown); |
|
202 |
#ifdef __cplusplus |
|
203 |
} |
|
204 |
#endif |
|
205 |
|
|
206 |
/** |
|
207 |
* @brief Retrieves the system uptime. |
|
208 |
* |
|
209 |
* @param[out] ut The system uptime. |
|
210 |
*/ |
|
211 |
static inline void aosSysGetUptime(aos_timestamp_t* ut) |
|
212 |
{ |
|
213 |
aosDbgCheck(ut != NULL); |
|
214 |
|
|
215 |
chSysLock(); |
|
216 |
aosSysGetUptimeX(ut); |
|
217 |
chSysUnlock(); |
|
218 |
|
|
219 |
return; |
|
220 |
} |
|
221 |
|
|
222 |
#endif /* _AMIROOS_SYSTEM_H_ */ |
|
223 |
|
|
224 |
/** @} */ |
core/inc/aos_thread.h | ||
---|---|---|
1 |
/* |
|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
3 |
Copyright (C) 2016..2018 Thomas Schöpping et al. |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU General Public License as published by |
|
7 |
the Free Software Foundation, either version 3 of the License, or |
|
8 |
(at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU General Public License |
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
|
|
19 |
/** |
|
20 |
* @file aos_thread.h |
|
21 |
* @brief Thread macros and inline functions. |
|
22 |
* |
|
23 |
* @addtogroup aos_threads |
|
24 |
* @{ |
|
25 |
*/ |
|
26 |
|
|
27 |
#ifndef _AMIROOS_THREAD_H_ |
|
28 |
#define _AMIROOS_THREAD_H_ |
|
29 |
|
|
30 |
#include <aos_time.h> |
|
31 |
#include <aos_system.h> |
|
32 |
|
|
33 |
/** |
|
34 |
* @brief Minimum thread priority. |
|
35 |
*/ |
|
36 |
#define AOS_THD_LOWPRIO_MIN ((tprio_t)(LOWPRIO)) |
|
37 |
|
|
38 |
/** |
|
39 |
* @brief Maximum priority for background threads. |
|
40 |
*/ |
|
41 |
#define AOS_THD_LOWPRIO_MAX ((tprio_t)(LOWPRIO + ((NORMALPRIO - LOWPRIO) / 2))) |
|
42 |
|
|
43 |
/** |
|
44 |
* @brief Minimum priority for normal/standard threads. |
|
45 |
*/ |
|
46 |
#define AOS_THD_NORMALPRIO_MIN ((tprio_t)(AOS_THD_LOWPRIO_MAX + 1)) |
|
47 |
|
|
48 |
/** |
|
49 |
* @brief Maximum priority for normal/standard threads. |
|
50 |
*/ |
|
51 |
#define AOS_THD_NORMALPRIO_MAX ((tprio_t)(NORMALPRIO)) |
|
52 |
|
|
53 |
/** |
|
54 |
* @brief Minimum priority for important threads. |
|
55 |
*/ |
|
56 |
#define AOS_THD_HIGHPRIO_MIN ((tprio_t)(NORMALPRIO + 1)) |
|
57 |
|
|
58 |
/** |
|
59 |
* @brief Maximum priority for important threads. |
|
60 |
*/ |
|
61 |
#define AOS_THD_HIGHPRIO_MAX ((tprio_t)(NORMALPRIO + ((HIGHPRIO - NORMALPRIO) / 2))) |
|
62 |
|
|
63 |
/** |
|
64 |
* @brief Minimum priority for real-time threads. |
|
65 |
*/ |
|
66 |
#define AOS_THD_RTPRIO_MIN ((tprio_t)(AOS_THD_HIGHPRIO_MAX + 1)) |
|
67 |
|
|
68 |
/** |
|
69 |
* @brief Maximum priority for real-time threads. |
|
70 |
*/ |
|
71 |
#define AOS_THD_RTPRIO_MAX ((tprio_t)(HIGHPRIO - 1)) |
|
72 |
|
|
73 |
/** |
|
74 |
* @brief Priority for the system control thread. |
|
75 |
*/ |
|
76 |
#define AOS_THD_CTRLPRIO ((tprio_t)(HIGHPRIO)) |
|
77 |
|
|
78 |
/** |
|
79 |
* @brief Maximum timeframe that can be slept in system ticks. |
|
80 |
*/ |
|
81 |
#define AOS_THD_MAX_SLEEP_ST TIME_MAX_INTERVAL |
|
82 |
|
|
83 |
/** |
|
84 |
* @brief Maximum timeframe that can be slept in seconds. |
|
85 |
*/ |
|
86 |
#define AOS_THD_MAX_SLEEP_S (chTimeI2S(AOS_THD_MAX_SLEEP_ST) - 1) |
|
87 |
|
|
88 |
/** |
|
89 |
* @brief Maximum timeframe that can be slept in milliseconds. |
|
90 |
*/ |
|
91 |
#define AOS_THD_MAX_SLEEP_MS (chTimeI2MS(AOS_THD_MAX_SLEEP_ST) - 1) |
|
92 |
|
|
93 |
/** |
|
94 |
* @brief Maximum timeframe that can be slept in microseconds. |
|
95 |
*/ |
|
96 |
#define AOS_THD_MAX_SLEEP_US (chTimeI2US(AOS_THD_MAX_SLEEP_ST) - 1) |
|
97 |
|
|
98 |
#ifdef __cplusplus |
|
99 |
extern "C" { |
|
100 |
#endif |
|
101 |
void aosThdSleepUntilS(const aos_timestamp_t* t); |
|
102 |
#ifdef __cplusplus |
|
103 |
} |
|
104 |
#endif |
|
105 |
|
|
106 |
/** |
|
107 |
* @brief Lets the calling thread sleep the specified amount of microseconds. |
|
108 |
* |
|
109 |
* @param[in] us Time to sleep in microseconds. |
|
110 |
*/ |
|
111 |
static inline void aosThdUSleepS(const aos_interval_t us) |
|
112 |
{ |
|
113 |
aos_timestamp_t ut; |
|
114 |
|
|
115 |
aosSysGetUptimeX(&ut); |
|
116 |
ut += us; |
|
117 |
aosThdSleepUntilS(&ut); |
|
118 |
|
|
119 |
return; |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* @brief Lets the calling thread sleep the specified amount of milliseconds. |
|
124 |
* |
|
125 |
* @param[in] ms Time to sleep in milliseconds. |
|
126 |
*/ |
|
127 |
static inline void aosThdMSleepS(const uint32_t ms) |
|
128 |
{ |
|
129 |
aos_timestamp_t ut; |
|
130 |
|
|
131 |
aosSysGetUptimeX(&ut); |
|
132 |
ut += (aos_timestamp_t)ms * MICROSECONDS_PER_MILLISECOND; |
|
133 |
aosThdSleepUntilS(&ut); |
|
134 |
|
|
135 |
return; |
|
136 |
} |
|
137 |
|
|
138 |
/** |
|
139 |
* @brief Lets the calling thread sleep the specified amount of seconds. |
|
140 |
* |
|
141 |
* @param[in] s Time to sleep in seconds. |
|
142 |
*/ |
|
143 |
static inline void aosThdSSleepS(const uint32_t s) |
|
144 |
{ |
|
145 |
aos_timestamp_t ut; |
|
146 |
|
|
147 |
aosSysGetUptimeX(&ut); |
|
148 |
ut += (aos_timestamp_t)s * MICROSECONDS_PER_SECOND; |
|
149 |
aosThdSleepUntilS(&ut); |
|
150 |
|
|
151 |
return; |
|
152 |
} |
|
153 |
|
|
154 |
/** |
|
155 |
* @brief Lets the calling thread sleep the specified amount of seconds. |
|
156 |
* |
|
157 |
* @param[in] s Time to sleep in seconds. |
|
158 |
*/ |
|
159 |
static inline void aosThdSleepS(const float s) |
|
160 |
{ |
|
161 |
aos_timestamp_t ut; |
|
162 |
|
|
163 |
aosSysGetUptimeX(&ut); |
|
164 |
ut += (aos_timestamp_t)(s * MICROSECONDS_PER_SECOND); |
|
165 |
aosThdSleepUntilS(&ut); |
|
166 |
|
|
167 |
return; |
|
168 |
} |
|
169 |
|
|
170 |
/** |
|
171 |
* @brief Lets the calling thread sleep the specified amount of microseconds. |
|
172 |
* |
|
173 |
* @param[in] us Time to sleep in microseconds. |
|
174 |
*/ |
|
175 |
static inline void aosThdUSleep(const uint32_t us) |
|
176 |
{ |
|
177 |
chSysLock(); |
|
178 |
aosThdUSleepS(us); |
|
179 |
chSysUnlock(); |
|
180 |
|
|
181 |
return; |
|
182 |
} |
|
183 |
|
|
184 |
/** |
|
185 |
* @brief Lets the calling thread sleep the specified amount of milliseconds. |
|
186 |
* |
|
187 |
* @param[in] ms Time to sleep in milliseconds. |
|
188 |
*/ |
|
189 |
static inline void aosThdMSleep(const uint32_t ms) |
|
190 |
{ |
|
191 |
chSysLock(); |
|
192 |
aosThdMSleepS(ms); |
|
193 |
chSysUnlock(); |
|
194 |
|
|
195 |
return; |
|
196 |
} |
|
197 |
|
|
198 |
/** |
|
199 |
* @brief Lets the calling thread sleep the specified amount of seconds. |
|
200 |
* |
|
201 |
* @param[in] s Time to sleep in seconds. |
|
202 |
*/ |
|
203 |
static inline void aosThdSSleep(const uint32_t s) |
|
204 |
{ |
|
205 |
chSysLock(); |
|
206 |
aosThdSSleepS(s); |
|
207 |
chSysUnlock(); |
|
208 |
|
|
209 |
return; |
|
210 |
} |
|
211 |
|
|
212 |
/** |
|
213 |
* @brief Lets the calling thread sleep the specified amount of seconds. |
|
214 |
* |
|
215 |
* @param[in] s Time to sleep in seconds. |
|
216 |
*/ |
|
217 |
static inline void aosThdSleep(const float s) |
|
218 |
{ |
|
219 |
chSysLock(); |
|
220 |
aosThdSleepS(s); |
|
221 |
chSysUnlock(); |
|
222 |
|
|
223 |
return; |
|
224 |
} |
|
225 |
|
|
226 |
/** |
|
227 |
* @brief Lets the calling thread sleep until the specifide system uptime. |
|
228 |
* |
|
229 |
* @param[in] t Deadline until the thread will sleep. |
|
230 |
*/ |
|
231 |
static inline void aosThdSleepUntil(const aos_timestamp_t* t) |
|
232 |
{ |
|
233 |
chSysLock(); |
|
234 |
aosThdSleepUntilS(t); |
|
235 |
chSysUnlock(); |
|
236 |
|
|
237 |
return; |
|
238 |
} |
|
239 |
|
|
240 |
#endif /* _AMIROOS_THREAD_H_ */ |
|
241 |
|
|
242 |
/** @} */ |
core/inc/aos_time.h | ||
---|---|---|
1 |
/* |
|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
3 |
Copyright (C) 2016..2018 Thomas Schöpping et al. |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU General Public License as published by |
|
7 |
the Free Software Foundation, either version 3 of the License, or |
|
8 |
(at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY) without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU General Public License |
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/. |
|
17 |
*/ |
|
18 |
|
|
19 |
/** |
|
20 |
* @file aos_time.h |
|
21 |
* @brief Time related constants and data types. |
|
22 |
* |
|
23 |
* @addtogroup aos_time |
|
24 |
* @{ |
|
25 |
*/ |
|
26 |
|
|
27 |
#ifndef _AMIROOS_TIME_H_ |
|
28 |
#define _AMIROOS_TIME_H_ |
|
29 |
|
|
30 |
#include <stdint.h> |
|
31 |
|
|
32 |
/** |
|
33 |
* @brief Generic time to represent long time frames at high precision. |
|
34 |
* @note By definition the temporal resolution is 1us. |
|
35 |
*/ |
|
36 |
typedef uint64_t aos_timestamp_t; |
|
37 |
|
|
38 |
/** |
|
39 |
* @brief generic time to represent medium length time frames at high precision. |
|
40 |
* @note By definition the temporal resolution is 1us. |
|
41 |
*/ |
|
42 |
typedef uint32_t aos_interval_t; |
|
43 |
|
|
44 |
/** |
|
45 |
* @brief Generic time to represent long time frames at high precision. |
|
46 |
* @note By definition the temporal resolution is 1us. |
|
47 |
*/ |
|
48 |
typedef aos_timestamp_t aos_longinterval_t; |
|
49 |
|
|
50 |
#define MICROSECONDS_PER_MICROSECOND ((uint8_t) (1)) |
|
51 |
#define MILLISECONDS_PER_MILLISECOND ((uint8_t) (1)) |
|
52 |
#define SECONDS_PER_SECOND ((uint8_t) (1)) |
|
53 |
#define MINUTES_PER_MINUTE ((uint8_t) (1)) |
|
54 |
#define HOURS_PER_HOUR ((uint8_t) (1)) |
|
55 |
#define DAYS_PER_DAY ((uint8_t) (1)) |
|
56 |
#define WEEKS_PER_WEEK ((uint8_t) (1)) |
|
57 |
#define MONTHS_PER_MONTH ((uint8_t) (1)) |
|
58 |
#define YEARS_PER_YEAR ((uint8_t) (1)) |
|
59 |
#define DECADES_PER_DECADE ((uint8_t) (1)) |
|
60 |
#define CENTURIES_PER_CENTURY ((uint8_t) (1)) |
|
61 |
#define MILLENIUMS_PER_MILLENIUM ((uint8_t) (1)) |
|
62 |
|
|
63 |
#define MICROSECONDS_PER_MILLISECOND ((uint16_t) (1000)) |
|
64 |
#define MILLISECONDS_PER_SECOND ((uint16_t) (1000)) |
|
65 |
#define SECONDS_PER_MINUTE ((uint8_t) (60)) |
|
66 |
#define MINUTES_PER_HOUR ((uint8_t) (60)) |
|
67 |
#define HOURS_PER_DAY ((uint8_t) (24)) |
|
68 |
#define DAYS_PER_WEEK ((uint8_t) (7)) |
|
69 |
#define DAYS_PER_YEAR ((float) (365.25f)) |
|
70 |
#define MONTHS_PER_YEAR ((uint8_t) (12)) |
|
71 |
#define YEARS_PER_DECADE ((uint8_t) (10)) |
|
72 |
#define DECADES_PER_CENTURY ((uint8_t) (10)) |
|
73 |
#define CENTURIES_PER_MILLENIUM ((uint8_t) (10)) |
|
74 |
|
|
75 |
#define MICROSECONDS_PER_SECOND ((uint32_t) ((uint32_t)MICROSECONDS_PER_MILLISECOND * (uint32_t)MILLISECONDS_PER_SECOND)) |
|
76 |
#define MILLISECONDS_PER_MINUTE ((uint16_t) ((uint16_t)MILLISECONDS_PER_SECOND * (uint16_t)SECONDS_PER_MINUTE)) |
|
77 |
#define SECONDS_PER_HOUR ((uint16_t) ((uint16_t)SECONDS_PER_MINUTE * (uint16_t)MINUTES_PER_HOUR)) |
|
78 |
#define MINUTES_PER_DAY ((uint16_t) ((uint16_t)MINUTES_PER_HOUR * (uint16_t)HOURS_PER_DAY)) |
|
79 |
#define HOURS_PER_WEEK ((uint8_t) (HOURS_PER_DAY * DAYS_PER_WEEK)) |
|
80 |
#define HOURS_PER_YEAR ((uint16_t) ((float)HOURS_PER_DAY * DAYS_PER_YEAR)) |
|
81 |
#define DAYS_PER_MONTH ((float) (DAYS_PER_YEAR / (float)MONTHS_PER_YEAR)) |
|
82 |
#define DAYS_PER_DECADE ((float) (DAYS_PER_YEAR * (float)YEARS_PER_DECADE)) |
|
83 |
#define WEEKS_PER_YEAR ((float) (DAYS_PER_YEAR / (float)DAYS_PER_WEEK)) |
|
84 |
#define MONTHS_PER_DECADE ((uint8_t) (MONTHS_PER_YEAR * YEARS_PER_DECADE)) |
|
85 |
#define YEARS_PER_CENTURY ((uint8_t) (YEARS_PER_DECADE * DECADES_PER_CENTURY)) |
|
86 |
#define DECADES_PER_MILLENIUM ((uint8_t) (DECADES_PER_CENTURY * CENTURIES_PER_MILLENIUM)) |
|
87 |
|
|
88 |
#define MICROSECONDS_PER_MINUTE ((uint32_t) ((uint32_t)MICROSECONDS_PER_MILLISECOND * (uint32_t)MILLISECONDS_PER_MINUTE)) |
|
89 |
#define MILLISECONDS_PER_HOUR ((uint32_t) ((uint32_t)MILLISECONDS_PER_SECOND * (uint32_t)SECONDS_PER_HOUR)) |
|
90 |
#define SECONDS_PER_DAY ((uint32_t) ((uint32_t)SECONDS_PER_MINUTE * (uint32_t)MINUTES_PER_DAY)) |
|
91 |
#define MINUTES_PER_WEEK ((uint16_t) ((uint16_t)MINUTES_PER_HOUR * (uint16_t)HOURS_PER_WEEK)) |
|
92 |
#define HOURS_PER_MONTH ((float) ((float)HOURS_PER_DAY * DAYS_PER_MONTH)) |
|
93 |
#define HOURS_PER_DECADE ((uint32_t) ((float)HOURS_PER_DAY * DAYS_PER_DECADE)) |
|
94 |
#define MINUTES_PER_YEAR ((uint32_t) ((uint32_t)MINUTES_PER_HOUR * (uint32_t)HOURS_PER_YEAR)) |
|
95 |
#define DAYS_PER_CENTURY ((uint16_t) (DAYS_PER_YEAR * (float)YEARS_PER_CENTURY)) |
|
96 |
#define WEEKS_PER_MONTH ((float) (DAYS_PER_MONTH / (float)DAYS_PER_WEEK)) |
|
97 |
#define WEEKS_PER_DECADE ((float) (DAYS_PER_DECADE / (float)DAYS_PER_WEEK)) |
|
98 |
#define MONTHS_PER_CENTURY ((uint16_t) ((uint16_t)MONTHS_PER_YEAR * (uint16_t)YEARS_PER_CENTURY)) |
|
99 |
#define YEARS_PER_MILLENIUM ((uint16_t) ((uint16_t)YEARS_PER_DECADE * (uint16_t)DECADES_PER_MILLENIUM)) |
|
100 |
|
|
101 |
#define MICROSECONDS_PER_HOUR ((uint32_t) ((uint32_t)MICROSECONDS_PER_MILLISECOND * MILLISECONDS_PER_HOUR)) |
|
102 |
#define MILLISECONDS_PER_DAY ((uint32_t) ((uint32_t)MILLISECONDS_PER_SECOND * SECONDS_PER_DAY)) |
|
103 |
#define SECONDS_PER_WEEK ((uint32_t) (SECONDS_PER_MINUTE * (uint32_t)MINUTES_PER_WEEK)) |
|
104 |
#define SECONDS_PER_YEAR ((uint32_t) (SECONDS_PER_MINUTE * MINUTES_PER_YEAR)) |
|
105 |
#define MINUTES_PER_MONTH ((uint16_t) ((float)MINUTES_PER_HOUR * HOURS_PER_MONTH)) |
|
106 |
#define MINUTES_PER_DECADE ((uint32_t) ((uint32_t)MINUTES_PER_HOUR * HOURS_PER_DECADE)) |
|
107 |
#define HOURS_PER_CENTURY ((uint32_t) ((uint32_t)HOURS_PER_DAY * (uint32_t)DAYS_PER_CENTURY)) |
|
108 |
#define DAYS_PER_MILLENIUM ((uint32_t) (DAYS_PER_YEAR * (float)YEARS_PER_MILLENIUM)) |
Also available in: Unified diff