diff options
Diffstat (limited to 'lib/chibios/os/common/abstractions/nasa_cfe/osal')
11 files changed, 3728 insertions, 0 deletions
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/cfe_osal.mk b/lib/chibios/os/common/abstractions/nasa_cfe/osal/cfe_osal.mk new file mode 100644 index 000000000..c0add1c26 --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/cfe_osal.mk | |||
@@ -0,0 +1,8 @@ | |||
1 | # NASA CFE OSAL files. | ||
2 | CFEOSALSRC = $(CHIBIOS)/os/common/abstractions/nasa_cfe/osal/src/osapi.c | ||
3 | |||
4 | CFEOSALINC = $(CHIBIOS)/os/common/abstractions/nasa_cfe/osal/include | ||
5 | |||
6 | # Shared variables | ||
7 | ALLCSRC += $(CFEOSALSRC) | ||
8 | ALLINC += $(CFEOSALINC) | ||
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/common_types.h b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/common_types.h new file mode 100644 index 000000000..100a9c72e --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/common_types.h | |||
@@ -0,0 +1,267 @@ | |||
1 | /*--------------------------------------------------------------------------- | ||
2 | ** | ||
3 | ** Filename: | ||
4 | ** $Id: common_types.h 1.9 2014/01/14 16:28:32GMT-05:00 acudmore Exp $ | ||
5 | ** | ||
6 | ** Copyright (c) 2004-2006, United States government as represented by the | ||
7 | ** administrator of the National Aeronautics Space Administration. | ||
8 | ** All rights reserved. This software was created at NASAs Goddard | ||
9 | ** Space Flight Center pursuant to government contracts. | ||
10 | ** | ||
11 | ** This is governed by the NASA Open Source Agreement and may be used, | ||
12 | ** distributed and modified only pursuant to the terms of that agreement. | ||
13 | ** | ||
14 | ** Purpose: | ||
15 | ** Unit specification for common types. | ||
16 | ** | ||
17 | ** Design Notes: | ||
18 | ** Assumes make file has defined processor family | ||
19 | ** | ||
20 | ** References: | ||
21 | ** Flight Software Branch C Coding Standard Version 1.0a | ||
22 | ** | ||
23 | ** | ||
24 | ** Notes: | ||
25 | ** | ||
26 | ** | ||
27 | ** $Date: 2014/01/14 16:28:32GMT-05:00 $ | ||
28 | ** $Revision: 1.9 $ | ||
29 | ** $Log: common_types.h $ | ||
30 | ** Revision 1.9 2014/01/14 16:28:32GMT-05:00 acudmore | ||
31 | ** Fixed typo in macro for x86-64 | ||
32 | ** Revision 1.8 2013/08/09 13:58:04GMT-05:00 acudmore | ||
33 | ** Added int64 type, added support for ARM arch, added 64 bit x86 arch, added arch check for GCC arch macros, added check for proper data type sizes | ||
34 | ** Revision 1.7 2013/07/25 10:01:29GMT-05:00 acudmore | ||
35 | ** Added C++ support | ||
36 | ** Revision 1.6 2012/04/11 09:19:03GMT-05:00 acudmore | ||
37 | ** added OS_USED attribute | ||
38 | ** Revision 1.5 2010/02/18 16:43:29EST acudmore | ||
39 | ** Added SPARC processor section | ||
40 | ** Removed special characters from comments that cause problems with some tools. | ||
41 | ** Revision 1.4 2010/02/18 16:41:39EST acudmore | ||
42 | ** Added a block of defines for GCC specific pragmas and extensions. | ||
43 | ** Removed RTEMS boolean related ifdefs | ||
44 | ** moved OS_PACK into the GCC specific block | ||
45 | ** Revision 1.3 2010/02/01 12:31:17EST acudmore | ||
46 | ** Added uint64 type | ||
47 | ** Revision 1.2 2009/07/07 16:30:05EDT acudmore | ||
48 | ** Removed conditinal comp. around boolean for m68k. | ||
49 | ** This will need to be done for all RTEMS targets | ||
50 | ** Revision 1.1 2009/06/02 10:04:58EDT acudmore | ||
51 | ** Initial revision | ||
52 | ** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/os/inc/project.pj | ||
53 | ** Revision 1.1 2008/04/20 22:35:58EDT ruperera | ||
54 | ** Initial revision | ||
55 | ** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/inc/project.pj | ||
56 | ** Revision 1.1 2007/10/16 16:14:49EDT apcudmore | ||
57 | ** Initial revision | ||
58 | ** Member added to project d:/mksdata/MKS-OSAL-REPOSITORY/src/inc/project.pj | ||
59 | ** Revision 1.2 2006/06/08 14:28:32EDT David Kobe (dlkobe) | ||
60 | ** Added NASA Open Source Legal Statement | ||
61 | ** Revision 1.1 2005/06/09 09:57:51GMT-05:00 rperera | ||
62 | ** Initial revision | ||
63 | ** Member added to project d:/mksdata/MKS-CFE-REPOSITORY/cfe-core/inc/project.pj | ||
64 | ** Revision 1.6 2005/03/24 19:20:52 rmcgraw | ||
65 | ** Wrapped the boolean defintion for all three processors with #ifndef _USING_RTEMS_INCLUDES_ | ||
66 | ** | ||
67 | ** Revision 1.5 2005/03/10 16:59:08 acudmore | ||
68 | ** removed boolean prefix to TRUE and FALSE defintion to avoid vxWorks conflict. | ||
69 | ** | ||
70 | ** Revision 1.4 2005/03/07 20:23:34 acudmore | ||
71 | ** removed duplicate boolean definition | ||
72 | ** | ||
73 | ** Revision 1.3 2005/03/07 20:05:17 acudmore | ||
74 | ** updated with __PPC__ macro that gnu compiler uses | ||
75 | ** | ||
76 | ** Revision 1.2 2005/03/04 16:02:44 acudmore | ||
77 | ** added coldfire architecture | ||
78 | ** | ||
79 | ** Revision 1.1 2005/03/04 15:58:45 acudmore | ||
80 | ** Added common_types.h | ||
81 | ** | ||
82 | ** | ||
83 | ** | ||
84 | **-------------------------------------------------------------------------*/ | ||
85 | |||
86 | #ifndef _common_types_ | ||
87 | #define _common_types_ | ||
88 | |||
89 | #ifdef __cplusplus | ||
90 | extern "C" { | ||
91 | #endif | ||
92 | |||
93 | /* | ||
94 | ** Includes | ||
95 | */ | ||
96 | |||
97 | /* | ||
98 | ** Macro Definitions | ||
99 | */ | ||
100 | |||
101 | /* | ||
102 | ** Condition = TRUE is ok, Condition = FALSE is error | ||
103 | */ | ||
104 | #define CompileTimeAssert(Condition, Message) typedef char Message[(Condition) ? 1 : -1] | ||
105 | |||
106 | |||
107 | /* | ||
108 | ** Define compiler specific macros | ||
109 | ** The __extension__ compiler pragma is required | ||
110 | ** for the uint64 type using GCC with the ANSI C90 standard. | ||
111 | ** Other macros can go in here as needed, for example alignment | ||
112 | ** pragmas. | ||
113 | */ | ||
114 | #if defined (__GNUC__) | ||
115 | #define _EXTENSION_ __extension__ | ||
116 | #define OS_PACK __attribute__ ((packed)) | ||
117 | #define OS_ALIGN(n) __attribute__((aligned(n))) | ||
118 | #define OS_USED __attribute__((used)) | ||
119 | #else | ||
120 | #define _EXTENSION_ | ||
121 | #define OS_PACK | ||
122 | #define OS_ALIGN(n) | ||
123 | #define OS_USED | ||
124 | #endif | ||
125 | |||
126 | #if defined(_ix86_) || defined (__i386__) | ||
127 | /* ----------------------- Intel x86 processor family -------------------------*/ | ||
128 | /* Little endian */ | ||
129 | #undef _STRUCT_HIGH_BIT_FIRST_ | ||
130 | #define _STRUCT_LOW_BIT_FIRST_ | ||
131 | |||
132 | typedef unsigned char boolean; | ||
133 | typedef signed char int8; | ||
134 | typedef short int int16; | ||
135 | typedef long int int32; | ||
136 | _EXTENSION_ typedef long long int int64; | ||
137 | typedef unsigned char uint8; | ||
138 | typedef unsigned short int uint16; | ||
139 | typedef unsigned long int uint32; | ||
140 | _EXTENSION_ typedef unsigned long long int uint64; | ||
141 | |||
142 | typedef unsigned long int cpuaddr; | ||
143 | |||
144 | #elif defined (_ix64_) || defined (__x86_64__) | ||
145 | /* ----------------------- Intel/AMD x64 processor family -------------------------*/ | ||
146 | /* Little endian */ | ||
147 | #undef _STRUCT_HIGH_BIT_FIRST_ | ||
148 | #define _STRUCT_LOW_BIT_FIRST_ | ||
149 | |||
150 | typedef unsigned char boolean; | ||
151 | typedef signed char int8; | ||
152 | typedef short int int16; | ||
153 | typedef int int32; | ||
154 | typedef long int int64; | ||
155 | typedef unsigned char uint8; | ||
156 | typedef unsigned short int uint16; | ||
157 | typedef unsigned int uint32; | ||
158 | typedef unsigned long int uint64; | ||
159 | |||
160 | typedef unsigned long int cpuaddr; | ||
161 | |||
162 | #elif defined(__PPC__) || defined (__ppc__) | ||
163 | /* ----------------------- Motorola Power PC family ---------------------------*/ | ||
164 | /* The PPC can be programmed to be big or little endian, we assume native */ | ||
165 | /* Big endian */ | ||
166 | #define _STRUCT_HIGH_BIT_FIRST_ | ||
167 | #undef _STRUCT_LOW_BIT_FIRST_ | ||
168 | |||
169 | typedef unsigned char boolean; | ||
170 | typedef signed char int8; | ||
171 | typedef short int int16; | ||
172 | typedef long int int32; | ||
173 | _EXTENSION_ typedef long long int int64; | ||
174 | typedef unsigned char uint8; | ||
175 | typedef unsigned short int uint16; | ||
176 | typedef unsigned long int uint32; | ||
177 | _EXTENSION_ typedef unsigned long long int uint64; | ||
178 | |||
179 | typedef unsigned long int cpuaddr; | ||
180 | |||
181 | #elif defined(_m68k_) || defined(__m68k__) | ||
182 | /* ----------------------- Motorola m68k/Coldfire family ---------------------------*/ | ||
183 | /* Big endian */ | ||
184 | #define _STRUCT_HIGH_BIT_FIRST_ | ||
185 | #undef _STRUCT_LOW_BIT_FIRST_ | ||
186 | |||
187 | typedef unsigned char boolean; | ||
188 | typedef signed char int8; | ||
189 | typedef short int int16; | ||
190 | typedef long int int32; | ||
191 | _EXTENSION_ typedef long long int int64; | ||
192 | typedef unsigned char uint8; | ||
193 | typedef unsigned short int uint16; | ||
194 | typedef unsigned long int uint32; | ||
195 | _EXTENSION_ typedef unsigned long long int uint64; | ||
196 | |||
197 | typedef unsigned long int cpuaddr; | ||
198 | |||
199 | #elif defined (__ARM__) || defined(__arm__) | ||
200 | /* ----------------------- ARM processor family -------------------------*/ | ||
201 | /* Little endian */ | ||
202 | #undef _STRUCT_HIGH_BIT_FIRST_ | ||
203 | #define _STRUCT_LOW_BIT_FIRST_ | ||
204 | |||
205 | typedef unsigned char boolean; | ||
206 | typedef signed char int8; | ||
207 | typedef short int int16; | ||
208 | typedef long int int32; | ||
209 | _EXTENSION_ typedef long long int int64; | ||
210 | typedef unsigned char uint8; | ||
211 | typedef unsigned short int uint16; | ||
212 | typedef unsigned long int uint32; | ||
213 | _EXTENSION_ typedef unsigned long long int uint64; | ||
214 | |||
215 | typedef unsigned long int cpuaddr; | ||
216 | |||
217 | #elif defined(__SPARC__) || defined (_sparc_) | ||
218 | /* ----------------------- SPARC/LEON family ---------------------------*/ | ||
219 | /* SPARC Big endian */ | ||
220 | #define _STRUCT_HIGH_BIT_FIRST_ | ||
221 | #undef _STRUCT_LOW_BIT_FIRST_ | ||
222 | |||
223 | typedef unsigned char boolean; | ||
224 | typedef signed char int8; | ||
225 | typedef short int int16; | ||
226 | typedef long int int32; | ||
227 | _EXTENSION_ typedef long long int int64; | ||
228 | typedef unsigned char uint8; | ||
229 | typedef unsigned short int uint16; | ||
230 | typedef unsigned long int uint32; | ||
231 | _EXTENSION_ typedef unsigned long long int uint64; | ||
232 | |||
233 | typedef unsigned long int cpuaddr; | ||
234 | |||
235 | #else /* not any of the above */ | ||
236 | #error undefined processor | ||
237 | #endif /* processor types */ | ||
238 | |||
239 | #ifndef NULL /* pointer to nothing */ | ||
240 | #define NULL ((void *) 0) | ||
241 | #endif | ||
242 | |||
243 | #ifndef TRUE /* Boolean true */ | ||
244 | #define TRUE (1) | ||
245 | #endif | ||
246 | |||
247 | #ifndef FALSE /* Boolean false */ | ||
248 | #define FALSE (0) | ||
249 | #endif | ||
250 | |||
251 | /* | ||
252 | ** Check Sizes | ||
253 | */ | ||
254 | CompileTimeAssert(sizeof(uint8)==1, TypeUint8WrongSize); | ||
255 | CompileTimeAssert(sizeof(uint16)==2, TypeUint16WrongSize); | ||
256 | CompileTimeAssert(sizeof(uint32)==4, TypeUint32WrongSize); | ||
257 | CompileTimeAssert(sizeof(uint64)==8, TypeUint64WrongSize); | ||
258 | CompileTimeAssert(sizeof(int8)==1, Typeint8WrongSize); | ||
259 | CompileTimeAssert(sizeof(int16)==2, Typeint16WrongSize); | ||
260 | CompileTimeAssert(sizeof(int32)==4, Typeint32WrongSize); | ||
261 | CompileTimeAssert(sizeof(int64)==8, Typeint64WrongSize); | ||
262 | |||
263 | #ifdef __cplusplus | ||
264 | } | ||
265 | #endif | ||
266 | |||
267 | #endif /* _common_types_ */ | ||
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-core.h b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-core.h new file mode 100644 index 000000000..8c9b13a78 --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-core.h | |||
@@ -0,0 +1,274 @@ | |||
1 | /* | ||
2 | ** File: osapi-os-core.h | ||
3 | ** | ||
4 | ** Copyright (c) 2004-2006, United States government as represented by the | ||
5 | ** administrator of the National Aeronautics Space Administration. | ||
6 | ** All rights reserved. This software was created at NASAs Goddard | ||
7 | ** Space Flight Center pursuant to government contracts. | ||
8 | ** | ||
9 | ** This is governed by the NASA Open Source Agreement and may be used, | ||
10 | ** distributed and modified only pursuant to the terms of that agreement. | ||
11 | ** | ||
12 | ** Author: Ezra Yeheksli -Code 582/Raytheon | ||
13 | ** | ||
14 | ** Purpose: Contains functions prototype definitions and variables declarations | ||
15 | ** for the OS Abstraction Layer, Core OS module | ||
16 | ** | ||
17 | ** $Revision: 1.8 $ | ||
18 | ** | ||
19 | ** $Date: 2013/07/25 10:02:00GMT-05:00 $ | ||
20 | ** | ||
21 | ** $Log: osapi-os-core.h $ | ||
22 | ** Revision 1.8 2013/07/25 10:02:00GMT-05:00 acudmore | ||
23 | ** removed circular include "osapi.h" | ||
24 | ** Revision 1.7 2012/04/11 09:30:48GMT-05:00 acudmore | ||
25 | ** Added OS_printf_enable and OS_printf_disable | ||
26 | ** Revision 1.6 2010/11/12 12:00:17EST acudmore | ||
27 | ** replaced copyright character with (c) and added open source notice where needed. | ||
28 | ** Revision 1.5 2010/11/10 15:33:14EST acudmore | ||
29 | ** Updated IntAttachHandler prototype | ||
30 | ** Revision 1.4 2010/03/08 12:06:28EST acudmore | ||
31 | ** added function pointer type to get rid of warnings | ||
32 | ** Revision 1.3 2010/02/01 12:37:15EST acudmore | ||
33 | ** added return code to OS API init | ||
34 | ** Revision 1.2 2009/08/04 10:49:09EDT acudmore | ||
35 | ** | ||
36 | */ | ||
37 | |||
38 | #ifndef _osapi_core_ | ||
39 | #define _osapi_core_ | ||
40 | |||
41 | #include <stdarg.h> /* for va_list */ | ||
42 | |||
43 | /*difines constants for OS_BinSemCreate for state of semaphore */ | ||
44 | #define OS_SEM_FULL 1 | ||
45 | #define OS_SEM_EMPTY 0 | ||
46 | |||
47 | /* #define for enabling floating point operations on a task*/ | ||
48 | #define OS_FP_ENABLED 1 | ||
49 | |||
50 | /* tables for the properties of objects */ | ||
51 | |||
52 | /*tasks */ | ||
53 | typedef struct | ||
54 | { | ||
55 | char name [OS_MAX_API_NAME]; | ||
56 | uint32 creator; | ||
57 | uint32 stack_size; | ||
58 | uint32 priority; | ||
59 | uint32 OStask_id; | ||
60 | }OS_task_prop_t; | ||
61 | |||
62 | /* queues */ | ||
63 | typedef struct | ||
64 | { | ||
65 | char name [OS_MAX_API_NAME]; | ||
66 | uint32 creator; | ||
67 | }OS_queue_prop_t; | ||
68 | |||
69 | /* Binary Semaphores */ | ||
70 | typedef struct | ||
71 | { | ||
72 | char name [OS_MAX_API_NAME]; | ||
73 | uint32 creator; | ||
74 | int32 value; | ||
75 | }OS_bin_sem_prop_t; | ||
76 | |||
77 | /* Counting Semaphores */ | ||
78 | typedef struct | ||
79 | { | ||
80 | char name [OS_MAX_API_NAME]; | ||
81 | uint32 creator; | ||
82 | int32 value; | ||
83 | }OS_count_sem_prop_t; | ||
84 | |||
85 | /* Mutexes */ | ||
86 | typedef struct | ||
87 | { | ||
88 | char name [OS_MAX_API_NAME]; | ||
89 | uint32 creator; | ||
90 | }OS_mut_sem_prop_t; | ||
91 | |||
92 | |||
93 | /* struct for OS_GetLocalTime() */ | ||
94 | |||
95 | typedef struct | ||
96 | { | ||
97 | uint32 seconds; | ||
98 | uint32 microsecs; | ||
99 | }OS_time_t; | ||
100 | |||
101 | /* heap info */ | ||
102 | typedef struct | ||
103 | { | ||
104 | uint32 free_bytes; | ||
105 | uint32 free_blocks; | ||
106 | uint32 largest_free_block; | ||
107 | }OS_heap_prop_t; | ||
108 | |||
109 | |||
110 | /* This typedef is for the OS_GetErrorName function, to ensure | ||
111 | * everyone is making an array of the same length */ | ||
112 | |||
113 | typedef char os_err_name_t[35]; | ||
114 | |||
115 | /* | ||
116 | ** These typedefs are for the task entry point | ||
117 | */ | ||
118 | typedef void osal_task; | ||
119 | typedef osal_task ((*osal_task_entry)(void)); | ||
120 | |||
121 | /* | ||
122 | ** Exported Functions | ||
123 | */ | ||
124 | |||
125 | /* | ||
126 | ** Initialization of API | ||
127 | */ | ||
128 | int32 OS_API_Init (void); | ||
129 | |||
130 | |||
131 | /* | ||
132 | ** Task API | ||
133 | */ | ||
134 | |||
135 | int32 OS_TaskCreate (uint32 *task_id, const char *task_name, | ||
136 | osal_task_entry function_pointer, | ||
137 | const uint32 *stack_pointer, | ||
138 | uint32 stack_size, | ||
139 | uint32 priority, uint32 flags); | ||
140 | |||
141 | int32 OS_TaskDelete (uint32 task_id); | ||
142 | void OS_TaskExit (void); | ||
143 | int32 OS_TaskInstallDeleteHandler(void *function_pointer); | ||
144 | int32 OS_TaskDelay (uint32 millisecond); | ||
145 | int32 OS_TaskSetPriority (uint32 task_id, uint32 new_priority); | ||
146 | int32 OS_TaskRegister (void); | ||
147 | uint32 OS_TaskGetId (void); | ||
148 | int32 OS_TaskGetIdByName (uint32 *task_id, const char *task_name); | ||
149 | int32 OS_TaskGetInfo (uint32 task_id, OS_task_prop_t *task_prop); | ||
150 | |||
151 | /* | ||
152 | ** Message Queue API | ||
153 | */ | ||
154 | |||
155 | /* | ||
156 | ** Queue Create now has the Queue ID returned to the caller. | ||
157 | */ | ||
158 | int32 OS_QueueCreate (uint32 *queue_id, const char *queue_name, | ||
159 | uint32 queue_depth, uint32 data_size, uint32 flags); | ||
160 | int32 OS_QueueDelete (uint32 queue_id); | ||
161 | int32 OS_QueueGet (uint32 queue_id, void *data, uint32 size, | ||
162 | uint32 *size_copied, int32 timeout); | ||
163 | int32 OS_QueuePut (uint32 queue_id, void *data, uint32 size, | ||
164 | uint32 flags); | ||
165 | int32 OS_QueueGetIdByName (uint32 *queue_id, const char *queue_name); | ||
166 | int32 OS_QueueGetInfo (uint32 queue_id, OS_queue_prop_t *queue_prop); | ||
167 | |||
168 | /* | ||
169 | ** Semaphore API | ||
170 | */ | ||
171 | |||
172 | int32 OS_BinSemCreate (uint32 *sem_id, const char *sem_name, | ||
173 | uint32 sem_initial_value, uint32 options); | ||
174 | int32 OS_BinSemFlush (uint32 sem_id); | ||
175 | int32 OS_BinSemGive (uint32 sem_id); | ||
176 | int32 OS_BinSemTake (uint32 sem_id); | ||
177 | int32 OS_BinSemTimedWait (uint32 sem_id, uint32 msecs); | ||
178 | int32 OS_BinSemDelete (uint32 sem_id); | ||
179 | int32 OS_BinSemGetIdByName (uint32 *sem_id, const char *sem_name); | ||
180 | int32 OS_BinSemGetInfo (uint32 sem_id, OS_bin_sem_prop_t *bin_prop); | ||
181 | |||
182 | int32 OS_CountSemCreate (uint32 *sem_id, const char *sem_name, | ||
183 | uint32 sem_initial_value, uint32 options); | ||
184 | int32 OS_CountSemGive (uint32 sem_id); | ||
185 | int32 OS_CountSemTake (uint32 sem_id); | ||
186 | int32 OS_CountSemTimedWait (uint32 sem_id, uint32 msecs); | ||
187 | int32 OS_CountSemDelete (uint32 sem_id); | ||
188 | int32 OS_CountSemGetIdByName (uint32 *sem_id, const char *sem_name); | ||
189 | int32 OS_CountSemGetInfo (uint32 sem_id, OS_count_sem_prop_t *count_prop); | ||
190 | |||
191 | /* | ||
192 | ** Mutex API | ||
193 | */ | ||
194 | |||
195 | int32 OS_MutSemCreate (uint32 *sem_id, const char *sem_name, uint32 options); | ||
196 | int32 OS_MutSemGive (uint32 sem_id); | ||
197 | int32 OS_MutSemTake (uint32 sem_id); | ||
198 | int32 OS_MutSemDelete (uint32 sem_id); | ||
199 | int32 OS_MutSemGetIdByName (uint32 *sem_id, const char *sem_name); | ||
200 | int32 OS_MutSemGetInfo (uint32 sem_id, OS_mut_sem_prop_t *mut_prop); | ||
201 | |||
202 | /* | ||
203 | ** OS Time/Tick related API | ||
204 | */ | ||
205 | |||
206 | int32 OS_Milli2Ticks (uint32 milli_seconds); | ||
207 | int32 OS_Tick2Micros (void); | ||
208 | int32 OS_GetLocalTime (OS_time_t *time_struct); | ||
209 | int32 OS_SetLocalTime (OS_time_t *time_struct); | ||
210 | |||
211 | /* | ||
212 | ** Exception API | ||
213 | */ | ||
214 | |||
215 | int32 OS_ExcAttachHandler (uint32 ExceptionNumber, | ||
216 | void (*ExceptionHandler)(uint32, uint32 *,uint32), | ||
217 | int32 parameter); | ||
218 | int32 OS_ExcEnable (int32 ExceptionNumber); | ||
219 | int32 OS_ExcDisable (int32 ExceptionNumber); | ||
220 | |||
221 | /* | ||
222 | ** Floating Point Unit API | ||
223 | */ | ||
224 | |||
225 | int32 OS_FPUExcAttachHandler (uint32 ExceptionNumber, void * ExceptionHandler , | ||
226 | int32 parameter); | ||
227 | int32 OS_FPUExcEnable (int32 ExceptionNumber); | ||
228 | int32 OS_FPUExcDisable (int32 ExceptionNumber); | ||
229 | int32 OS_FPUExcSetMask (uint32 mask); | ||
230 | int32 OS_FPUExcGetMask (uint32 *mask); | ||
231 | |||
232 | /* | ||
233 | ** Interrupt API | ||
234 | */ | ||
235 | int32 OS_IntAttachHandler (uint32 InterruptNumber, osal_task_entry InterruptHandler, int32 parameter); | ||
236 | int32 OS_IntUnlock (int32 IntLevel); | ||
237 | int32 OS_IntLock (void); | ||
238 | |||
239 | int32 OS_IntEnable (int32 Level); | ||
240 | int32 OS_IntDisable (int32 Level); | ||
241 | |||
242 | int32 OS_IntSetMask (uint32 mask); | ||
243 | int32 OS_IntGetMask (uint32 *mask); | ||
244 | int32 OS_IntAck (int32 InterruptNumber); | ||
245 | |||
246 | /* | ||
247 | ** Shared memory API | ||
248 | */ | ||
249 | int32 OS_ShMemInit (void); | ||
250 | int32 OS_ShMemCreate (uint32 *Id, uint32 NBytes, char* SegName); | ||
251 | int32 OS_ShMemSemTake (uint32 Id); | ||
252 | int32 OS_ShMemSemGive (uint32 Id); | ||
253 | int32 OS_ShMemAttach (uint32 * Address, uint32 Id); | ||
254 | int32 OS_ShMemGetIdByName (uint32 *ShMemId, const char *SegName ); | ||
255 | |||
256 | /* | ||
257 | ** Heap API | ||
258 | */ | ||
259 | int32 OS_HeapGetInfo (OS_heap_prop_t *heap_prop); | ||
260 | |||
261 | /* | ||
262 | ** API for useful debugging function | ||
263 | */ | ||
264 | int32 OS_GetErrorName (int32 error_num, os_err_name_t* err_name); | ||
265 | |||
266 | |||
267 | /* | ||
268 | ** Abstraction for printf statements | ||
269 | */ | ||
270 | void OS_printf( const char *string, ...); | ||
271 | void OS_printf_disable(void); | ||
272 | void OS_printf_enable(void); | ||
273 | |||
274 | #endif | ||
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-custom.h b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-custom.h new file mode 100644 index 000000000..15a308848 --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-custom.h | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file osapi-os-custom.h | ||
19 | * @brief Custom OSAPI extensions header. | ||
20 | * | ||
21 | * @addtogroup osapi-custom | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef OSAPI_CUSTOM_H | ||
26 | #define OSAPI_CUSTOM_H | ||
27 | |||
28 | /*===========================================================================*/ | ||
29 | /* Module constants. */ | ||
30 | /*===========================================================================*/ | ||
31 | |||
32 | /*===========================================================================*/ | ||
33 | /* Module pre-compile time settings. */ | ||
34 | /*===========================================================================*/ | ||
35 | |||
36 | /*===========================================================================*/ | ||
37 | /* Derived constants and error checks. */ | ||
38 | /*===========================================================================*/ | ||
39 | |||
40 | /*===========================================================================*/ | ||
41 | /* Module data structures and types. */ | ||
42 | /*===========================================================================*/ | ||
43 | |||
44 | /*===========================================================================*/ | ||
45 | /* Module macros. */ | ||
46 | /*===========================================================================*/ | ||
47 | |||
48 | /*===========================================================================*/ | ||
49 | /* External declarations. */ | ||
50 | /*===========================================================================*/ | ||
51 | |||
52 | #ifdef __cplusplus | ||
53 | extern "C" { | ||
54 | #endif | ||
55 | void OS_set_printf(int (*printf)(const char *fmt, ...)); | ||
56 | boolean OS_TaskDeleteCheck(void); | ||
57 | int32 OS_TaskWait(uint32 task_id); | ||
58 | #ifdef __cplusplus | ||
59 | } | ||
60 | #endif | ||
61 | |||
62 | /*===========================================================================*/ | ||
63 | /* Module inline functions. */ | ||
64 | /*===========================================================================*/ | ||
65 | |||
66 | #endif /* OSAPI_CUSTOM_H */ | ||
67 | |||
68 | /** @} */ | ||
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-filesys.h b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-filesys.h new file mode 100644 index 000000000..c46800341 --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-filesys.h | |||
@@ -0,0 +1,419 @@ | |||
1 | /* | ||
2 | ** File: osapi-os-filesys.h | ||
3 | ** | ||
4 | ** Copyright (c) 2004-2006, United States government as represented by the | ||
5 | ** administrator of the National Aeronautics Space Administration. | ||
6 | ** All rights reserved. This software was created at NASAs Goddard | ||
7 | ** Space Flight Center pursuant to government contracts. | ||
8 | ** | ||
9 | ** This is governed by the NASA Open Source Agreement and may be used, | ||
10 | ** distributed and modified only pursuant to the terms of that agreement. | ||
11 | ** | ||
12 | ** Author: Alan Cudmore Code 582 | ||
13 | ** | ||
14 | ** Purpose: Contains functions prototype definitions and variables declarations | ||
15 | ** for the OS Abstraction Layer, File System module | ||
16 | ** | ||
17 | ** $Revision: 1.11 $ | ||
18 | ** | ||
19 | ** $Date: 2013/12/16 12:57:41GMT-05:00 $ | ||
20 | ** | ||
21 | ** $Log: osapi-os-filesys.h $ | ||
22 | ** Revision 1.11 2013/12/16 12:57:41GMT-05:00 acudmore | ||
23 | ** Added macros for Volume name length and physical device name length | ||
24 | ** Revision 1.10 2013/07/29 12:05:48GMT-05:00 acudmore | ||
25 | ** Added define for device and volume name length | ||
26 | ** Revision 1.9 2013/07/25 14:31:21GMT-05:00 acudmore | ||
27 | ** Added prototype and datatype for OS_GetFsInfo | ||
28 | ** Revision 1.8 2011/12/05 12:04:21GMT-05:00 acudmore | ||
29 | ** Added OS_rewinddir API | ||
30 | ** Revision 1.7 2011/04/05 16:01:12EDT acudmore | ||
31 | ** Added OS_CloseFileByName and OS_CloseAllFiles | ||
32 | ** Revision 1.6 2010/11/15 11:04:38EST acudmore | ||
33 | ** Added OS_FileOpenCheck function. | ||
34 | ** Revision 1.5 2010/11/12 12:00:18EST acudmore | ||
35 | ** replaced copyright character with (c) and added open source notice where needed. | ||
36 | ** Revision 1.4 2010/02/01 12:28:57EST acudmore | ||
37 | ** Added OS_fsBytesFree API | ||
38 | ** Revision 1.3 2010/01/25 14:44:26EST acudmore | ||
39 | ** renamed "new" variable to avoid C++ reserved name conflict. | ||
40 | ** Revision 1.2 2009/07/14 15:16:05EDT acudmore | ||
41 | ** Added OS_TranslatePath to the API | ||
42 | ** Revision 1.1 2008/04/20 22:36:01EDT ruperera | ||
43 | ** Initial revision | ||
44 | ** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/os/inc/project.pj | ||
45 | ** Revision 1.1 2007/10/16 16:14:52EDT apcudmore | ||
46 | ** Initial revision | ||
47 | ** Member added to project d:/mksdata/MKS-OSAL-REPOSITORY/src/os/inc/project.pj | ||
48 | ** Revision 1.1 2007/08/24 13:43:24EDT apcudmore | ||
49 | ** Initial revision | ||
50 | ** Member added to project d:/mksdata/MKS-CFE-PROJECT/fsw/cfe-core/os/inc/project.pj | ||
51 | ** Revision 1.17 2007/06/07 09:59:14EDT njyanchik | ||
52 | ** I replaced the second OS_cp definition with OS_mv | ||
53 | ** Revision 1.16 2007/06/05 16:25:33EDT apcudmore | ||
54 | ** Increased Number of volume table entries from 10 to 14. | ||
55 | ** Added 2 extra EEPROM disk mappings to RAD750 Volume table + 2 spares | ||
56 | ** Added 4 spares to every other volume table. | ||
57 | ** Revision 1.15 2007/05/25 09:17:56EDT njyanchik | ||
58 | ** I added the rmfs call to the OSAL and updated the unit test stubs to match | ||
59 | ** Revision 1.14 2007/03/21 10:15:29EST njyanchik | ||
60 | ** I mistakenly put the wrong length in for the path in the OS_FDTableEntry structure, and I added | ||
61 | ** some code that will set and out of range file descriptors .IsValid flag to false in OS_FDGetInfo | ||
62 | ** Revision 1.13 2007/03/06 11:52:46EST njyanchik | ||
63 | ** This change goes with the previous CP, I forgot to include it | ||
64 | ** Revision 1.12 2007/02/28 14:57:45EST njyanchik | ||
65 | ** The updates for supporting copying and moving files are now supported | ||
66 | ** Revision 1.11 2007/02/27 15:22:11EST njyanchik | ||
67 | ** This CP has the initial import of the new file descripor table mechanism | ||
68 | ** Revision 1.10 2006/12/20 10:27:09EST njyanchik | ||
69 | ** This change package incorporates all the changes necessary for the addition | ||
70 | ** of a new API to get the real physical drive undernieth a mount point | ||
71 | ** Revision 1.9 2006/11/14 14:44:28GMT-05:00 njyanchik | ||
72 | ** Checks were added to the OS fs calls that look at the return of a function that | ||
73 | ** changes the name of paths from abstracted to local path names. | ||
74 | ** Revision 1.8 2006/10/30 16:12:19GMT-05:00 apcudmore | ||
75 | ** Updated Compact flash and RAM device names for vxWorks 6.2 changes. | ||
76 | ** Revision 1.7 2006/10/25 11:31:18EDT njyanchik | ||
77 | ** This CP incorporates changes to every bsp_voltab.c file. I increased the number | ||
78 | ** entries in the volume table to 10. I also changed the #define in the os_filesys.h | ||
79 | ** file for the number of entries to match. | ||
80 | ** | ||
81 | ** This update also includes adding the prototype for OS_initfs in os_filesys.h | ||
82 | ** Revision 1.6 2006/09/26 09:03:46GMT-05:00 njyanchik | ||
83 | ** Contains the initial import of the ES Shell commands interface | ||
84 | ** Revision 1.5 2006/07/25 15:37:52EDT njyanchik | ||
85 | ** It turns out the both the FS app and the OSAL were incorrect where file descriptors are | ||
86 | ** concerned. the file descriptors should be int32 across the board. | ||
87 | ** Revision 1.4 2006/01/20 11:56:18EST njyanchik | ||
88 | ** Fixed header file information to match api document | ||
89 | ** Revision 1.26 2005/07/12 17:13:56 nyanchik | ||
90 | ** Moved the Volume table to a bsp table in the arch directories. | ||
91 | ** | ||
92 | ** Revision 1.2 2005/07/11 16:26:57EDT apcudmore | ||
93 | ** OSAPI 2.0 integration | ||
94 | ** Revision 1.25 2005/07/06 16:11:17 nyanchik | ||
95 | ** *** empty log message *** | ||
96 | ** | ||
97 | ** Revision 1.24 2005/07/05 18:34:55 nyanchik | ||
98 | ** fixed issues found in code walkthrogh. Also removed the OS_Info* functions that are going in the BSP | ||
99 | ** | ||
100 | ** Revision 1.23 2005/06/17 19:46:34 nyanchik | ||
101 | ** added new file system style to linux and rtems. | ||
102 | ** | ||
103 | ** Revision 1.22 2005/06/15 16:43:48 nyanchik | ||
104 | ** added extra parenthesis for the .h file # defines | ||
105 | ** | ||
106 | ** Revision 1.21 2005/06/06 14:17:42 nyanchik | ||
107 | ** added headers to osapi-os-core.h and osapi-os-filesys.h | ||
108 | ** | ||
109 | ** Revision 1.20 2005/06/02 18:04:24 nyanchik | ||
110 | ** *** empty log message *** | ||
111 | ** | ||
112 | ** Revision 1.1 2005/03/15 18:26:32 nyanchik | ||
113 | ** *** empty log message *** | ||
114 | ** | ||
115 | ** | ||
116 | ** Date Written: | ||
117 | ** | ||
118 | ** | ||
119 | */ | ||
120 | |||
121 | #ifndef _osapi_filesys_ | ||
122 | #define _osapi_filesys_ | ||
123 | #include <stdio.h> | ||
124 | #include <stdlib.h> | ||
125 | #include <dirent.h> | ||
126 | #include <sys/stat.h> | ||
127 | |||
128 | #define OS_READ_ONLY 0 | ||
129 | #define OS_WRITE_ONLY 1 | ||
130 | #define OS_READ_WRITE 2 | ||
131 | |||
132 | #define OS_SEEK_SET 0 | ||
133 | #define OS_SEEK_CUR 1 | ||
134 | #define OS_SEEK_END 2 | ||
135 | |||
136 | #define OS_CHK_ONLY 0 | ||
137 | #define OS_REPAIR 1 | ||
138 | |||
139 | #define FS_BASED 0 | ||
140 | #define RAM_DISK 1 | ||
141 | #define EEPROM_DISK 2 | ||
142 | #define ATA_DISK 3 | ||
143 | |||
144 | |||
145 | /* | ||
146 | ** Number of entries in the internal volume table | ||
147 | */ | ||
148 | #define NUM_TABLE_ENTRIES 14 | ||
149 | |||
150 | /* | ||
151 | ** Length of a Device and Volume name | ||
152 | */ | ||
153 | #define OS_FS_DEV_NAME_LEN 32 | ||
154 | #define OS_FS_PHYS_NAME_LEN 64 | ||
155 | #define OS_FS_VOL_NAME_LEN 32 | ||
156 | |||
157 | |||
158 | /* | ||
159 | ** Defines for File System Calls | ||
160 | */ | ||
161 | #define OS_FS_SUCCESS 0 | ||
162 | #define OS_FS_ERROR (-1) | ||
163 | #define OS_FS_ERR_INVALID_POINTER (-2) | ||
164 | #define OS_FS_ERR_PATH_TOO_LONG (-3) | ||
165 | #define OS_FS_ERR_NAME_TOO_LONG (-4) | ||
166 | #define OS_FS_UNIMPLEMENTED (-5) | ||
167 | #define OS_FS_ERR_DRIVE_NOT_CREATED (-6) | ||
168 | #define OS_FS_ERR_DEVICE_NOT_FREE (-7) | ||
169 | #define OS_FS_ERR_PATH_INVALID (-8) | ||
170 | #define OS_FS_ERR_NO_FREE_FDS (-9) | ||
171 | #define OS_FS_ERR_INVALID_FD (-10) | ||
172 | |||
173 | /* This typedef is for the OS_FS_GetErrorName function, to ensure | ||
174 | * everyone is making an array of the same length */ | ||
175 | |||
176 | typedef char os_fs_err_name_t[35]; | ||
177 | |||
178 | |||
179 | /* | ||
180 | ** Internal structure of the OS volume table for | ||
181 | ** mounted file systems and path translation | ||
182 | */ | ||
183 | typedef struct | ||
184 | { | ||
185 | char DeviceName [OS_FS_DEV_NAME_LEN]; | ||
186 | char PhysDevName [OS_FS_PHYS_NAME_LEN]; | ||
187 | uint32 VolumeType; | ||
188 | uint8 VolatileFlag; | ||
189 | uint8 FreeFlag; | ||
190 | uint8 IsMounted; | ||
191 | char VolumeName [OS_FS_VOL_NAME_LEN]; | ||
192 | char MountPoint [OS_MAX_PATH_LEN]; | ||
193 | uint32 BlockSize; | ||
194 | |||
195 | }OS_VolumeInfo_t; | ||
196 | |||
197 | typedef struct | ||
198 | { | ||
199 | int32 OSfd; /* The underlying OS's file descriptor */ | ||
200 | char Path[OS_MAX_PATH_LEN]; /* The path of the file opened */ | ||
201 | uint32 User; /* The task id of the task who opened the file*/ | ||
202 | uint8 IsValid; /* Whether or not this entry is valid */ | ||
203 | }OS_FDTableEntry; | ||
204 | |||
205 | typedef struct | ||
206 | { | ||
207 | uint32 MaxFds; /* Total number of file descriptors */ | ||
208 | uint32 FreeFds; /* Total number that are free */ | ||
209 | uint32 MaxVolumes; /* Maximum number of volumes */ | ||
210 | uint32 FreeVolumes; /* Total number of volumes free */ | ||
211 | } os_fsinfo_t; | ||
212 | |||
213 | /* modified to posix calls, since all of the | ||
214 | * applicable OSes use the posix calls */ | ||
215 | |||
216 | typedef struct stat os_fstat_t; | ||
217 | typedef DIR* os_dirp_t; | ||
218 | typedef struct dirent os_dirent_t; | ||
219 | /* still don't know what this should be*/ | ||
220 | typedef unsigned long int os_fshealth_t; | ||
221 | |||
222 | /* | ||
223 | * Exported Functions | ||
224 | */ | ||
225 | |||
226 | |||
227 | /****************************************************************************** | ||
228 | ** Standard File system API | ||
229 | ******************************************************************************/ | ||
230 | /* | ||
231 | * Initializes the File System functions | ||
232 | */ | ||
233 | |||
234 | int32 OS_FS_Init(void); | ||
235 | |||
236 | /* | ||
237 | * Creates a file specified by path | ||
238 | */ | ||
239 | int32 OS_creat (const char *path, int32 access); | ||
240 | |||
241 | /* | ||
242 | * Opend a file for reading/writing. Returns file descriptor | ||
243 | */ | ||
244 | int32 OS_open (const char *path, int32 access, uint32 mode); | ||
245 | |||
246 | /* | ||
247 | * Closes an open file. | ||
248 | */ | ||
249 | int32 OS_close (int32 filedes); | ||
250 | |||
251 | /* | ||
252 | * Reads nbytes bytes from file into buffer | ||
253 | */ | ||
254 | int32 OS_read (int32 filedes, void *buffer, uint32 nbytes); | ||
255 | |||
256 | /* | ||
257 | * Write nybytes bytes of buffer into the file | ||
258 | */ | ||
259 | int32 OS_write (int32 filedes, void *buffer, uint32 nbytes); | ||
260 | |||
261 | /* | ||
262 | * Changes the permissions of a file | ||
263 | */ | ||
264 | int32 OS_chmod (const char *path, uint32 access); | ||
265 | |||
266 | /* | ||
267 | * Returns file status information in filestats | ||
268 | */ | ||
269 | int32 OS_stat (const char *path, os_fstat_t *filestats); | ||
270 | |||
271 | /* | ||
272 | * Seeks to the specified position of an open file | ||
273 | */ | ||
274 | int32 OS_lseek (int32 filedes, int32 offset, uint32 whence); | ||
275 | |||
276 | /* | ||
277 | * Removes a file from the file system | ||
278 | */ | ||
279 | int32 OS_remove (const char *path); | ||
280 | |||
281 | /* | ||
282 | * Renames a file in the file system | ||
283 | */ | ||
284 | int32 OS_rename (const char *old_filename, const char *new_filename); | ||
285 | |||
286 | /* | ||
287 | * copies a single file from src to dest | ||
288 | */ | ||
289 | int32 OS_cp (const char *src, const char *dest); | ||
290 | |||
291 | /* | ||
292 | * moves a single file from src to dest | ||
293 | */ | ||
294 | int32 OS_mv (const char *src, const char *dest); | ||
295 | |||
296 | /* | ||
297 | * Copies the info of an open file to the structure | ||
298 | */ | ||
299 | int32 OS_FDGetInfo (int32 filedes, OS_FDTableEntry *fd_prop); | ||
300 | |||
301 | /* | ||
302 | ** Check to see if a file is open | ||
303 | */ | ||
304 | int32 OS_FileOpenCheck(char *Filename); | ||
305 | |||
306 | /* | ||
307 | ** Close all open files | ||
308 | */ | ||
309 | int32 OS_CloseAllFiles(void); | ||
310 | |||
311 | /* | ||
312 | ** Close a file by filename | ||
313 | */ | ||
314 | int32 OS_CloseFileByName(char *Filename); | ||
315 | |||
316 | |||
317 | /****************************************************************************** | ||
318 | ** Directory API | ||
319 | ******************************************************************************/ | ||
320 | |||
321 | /* | ||
322 | * Makes a new directory | ||
323 | */ | ||
324 | int32 OS_mkdir (const char *path, uint32 access); | ||
325 | |||
326 | /* | ||
327 | * Opens a directory for searching | ||
328 | */ | ||
329 | os_dirp_t OS_opendir (const char *path); | ||
330 | |||
331 | /* | ||
332 | * Closes an open directory | ||
333 | */ | ||
334 | int32 OS_closedir(os_dirp_t directory); | ||
335 | |||
336 | /* | ||
337 | * Rewinds an open directory | ||
338 | */ | ||
339 | void OS_rewinddir(os_dirp_t directory); | ||
340 | |||
341 | /* | ||
342 | * Reads the next object in the directory | ||
343 | */ | ||
344 | os_dirent_t * OS_readdir (os_dirp_t directory); | ||
345 | |||
346 | /* | ||
347 | * Removes an empty directory from the file system. | ||
348 | */ | ||
349 | int32 OS_rmdir (const char *path); | ||
350 | |||
351 | /****************************************************************************** | ||
352 | ** System Level API | ||
353 | ******************************************************************************/ | ||
354 | /* | ||
355 | * Makes a file system | ||
356 | */ | ||
357 | int32 OS_mkfs (char *address,char *devname, char *volname, | ||
358 | uint32 blocksize, uint32 numblocks); | ||
359 | /* | ||
360 | * Mounts a file system | ||
361 | */ | ||
362 | int32 OS_mount (const char *devname, char *mountpoint); | ||
363 | |||
364 | /* | ||
365 | * Initializes an existing file system | ||
366 | */ | ||
367 | int32 OS_initfs (char *address,char *devname, char *volname, | ||
368 | uint32 blocksize, uint32 numblocks); | ||
369 | |||
370 | /* | ||
371 | * removes a file system | ||
372 | */ | ||
373 | int32 OS_rmfs (char *devname); | ||
374 | |||
375 | /* | ||
376 | * Unmounts a mounted file system | ||
377 | */ | ||
378 | int32 OS_unmount (const char *mountpoint); | ||
379 | |||
380 | /* | ||
381 | * Returns the number of free blocks in a file system | ||
382 | */ | ||
383 | int32 OS_fsBlocksFree (const char *name); | ||
384 | |||
385 | /* | ||
386 | ** Returns the number of free bytes in a file system | ||
387 | ** Note the 64 bit data type to support filesystems that | ||
388 | ** are greater than 4 Gigabytes | ||
389 | */ | ||
390 | int32 OS_fsBytesFree (const char *name, uint64 *bytes_free); | ||
391 | |||
392 | /* | ||
393 | * Checks the health of a file system and repairs it if neccesary | ||
394 | */ | ||
395 | os_fshealth_t OS_chkfs (const char *name, boolean repair); | ||
396 | |||
397 | /* | ||
398 | * Returns in the parameter the physical drive underneith the mount point | ||
399 | */ | ||
400 | int32 OS_FS_GetPhysDriveName (char * PhysDriveName, char * MountPoint); | ||
401 | |||
402 | /* | ||
403 | ** Translates a OSAL Virtual file system path to a host Local path | ||
404 | */ | ||
405 | int32 OS_TranslatePath ( const char *VirtualPath, char *LocalPath); | ||
406 | |||
407 | /* | ||
408 | ** Returns information about the file system in an os_fsinfo_t | ||
409 | */ | ||
410 | int32 OS_GetFsInfo(os_fsinfo_t *filesys_info); | ||
411 | |||
412 | /****************************************************************************** | ||
413 | ** Shell API | ||
414 | ******************************************************************************/ | ||
415 | |||
416 | /* executes the shell command passed into is and writes the output of that | ||
417 | * command to the file specified by the given OSAPI file descriptor */ | ||
418 | int32 OS_ShellOutputToFile(char* Cmd, int32 OS_fd); | ||
419 | #endif | ||
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-loader.h b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-loader.h new file mode 100644 index 000000000..4f0b21b62 --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-loader.h | |||
@@ -0,0 +1,91 @@ | |||
1 | /* | ||
2 | ** File: osapi-os-loader.h | ||
3 | ** | ||
4 | ** Copyright (c) 2004-2006, United States government as represented by the | ||
5 | ** administrator of the National Aeronautics Space Administration. | ||
6 | ** All rights reserved. This software was created at NASAs Goddard | ||
7 | ** Space Flight Center pursuant to government contracts. | ||
8 | ** | ||
9 | ** This is governed by the NASA Open Source Agreement and may be used, | ||
10 | ** distributed and modified only pursuant to the terms of that agreement. | ||
11 | ** | ||
12 | ** Author: Alan Cudmore - Code 582 | ||
13 | ** | ||
14 | ** Purpose: Contains functions prototype definitions and variables declarations | ||
15 | ** for the OS Abstraction Layer, Object file loader API | ||
16 | ** | ||
17 | ** $Revision: 1.5 $ | ||
18 | ** | ||
19 | ** $Date: 2013/07/25 10:02:08GMT-05:00 $ | ||
20 | ** | ||
21 | ** $Log: osapi-os-loader.h $ | ||
22 | ** Revision 1.5 2013/07/25 10:02:08GMT-05:00 acudmore | ||
23 | ** removed circular include "osapi.h" | ||
24 | ** Revision 1.4 2010/11/12 12:00:18GMT-05:00 acudmore | ||
25 | ** replaced copyright character with (c) and added open source notice where needed. | ||
26 | ** Revision 1.3 2010/02/01 12:38:06EST acudmore | ||
27 | ** added return code to OS_ModuleTableInit | ||
28 | ** Revision 1.2 2008/06/20 15:13:43EDT apcudmore | ||
29 | ** Checked in new Module loader/symbol table functionality | ||
30 | ** Revision 1.1 2008/04/20 22:36:02EDT ruperera | ||
31 | ** Initial revision | ||
32 | ** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/os/inc/project.pj | ||
33 | ** Revision 1.1 2008/02/07 11:08:24EST apcudmore | ||
34 | ** Initial revision | ||
35 | ** Member added to project d:/mksdata/MKS-OSAL-REPOSITORY/src/os/inc/project.pj | ||
36 | ** | ||
37 | ** | ||
38 | */ | ||
39 | |||
40 | #ifndef _osapi_loader_ | ||
41 | #define _osapi_loader_ | ||
42 | |||
43 | /* | ||
44 | ** Defines | ||
45 | */ | ||
46 | |||
47 | |||
48 | /* | ||
49 | ** Typedefs | ||
50 | */ | ||
51 | |||
52 | typedef struct | ||
53 | { | ||
54 | uint32 valid; | ||
55 | uint32 code_address; | ||
56 | uint32 code_size; | ||
57 | uint32 data_address; | ||
58 | uint32 data_size; | ||
59 | uint32 bss_address; | ||
60 | uint32 bss_size; | ||
61 | uint32 flags; | ||
62 | } OS_module_address_t; | ||
63 | |||
64 | typedef struct | ||
65 | { | ||
66 | int free; | ||
67 | uint32 entry_point; | ||
68 | uint32 host_module_id; | ||
69 | char filename[OS_MAX_PATH_LEN]; | ||
70 | char name[OS_MAX_API_NAME]; | ||
71 | OS_module_address_t addr; | ||
72 | |||
73 | } OS_module_record_t; | ||
74 | |||
75 | /* | ||
76 | ** Loader API | ||
77 | */ | ||
78 | int32 OS_ModuleTableInit ( void ); | ||
79 | |||
80 | int32 OS_SymbolLookup (uint32 *symbol_address, char *symbol_name ); | ||
81 | |||
82 | int32 OS_SymbolTableDump ( char *filename, uint32 size_limit ); | ||
83 | |||
84 | int32 OS_ModuleLoad ( uint32 *module_id, char *module_name, char *filename ); | ||
85 | |||
86 | int32 OS_ModuleUnload ( uint32 module_id ); | ||
87 | |||
88 | int32 OS_ModuleInfo ( uint32 module_id, OS_module_record_t *module_info ); | ||
89 | |||
90 | |||
91 | #endif | ||
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-net.h b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-net.h new file mode 100644 index 000000000..b8cc67d69 --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-net.h | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | ** File: osapi-os-net.h | ||
3 | ** | ||
4 | ** Copyright (c) 2004-2006, United States government as represented by the | ||
5 | ** administrator of the National Aeronautics Space Administration. | ||
6 | ** All rights reserved. This software was created at NASAs Goddard | ||
7 | ** Space Flight Center pursuant to government contracts. | ||
8 | ** | ||
9 | ** This is governed by the NASA Open Source Agreement and may be used, | ||
10 | ** distributed and modified only pursuant to the terms of that agreement. | ||
11 | ** | ||
12 | ** Author: Alan Cudmore Code 582 | ||
13 | ** | ||
14 | ** Purpose: Contains functions prototype definitions and variables declarations | ||
15 | ** for the OS Abstraction Layer, Network Module | ||
16 | ** | ||
17 | ** $Revision: 1.2 $ | ||
18 | ** | ||
19 | ** $Date: 2010/11/12 12:00:19GMT-05:00 $ | ||
20 | ** | ||
21 | ** $Log: osapi-os-net.h $ | ||
22 | ** Revision 1.2 2010/11/12 12:00:19GMT-05:00 acudmore | ||
23 | ** replaced copyright character with (c) and added open source notice where needed. | ||
24 | ** Revision 1.1 2008/04/20 22:36:02EDT ruperera | ||
25 | ** Initial revision | ||
26 | ** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/os/inc/project.pj | ||
27 | ** Revision 1.1 2007/10/16 16:14:52EDT apcudmore | ||
28 | ** Initial revision | ||
29 | ** Member added to project d:/mksdata/MKS-OSAL-REPOSITORY/src/os/inc/project.pj | ||
30 | ** Revision 1.1 2007/08/24 13:43:25EDT apcudmore | ||
31 | ** Initial revision | ||
32 | ** Member added to project d:/mksdata/MKS-CFE-PROJECT/fsw/cfe-core/os/inc/project.pj | ||
33 | ** Revision 1.3 2006/01/20 11:56:18EST njyanchik | ||
34 | ** Fixed header file information to match api document | ||
35 | ** Revision 1.4 2005/06/07 16:49:31 nyanchik | ||
36 | ** changed returns code for osapi.c to all int32 from uint32 | ||
37 | ** | ||
38 | ** Revision 1.3 2005/03/22 19:04:54 acudmore | ||
39 | ** fixed uint type | ||
40 | ** | ||
41 | ** Revision 1.2 2005/03/22 18:59:33 acudmore | ||
42 | ** updated prototype | ||
43 | ** | ||
44 | ** Revision 1.1 2005/03/22 18:58:51 acudmore | ||
45 | ** added osapi network interface | ||
46 | ** | ||
47 | ** Revision 1.1 2005/03/15 18:26:32 nyanchik | ||
48 | ** *** empty log message *** | ||
49 | ** | ||
50 | ** | ||
51 | ** Date Written: | ||
52 | ** | ||
53 | ** | ||
54 | */ | ||
55 | #ifndef _osapi_network_ | ||
56 | #define _osapi_network_ | ||
57 | |||
58 | int32 OS_NetworkGetID (void); | ||
59 | int32 OS_NetworkGetHostName (char *host_name, uint32 name_len); | ||
60 | |||
61 | #endif | ||
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-timer.h b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-timer.h new file mode 100644 index 000000000..8082c6227 --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-os-timer.h | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | ** File: osapi-os-timer.h | ||
3 | ** | ||
4 | ** Copyright (c) 2004-2006, United States government as represented by the | ||
5 | ** administrator of the National Aeronautics Space Administration. | ||
6 | ** All rights reserved. This software was created at NASAs Goddard | ||
7 | ** Space Flight Center pursuant to government contracts. | ||
8 | ** | ||
9 | ** This is governed by the NASA Open Source Agreement and may be used, | ||
10 | ** distributed and modified only pursuant to the terms of that agreement. | ||
11 | ** | ||
12 | ** Author: Alan Cudmore - Code 582 | ||
13 | ** | ||
14 | ** Purpose: Contains functions prototype definitions and variable declarations | ||
15 | ** for the OS Abstraction Layer, Timer API | ||
16 | ** | ||
17 | ** $Revision: 1.5 $ | ||
18 | ** | ||
19 | ** $Date: 2013/07/25 10:02:20GMT-05:00 $ | ||
20 | ** | ||
21 | ** $Log: osapi-os-timer.h $ | ||
22 | ** Revision 1.5 2013/07/25 10:02:20GMT-05:00 acudmore | ||
23 | ** removed circular include "osapi.h" | ||
24 | ** Revision 1.4 2010/11/12 12:00:19GMT-05:00 acudmore | ||
25 | ** replaced copyright character with (c) and added open source notice where needed. | ||
26 | ** Revision 1.3 2010/02/01 12:38:34EST acudmore | ||
27 | ** Added return code to OS_TimerAPIInit | ||
28 | ** Revision 1.2 2008/08/26 13:52:52EDT apcudmore | ||
29 | ** removed linux specific define | ||
30 | ** Revision 1.1 2008/08/20 16:12:07EDT apcudmore | ||
31 | ** Initial revision | ||
32 | ** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/os/inc/project.pj | ||
33 | ** | ||
34 | ** | ||
35 | */ | ||
36 | |||
37 | #ifndef _osapi_timer_ | ||
38 | #define _osapi_timer_ | ||
39 | |||
40 | /* | ||
41 | ** Typedefs | ||
42 | */ | ||
43 | typedef void (*OS_TimerCallback_t)(uint32 timer_id); | ||
44 | |||
45 | typedef struct | ||
46 | { | ||
47 | char name[OS_MAX_API_NAME]; | ||
48 | uint32 creator; | ||
49 | uint32 start_time; | ||
50 | uint32 interval_time; | ||
51 | uint32 accuracy; | ||
52 | |||
53 | } OS_timer_prop_t; | ||
54 | |||
55 | |||
56 | /* | ||
57 | ** Timer API | ||
58 | */ | ||
59 | int32 OS_TimerAPIInit (void); | ||
60 | |||
61 | int32 OS_TimerCreate (uint32 *timer_id, const char *timer_name, uint32 *clock_accuracy, OS_TimerCallback_t callback_ptr); | ||
62 | int32 OS_TimerSet (uint32 timer_id, uint32 start_msec, uint32 interval_msec); | ||
63 | int32 OS_TimerDelete (uint32 timer_id); | ||
64 | |||
65 | int32 OS_TimerGetIdByName (uint32 *timer_id, const char *timer_name); | ||
66 | int32 OS_TimerGetInfo (uint32 timer_id, OS_timer_prop_t *timer_prop); | ||
67 | |||
68 | #endif | ||
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-version.h b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-version.h new file mode 100644 index 000000000..331e96c94 --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi-version.h | |||
@@ -0,0 +1,48 @@ | |||
1 | /************************************************************************ | ||
2 | ** File: | ||
3 | ** $Id: osapi-version.h 1.11 2014/05/02 13:53:14GMT-05:00 acudmore Exp $ | ||
4 | ** | ||
5 | ** Copyright (c) 2004-2006, United States government as represented by the | ||
6 | ** administrator of the National Aeronautics Space Administration. | ||
7 | ** All rights reserved. This software was created at NASAs Goddard | ||
8 | ** Space Flight Center pursuant to government contracts. | ||
9 | ** | ||
10 | ** This is governed by the NASA Open Source Agreement and may be used, | ||
11 | ** distributed and modified only pursuant to the terms of that agreement. | ||
12 | ** | ||
13 | ** Purpose: | ||
14 | ** The OSAL version numbers | ||
15 | ** | ||
16 | ** Notes: | ||
17 | ** | ||
18 | ** $Log: osapi-version.h $ | ||
19 | ** Revision 1.11 2014/05/02 13:53:14GMT-05:00 acudmore | ||
20 | ** Updated version to 4.1.1 | ||
21 | ** Revision 1.10 2014/01/23 16:33:31GMT-05:00 acudmore | ||
22 | ** Update for 4.1 release | ||
23 | ** Revision 1.9 2013/01/16 14:35:18GMT-05:00 acudmore | ||
24 | ** updated version label | ||
25 | ** Revision 1.8 2012/04/16 14:57:04GMT-05:00 acudmore | ||
26 | ** Updated version label to 3.5.0.0 | ||
27 | ** Revision 1.7 2012/01/17 16:04:29EST acudmore | ||
28 | ** Updated version to 3.4.1 | ||
29 | ** Revision 1.6 2011/12/05 15:45:16EST acudmore | ||
30 | ** Updated version label to 3.4.0 | ||
31 | ** Initial revision | ||
32 | ** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/os/inc/project.pj | ||
33 | ** | ||
34 | *************************************************************************/ | ||
35 | #ifndef _osapi_version_h_ | ||
36 | #define _osapi_version_h_ | ||
37 | |||
38 | #define OS_MAJOR_VERSION (4) | ||
39 | #define OS_MINOR_VERSION (1) | ||
40 | #define OS_REVISION (1) | ||
41 | #define OS_MISSION_REV (0) | ||
42 | |||
43 | |||
44 | #endif /* _osapi_version_h_ */ | ||
45 | |||
46 | /************************/ | ||
47 | /* End of File Comment */ | ||
48 | /************************/ | ||
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi.h b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi.h new file mode 100644 index 000000000..72a7c340a --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/include/osapi.h | |||
@@ -0,0 +1,143 @@ | |||
1 | /* | ||
2 | ** File: osapi.h | ||
3 | ** | ||
4 | ** Copyright (c) 2004-2006, United States government as represented by the | ||
5 | ** administrator of the National Aeronautics Space Administration. | ||
6 | ** All rights reserved. This software was created at NASAs Goddard | ||
7 | ** Space Flight Center pursuant to government contracts. | ||
8 | ** | ||
9 | ** This is governed by the NASA Open Source Agreement and may be used, | ||
10 | ** distributed and modified only pursuant to the terms of that agreement. | ||
11 | ** | ||
12 | ** Author: Alan Cudmore - Code 582 | ||
13 | ** | ||
14 | ** Purpose: Contains functions prototype definitions and variables declarations | ||
15 | ** for the OS Abstraction Layer, Core OS module | ||
16 | ** | ||
17 | ** $Revision: 1.10 $ | ||
18 | ** | ||
19 | ** $Date: 2013/07/25 10:01:32GMT-05:00 $ | ||
20 | ** | ||
21 | ** $Log: osapi.h $ | ||
22 | ** Revision 1.10 2013/07/25 10:01:32GMT-05:00 acudmore | ||
23 | ** Added C++ support | ||
24 | ** Revision 1.9 2010/11/12 12:00:17GMT-05:00 acudmore | ||
25 | ** replaced copyright character with (c) and added open source notice where needed. | ||
26 | ** Revision 1.8 2010/03/08 15:57:20EST acudmore | ||
27 | ** include new OSAL version header file | ||
28 | ** Revision 1.7 2009/08/10 14:01:10EDT acudmore | ||
29 | ** Reset OSAL version for trunk | ||
30 | ** Revision 1.6 2009/08/10 13:55:49EDT acudmore | ||
31 | ** Updated OSAL version defines to 3.0 | ||
32 | ** Revision 1.5 2009/06/10 14:15:55EDT acudmore | ||
33 | ** Removed HAL include files. HAL code was removed from OSAL. | ||
34 | ** Revision 1.4 2008/08/20 16:12:51EDT apcudmore | ||
35 | ** Updated timer error codes | ||
36 | ** Revision 1.3 2008/08/20 15:46:27EDT apcudmore | ||
37 | ** Add support for timer API | ||
38 | ** Revision 1.2 2008/06/20 15:13:43EDT apcudmore | ||
39 | ** Checked in new Module loader/symbol table functionality | ||
40 | ** Revision 1.1 2008/04/20 22:36:02EDT ruperera | ||
41 | ** Initial revision | ||
42 | ** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/os/inc/project.pj | ||
43 | ** Revision 1.6 2008/02/14 11:29:10EST apcudmore | ||
44 | ** Updated version define ( 2.11 ) | ||
45 | ** Revision 1.5 2008/02/07 11:31:58EST apcudmore | ||
46 | ** Fixed merge problem | ||
47 | ** Revision 1.4 2008/02/07 11:07:29EST apcudmore | ||
48 | ** Added dynamic loader / Symbol lookup API | ||
49 | ** -- API only, next release will have functionality | ||
50 | ** Revision 1.2 2008/01/29 14:30:49EST njyanchik | ||
51 | ** I added code to all the ports that allow the values of both binary and counting semaphores to be | ||
52 | ** gotten through the OS_*SemGetInfo API. | ||
53 | ** Revision 1.1 2007/10/16 16:14:52EDT apcudmore | ||
54 | ** Initial revision | ||
55 | ** Member added to project d:/mksdata/MKS-OSAL-REPOSITORY/src/os/inc/project.pj | ||
56 | ** Revision 1.2 2007/09/28 15:46:49EDT rjmcgraw | ||
57 | ** Updated version numbers to 5.0 | ||
58 | ** Revision 1.1 2007/08/24 13:43:25EDT apcudmore | ||
59 | ** Initial revision | ||
60 | ** Member added to project d:/mksdata/MKS-CFE-PROJECT/fsw/cfe-core/os/inc/project.pj | ||
61 | ** Revision 1.9.1.1 2007/05/21 08:58:51EDT njyanchik | ||
62 | ** The trunk version number has been updated to version 0.0 | ||
63 | ** Revision 1.9 2006/06/12 10:20:07EDT rjmcgraw | ||
64 | ** Updated OS_MINOR_VERSION from 3 to 4 | ||
65 | ** Revision 1.8 2006/02/03 09:30:45EST njyanchik | ||
66 | ** Changed version number to 2.3 | ||
67 | ** Revision 1.7 2006/01/20 11:56:16EST njyanchik | ||
68 | ** Fixed header file information to match api document | ||
69 | ** Revision 1.15 2005/11/09 13:35:49 nyanchik | ||
70 | ** Revisions for 2.2 include: | ||
71 | ** a new scheduler mapper for Linux and OS X | ||
72 | ** addition of OS_printf function | ||
73 | ** fixed issues that would cause warnings at compile time | ||
74 | ** | ||
75 | ** | ||
76 | */ | ||
77 | |||
78 | #ifndef _osapi_ | ||
79 | #define _osapi_ | ||
80 | |||
81 | #include "common_types.h" | ||
82 | |||
83 | #ifdef __cplusplus | ||
84 | extern "C" { | ||
85 | #endif | ||
86 | |||
87 | #define OS_SUCCESS (0) | ||
88 | #define OS_ERROR (-1) | ||
89 | #define OS_INVALID_POINTER (-2) | ||
90 | #define OS_ERROR_ADDRESS_MISALIGNED (-3) | ||
91 | #define OS_ERROR_TIMEOUT (-4) | ||
92 | #define OS_INVALID_INT_NUM (-5) | ||
93 | #define OS_SEM_FAILURE (-6) | ||
94 | #define OS_SEM_TIMEOUT (-7) | ||
95 | #define OS_QUEUE_EMPTY (-8) | ||
96 | #define OS_QUEUE_FULL (-9) | ||
97 | #define OS_QUEUE_TIMEOUT (-10) | ||
98 | #define OS_QUEUE_INVALID_SIZE (-11) | ||
99 | #define OS_QUEUE_ID_ERROR (-12) | ||
100 | #define OS_ERR_NAME_TOO_LONG (-13) | ||
101 | #define OS_ERR_NO_FREE_IDS (-14) | ||
102 | #define OS_ERR_NAME_TAKEN (-15) | ||
103 | #define OS_ERR_INVALID_ID (-16) | ||
104 | #define OS_ERR_NAME_NOT_FOUND (-17) | ||
105 | #define OS_ERR_SEM_NOT_FULL (-18) | ||
106 | #define OS_ERR_INVALID_PRIORITY (-19) | ||
107 | #define OS_INVALID_SEM_VALUE (-20) | ||
108 | #define OS_ERR_FILE (-27) | ||
109 | #define OS_ERR_NOT_IMPLEMENTED (-28) | ||
110 | #define OS_TIMER_ERR_INVALID_ARGS (-29) | ||
111 | #define OS_TIMER_ERR_TIMER_ID (-30) | ||
112 | #define OS_TIMER_ERR_UNAVAILABLE (-31) | ||
113 | #define OS_TIMER_ERR_INTERNAL (-32) | ||
114 | |||
115 | /* | ||
116 | ** Defines for Queue Timeout parameters | ||
117 | */ | ||
118 | #define OS_PEND (0) | ||
119 | #define OS_CHECK (-1) | ||
120 | |||
121 | #include "osapi-version.h" | ||
122 | |||
123 | /* | ||
124 | ** Include the configuration file | ||
125 | */ | ||
126 | #include "osconfig.h" | ||
127 | |||
128 | /* | ||
129 | ** Include the OS API modules | ||
130 | */ | ||
131 | #include "osapi-os-core.h" | ||
132 | //#include "osapi-os-filesys.h" | ||
133 | //#include "osapi-os-net.h" | ||
134 | //#include "osapi-os-loader.h" | ||
135 | #include "osapi-os-timer.h" | ||
136 | #include "osapi-os-custom.h" | ||
137 | |||
138 | #ifdef __cplusplus | ||
139 | } | ||
140 | #endif | ||
141 | |||
142 | #endif | ||
143 | |||
diff --git a/lib/chibios/os/common/abstractions/nasa_cfe/osal/src/osapi.c b/lib/chibios/os/common/abstractions/nasa_cfe/osal/src/osapi.c new file mode 100644 index 000000000..ea0ac535b --- /dev/null +++ b/lib/chibios/os/common/abstractions/nasa_cfe/osal/src/osapi.c | |||
@@ -0,0 +1,2281 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file osapi.c | ||
19 | * @brief OS API module code. | ||
20 | * | ||
21 | * @addtogroup nasa_osapi | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include <stdarg.h> | ||
26 | #include <string.h> | ||
27 | |||
28 | #include "ch.h" | ||
29 | |||
30 | #include "common_types.h" | ||
31 | #include "osapi.h" | ||
32 | |||
33 | #if CH_CFG_ST_FREQUENCY > 1000000 | ||
34 | #error "CH_CFG_ST_FREQUENCY limit is 1000000" | ||
35 | #endif | ||
36 | |||
37 | #if (CH_CFG_ST_FREQUENCY % 1000) != 0 | ||
38 | #error "CH_CFG_ST_FREQUENCY is not a multiple of 1000" | ||
39 | #endif | ||
40 | |||
41 | #if CH_CFG_USE_REGISTRY == FALSE | ||
42 | #error "NASA OSAL requires CH_CFG_USE_REGISTRY" | ||
43 | #endif | ||
44 | |||
45 | #if CH_CFG_USE_EVENTS == FALSE | ||
46 | #error "NASA OSAL requires CH_CFG_USE_EVENTS" | ||
47 | #endif | ||
48 | |||
49 | #if CH_CFG_USE_MUTEXES == FALSE | ||
50 | #error "NASA OSAL requires CH_CFG_USE_MUTEXES" | ||
51 | #endif | ||
52 | |||
53 | #if CH_CFG_USE_SEMAPHORES == FALSE | ||
54 | #error "NASA OSAL requires CH_CFG_USE_SEMAPHORES" | ||
55 | #endif | ||
56 | |||
57 | #if CH_CFG_USE_MEMCORE == FALSE | ||
58 | #error "NASA OSAL requires CH_CFG_USE_MEMCORE" | ||
59 | #endif | ||
60 | |||
61 | #if CH_CFG_USE_MEMPOOLS == FALSE | ||
62 | #error "NASA OSAL requires CH_CFG_USE_MEMPOOLS" | ||
63 | #endif | ||
64 | |||
65 | #if CH_CFG_USE_HEAP == FALSE | ||
66 | #error "NASA OSAL requires CH_CFG_USE_HEAP" | ||
67 | #endif | ||
68 | |||
69 | /*===========================================================================*/ | ||
70 | /* Module local definitions. */ | ||
71 | /*===========================================================================*/ | ||
72 | |||
73 | #define MIN_PRIORITY 1 | ||
74 | #define MAX_PRIORITY 255 | ||
75 | |||
76 | #define MIN_MESSAGE_SIZE 4 | ||
77 | #define MAX_MESSAGE_SIZE 16384 | ||
78 | |||
79 | #define MIN_QUEUE_DEPTH 1 | ||
80 | #define MAX_QUEUE_DEPTH 16384 | ||
81 | |||
82 | /*===========================================================================*/ | ||
83 | /* Module exported variables. */ | ||
84 | /*===========================================================================*/ | ||
85 | |||
86 | /*===========================================================================*/ | ||
87 | /* Module local types. */ | ||
88 | /*===========================================================================*/ | ||
89 | |||
90 | /** | ||
91 | * @brief Generic function pointer type. | ||
92 | */ | ||
93 | typedef void (*funcptr_t)(void); | ||
94 | |||
95 | /** | ||
96 | * @brief Type of OSAL timer. | ||
97 | */ | ||
98 | typedef struct { | ||
99 | uint32 is_free; | ||
100 | char name[OS_MAX_API_NAME]; | ||
101 | OS_TimerCallback_t callback_ptr; | ||
102 | uint32 start_time; | ||
103 | uint32 interval_time; | ||
104 | virtual_timer_t vt; | ||
105 | } osal_timer_t; | ||
106 | |||
107 | /** | ||
108 | * @brief Type of an OSAL queue. | ||
109 | */ | ||
110 | typedef struct { | ||
111 | uint32 is_free; | ||
112 | char name[OS_MAX_API_NAME]; | ||
113 | semaphore_t free_msgs; | ||
114 | memory_pool_t messages; | ||
115 | mailbox_t mb; | ||
116 | msg_t *mb_buffer; | ||
117 | void *q_buffer; | ||
118 | uint32 depth; | ||
119 | uint32 size; | ||
120 | } osal_queue_t; | ||
121 | |||
122 | /** | ||
123 | * @brief Type of an osal message with minimum size. | ||
124 | */ | ||
125 | typedef struct { | ||
126 | size_t size; | ||
127 | char buf[4]; | ||
128 | } osal_message_t; | ||
129 | |||
130 | /** | ||
131 | * @brief Type of OSAL main structure. | ||
132 | */ | ||
133 | typedef struct { | ||
134 | bool printf_enabled; | ||
135 | int (*printf)(const char *fmt, ...); | ||
136 | virtual_timer_t vt; | ||
137 | OS_time_t localtime; | ||
138 | memory_pool_t timers_pool; | ||
139 | memory_pool_t queues_pool; | ||
140 | memory_pool_t binary_semaphores_pool; | ||
141 | memory_pool_t count_semaphores_pool; | ||
142 | memory_pool_t mutexes_pool; | ||
143 | osal_timer_t timers[OS_MAX_TIMERS]; | ||
144 | osal_queue_t queues[OS_MAX_QUEUES]; | ||
145 | binary_semaphore_t binary_semaphores[OS_MAX_BIN_SEMAPHORES]; | ||
146 | semaphore_t count_semaphores[OS_MAX_COUNT_SEMAPHORES]; | ||
147 | mutex_t mutexes[OS_MAX_MUTEXES]; | ||
148 | } osal_t; | ||
149 | |||
150 | /*===========================================================================*/ | ||
151 | /* Module local variables. */ | ||
152 | /*===========================================================================*/ | ||
153 | |||
154 | static osal_t osal; | ||
155 | |||
156 | /*===========================================================================*/ | ||
157 | /* Module local functions. */ | ||
158 | /*===========================================================================*/ | ||
159 | |||
160 | /** | ||
161 | * @brief System time callback. | ||
162 | */ | ||
163 | static void systime_update(void *p) { | ||
164 | sysinterval_t delay = (sysinterval_t)p; | ||
165 | |||
166 | chSysLockFromISR(); | ||
167 | osal.localtime.microsecs += 1000; | ||
168 | if (osal.localtime.microsecs >= 1000000) { | ||
169 | osal.localtime.microsecs = 0; | ||
170 | osal.localtime.seconds++; | ||
171 | } | ||
172 | chVTDoSetI(&osal.vt, delay, systime_update, p); | ||
173 | chSysUnlockFromISR(); | ||
174 | } | ||
175 | |||
176 | /** | ||
177 | * @brief Virtual timers callback. | ||
178 | */ | ||
179 | static void timer_handler(void *p) { | ||
180 | osal_timer_t *otp = (osal_timer_t *)p; | ||
181 | |||
182 | /* Real callback.*/ | ||
183 | otp->callback_ptr((uint32)p); | ||
184 | |||
185 | /* Timer restart if an interval is defined.*/ | ||
186 | if (otp->interval_time != 0) { | ||
187 | chSysLockFromISR(); | ||
188 | chVTSetI(&otp->vt, TIME_US2I(otp->interval_time), timer_handler, p); | ||
189 | chSysUnlockFromISR(); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | /** | ||
194 | * @brief Finds a queue by name. | ||
195 | */ | ||
196 | uint32 queue_find(const char *queue_name) { | ||
197 | osal_queue_t *oqp; | ||
198 | |||
199 | /* Searching the queue in the table.*/ | ||
200 | for (oqp = &osal.queues[0]; oqp < &osal.queues[OS_MAX_QUEUES]; oqp++) { | ||
201 | /* Entering a reentrant critical zone.*/ | ||
202 | syssts_t sts = chSysGetStatusAndLockX(); | ||
203 | |||
204 | if (!oqp->is_free && | ||
205 | (strncmp(oqp->name, queue_name, OS_MAX_API_NAME - 1) == 0)) { | ||
206 | /* Leaving the critical zone.*/ | ||
207 | chSysRestoreStatusX(sts); | ||
208 | return (uint32)oqp; | ||
209 | } | ||
210 | |||
211 | /* Leaving the critical zone.*/ | ||
212 | chSysRestoreStatusX(sts); | ||
213 | } | ||
214 | |||
215 | return 0; | ||
216 | } | ||
217 | |||
218 | /** | ||
219 | * @brief Finds a timer by name. | ||
220 | */ | ||
221 | uint32 timer_find(const char *timer_name) { | ||
222 | osal_timer_t *otp; | ||
223 | |||
224 | /* Searching the queue in the table.*/ | ||
225 | for (otp = &osal.timers[0]; otp < &osal.timers[OS_MAX_TIMERS]; otp++) { | ||
226 | /* Entering a reentrant critical zone.*/ | ||
227 | syssts_t sts = chSysGetStatusAndLockX(); | ||
228 | |||
229 | if (!otp->is_free && | ||
230 | (strncmp(otp->name, timer_name, OS_MAX_API_NAME - 1) == 0)) { | ||
231 | /* Leaving the critical zone.*/ | ||
232 | chSysRestoreStatusX(sts); | ||
233 | return (uint32)otp; | ||
234 | } | ||
235 | |||
236 | /* Leaving the critical zone.*/ | ||
237 | chSysRestoreStatusX(sts); | ||
238 | } | ||
239 | |||
240 | return 0; | ||
241 | } | ||
242 | |||
243 | /*===========================================================================*/ | ||
244 | /* Module exported functions. */ | ||
245 | /*===========================================================================*/ | ||
246 | |||
247 | /*-- Initialization API -----------------------------------------------------*/ | ||
248 | |||
249 | /** | ||
250 | * @brief OS initialization. | ||
251 | * @details This function returns initializes the internal data structures | ||
252 | * of the OS Abstraction Layer. It must be called in the application | ||
253 | * startup code before calling any other OS routines. | ||
254 | * | ||
255 | * @return An error code. | ||
256 | * | ||
257 | * @api | ||
258 | */ | ||
259 | int32 OS_API_Init(void) { | ||
260 | |||
261 | chSysInit(); | ||
262 | |||
263 | /* OS_printf() initially disabled.*/ | ||
264 | osal.printf_enabled = false; | ||
265 | osal.printf = NULL; | ||
266 | |||
267 | /* System time handling.*/ | ||
268 | osal.localtime.microsecs = 0; | ||
269 | osal.localtime.seconds = 0; | ||
270 | chVTObjectInit(&osal.vt); | ||
271 | chVTSet(&osal.vt, TIME_MS2I(1), systime_update, (void *)TIME_MS2I(1)); | ||
272 | |||
273 | /* Timers pool initialization.*/ | ||
274 | chPoolObjectInit(&osal.timers_pool, | ||
275 | sizeof (osal_timer_t), | ||
276 | NULL); | ||
277 | chPoolLoadArray(&osal.timers_pool, | ||
278 | &osal.timers[0], | ||
279 | OS_MAX_TIMERS); | ||
280 | |||
281 | /* Queues pool initialization.*/ | ||
282 | chPoolObjectInit(&osal.queues_pool, | ||
283 | sizeof (osal_queue_t), | ||
284 | NULL); | ||
285 | chPoolLoadArray(&osal.queues_pool, | ||
286 | &osal.queues[0], | ||
287 | OS_MAX_QUEUES); | ||
288 | |||
289 | /* Binary Semaphores pool initialization.*/ | ||
290 | chPoolObjectInit(&osal.binary_semaphores_pool, | ||
291 | sizeof (binary_semaphore_t), | ||
292 | NULL); | ||
293 | chPoolLoadArray(&osal.binary_semaphores_pool, | ||
294 | &osal.binary_semaphores[0], | ||
295 | OS_MAX_BIN_SEMAPHORES); | ||
296 | |||
297 | /* Counter Semaphores pool initialization.*/ | ||
298 | chPoolObjectInit(&osal.count_semaphores_pool, | ||
299 | sizeof (semaphore_t), | ||
300 | NULL); | ||
301 | chPoolLoadArray(&osal.count_semaphores_pool, | ||
302 | &osal.count_semaphores[0], | ||
303 | OS_MAX_COUNT_SEMAPHORES); | ||
304 | |||
305 | /* Mutexes pool initialization.*/ | ||
306 | chPoolObjectInit(&osal.mutexes_pool, | ||
307 | sizeof (mutex_t), | ||
308 | NULL); | ||
309 | chPoolLoadArray(&osal.mutexes_pool, | ||
310 | &osal.mutexes[0], | ||
311 | OS_MAX_MUTEXES); | ||
312 | |||
313 | return OS_SUCCESS; | ||
314 | } | ||
315 | |||
316 | /*-- Various API -----------------------------------------------------------*/ | ||
317 | |||
318 | /** | ||
319 | * @brief OS printf-like function. | ||
320 | * @note It is initially disabled. | ||
321 | * | ||
322 | * @param[in] string formatter string | ||
323 | * | ||
324 | * @api | ||
325 | */ | ||
326 | void OS_printf(const char *string, ...) { | ||
327 | va_list ap; | ||
328 | |||
329 | if (osal.printf_enabled && (osal.printf != NULL)) { | ||
330 | va_start(ap, string); | ||
331 | (void) osal.printf(string); | ||
332 | va_end(ap); | ||
333 | } | ||
334 | } | ||
335 | |||
336 | /** | ||
337 | * @brief Disables @p OS_printf(). | ||
338 | * | ||
339 | * @api | ||
340 | */ | ||
341 | void OS_printf_disable(void) { | ||
342 | |||
343 | osal.printf_enabled = false; | ||
344 | } | ||
345 | |||
346 | /** | ||
347 | * @brief Enables @p OS_printf(). | ||
348 | * | ||
349 | * @api | ||
350 | */ | ||
351 | void OS_printf_enable(void) { | ||
352 | |||
353 | osal.printf_enabled = true; | ||
354 | } | ||
355 | |||
356 | /** | ||
357 | * @brief Sets the system printf function. | ||
358 | * @note By default the printf function is not defined. | ||
359 | * @note This is a ChibiOS/RT extension. | ||
360 | * | ||
361 | * @param[in] printf pointer to a @p printf() like function | ||
362 | * | ||
363 | * @api | ||
364 | */ | ||
365 | void OS_set_printf(int (*printf)(const char *fmt, ...)) { | ||
366 | |||
367 | osal.printf = printf; | ||
368 | } | ||
369 | |||
370 | /** | ||
371 | * @brief System tick period in microseconds. | ||
372 | * | ||
373 | * @return The system tick period. | ||
374 | */ | ||
375 | int32 OS_Tick2Micros(void) { | ||
376 | |||
377 | return 1000000 / CH_CFG_ST_FREQUENCY; | ||
378 | } | ||
379 | |||
380 | /** | ||
381 | * @brief Returns the local time. | ||
382 | * | ||
383 | * @param[out] time_struct the system time | ||
384 | * @return An error code. | ||
385 | * | ||
386 | * @api | ||
387 | */ | ||
388 | int32 OS_GetLocalTime(OS_time_t *time_struct) { | ||
389 | |||
390 | if (time_struct == NULL) { | ||
391 | return OS_INVALID_POINTER; | ||
392 | } | ||
393 | |||
394 | chSysLock(); | ||
395 | *time_struct = osal.localtime; | ||
396 | chSysUnlock(); | ||
397 | |||
398 | return OS_SUCCESS; | ||
399 | } | ||
400 | |||
401 | /** | ||
402 | * @brief Changes the local time. | ||
403 | * | ||
404 | * @param[in] time_struct the system time | ||
405 | * @return An error code. | ||
406 | * | ||
407 | * @api | ||
408 | */ | ||
409 | int32 OS_SetLocalTime(OS_time_t *time_struct) { | ||
410 | |||
411 | if (time_struct == NULL) { | ||
412 | return OS_INVALID_POINTER; | ||
413 | } | ||
414 | |||
415 | chSysLock(); | ||
416 | osal.localtime = *time_struct; | ||
417 | chSysUnlock(); | ||
418 | |||
419 | return OS_SUCCESS; | ||
420 | } | ||
421 | |||
422 | /** | ||
423 | * @brief Conversion from milliseconds to ticks. | ||
424 | * | ||
425 | * @param[in] milli_seconds the time in milliseconds | ||
426 | * @return The system ticks. | ||
427 | * | ||
428 | * @api | ||
429 | */ | ||
430 | int32 OS_Milli2Ticks(uint32 milli_seconds) { | ||
431 | |||
432 | return (int32)TIME_MS2I(milli_seconds); | ||
433 | } | ||
434 | |||
435 | /*-- timers API -------------------------------------------------------------*/ | ||
436 | |||
437 | /** | ||
438 | * @brief Timer creation. | ||
439 | * | ||
440 | * @param[out] timer_id pointer to a timer id variable | ||
441 | * @param[in] timer_name the timer name | ||
442 | * @param[out] clock_accuracy timer accuracy in microseconds | ||
443 | * @param[in] callback_ptr timer callback | ||
444 | * @return An error code. | ||
445 | * | ||
446 | * @api | ||
447 | */ | ||
448 | int32 OS_TimerCreate(uint32 *timer_id, const char *timer_name, | ||
449 | uint32 *clock_accuracy, OS_TimerCallback_t callback_ptr) { | ||
450 | osal_timer_t *otp; | ||
451 | |||
452 | /* NULL pointer checks.*/ | ||
453 | if ((timer_id == NULL) || (timer_name == NULL) || | ||
454 | (clock_accuracy == NULL)) { | ||
455 | return OS_INVALID_POINTER; | ||
456 | } | ||
457 | |||
458 | /* NULL callback check.*/ | ||
459 | if (callback_ptr == NULL) { | ||
460 | *timer_id = 0; | ||
461 | return OS_TIMER_ERR_INVALID_ARGS; | ||
462 | } | ||
463 | |||
464 | /* Checking timer name length.*/ | ||
465 | if (strlen(timer_name) >= OS_MAX_API_NAME) { | ||
466 | *timer_id = 0; | ||
467 | return OS_ERR_NAME_TOO_LONG; | ||
468 | } | ||
469 | |||
470 | /* Checking if the name is already taken.*/ | ||
471 | if (timer_find(timer_name) > 0) { | ||
472 | *timer_id = 0; | ||
473 | return OS_ERR_NAME_TAKEN; | ||
474 | } | ||
475 | |||
476 | /* Getting object.*/ | ||
477 | otp = chPoolAlloc(&osal.timers_pool); | ||
478 | if (otp == NULL) { | ||
479 | *timer_id = 0; | ||
480 | return OS_ERR_NO_FREE_IDS; | ||
481 | } | ||
482 | |||
483 | strncpy(otp->name, timer_name, OS_MAX_API_NAME - 1); | ||
484 | chVTObjectInit(&otp->vt); | ||
485 | otp->start_time = 0; | ||
486 | otp->interval_time = 0; | ||
487 | otp->callback_ptr = callback_ptr; | ||
488 | otp->is_free = 0; /* Note, last.*/ | ||
489 | |||
490 | *timer_id = (uint32)otp; | ||
491 | *clock_accuracy = (uint32)(1000000 / CH_CFG_ST_FREQUENCY); | ||
492 | |||
493 | return OS_SUCCESS; | ||
494 | } | ||
495 | |||
496 | /** | ||
497 | * @brief Timer deletion. | ||
498 | * | ||
499 | * @param[in] timer_id timer id variable | ||
500 | * @return An error code. | ||
501 | * | ||
502 | * @api | ||
503 | */ | ||
504 | int32 OS_TimerDelete(uint32 timer_id) { | ||
505 | osal_timer_t *otp = (osal_timer_t *)timer_id; | ||
506 | |||
507 | /* Range check.*/ | ||
508 | if ((otp < &osal.timers[0]) || | ||
509 | (otp >= &osal.timers[OS_MAX_TIMERS]) || | ||
510 | (otp->is_free)) { | ||
511 | return OS_ERR_INVALID_ID; | ||
512 | } | ||
513 | |||
514 | chSysLock(); | ||
515 | |||
516 | /* Marking as no more free, will be overwritten by the pool pointer.*/ | ||
517 | otp->is_free = 1; | ||
518 | |||
519 | /* Resetting the timer.*/ | ||
520 | chVTResetI(&otp->vt); | ||
521 | otp->start_time = 0; | ||
522 | otp->interval_time = 0; | ||
523 | |||
524 | /* Flagging it as unused and returning it to the pool.*/ | ||
525 | chPoolFreeI(&osal.timers_pool, (void *)otp); | ||
526 | |||
527 | chSysUnlock(); | ||
528 | |||
529 | return OS_SUCCESS; | ||
530 | } | ||
531 | |||
532 | /** | ||
533 | * @brief Timer deletion. | ||
534 | * @note This function can be safely called from timer callbacks or ISRs. | ||
535 | * | ||
536 | * @param[in] timer_id timer id variable | ||
537 | * @param[in] start_time start time in microseconds or zero | ||
538 | * @param[in] interval_time interval time in microseconds or zero | ||
539 | * @return An error code. | ||
540 | * | ||
541 | * @api | ||
542 | */ | ||
543 | int32 OS_TimerSet(uint32 timer_id, uint32 start_time, uint32 interval_time) { | ||
544 | syssts_t sts; | ||
545 | osal_timer_t *otp = (osal_timer_t *)timer_id; | ||
546 | |||
547 | /* Range check.*/ | ||
548 | if ((otp < &osal.timers[0]) || | ||
549 | (otp >= &osal.timers[OS_MAX_TIMERS]) || | ||
550 | (otp->is_free)) { | ||
551 | return OS_ERR_INVALID_ID; | ||
552 | } | ||
553 | |||
554 | /* Entering a reentrant critical zone.*/ | ||
555 | sts = chSysGetStatusAndLockX(); | ||
556 | |||
557 | if (start_time == 0) { | ||
558 | chVTResetI(&otp->vt); | ||
559 | } | ||
560 | else { | ||
561 | otp->start_time = start_time; | ||
562 | otp->interval_time = interval_time; | ||
563 | chVTSetI(&otp->vt, TIME_US2I(start_time), timer_handler, (void *)timer_id); | ||
564 | } | ||
565 | |||
566 | /* Leaving the critical zone.*/ | ||
567 | chSysRestoreStatusX(sts); | ||
568 | |||
569 | return OS_SUCCESS; | ||
570 | } | ||
571 | |||
572 | /** | ||
573 | * @brief Retrieves a timer id by name. | ||
574 | * | ||
575 | * @param[out] timer_id pointer to a timer id variable | ||
576 | * @param[in] sem_name the timer name | ||
577 | * @return An error code. | ||
578 | * | ||
579 | * @api | ||
580 | */ | ||
581 | int32 OS_TimerGetIdByName(uint32 *timer_id, const char *timer_name) { | ||
582 | |||
583 | /* NULL pointer checks.*/ | ||
584 | if ((timer_id == NULL) || (timer_name == NULL)) { | ||
585 | return OS_INVALID_POINTER; | ||
586 | } | ||
587 | |||
588 | /* Checking name length.*/ | ||
589 | if (strlen(timer_name) >= OS_MAX_API_NAME) { | ||
590 | return OS_ERR_NAME_TOO_LONG; | ||
591 | } | ||
592 | |||
593 | /* Searching the queue.*/ | ||
594 | *timer_id = timer_find(timer_name); | ||
595 | if (*timer_id > 0) { | ||
596 | return OS_SUCCESS; | ||
597 | } | ||
598 | |||
599 | return OS_ERR_NAME_NOT_FOUND; | ||
600 | } | ||
601 | |||
602 | /** | ||
603 | * @brief Returns timer information. | ||
604 | * @note This function can be safely called from timer callbacks or ISRs. | ||
605 | * | ||
606 | * @param[in] timer_id timer id variable | ||
607 | * @param[in] timer_prop timer properties | ||
608 | * @return An error code. | ||
609 | * | ||
610 | * @api | ||
611 | */ | ||
612 | int32 OS_TimerGetInfo(uint32 timer_id, OS_timer_prop_t *timer_prop) { | ||
613 | syssts_t sts; | ||
614 | osal_timer_t *otp = (osal_timer_t *)timer_id; | ||
615 | |||
616 | /* NULL pointer checks.*/ | ||
617 | if (timer_prop == NULL) { | ||
618 | return OS_INVALID_POINTER; | ||
619 | } | ||
620 | |||
621 | /* Range check.*/ | ||
622 | if ((otp < &osal.timers[0]) || | ||
623 | (otp >= &osal.timers[OS_MAX_TIMERS]) || | ||
624 | (otp->is_free)) { | ||
625 | return OS_ERR_INVALID_ID; | ||
626 | } | ||
627 | |||
628 | /* Entering a reentrant critical zone.*/ | ||
629 | sts = chSysGetStatusAndLockX(); | ||
630 | |||
631 | /* If the timer is not in use then error.*/ | ||
632 | if (otp->is_free) { | ||
633 | /* Leaving the critical zone.*/ | ||
634 | chSysRestoreStatusX(sts); | ||
635 | return OS_ERR_INVALID_ID; | ||
636 | } | ||
637 | |||
638 | strncpy(timer_prop->name, otp->name, OS_MAX_API_NAME - 1); | ||
639 | timer_prop->creator = (uint32)0; | ||
640 | timer_prop->start_time = otp->start_time; | ||
641 | timer_prop->interval_time = otp->interval_time; | ||
642 | timer_prop->accuracy = (uint32)(1000000 / CH_CFG_ST_FREQUENCY); | ||
643 | |||
644 | /* Leaving the critical zone.*/ | ||
645 | chSysRestoreStatusX(sts); | ||
646 | |||
647 | return OS_SUCCESS; | ||
648 | } | ||
649 | |||
650 | /*-- Queues API -------------------------------------------------------------*/ | ||
651 | |||
652 | /** | ||
653 | * @brief Queue creation. | ||
654 | * | ||
655 | * @param[out] queue_id pointer to a queue id variable | ||
656 | * @param[in] queue_name the queue name | ||
657 | * @param[in] queue_depth desired queue depth | ||
658 | * @param[in] data_size maximum message size | ||
659 | * @param[in] flags queue option flags | ||
660 | * @return An error code. | ||
661 | * | ||
662 | * @api | ||
663 | */ | ||
664 | int32 OS_QueueCreate(uint32 *queue_id, const char *queue_name, | ||
665 | uint32 queue_depth, uint32 data_size, uint32 flags) { | ||
666 | osal_queue_t *oqp; | ||
667 | size_t msgsize; | ||
668 | |||
669 | (void)flags; | ||
670 | |||
671 | /* NULL pointer checks.*/ | ||
672 | if ((queue_id == NULL) || (queue_name == NULL)) { | ||
673 | return OS_INVALID_POINTER; | ||
674 | } | ||
675 | |||
676 | /* Checking queue name length.*/ | ||
677 | if (strlen(queue_name) >= OS_MAX_API_NAME) { | ||
678 | *queue_id = 0; | ||
679 | return OS_ERR_NAME_TOO_LONG; | ||
680 | } | ||
681 | |||
682 | /* Checking if the name is already taken.*/ | ||
683 | if (queue_find(queue_name) > 0) { | ||
684 | *queue_id = 0; | ||
685 | return OS_ERR_NAME_TAKEN; | ||
686 | } | ||
687 | |||
688 | /* Checks on queue limits. There is no dedicated error code.*/ | ||
689 | if ((data_size < MIN_MESSAGE_SIZE) || (data_size > MAX_MESSAGE_SIZE) || | ||
690 | (queue_depth < MIN_QUEUE_DEPTH) || (queue_depth > MAX_QUEUE_DEPTH)) { | ||
691 | *queue_id = 0; | ||
692 | return OS_ERROR; | ||
693 | } | ||
694 | |||
695 | /* Getting object.*/ | ||
696 | oqp = chPoolAlloc(&osal.queues_pool); | ||
697 | if (oqp == NULL) { | ||
698 | *queue_id = 0; | ||
699 | return OS_ERR_NO_FREE_IDS; | ||
700 | } | ||
701 | |||
702 | /* Attempting messages buffer allocation.*/ | ||
703 | msgsize = MEM_ALIGN_NEXT(data_size + sizeof (size_t), PORT_NATURAL_ALIGN); | ||
704 | oqp->mb_buffer = chHeapAllocAligned(NULL, | ||
705 | msgsize * (size_t)queue_depth, | ||
706 | PORT_NATURAL_ALIGN); | ||
707 | if (oqp->mb_buffer == NULL) { | ||
708 | *queue_id = 0; | ||
709 | return OS_ERROR; | ||
710 | } | ||
711 | |||
712 | /* Attempting queue buffer allocation.*/ | ||
713 | oqp->q_buffer = chHeapAllocAligned(NULL, | ||
714 | sizeof (msg_t) * (size_t)queue_depth, | ||
715 | PORT_NATURAL_ALIGN); | ||
716 | if (oqp->q_buffer == NULL) { | ||
717 | *queue_id = 0; | ||
718 | chHeapFree(oqp->mb_buffer); | ||
719 | return OS_ERROR; | ||
720 | } | ||
721 | |||
722 | /* Initializing object static parts.*/ | ||
723 | strncpy(oqp->name, queue_name, OS_MAX_API_NAME - 1); | ||
724 | chMBObjectInit(&oqp->mb, oqp->q_buffer, (size_t)queue_depth); | ||
725 | chSemObjectInit(&oqp->free_msgs, (cnt_t)queue_depth); | ||
726 | chPoolObjectInit(&oqp->messages, msgsize, NULL); | ||
727 | chPoolLoadArray(&oqp->messages, oqp->mb_buffer, (size_t)queue_depth); | ||
728 | oqp->depth = queue_depth; | ||
729 | oqp->size = data_size; | ||
730 | oqp->is_free = 0; /* Note, last.*/ | ||
731 | *queue_id = (uint32)oqp; | ||
732 | |||
733 | return OS_SUCCESS; | ||
734 | } | ||
735 | |||
736 | /** | ||
737 | * @brief Queue deletion. | ||
738 | * | ||
739 | * @param[in] queue_id queue id variable | ||
740 | * @return An error code. | ||
741 | * | ||
742 | * @api | ||
743 | */ | ||
744 | int32 OS_QueueDelete(uint32 queue_id) { | ||
745 | osal_queue_t *oqp = (osal_queue_t *)queue_id; | ||
746 | void *q_buffer, *mb_buffer; | ||
747 | |||
748 | /* Range check.*/ | ||
749 | if ((oqp < &osal.queues[0]) || | ||
750 | (oqp >= &osal.queues[OS_MAX_QUEUES]) || | ||
751 | (oqp->is_free)) { | ||
752 | return OS_ERR_INVALID_ID; | ||
753 | } | ||
754 | |||
755 | /* Critical zone.*/ | ||
756 | chSysLock(); | ||
757 | |||
758 | /* Marking as no more free, will be overwritten by the pool pointer.*/ | ||
759 | oqp->is_free = 1; | ||
760 | |||
761 | /* Pointers to areas to be freed.*/ | ||
762 | q_buffer = oqp->q_buffer; | ||
763 | mb_buffer = oqp->mb_buffer; | ||
764 | |||
765 | /* Resetting the queue.*/ | ||
766 | chMBResetI(&oqp->mb); | ||
767 | chSemResetI(&oqp->free_msgs, 0); | ||
768 | |||
769 | /* Flagging it as unused and returning it to the pool.*/ | ||
770 | chPoolFreeI(&osal.queues_pool, (void *)oqp); | ||
771 | |||
772 | chSchRescheduleS(); | ||
773 | |||
774 | /* Leaving critical zone.*/ | ||
775 | chSysUnlock(); | ||
776 | |||
777 | /* Freeing buffers, outside critical zone, slow heap operation.*/ | ||
778 | chHeapFree(q_buffer); | ||
779 | chHeapFree(mb_buffer); | ||
780 | |||
781 | return OS_SUCCESS; | ||
782 | } | ||
783 | |||
784 | /** | ||
785 | * @brief Retrieves a message from the queue. | ||
786 | * | ||
787 | * @param[in] queue_id queue id variable | ||
788 | * @param[out] data message buffer pointer | ||
789 | * @param[in] size size of the buffer | ||
790 | * @param[out] size_copied size of the received message | ||
791 | * @param[in] timeout timeout in ticks, the special values @p OS_PEND | ||
792 | * and @p OS_CHECK can be specified | ||
793 | * @return An error code. | ||
794 | * | ||
795 | * @api | ||
796 | */ | ||
797 | int32 OS_QueueGet(uint32 queue_id, void *data, uint32 size, | ||
798 | uint32 *size_copied, int32 timeout) { | ||
799 | osal_queue_t *oqp = (osal_queue_t *)queue_id; | ||
800 | msg_t msg, msgsts; | ||
801 | void *body; | ||
802 | |||
803 | /* NULL pointer checks.*/ | ||
804 | if ((data == NULL) || (size_copied == NULL)) { | ||
805 | return OS_INVALID_POINTER; | ||
806 | } | ||
807 | |||
808 | /* Range check.*/ | ||
809 | if ((oqp < &osal.queues[0]) || | ||
810 | (oqp >= &osal.queues[OS_MAX_QUEUES]) || | ||
811 | (oqp->is_free)) { | ||
812 | return OS_ERR_INVALID_ID; | ||
813 | } | ||
814 | |||
815 | /* Check on minimum size.*/ | ||
816 | if (size < oqp->size) { | ||
817 | return OS_QUEUE_INVALID_SIZE; | ||
818 | } | ||
819 | |||
820 | /* Special time handling.*/ | ||
821 | if (timeout == OS_PEND) { | ||
822 | msgsts = chMBFetchTimeout(&oqp->mb, &msg, TIME_INFINITE); | ||
823 | if (msgsts < MSG_OK) { | ||
824 | *size_copied = 0; | ||
825 | return OS_ERROR; | ||
826 | } | ||
827 | } | ||
828 | else if (timeout == OS_CHECK) { | ||
829 | msgsts = chMBFetchTimeout(&oqp->mb, &msg, TIME_IMMEDIATE); | ||
830 | if (msgsts < MSG_OK) { | ||
831 | *size_copied = 0; | ||
832 | return OS_QUEUE_EMPTY; | ||
833 | } | ||
834 | } | ||
835 | else { | ||
836 | msgsts = chMBFetchTimeout(&oqp->mb, &msg, (sysinterval_t)timeout); | ||
837 | if (msgsts < MSG_OK) { | ||
838 | *size_copied = 0; | ||
839 | return OS_QUEUE_TIMEOUT; | ||
840 | } | ||
841 | } | ||
842 | |||
843 | /* Message body and size.*/ | ||
844 | *size_copied = ((osal_message_t *)msg)->size; | ||
845 | body = (void *)((osal_message_t *)msg)->buf; | ||
846 | |||
847 | /* Copying the message body.*/ | ||
848 | memcpy(data, body, *size_copied); | ||
849 | |||
850 | /* Freeing the message buffer.*/ | ||
851 | chPoolFree(&oqp->messages, (void *)msg); | ||
852 | chSemSignal(&oqp->free_msgs); | ||
853 | |||
854 | return OS_SUCCESS; | ||
855 | } | ||
856 | |||
857 | /** | ||
858 | * @brief Puts a message in the queue. | ||
859 | * | ||
860 | * @param[in] queue_id queue id variable | ||
861 | * @param[in] data message buffer pointer | ||
862 | * @param[in] size size of the message | ||
863 | * @param[in] flags operation flags | ||
864 | * @return An error code. | ||
865 | * | ||
866 | * @api | ||
867 | */ | ||
868 | int32 OS_QueuePut(uint32 queue_id, void *data, uint32 size, uint32 flags) { | ||
869 | osal_queue_t *oqp = (osal_queue_t *)queue_id; | ||
870 | msg_t msgsts; | ||
871 | osal_message_t *omsg; | ||
872 | |||
873 | (void)flags; | ||
874 | |||
875 | /* NULL pointer checks.*/ | ||
876 | if (data == NULL) { | ||
877 | return OS_INVALID_POINTER; | ||
878 | } | ||
879 | |||
880 | /* Range check.*/ | ||
881 | if ((oqp < &osal.queues[0]) || | ||
882 | (oqp >= &osal.queues[OS_MAX_QUEUES]) || | ||
883 | (oqp->is_free)) { | ||
884 | return OS_ERR_INVALID_ID; | ||
885 | } | ||
886 | |||
887 | /* Check on maximum size.*/ | ||
888 | if (size > oqp->size) { | ||
889 | return OS_QUEUE_INVALID_SIZE; | ||
890 | } | ||
891 | |||
892 | /* Getting a message buffer from the pool.*/ | ||
893 | msgsts = chSemWait(&oqp->free_msgs); | ||
894 | if (msgsts < MSG_OK) { | ||
895 | return OS_ERROR; | ||
896 | } | ||
897 | omsg = chPoolAlloc(&oqp->messages); | ||
898 | |||
899 | /* Filling message size and data.*/ | ||
900 | omsg->size = (size_t)size; | ||
901 | memcpy(omsg->buf, data, size); | ||
902 | |||
903 | /* Posting the message.*/ | ||
904 | msgsts = chMBPostTimeout(&oqp->mb, (msg_t)omsg, TIME_INFINITE); | ||
905 | if (msgsts < MSG_OK) { | ||
906 | return OS_ERROR; | ||
907 | } | ||
908 | |||
909 | return OS_SUCCESS; | ||
910 | } | ||
911 | |||
912 | /** | ||
913 | * @brief Retrieves a queue id by name. | ||
914 | * | ||
915 | * @param[out] queue_id pointer to a queue id variable | ||
916 | * @param[in] sem_name the queue name | ||
917 | * @return An error code. | ||
918 | * | ||
919 | * @api | ||
920 | */ | ||
921 | int32 OS_QueueGetIdByName(uint32 *queue_id, const char *queue_name) { | ||
922 | |||
923 | /* NULL pointer checks.*/ | ||
924 | if ((queue_id == NULL) || (queue_name == NULL)) { | ||
925 | return OS_INVALID_POINTER; | ||
926 | } | ||
927 | |||
928 | /* Checking name length.*/ | ||
929 | if (strlen(queue_name) >= OS_MAX_API_NAME) { | ||
930 | return OS_ERR_NAME_TOO_LONG; | ||
931 | } | ||
932 | |||
933 | /* Searching the queue.*/ | ||
934 | *queue_id = queue_find(queue_name); | ||
935 | if (*queue_id > 0) { | ||
936 | return OS_SUCCESS; | ||
937 | } | ||
938 | |||
939 | return OS_ERR_NAME_NOT_FOUND; | ||
940 | } | ||
941 | |||
942 | /** | ||
943 | * @brief Returns queue information. | ||
944 | * @note This function can be safely called from timer callbacks or ISRs. | ||
945 | * | ||
946 | * @param[in] queue_id queue id variable | ||
947 | * @param[in] queue_prop queue properties | ||
948 | * @return An error code. | ||
949 | * | ||
950 | * @api | ||
951 | */ | ||
952 | int32 OS_QueueGetInfo (uint32 queue_id, OS_queue_prop_t *queue_prop) { | ||
953 | osal_queue_t *oqp = (osal_queue_t *)queue_id; | ||
954 | syssts_t sts; | ||
955 | |||
956 | /* NULL pointer checks.*/ | ||
957 | if (queue_prop == NULL) { | ||
958 | return OS_INVALID_POINTER; | ||
959 | } | ||
960 | |||
961 | /* Range check.*/ | ||
962 | if ((oqp < &osal.queues[0]) || | ||
963 | (oqp >= &osal.queues[OS_MAX_QUEUES]) || | ||
964 | (oqp->is_free)) { | ||
965 | return OS_ERR_INVALID_ID; | ||
966 | } | ||
967 | |||
968 | /* Entering a reentrant critical zone.*/ | ||
969 | sts = chSysGetStatusAndLockX(); | ||
970 | |||
971 | /* If the queue is not in use then error.*/ | ||
972 | if (oqp->is_free) { | ||
973 | /* Leaving the critical zone.*/ | ||
974 | chSysRestoreStatusX(sts); | ||
975 | return OS_ERR_INVALID_ID; | ||
976 | } | ||
977 | |||
978 | strncpy(queue_prop->name, oqp->name, OS_MAX_API_NAME - 1); | ||
979 | queue_prop->creator = (uint32)0; | ||
980 | |||
981 | /* Leaving the critical zone.*/ | ||
982 | chSysRestoreStatusX(sts); | ||
983 | |||
984 | return OS_SUCCESS; | ||
985 | |||
986 | return OS_ERR_NOT_IMPLEMENTED; | ||
987 | } | ||
988 | |||
989 | /*-- Binary Semaphore API ---------------------------------------------------*/ | ||
990 | |||
991 | /** | ||
992 | * @brief Binary semaphore creation. | ||
993 | * | ||
994 | * @param[out] sem_id pointer to a binary semaphore id variable | ||
995 | * @param[in] sem_name the binary semaphore name | ||
996 | * @param[in] sem_initial_value semaphore initial value | ||
997 | * @param[in] options semaphore options | ||
998 | * @return An error code. | ||
999 | * | ||
1000 | * @api | ||
1001 | */ | ||
1002 | int32 OS_BinSemCreate(uint32 *sem_id, const char *sem_name, | ||
1003 | uint32 sem_initial_value, uint32 options) { | ||
1004 | binary_semaphore_t *bsp; | ||
1005 | |||
1006 | (void)options; | ||
1007 | |||
1008 | /* NULL pointer checks.*/ | ||
1009 | if ((sem_id == NULL) || (sem_name == NULL)) { | ||
1010 | return OS_INVALID_POINTER; | ||
1011 | } | ||
1012 | |||
1013 | /* Checking semaphore name length.*/ | ||
1014 | if (strlen(sem_name) >= OS_MAX_API_NAME) { | ||
1015 | return OS_ERR_NAME_TOO_LONG; | ||
1016 | } | ||
1017 | |||
1018 | /* Semaphore counter check, it is binary so only 0 and 1.*/ | ||
1019 | if (sem_initial_value > 1) { | ||
1020 | return OS_INVALID_INT_NUM; | ||
1021 | } | ||
1022 | |||
1023 | /* Getting object.*/ | ||
1024 | bsp = chPoolAlloc(&osal.binary_semaphores_pool); | ||
1025 | if (bsp == NULL) { | ||
1026 | return OS_ERR_NO_FREE_IDS; | ||
1027 | } | ||
1028 | |||
1029 | /* Semaphore is initialized.*/ | ||
1030 | chBSemObjectInit(bsp, sem_initial_value == 0 ? true : false); | ||
1031 | |||
1032 | *sem_id = (uint32)bsp; | ||
1033 | |||
1034 | return OS_SUCCESS; | ||
1035 | } | ||
1036 | |||
1037 | /** | ||
1038 | * @brief Binary semaphore deletion. | ||
1039 | * | ||
1040 | * @param[in] sem_id binary semaphore id variable | ||
1041 | * @return An error code. | ||
1042 | * | ||
1043 | * @api | ||
1044 | */ | ||
1045 | int32 OS_BinSemDelete(uint32 sem_id) { | ||
1046 | binary_semaphore_t *bsp = (binary_semaphore_t *)sem_id; | ||
1047 | |||
1048 | /* Range check.*/ | ||
1049 | if ((bsp < &osal.binary_semaphores[0]) || | ||
1050 | (bsp >= &osal.binary_semaphores[OS_MAX_BIN_SEMAPHORES])) { | ||
1051 | return OS_ERR_INVALID_ID; | ||
1052 | } | ||
1053 | |||
1054 | chSysLock(); | ||
1055 | |||
1056 | /* Resetting the semaphore, no threads in queue.*/ | ||
1057 | chBSemResetI(bsp, true); | ||
1058 | |||
1059 | /* Flagging it as unused and returning it to the pool.*/ | ||
1060 | bsp->sem.queue.prev = NULL; | ||
1061 | chPoolFreeI(&osal.binary_semaphores_pool, (void *)bsp); | ||
1062 | |||
1063 | /* Required because some thread could have been made ready.*/ | ||
1064 | chSchRescheduleS(); | ||
1065 | |||
1066 | chSysUnlock(); | ||
1067 | |||
1068 | return OS_SUCCESS; | ||
1069 | } | ||
1070 | |||
1071 | /** | ||
1072 | * @brief Binary semaphore flush. | ||
1073 | * @note The state of the binary semaphore is not changed. | ||
1074 | * @note This function can be safely called from timer callbacks or ISRs. | ||
1075 | * | ||
1076 | * @param[in] sem_id binary semaphore id variable | ||
1077 | * @return An error code. | ||
1078 | * | ||
1079 | * @api | ||
1080 | */ | ||
1081 | int32 OS_BinSemFlush(uint32 sem_id) { | ||
1082 | syssts_t sts; | ||
1083 | binary_semaphore_t *bsp = (binary_semaphore_t *)sem_id; | ||
1084 | |||
1085 | /* Range check.*/ | ||
1086 | if ((bsp < &osal.binary_semaphores[0]) || | ||
1087 | (bsp >= &osal.binary_semaphores[OS_MAX_BIN_SEMAPHORES])) { | ||
1088 | return OS_ERR_INVALID_ID; | ||
1089 | } | ||
1090 | |||
1091 | /* Entering a reentrant critical zone.*/ | ||
1092 | sts = chSysGetStatusAndLockX(); | ||
1093 | |||
1094 | /* If the semaphore is not in use then error.*/ | ||
1095 | if (bsp->sem.queue.prev == NULL) { | ||
1096 | /* Leaving the critical zone.*/ | ||
1097 | chSysRestoreStatusX(sts); | ||
1098 | return OS_SEM_FAILURE; | ||
1099 | } | ||
1100 | |||
1101 | /* If the semaphore state is "not taken" then it is not touched.*/ | ||
1102 | if (bsp->sem.cnt < 0) { | ||
1103 | chBSemResetI(bsp, true); | ||
1104 | } | ||
1105 | |||
1106 | /* Leaving the critical zone.*/ | ||
1107 | chSysRestoreStatusX(sts); | ||
1108 | |||
1109 | return OS_SUCCESS; | ||
1110 | } | ||
1111 | |||
1112 | /** | ||
1113 | * @brief Binary semaphore give. | ||
1114 | * @note This function can be safely called from timer callbacks or ISRs. | ||
1115 | * | ||
1116 | * @param[in] sem_id binary semaphore id variable | ||
1117 | * @return An error code. | ||
1118 | * | ||
1119 | * @api | ||
1120 | */ | ||
1121 | int32 OS_BinSemGive(uint32 sem_id) { | ||
1122 | syssts_t sts; | ||
1123 | binary_semaphore_t *bsp = (binary_semaphore_t *)sem_id; | ||
1124 | |||
1125 | /* Range check.*/ | ||
1126 | if ((bsp < &osal.binary_semaphores[0]) || | ||
1127 | (bsp >= &osal.binary_semaphores[OS_MAX_BIN_SEMAPHORES])) { | ||
1128 | return OS_ERR_INVALID_ID; | ||
1129 | } | ||
1130 | |||
1131 | /* Entering a reentrant critical zone.*/ | ||
1132 | sts = chSysGetStatusAndLockX(); | ||
1133 | |||
1134 | /* If the semaphore is not in use then error.*/ | ||
1135 | if (bsp->sem.queue.prev == NULL) { | ||
1136 | /* Leaving the critical zone.*/ | ||
1137 | chSysRestoreStatusX(sts); | ||
1138 | return OS_SEM_FAILURE; | ||
1139 | } | ||
1140 | |||
1141 | chBSemSignalI(bsp); | ||
1142 | |||
1143 | /* Leaving the critical zone.*/ | ||
1144 | chSysRestoreStatusX(sts); | ||
1145 | |||
1146 | return OS_SUCCESS; | ||
1147 | } | ||
1148 | |||
1149 | /** | ||
1150 | * @brief Binary semaphore take. | ||
1151 | * | ||
1152 | * @param[in] sem_id binary semaphore id variable | ||
1153 | * @return An error code. | ||
1154 | * | ||
1155 | * @api | ||
1156 | */ | ||
1157 | int32 OS_BinSemTake(uint32 sem_id) { | ||
1158 | binary_semaphore_t *bsp = (binary_semaphore_t *)sem_id; | ||
1159 | |||
1160 | /* Range check.*/ | ||
1161 | if ((bsp < &osal.binary_semaphores[0]) || | ||
1162 | (bsp >= &osal.binary_semaphores[OS_MAX_BIN_SEMAPHORES])) { | ||
1163 | return OS_ERR_INVALID_ID; | ||
1164 | } | ||
1165 | |||
1166 | chSysLock(); | ||
1167 | |||
1168 | /* If the semaphore is not in use then error.*/ | ||
1169 | if (bsp->sem.queue.prev == NULL) { | ||
1170 | chSysUnlock(); | ||
1171 | return OS_SEM_FAILURE; | ||
1172 | } | ||
1173 | |||
1174 | (void) chBSemWaitS(bsp); | ||
1175 | |||
1176 | chSysUnlock(); | ||
1177 | |||
1178 | return OS_SUCCESS; | ||
1179 | } | ||
1180 | |||
1181 | /** | ||
1182 | * @brief Binary semaphore take with timeout. | ||
1183 | * | ||
1184 | * @param[in] sem_id binary semaphore id variable | ||
1185 | * @param[in] msecs timeout in milliseconds | ||
1186 | * @return An error code. | ||
1187 | * | ||
1188 | * @api | ||
1189 | */ | ||
1190 | int32 OS_BinSemTimedWait(uint32 sem_id, uint32 msecs) { | ||
1191 | binary_semaphore_t *bsp = (binary_semaphore_t *)sem_id; | ||
1192 | msg_t msg; | ||
1193 | |||
1194 | /* Range check.*/ | ||
1195 | if ((bsp < &osal.binary_semaphores[0]) || | ||
1196 | (bsp >= &osal.binary_semaphores[OS_MAX_BIN_SEMAPHORES])) { | ||
1197 | return OS_ERR_INVALID_ID; | ||
1198 | } | ||
1199 | |||
1200 | /* Timeouts of zero not allowed.*/ | ||
1201 | if (msecs == 0) { | ||
1202 | return OS_INVALID_INT_NUM; | ||
1203 | } | ||
1204 | |||
1205 | chSysLock(); | ||
1206 | |||
1207 | /* If the semaphore is not in use then error.*/ | ||
1208 | if (bsp->sem.queue.prev == NULL) { | ||
1209 | chSysUnlock(); | ||
1210 | return OS_SEM_FAILURE; | ||
1211 | } | ||
1212 | |||
1213 | msg = chBSemWaitTimeoutS(bsp, TIME_MS2I(msecs)); | ||
1214 | |||
1215 | chSysUnlock(); | ||
1216 | |||
1217 | return msg == MSG_TIMEOUT ? OS_SEM_TIMEOUT : OS_SUCCESS; | ||
1218 | } | ||
1219 | |||
1220 | /** | ||
1221 | * @brief Retrieves a binary semaphore id by name. | ||
1222 | * @note It is not currently implemented. | ||
1223 | * | ||
1224 | * @param[out] sem_id pointer to a binary semaphore id variable | ||
1225 | * @param[in] sem_name the binary semaphore name | ||
1226 | * @return An error code. | ||
1227 | * | ||
1228 | * @api | ||
1229 | */ | ||
1230 | int32 OS_BinSemGetIdByName(uint32 *sem_id, const char *sem_name) { | ||
1231 | |||
1232 | /* NULL pointer checks.*/ | ||
1233 | if ((sem_id == NULL) || (sem_name == NULL)) { | ||
1234 | return OS_INVALID_POINTER; | ||
1235 | } | ||
1236 | |||
1237 | /* Checking name length.*/ | ||
1238 | if (strlen(sem_name) >= OS_MAX_API_NAME) { | ||
1239 | return OS_ERR_NAME_TOO_LONG; | ||
1240 | } | ||
1241 | |||
1242 | return OS_ERR_NOT_IMPLEMENTED; | ||
1243 | } | ||
1244 | |||
1245 | /** | ||
1246 | * @brief Returns binary semaphore information. | ||
1247 | * @note This function can be safely called from timer callbacks or ISRs. | ||
1248 | * @note It is not currently implemented. | ||
1249 | * | ||
1250 | * @param[in] sem_id binary semaphore id variable | ||
1251 | * @param[in] bin_prop binary semaphore properties | ||
1252 | * @return An error code. | ||
1253 | * | ||
1254 | * @api | ||
1255 | */ | ||
1256 | int32 OS_BinSemGetInfo(uint32 sem_id, OS_bin_sem_prop_t *bin_prop) { | ||
1257 | syssts_t sts; | ||
1258 | binary_semaphore_t *bsp = (binary_semaphore_t *)sem_id; | ||
1259 | |||
1260 | /* NULL pointer checks.*/ | ||
1261 | if (bin_prop == NULL) { | ||
1262 | return OS_INVALID_POINTER; | ||
1263 | } | ||
1264 | |||
1265 | /* Range check.*/ | ||
1266 | if ((bsp < &osal.binary_semaphores[0]) || | ||
1267 | (bsp >= &osal.binary_semaphores[OS_MAX_BIN_SEMAPHORES])) { | ||
1268 | return OS_ERR_INVALID_ID; | ||
1269 | } | ||
1270 | |||
1271 | /* Entering a reentrant critical zone.*/ | ||
1272 | sts = chSysGetStatusAndLockX(); | ||
1273 | |||
1274 | /* If the semaphore is not in use then error.*/ | ||
1275 | if (bsp->sem.queue.prev == NULL) { | ||
1276 | /* Leaving the critical zone.*/ | ||
1277 | chSysRestoreStatusX(sts); | ||
1278 | return OS_ERR_INVALID_ID; | ||
1279 | } | ||
1280 | |||
1281 | /* Leaving the critical zone.*/ | ||
1282 | chSysRestoreStatusX(sts); | ||
1283 | |||
1284 | return OS_ERR_NOT_IMPLEMENTED; | ||
1285 | } | ||
1286 | |||
1287 | /*-- Counter Semaphore API --------------------------------------------------*/ | ||
1288 | |||
1289 | /** | ||
1290 | * @brief Counter semaphore creation. | ||
1291 | * | ||
1292 | * @param[out] sem_id pointer to a counter semaphore id variable | ||
1293 | * @param[in] sem_name the counter semaphore name | ||
1294 | * @param[in] sem_initial_value semaphore initial value | ||
1295 | * @param[in] options semaphore options | ||
1296 | * @return An error code. | ||
1297 | * | ||
1298 | * @api | ||
1299 | */ | ||
1300 | int32 OS_CountSemCreate(uint32 *sem_id, const char *sem_name, | ||
1301 | uint32 sem_initial_value, uint32 options) { | ||
1302 | semaphore_t *sp; | ||
1303 | |||
1304 | (void)options; | ||
1305 | |||
1306 | /* NULL pointer checks.*/ | ||
1307 | if ((sem_id == NULL) || (sem_name == NULL)) { | ||
1308 | return OS_INVALID_POINTER; | ||
1309 | } | ||
1310 | |||
1311 | /* Checking semaphore name length.*/ | ||
1312 | if (strlen(sem_name) >= OS_MAX_API_NAME) { | ||
1313 | return OS_ERR_NAME_TOO_LONG; | ||
1314 | } | ||
1315 | |||
1316 | /* Semaphore counter check, it must be non-negative.*/ | ||
1317 | if ((int32)sem_initial_value < 0) { | ||
1318 | return OS_INVALID_INT_NUM; | ||
1319 | } | ||
1320 | |||
1321 | /* Getting object.*/ | ||
1322 | sp = chPoolAlloc(&osal.count_semaphores_pool); | ||
1323 | if (sp == NULL) { | ||
1324 | return OS_ERR_NO_FREE_IDS; | ||
1325 | } | ||
1326 | |||
1327 | /* Semaphore is initialized.*/ | ||
1328 | chSemObjectInit(sp, (cnt_t)sem_initial_value); | ||
1329 | |||
1330 | *sem_id = (uint32)sp; | ||
1331 | |||
1332 | return OS_SUCCESS; | ||
1333 | } | ||
1334 | |||
1335 | /** | ||
1336 | * @brief Counter semaphore deletion. | ||
1337 | * | ||
1338 | * @param[in] sem_id counter semaphore id variable | ||
1339 | * @return An error code. | ||
1340 | * | ||
1341 | * @api | ||
1342 | */ | ||
1343 | int32 OS_CountSemDelete(uint32 sem_id) { | ||
1344 | semaphore_t *sp = (semaphore_t *)sem_id; | ||
1345 | |||
1346 | /* Range check.*/ | ||
1347 | if ((sp < &osal.count_semaphores[0]) || | ||
1348 | (sp >= &osal.count_semaphores[OS_MAX_COUNT_SEMAPHORES])) { | ||
1349 | return OS_ERR_INVALID_ID; | ||
1350 | } | ||
1351 | |||
1352 | chSysLock(); | ||
1353 | |||
1354 | /* Resetting the semaphore, no threads in queue.*/ | ||
1355 | chSemResetI(sp, 0); | ||
1356 | |||
1357 | /* Flagging it as unused and returning it to the pool.*/ | ||
1358 | sp->queue.prev = NULL; | ||
1359 | chPoolFreeI(&osal.count_semaphores_pool, (void *)sp); | ||
1360 | |||
1361 | /* Required because some thread could have been made ready.*/ | ||
1362 | chSchRescheduleS(); | ||
1363 | |||
1364 | chSysUnlock(); | ||
1365 | |||
1366 | return OS_SUCCESS; | ||
1367 | } | ||
1368 | |||
1369 | /** | ||
1370 | * @brief Counter semaphore give. | ||
1371 | * @note This function can be safely called from timer callbacks or ISRs. | ||
1372 | * | ||
1373 | * @param[in] sem_id counter semaphore id variable | ||
1374 | * @return An error code. | ||
1375 | * | ||
1376 | * @api | ||
1377 | */ | ||
1378 | int32 OS_CountSemGive(uint32 sem_id) { | ||
1379 | syssts_t sts; | ||
1380 | semaphore_t *sp = (semaphore_t *)sem_id; | ||
1381 | |||
1382 | /* Range check.*/ | ||
1383 | if ((sp < &osal.count_semaphores[0]) || | ||
1384 | (sp >= &osal.count_semaphores[OS_MAX_COUNT_SEMAPHORES])) { | ||
1385 | return OS_ERR_INVALID_ID; | ||
1386 | } | ||
1387 | |||
1388 | /* Entering a reentrant critical zone.*/ | ||
1389 | sts = chSysGetStatusAndLockX(); | ||
1390 | |||
1391 | /* If the semaphore is not in use then error.*/ | ||
1392 | if (sp->queue.prev == NULL) { | ||
1393 | /* Leaving the critical zone.*/ | ||
1394 | chSysRestoreStatusX(sts); | ||
1395 | return OS_SEM_FAILURE; | ||
1396 | } | ||
1397 | |||
1398 | chSemSignalI(sp); | ||
1399 | |||
1400 | /* Leaving the critical zone.*/ | ||
1401 | chSysRestoreStatusX(sts); | ||
1402 | |||
1403 | return OS_SUCCESS; | ||
1404 | } | ||
1405 | |||
1406 | /** | ||
1407 | * @brief Counter semaphore take. | ||
1408 | * | ||
1409 | * @param[in] sem_id counter semaphore id variable | ||
1410 | * @return An error code. | ||
1411 | * | ||
1412 | * @api | ||
1413 | */ | ||
1414 | int32 OS_CountSemTake(uint32 sem_id) { | ||
1415 | semaphore_t *sp = (semaphore_t *)sem_id; | ||
1416 | |||
1417 | /* Range check.*/ | ||
1418 | if ((sp < &osal.count_semaphores[0]) || | ||
1419 | (sp >= &osal.count_semaphores[OS_MAX_COUNT_SEMAPHORES])) { | ||
1420 | return OS_ERR_INVALID_ID; | ||
1421 | } | ||
1422 | |||
1423 | chSysLock(); | ||
1424 | |||
1425 | /* If the semaphore is not in use then error.*/ | ||
1426 | if (sp->queue.prev == NULL) { | ||
1427 | chSysUnlock(); | ||
1428 | return OS_SEM_FAILURE; | ||
1429 | } | ||
1430 | |||
1431 | (void) chSemWaitS(sp); | ||
1432 | |||
1433 | chSysUnlock(); | ||
1434 | |||
1435 | return OS_SUCCESS; | ||
1436 | } | ||
1437 | |||
1438 | /** | ||
1439 | * @brief Counter semaphore take with timeout. | ||
1440 | * | ||
1441 | * @param[in] sem_id counter semaphore id variable | ||
1442 | * @param[in] msecs timeout in milliseconds | ||
1443 | * @return An error code. | ||
1444 | * | ||
1445 | * @api | ||
1446 | */ | ||
1447 | int32 OS_CountSemTimedWait(uint32 sem_id, uint32 msecs) { | ||
1448 | semaphore_t *sp = (semaphore_t *)sem_id; | ||
1449 | msg_t msg; | ||
1450 | |||
1451 | /* Range check.*/ | ||
1452 | if ((sp < &osal.count_semaphores[0]) || | ||
1453 | (sp >= &osal.count_semaphores[OS_MAX_COUNT_SEMAPHORES])) { | ||
1454 | return OS_ERR_INVALID_ID; | ||
1455 | } | ||
1456 | |||
1457 | /* Timeouts of zero not allowed.*/ | ||
1458 | if (msecs == 0) { | ||
1459 | return OS_INVALID_INT_NUM; | ||
1460 | } | ||
1461 | |||
1462 | chSysLock(); | ||
1463 | |||
1464 | /* If the semaphore is not in use then error.*/ | ||
1465 | if (sp->queue.prev == NULL) { | ||
1466 | chSysUnlock(); | ||
1467 | return OS_SEM_FAILURE; | ||
1468 | } | ||
1469 | |||
1470 | msg = chSemWaitTimeoutS(sp, TIME_MS2I(msecs)); | ||
1471 | |||
1472 | chSysUnlock(); | ||
1473 | |||
1474 | return msg == MSG_TIMEOUT ? OS_SEM_TIMEOUT : OS_SUCCESS; | ||
1475 | } | ||
1476 | |||
1477 | /** | ||
1478 | * @brief Retrieves a counter semaphore id by name. | ||
1479 | * @note It is not currently implemented. | ||
1480 | * | ||
1481 | * @param[out] sem_id pointer to a counter semaphore id variable | ||
1482 | * @param[in] sem_name the counter semaphore name | ||
1483 | * @return An error code. | ||
1484 | * | ||
1485 | * @api | ||
1486 | */ | ||
1487 | int32 OS_CountSemGetIdByName(uint32 *sem_id, const char *sem_name) { | ||
1488 | |||
1489 | /* NULL pointer checks.*/ | ||
1490 | if ((sem_id == NULL) || (sem_name == NULL)) { | ||
1491 | return OS_INVALID_POINTER; | ||
1492 | } | ||
1493 | |||
1494 | /* Checking name length.*/ | ||
1495 | if (strlen(sem_name) >= OS_MAX_API_NAME) { | ||
1496 | return OS_ERR_NAME_TOO_LONG; | ||
1497 | } | ||
1498 | |||
1499 | return OS_ERR_NOT_IMPLEMENTED; | ||
1500 | } | ||
1501 | |||
1502 | /** | ||
1503 | * @brief Returns counter semaphore information. | ||
1504 | * @note This function can be safely called from timer callbacks or ISRs. | ||
1505 | * @note It is not currently implemented. | ||
1506 | * | ||
1507 | * @param[in] sem_id counter semaphore id variable | ||
1508 | * @param[in] sem_prop counter semaphore properties | ||
1509 | * @return An error code. | ||
1510 | * | ||
1511 | * @api | ||
1512 | */ | ||
1513 | int32 OS_CountSemGetInfo(uint32 sem_id, OS_count_sem_prop_t *sem_prop) { | ||
1514 | syssts_t sts; | ||
1515 | semaphore_t *sp = (semaphore_t *)sem_id; | ||
1516 | |||
1517 | /* NULL pointer checks.*/ | ||
1518 | if (sem_prop == NULL) { | ||
1519 | return OS_INVALID_POINTER; | ||
1520 | } | ||
1521 | |||
1522 | /* Range check.*/ | ||
1523 | if ((sp < &osal.count_semaphores[0]) || | ||
1524 | (sp >= &osal.count_semaphores[OS_MAX_BIN_SEMAPHORES])) { | ||
1525 | return OS_ERR_INVALID_ID; | ||
1526 | } | ||
1527 | |||
1528 | /* Entering a reentrant critical zone.*/ | ||
1529 | sts = chSysGetStatusAndLockX(); | ||
1530 | |||
1531 | /* If the semaphore is not in use then error.*/ | ||
1532 | if (sp->queue.prev == NULL) { | ||
1533 | /* Leaving the critical zone.*/ | ||
1534 | chSysRestoreStatusX(sts); | ||
1535 | return OS_ERR_INVALID_ID; | ||
1536 | } | ||
1537 | |||
1538 | /* Leaving the critical zone.*/ | ||
1539 | chSysRestoreStatusX(sts); | ||
1540 | |||
1541 | return OS_ERR_NOT_IMPLEMENTED; | ||
1542 | } | ||
1543 | |||
1544 | /*-- Mutex API --------------------------------------------------------------*/ | ||
1545 | |||
1546 | /** | ||
1547 | * @brief Mutex creation. | ||
1548 | * | ||
1549 | * @param[out] sem_id pointer to a mutex id variable | ||
1550 | * @param[in] sem_name the mutex name | ||
1551 | * @param[in] options mutex options | ||
1552 | * @return An error code. | ||
1553 | * | ||
1554 | * @api | ||
1555 | */ | ||
1556 | int32 OS_MutSemCreate(uint32 *sem_id, const char *sem_name, uint32 options) { | ||
1557 | mutex_t *mp; | ||
1558 | |||
1559 | (void)options; | ||
1560 | |||
1561 | /* NULL pointer checks.*/ | ||
1562 | if ((sem_id == NULL) || (sem_name == NULL)) { | ||
1563 | return OS_INVALID_POINTER; | ||
1564 | } | ||
1565 | |||
1566 | /* Checking semaphore name length.*/ | ||
1567 | if (strlen(sem_name) >= OS_MAX_API_NAME) { | ||
1568 | return OS_ERR_NAME_TOO_LONG; | ||
1569 | } | ||
1570 | |||
1571 | /* Getting object.*/ | ||
1572 | mp = chPoolAlloc(&osal.mutexes_pool); | ||
1573 | if (mp == NULL) { | ||
1574 | return OS_ERR_NO_FREE_IDS; | ||
1575 | } | ||
1576 | |||
1577 | /* Semaphore is initialized.*/ | ||
1578 | chMtxObjectInit(mp); | ||
1579 | |||
1580 | *sem_id = (uint32)mp; | ||
1581 | |||
1582 | return OS_SUCCESS; | ||
1583 | } | ||
1584 | |||
1585 | /** | ||
1586 | * @brief Mutex deletion. | ||
1587 | * | ||
1588 | * @param[in] sem_id mutex id variable | ||
1589 | * @return An error code. | ||
1590 | * | ||
1591 | * @api | ||
1592 | */ | ||
1593 | int32 OS_MutSemDelete(uint32 sem_id) { | ||
1594 | mutex_t *mp = (mutex_t *)sem_id; | ||
1595 | |||
1596 | /* Range check.*/ | ||
1597 | if ((mp < &osal.mutexes[0]) || | ||
1598 | (mp >= &osal.mutexes[OS_MAX_MUTEXES])) { | ||
1599 | return OS_ERR_INVALID_ID; | ||
1600 | } | ||
1601 | |||
1602 | chSysLock(); | ||
1603 | |||
1604 | /* Resetting the mutex, no threads in queue.*/ | ||
1605 | chMtxUnlockAllS(); | ||
1606 | |||
1607 | /* Flagging it as unused and returning it to the pool.*/ | ||
1608 | mp->queue.prev = NULL; | ||
1609 | chPoolFreeI(&osal.mutexes_pool, (void *)mp); | ||
1610 | |||
1611 | /* Required because some thread could have been made ready.*/ | ||
1612 | chSchRescheduleS(); | ||
1613 | |||
1614 | chSysUnlock(); | ||
1615 | |||
1616 | return OS_SUCCESS; | ||
1617 | } | ||
1618 | |||
1619 | /** | ||
1620 | * @brief Mutex give. | ||
1621 | * | ||
1622 | * @param[in] sem_id mutex id variable | ||
1623 | * @return An error code. | ||
1624 | * | ||
1625 | * @api | ||
1626 | */ | ||
1627 | int32 OS_MutSemGive(uint32 sem_id) { | ||
1628 | mutex_t *mp = (mutex_t *)sem_id; | ||
1629 | |||
1630 | /* Range check.*/ | ||
1631 | if ((mp < &osal.mutexes[0]) || | ||
1632 | (mp >= &osal.mutexes[OS_MAX_COUNT_SEMAPHORES])) { | ||
1633 | return OS_ERR_INVALID_ID; | ||
1634 | } | ||
1635 | |||
1636 | chSysLock(); | ||
1637 | |||
1638 | /* If the mutex is not in use then error.*/ | ||
1639 | if (mp->queue.prev == NULL) { | ||
1640 | chSysUnlock(); | ||
1641 | return OS_SEM_FAILURE; | ||
1642 | } | ||
1643 | |||
1644 | chMtxUnlockS(mp); | ||
1645 | chSchRescheduleS(); | ||
1646 | |||
1647 | chSysUnlock(); | ||
1648 | |||
1649 | return OS_SUCCESS; | ||
1650 | } | ||
1651 | |||
1652 | /** | ||
1653 | * @brief Mutex take. | ||
1654 | * | ||
1655 | * @param[in] sem_id mutex id variable | ||
1656 | * @return An error code. | ||
1657 | * | ||
1658 | * @api | ||
1659 | */ | ||
1660 | int32 OS_MutSemTake(uint32 sem_id) { | ||
1661 | mutex_t *mp = (mutex_t *)sem_id; | ||
1662 | |||
1663 | /* Range check.*/ | ||
1664 | if ((mp < &osal.mutexes[0]) || | ||
1665 | (mp >= &osal.mutexes[OS_MAX_COUNT_SEMAPHORES])) { | ||
1666 | return OS_ERR_INVALID_ID; | ||
1667 | } | ||
1668 | |||
1669 | chSysLock(); | ||
1670 | |||
1671 | /* If the mutex is not in use then error.*/ | ||
1672 | if (mp->queue.prev == NULL) { | ||
1673 | chSysUnlock(); | ||
1674 | return OS_SEM_FAILURE; | ||
1675 | } | ||
1676 | |||
1677 | chMtxLockS(mp); | ||
1678 | |||
1679 | chSysUnlock(); | ||
1680 | |||
1681 | return OS_SUCCESS; | ||
1682 | } | ||
1683 | |||
1684 | /** | ||
1685 | * @brief Retrieves a mutex id by name. | ||
1686 | * @note It is not currently implemented. | ||
1687 | * | ||
1688 | * @param[out] sem_id pointer to a mutex id variable | ||
1689 | * @param[in] sem_name the mutex name | ||
1690 | * @return An error code. | ||
1691 | * | ||
1692 | * @api | ||
1693 | */ | ||
1694 | int32 OS_MutSemGetIdByName(uint32 *sem_id, const char *sem_name) { | ||
1695 | |||
1696 | /* NULL pointer checks.*/ | ||
1697 | if ((sem_id == NULL) || (sem_name == NULL)) { | ||
1698 | return OS_INVALID_POINTER; | ||
1699 | } | ||
1700 | |||
1701 | /* Checking name length.*/ | ||
1702 | if (strlen(sem_name) >= OS_MAX_API_NAME) { | ||
1703 | return OS_ERR_NAME_TOO_LONG; | ||
1704 | } | ||
1705 | |||
1706 | return OS_ERR_NOT_IMPLEMENTED; | ||
1707 | } | ||
1708 | |||
1709 | /** | ||
1710 | * @brief Returns mutex information. | ||
1711 | * @note This function can be safely called from timer callbacks or ISRs. | ||
1712 | * @note It is not currently implemented. | ||
1713 | * | ||
1714 | * @param[in] sem_id mutex id variable | ||
1715 | * @param[in] sem_prop mutex properties | ||
1716 | * @return An error code. | ||
1717 | * | ||
1718 | * @api | ||
1719 | */ | ||
1720 | int32 OS_MutSemGetInfo(uint32 sem_id, OS_mut_sem_prop_t *sem_prop) { | ||
1721 | syssts_t sts; | ||
1722 | mutex_t *mp = (mutex_t *)sem_id; | ||
1723 | |||
1724 | /* NULL pointer checks.*/ | ||
1725 | if (sem_prop == NULL) { | ||
1726 | return OS_INVALID_POINTER; | ||
1727 | } | ||
1728 | |||
1729 | /* Range check.*/ | ||
1730 | if ((mp < &osal.mutexes[0]) || | ||
1731 | (mp >= &osal.mutexes[OS_MAX_BIN_SEMAPHORES])) { | ||
1732 | return OS_ERR_INVALID_ID; | ||
1733 | } | ||
1734 | |||
1735 | /* Entering a reentrant critical zone.*/ | ||
1736 | sts = chSysGetStatusAndLockX(); | ||
1737 | |||
1738 | /* If the mutex is not in use then error.*/ | ||
1739 | if (mp->queue.prev == NULL) { | ||
1740 | /* Leaving the critical zone.*/ | ||
1741 | chSysRestoreStatusX(sts); | ||
1742 | return OS_ERR_INVALID_ID; | ||
1743 | } | ||
1744 | |||
1745 | /* Leaving the critical zone.*/ | ||
1746 | chSysRestoreStatusX(sts); | ||
1747 | |||
1748 | return OS_ERR_NOT_IMPLEMENTED; | ||
1749 | } | ||
1750 | |||
1751 | /*-- Task Control API -------------------------------------------------------*/ | ||
1752 | |||
1753 | /** | ||
1754 | * @brief Task creation. | ||
1755 | * @note The task name is not copied inside the task but kept by reference, | ||
1756 | * the name is supposed to be persistent, better if defined as a | ||
1757 | * sting constant. | ||
1758 | * | ||
1759 | * @param[out] task_id pointer to a task id variable | ||
1760 | * @param[in] task_name the task name | ||
1761 | * @param[in] function_pointer the task function | ||
1762 | * @param[in] stack_pointer base of stack area | ||
1763 | * @param[in] stack_size size of stack area | ||
1764 | * @param[in] priority the task priority | ||
1765 | * @param[in] flags task attributes | ||
1766 | * @return An error code. | ||
1767 | * | ||
1768 | * @api | ||
1769 | */ | ||
1770 | int32 OS_TaskCreate(uint32 *task_id, | ||
1771 | const char *task_name, | ||
1772 | osal_task_entry function_pointer, | ||
1773 | const uint32 *stack_pointer, | ||
1774 | uint32 stack_size, | ||
1775 | uint32 priority, | ||
1776 | uint32 flags) { | ||
1777 | tprio_t rt_prio; | ||
1778 | thread_t *tp; | ||
1779 | |||
1780 | (void)flags; | ||
1781 | |||
1782 | /* NULL pointer checks.*/ | ||
1783 | if ((task_id == NULL) || (task_name == NULL) || | ||
1784 | (function_pointer == NULL) || (stack_pointer == NULL)) { | ||
1785 | return OS_INVALID_POINTER; | ||
1786 | } | ||
1787 | |||
1788 | /* Checking alignment of stack base and size, it is application | ||
1789 | responsibility to pass correct values.*/ | ||
1790 | if (!MEM_IS_ALIGNED(stack_pointer, PORT_WORKING_AREA_ALIGN) || | ||
1791 | !MEM_IS_ALIGNED(stack_size, sizeof (stkalign_t))) { | ||
1792 | return OS_ERROR_ADDRESS_MISALIGNED; | ||
1793 | } | ||
1794 | |||
1795 | /* Checking task name length.*/ | ||
1796 | if (strlen(task_name) >= OS_MAX_API_NAME) { | ||
1797 | return OS_ERR_NAME_TOO_LONG; | ||
1798 | } | ||
1799 | |||
1800 | /* Checking priority range.*/ | ||
1801 | if ((priority < MIN_PRIORITY) || (priority > MAX_PRIORITY)) { | ||
1802 | return OS_ERR_INVALID_PRIORITY; | ||
1803 | } | ||
1804 | |||
1805 | /* Checking if the specified stack size is below the bare minimum.*/ | ||
1806 | if (stack_size < (uint32)THD_WORKING_AREA_SIZE(0)) { | ||
1807 | return OS_INVALID_INT_NUM; | ||
1808 | } | ||
1809 | |||
1810 | /* Checking if this working area is already in use by some thread, the | ||
1811 | error code is not very appropriate but this case seems to not be | ||
1812 | coveded by the specification.*/ | ||
1813 | tp = chRegFindThreadByWorkingArea((stkalign_t *)stack_pointer); | ||
1814 | if (tp != NULL) { | ||
1815 | /* Releasing the thread reference.*/ | ||
1816 | chThdRelease(tp); | ||
1817 | return OS_ERR_NO_FREE_IDS; | ||
1818 | } | ||
1819 | |||
1820 | /* Checking if the name is already in use.*/ | ||
1821 | if ((tp = chRegFindThreadByName(task_name)) != NULL) { | ||
1822 | /* Releasing the thread reference.*/ | ||
1823 | chThdRelease(tp); | ||
1824 | return OS_ERR_NAME_TAKEN; | ||
1825 | } | ||
1826 | |||
1827 | /* Converting priority to RT type.*/ | ||
1828 | rt_prio = (tprio_t)256 - (tprio_t)priority; | ||
1829 | if (rt_prio == 1) { | ||
1830 | rt_prio = 2; | ||
1831 | } | ||
1832 | |||
1833 | thread_descriptor_t td = { | ||
1834 | task_name, | ||
1835 | (stkalign_t *)stack_pointer, | ||
1836 | (stkalign_t *)((uint8_t *)stack_pointer + stack_size), | ||
1837 | rt_prio, | ||
1838 | (tfunc_t)(void *)function_pointer, | ||
1839 | NULL | ||
1840 | }; | ||
1841 | |||
1842 | /* Creating the task and detaching it, other APIs will have to gain a | ||
1843 | reference using the registry API.*/ | ||
1844 | tp = chThdCreate(&td); | ||
1845 | chThdRelease(tp); | ||
1846 | |||
1847 | /* Storing the task id.*/ | ||
1848 | *task_id = (uint32)tp; | ||
1849 | |||
1850 | return OS_SUCCESS; | ||
1851 | } | ||
1852 | |||
1853 | /** | ||
1854 | * @brief Installs a deletion handler. | ||
1855 | * @note It is implemented as hooks in chconf.h. | ||
1856 | * | ||
1857 | * @param[in] function_pointer the handler function | ||
1858 | * @return An error code. | ||
1859 | * | ||
1860 | * @api | ||
1861 | */ | ||
1862 | int32 OS_TaskInstallDeleteHandler(void *function_pointer) { | ||
1863 | |||
1864 | chThdGetSelfX()->osal_delete_handler = function_pointer; | ||
1865 | |||
1866 | return OS_SUCCESS; | ||
1867 | } | ||
1868 | |||
1869 | /** | ||
1870 | * @brief Check for task termination request. | ||
1871 | * @note This is a ChibiOS/RT extension, direct task delete is not | ||
1872 | * allowed in RT. | ||
1873 | * | ||
1874 | * @return The termination request flag. | ||
1875 | * @retval false if termination has not been requested. | ||
1876 | * @retval true if termination has been requested. | ||
1877 | * | ||
1878 | * @api | ||
1879 | */ | ||
1880 | boolean OS_TaskDeleteCheck(void) { | ||
1881 | |||
1882 | return (boolean)chThdShouldTerminateX(); | ||
1883 | } | ||
1884 | |||
1885 | /** | ||
1886 | * @brief Task delete. | ||
1887 | * @note Limitation, it does not actually kill the thread, it just sets a | ||
1888 | * flag in the thread that has then to terminate voluntarily. The | ||
1889 | * flag can be checked using @p chThdShouldTerminateX(). | ||
1890 | * | ||
1891 | * @param[in] task_id the task id | ||
1892 | * @return An error code. | ||
1893 | * | ||
1894 | * @api | ||
1895 | */ | ||
1896 | int32 OS_TaskDelete(uint32 task_id) { | ||
1897 | thread_t *tp = (thread_t *)task_id; | ||
1898 | funcptr_t fp; | ||
1899 | |||
1900 | /* Check for thread validity, getting a reference.*/ | ||
1901 | if (chRegFindThreadByPointer(tp) == NULL) { | ||
1902 | return OS_ERR_INVALID_ID; | ||
1903 | } | ||
1904 | |||
1905 | /* Asking for thread termination.*/ | ||
1906 | chThdTerminate(tp); | ||
1907 | |||
1908 | /* Getting the delete handler while the thread is still referenced.*/ | ||
1909 | fp = (funcptr_t)tp->osal_delete_handler; | ||
1910 | |||
1911 | /* Waiting for termination, releasing the reference.*/ | ||
1912 | chThdWait(tp); | ||
1913 | |||
1914 | /* Calling the delete handler, if defined.*/ | ||
1915 | if (fp != NULL) { | ||
1916 | fp(); | ||
1917 | } | ||
1918 | |||
1919 | return OS_SUCCESS; | ||
1920 | } | ||
1921 | |||
1922 | /** | ||
1923 | * @brief Task exit. | ||
1924 | * | ||
1925 | * @api | ||
1926 | */ | ||
1927 | void OS_TaskExit(void) { | ||
1928 | |||
1929 | chThdExit(MSG_OK); | ||
1930 | } | ||
1931 | |||
1932 | /** | ||
1933 | * @brief Wait for task termination. | ||
1934 | * @note This is a ChibiOS/RT extension, added for improved testability. | ||
1935 | * | ||
1936 | * @param[in] task_id the task id | ||
1937 | * @return An error code. | ||
1938 | * | ||
1939 | * @api | ||
1940 | */ | ||
1941 | int32 OS_TaskWait(uint32 task_id) { | ||
1942 | thread_t *tp = (thread_t *)task_id; | ||
1943 | |||
1944 | /* Check for thread validity, getting a reference.*/ | ||
1945 | if (chRegFindThreadByPointer(tp) == NULL) { | ||
1946 | return OS_ERR_INVALID_ID; | ||
1947 | } | ||
1948 | |||
1949 | (void) chThdWait(tp); | ||
1950 | |||
1951 | return OS_SUCCESS; | ||
1952 | } | ||
1953 | |||
1954 | /** | ||
1955 | * @brief Task delay. | ||
1956 | * | ||
1957 | * @param[in] milli_second the period in miliseconds | ||
1958 | * @return An error code. | ||
1959 | * | ||
1960 | * @api | ||
1961 | */ | ||
1962 | int32 OS_TaskDelay(uint32 milli_second) { | ||
1963 | |||
1964 | chThdSleepMilliseconds(milli_second); | ||
1965 | return OS_SUCCESS; | ||
1966 | } | ||
1967 | |||
1968 | /** | ||
1969 | * @brief Change task priority. | ||
1970 | * @note Priority 255 is not available and it is transformed internally in | ||
1971 | * 254. | ||
1972 | * | ||
1973 | * @param[in] task_id the task id | ||
1974 | * @param[in] new_priority the task new priority | ||
1975 | * @return An error code. | ||
1976 | * | ||
1977 | * @api | ||
1978 | */ | ||
1979 | int32 OS_TaskSetPriority(uint32 task_id, uint32 new_priority) { | ||
1980 | tprio_t rt_newprio; | ||
1981 | thread_t *tp = (thread_t *)task_id; | ||
1982 | |||
1983 | /* Checking priority range.*/ | ||
1984 | if ((new_priority < MIN_PRIORITY) || (new_priority > MAX_PRIORITY)) { | ||
1985 | return OS_ERR_INVALID_PRIORITY; | ||
1986 | } | ||
1987 | |||
1988 | /* Converting priority to RT type.*/ | ||
1989 | rt_newprio = (tprio_t)256 - (tprio_t)new_priority; | ||
1990 | if (rt_newprio == 1) { | ||
1991 | rt_newprio = 2; | ||
1992 | } | ||
1993 | |||
1994 | if (chThdGetPriorityX() == rt_newprio) { | ||
1995 | return OS_SUCCESS; | ||
1996 | } | ||
1997 | |||
1998 | /* Check for thread validity.*/ | ||
1999 | if (chRegFindThreadByPointer(tp) == NULL) { | ||
2000 | return OS_ERR_INVALID_ID; | ||
2001 | } | ||
2002 | |||
2003 | chSysLock(); | ||
2004 | |||
2005 | /* Changing priority.*/ | ||
2006 | if ((tp->hdr.pqueue.prio == tp->realprio) || | ||
2007 | (rt_newprio > tp->hdr.pqueue.prio)) { | ||
2008 | tp->hdr.pqueue.prio = rt_newprio; | ||
2009 | } | ||
2010 | tp->realprio = rt_newprio; | ||
2011 | |||
2012 | /* The following states need priority queues reordering.*/ | ||
2013 | switch (tp->state) { | ||
2014 | case CH_STATE_WTMTX: | ||
2015 | #if CH_CFG_USE_CONDVARS | ||
2016 | case CH_STATE_WTCOND: | ||
2017 | #endif | ||
2018 | #if CH_CFG_USE_SEMAPHORES_PRIORITY | ||
2019 | case CH_STATE_WTSEM: | ||
2020 | #endif | ||
2021 | #if CH_CFG_USE_MESSAGES && CH_CFG_USE_MESSAGES_PRIORITY | ||
2022 | case CH_STATE_SNDMSGQ: | ||
2023 | #endif | ||
2024 | /* Re-enqueues tp with its new priority on the queue.*/ | ||
2025 | ch_sch_prio_insert(ch_queue_dequeue(&tp->hdr.queue), | ||
2026 | (ch_queue_t *)tp->u.wtobjp); | ||
2027 | break; | ||
2028 | case CH_STATE_READY: | ||
2029 | #if CH_DBG_ENABLE_ASSERTS | ||
2030 | /* Prevents an assertion in chSchReadyI().*/ | ||
2031 | tp->state = CH_STATE_CURRENT; | ||
2032 | #endif | ||
2033 | /* Re-enqueues tp with its new priority on the ready list.*/ | ||
2034 | chSchReadyI((thread_t *)ch_queue_dequeue(&tp->hdr.queue)); | ||
2035 | break; | ||
2036 | } | ||
2037 | |||
2038 | /* Rescheduling.*/ | ||
2039 | chSchRescheduleS(); | ||
2040 | chSysUnlock(); | ||
2041 | |||
2042 | /* Releasing the thread reference.*/ | ||
2043 | chThdRelease(tp); | ||
2044 | |||
2045 | return OS_SUCCESS; | ||
2046 | } | ||
2047 | |||
2048 | /** | ||
2049 | * @brief Task registration. | ||
2050 | * @note In ChibiOS/RT it does nothing. | ||
2051 | * | ||
2052 | * @return An error code. | ||
2053 | * | ||
2054 | * @api | ||
2055 | */ | ||
2056 | int32 OS_TaskRegister(void) { | ||
2057 | |||
2058 | return OS_SUCCESS; | ||
2059 | } | ||
2060 | |||
2061 | /** | ||
2062 | * @brief Current task id. | ||
2063 | * @note This function can be safely called from timer callbacks or ISRs. | ||
2064 | * | ||
2065 | * @return The current task id. | ||
2066 | * | ||
2067 | * @api | ||
2068 | */ | ||
2069 | uint32 OS_TaskGetId(void) { | ||
2070 | |||
2071 | return (uint32)chThdGetSelfX(); | ||
2072 | } | ||
2073 | |||
2074 | /** | ||
2075 | * @brief Retrieves a task id by name. | ||
2076 | * | ||
2077 | * @param[out] task_id pointer to a task id variable | ||
2078 | * @param[in] task_name the task name | ||
2079 | * @return An error code. | ||
2080 | * | ||
2081 | * @api | ||
2082 | */ | ||
2083 | int32 OS_TaskGetIdByName(uint32 *task_id, const char *task_name) { | ||
2084 | thread_t *tp; | ||
2085 | |||
2086 | /* NULL pointer checks.*/ | ||
2087 | if ((task_id == NULL) || (task_name == NULL)) { | ||
2088 | return OS_INVALID_POINTER; | ||
2089 | } | ||
2090 | |||
2091 | /* Checking task name length.*/ | ||
2092 | if (strlen(task_name) >= OS_MAX_API_NAME) { | ||
2093 | return OS_ERR_NAME_TOO_LONG; | ||
2094 | } | ||
2095 | |||
2096 | /* Searching in the registry.*/ | ||
2097 | tp = chRegFindThreadByName(task_name); | ||
2098 | if (tp == NULL) { | ||
2099 | return OS_ERR_NAME_NOT_FOUND; | ||
2100 | } | ||
2101 | |||
2102 | *task_id = (uint32)tp; | ||
2103 | |||
2104 | /* Releasing the thread reference.*/ | ||
2105 | chThdRelease(tp); | ||
2106 | |||
2107 | return OS_SUCCESS; | ||
2108 | } | ||
2109 | |||
2110 | /** | ||
2111 | * @brief Returns task information. | ||
2112 | * @note This function can be safely called from timer callbacks or ISRs. | ||
2113 | * @note Priority 255 is not available and it is transformed internally in | ||
2114 | * 254. | ||
2115 | * | ||
2116 | * @param[in] task_id the task id | ||
2117 | * @param[in] task_prop task properties | ||
2118 | * @return An error code. | ||
2119 | * | ||
2120 | * @api | ||
2121 | */ | ||
2122 | int32 OS_TaskGetInfo(uint32 task_id, OS_task_prop_t *task_prop) { | ||
2123 | thread_t *tp = (thread_t *)task_id; | ||
2124 | size_t wasize = (size_t)tp - (size_t)tp->wabase + sizeof (thread_t); | ||
2125 | |||
2126 | /* NULL pointer checks.*/ | ||
2127 | if (task_prop == NULL) { | ||
2128 | return OS_INVALID_POINTER; | ||
2129 | } | ||
2130 | |||
2131 | /* Check for thread validity.*/ | ||
2132 | if (chRegFindThreadByPointer(tp) == NULL) { | ||
2133 | return OS_ERR_INVALID_ID; | ||
2134 | } | ||
2135 | |||
2136 | strncpy(task_prop->name, tp->name, OS_MAX_API_NAME - 1); | ||
2137 | task_prop->creator = (uint32)chSysGetIdleThreadX(); | ||
2138 | task_prop->stack_size = (uint32)MEM_ALIGN_NEXT(wasize, PORT_STACK_ALIGN); | ||
2139 | task_prop->priority = (uint32)256U - (uint32)tp->realprio; | ||
2140 | task_prop->OStask_id = task_id; | ||
2141 | |||
2142 | /* Releasing the thread reference.*/ | ||
2143 | chThdRelease(tp); | ||
2144 | |||
2145 | return OS_SUCCESS; | ||
2146 | } | ||
2147 | |||
2148 | /*-- System Interrupt API ---------------------------------------------------*/ | ||
2149 | |||
2150 | /* In ChibiOS interrupts are statically linked, the vectors table is in | ||
2151 | flash.*/ | ||
2152 | int32 OS_IntAttachHandler (uint32 InterruptNumber, | ||
2153 | osal_task_entry InterruptHandler, | ||
2154 | int32 parameter) { | ||
2155 | (void)InterruptNumber; | ||
2156 | (void)parameter; | ||
2157 | |||
2158 | /* NULL pointer checks.*/ | ||
2159 | if (InterruptHandler == NULL) { | ||
2160 | return OS_INVALID_POINTER; | ||
2161 | } | ||
2162 | |||
2163 | return OS_ERR_NOT_IMPLEMENTED; | ||
2164 | } | ||
2165 | |||
2166 | int32 OS_IntLock(void) { | ||
2167 | |||
2168 | return (int32)chSysGetStatusAndLockX(); | ||
2169 | } | ||
2170 | |||
2171 | int32 OS_IntUnlock(int32 IntLevel) { | ||
2172 | |||
2173 | chSysRestoreStatusX((syssts_t) IntLevel); | ||
2174 | |||
2175 | return OS_SUCCESS; | ||
2176 | } | ||
2177 | |||
2178 | int32 OS_IntEnable(int32 Level) { | ||
2179 | |||
2180 | NVIC_EnableIRQ((IRQn_Type)Level); | ||
2181 | |||
2182 | return OS_SUCCESS; | ||
2183 | } | ||
2184 | |||
2185 | int32 OS_IntDisable(int32 Level) { | ||
2186 | |||
2187 | NVIC_DisableIRQ((IRQn_Type)Level); | ||
2188 | |||
2189 | return OS_SUCCESS; | ||
2190 | } | ||
2191 | |||
2192 | int32 OS_IntAck(int32 InterruptNumber) { | ||
2193 | |||
2194 | NVIC_ClearPendingIRQ((IRQn_Type)InterruptNumber); | ||
2195 | |||
2196 | return OS_SUCCESS; | ||
2197 | } | ||
2198 | |||
2199 | /*-- System Exception API ---------------------------------------------------*/ | ||
2200 | |||
2201 | /* In ChibiOS exceptions are statically linked, the vectors table is in | ||
2202 | flash.*/ | ||
2203 | int32 OS_ExcAttachHandler(uint32 ExceptionNumber, | ||
2204 | void (*ExceptionHandler)(uint32, uint32 *,uint32), | ||
2205 | int32 parameter) { | ||
2206 | |||
2207 | (void)ExceptionNumber; | ||
2208 | (void)parameter; | ||
2209 | |||
2210 | /* NULL pointer checks.*/ | ||
2211 | if (ExceptionHandler == NULL) { | ||
2212 | return OS_INVALID_POINTER; | ||
2213 | } | ||
2214 | |||
2215 | return OS_ERR_NOT_IMPLEMENTED; | ||
2216 | } | ||
2217 | |||
2218 | /* No exceptions masking.*/ | ||
2219 | int32 OS_ExcEnable(int32 ExceptionNumber) { | ||
2220 | |||
2221 | (void)ExceptionNumber; | ||
2222 | |||
2223 | return OS_ERR_NOT_IMPLEMENTED; | ||
2224 | } | ||
2225 | |||
2226 | /* No exceptions masking.*/ | ||
2227 | int32 OS_ExcDisable(int32 ExceptionNumber) { | ||
2228 | |||
2229 | (void)ExceptionNumber; | ||
2230 | |||
2231 | return OS_ERR_NOT_IMPLEMENTED; | ||
2232 | } | ||
2233 | |||
2234 | /*-- Floating Point Unit API ------------------------------------------------*/ | ||
2235 | |||
2236 | /* In ChibiOS exceptions are statically linked, the vectors table is in | ||
2237 | flash.*/ | ||
2238 | int32 OS_FPUExcAttachHandler(uint32 ExceptionNumber, | ||
2239 | void * ExceptionHandler , | ||
2240 | int32 parameter) { | ||
2241 | |||
2242 | (void)ExceptionNumber; | ||
2243 | (void)parameter; | ||
2244 | |||
2245 | /* NULL pointer checks.*/ | ||
2246 | if (ExceptionHandler == NULL) { | ||
2247 | return OS_INVALID_POINTER; | ||
2248 | } | ||
2249 | |||
2250 | return OS_ERR_NOT_IMPLEMENTED; | ||
2251 | } | ||
2252 | |||
2253 | int32 OS_FPUExcEnable(int32 ExceptionNumber) { | ||
2254 | |||
2255 | (void)ExceptionNumber; | ||
2256 | |||
2257 | return OS_ERR_NOT_IMPLEMENTED; | ||
2258 | } | ||
2259 | |||
2260 | int32 OS_FPUExcDisable(int32 ExceptionNumber) { | ||
2261 | |||
2262 | (void)ExceptionNumber; | ||
2263 | |||
2264 | return OS_ERR_NOT_IMPLEMENTED; | ||
2265 | } | ||
2266 | |||
2267 | int32 OS_FPUExcSetMask(uint32 mask) { | ||
2268 | |||
2269 | (void)mask; | ||
2270 | |||
2271 | return OS_ERR_NOT_IMPLEMENTED; | ||
2272 | } | ||
2273 | |||
2274 | int32 OS_FPUExcGetMask(uint32 *mask) { | ||
2275 | |||
2276 | (void)mask; | ||
2277 | |||
2278 | return OS_ERR_NOT_IMPLEMENTED; | ||
2279 | } | ||
2280 | |||
2281 | /** @} */ | ||