Developer World
Spresense SDK Library v3.2.0-ebc0364
os_wrapper.h
1/****************************************************************************
2 * modules/include/memutils/os_utils/os_wrapper.h
3 *
4 * Copyright 2018 Sony Semiconductor Solutions Corporation
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3. Neither the name of Sony Semiconductor Solutions Corporation nor
17 * the names of its contributors may be used to endorse or promote
18 * products derived from this software without specific prior written
19 * permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ****************************************************************************/
35
36#ifndef _OS_WRAPPER_H_
37#define _OS_WRAPPER_H_
38
39#if !defined(OS_TYPE_FREERTOS) && !defined(_POSIX)
40#include "../os/merlot/osal/uitron/os_wrapper_rename.h"
41#endif
42
43#ifdef __cplusplus
44extern "C" {
45#endif /* __cplusplus */
46
47#include <stdbool.h>
48#include <stdint.h>
49#include <errno.h>
50
51#ifdef OS_TYPE_FREERTOS
52
53#include <freertos_inc.h>
54
55typedef unsigned int SYS_CpuId;
56typedef int16_t SYS_Id;
57typedef uint32_t SYS_FlagPattern;
58typedef struct t_msg {
59 struct t_msg *next;
60} SYS_Message;
61typedef int SYS_Timeout;
62typedef unsigned int SYS_WaitMode;
63typedef unsigned int SYS_Time;
64typedef unsigned int SYS_RelativeTime;
65typedef uint32_t SYS_Attribute;
66typedef unsigned int SYS_Status;
67typedef TaskHandle_t SYS_Task;
68typedef TimerHandle_t SYS_CyclicHandler;
69typedef TimerHandle_t SYS_AlarmHandler;
70typedef void *SYS_CyclicHandlerInfo;
71typedef void *SYS_AlarmHandlerInfo;
72
73#elif !defined(_POSIX) /* OS_TYPE_FREERTOS */
74
75#include <itron.h>
76#include <refcnt_mpf.h>
77
78typedef unsigned int SYS_CpuId;
79typedef ID SYS_Id;
80typedef FLGPTN SYS_FlagPattern;
81typedef T_MSG SYS_Message;
82typedef TMO SYS_Timeout;
83typedef MODE SYS_WaitMode;
84typedef SYSTIM SYS_Time;
85typedef RELTIM SYS_RelativeTime;
86typedef ATR SYS_Attribute;
87typedef STAT SYS_Status;
88typedef ID SYS_Task;
89typedef ID SYS_CyclicHandler;
90typedef ID SYS_AlarmHandler;
91typedef void *SYS_CyclicHandlerInfo;
92typedef void *SYS_AlarmHandlerInfo;
93
94#endif /* OS_TYPE_FREERTOS */
95
96/* Data structure for refer series service call */
97#if !defined(_POSIX) /* _POSIX */
98
99typedef struct {
100 void *arg;
101 void (*function)(void *arg);
102 const char *name;
103 int priority;
104 unsigned long stackSize;
106
107typedef struct {
108 SYS_Attribute attribute;
109 unsigned int initialCount;
110 unsigned int maxCount;
112
113typedef struct {
114 SYS_Attribute attribute;
115 SYS_FlagPattern initialPattern;
117
118typedef struct {
119 SYS_Attribute attribute;
121
122typedef struct {
123 unsigned int blockCount;
124 unsigned int blockSize;
125 void *pool;
127
128typedef struct {
129 void *arg;
130 void (*handler)(SYS_CyclicHandlerInfo info);
131 const char *name;
132 SYS_RelativeTime cycle;
134
135typedef struct {
136 void *arg;
137 void (*handler)(SYS_AlarmHandlerInfo info);
138 const char *name;
140
141typedef struct TaskStatus {
142 SYS_Status status;
143 int priority;
145
146typedef struct SemaphoreStatus {
147 unsigned int semaphoreCount; /* Current count */
149
150typedef struct FlagStatus {
151 SYS_FlagPattern flagPattern; /* Current pattern */
153
154typedef struct MailboxStatus {
155 SYS_Message *message; /* Next receive message */
157
158typedef struct MemoryPoolStatus {
159 unsigned int freeBlocks;
161
162typedef struct CyclicHandlerStatus {
163 SYS_Status status;
165
166typedef struct AlarmHandlerStatus {
167 SYS_Status status;
169
170/* Task Management Functions */
171int SYS_CreateTask(SYS_Task *desc, const SYS_CreateTaskParams *params);
172int SYS_DeleteTask(SYS_Task desc);
173int SYS_ChangeTaskPriority(SYS_Task desc, int prio);
174int SYS_GetTaskPriority(SYS_Task desc, int *prio);
175int SYS_ReferTask(SYS_Task desc, SYS_TaskStatus *taskStatus);
176
177/* Task Dependent Synchronization Functions */
178int SYS_SleepTask(SYS_Timeout timeout);
179int SYS_SuspendTask(SYS_Task desc);
180int SYS_ResumeTask(SYS_Task desc);
181int SYS_DelayTask(SYS_RelativeTime delay);
182
183/* Synchronization and Communication Functions */
184int SYS_CreateSemaphore(SYS_Id id, const SYS_CreateSemaphoreParams *params);
185int SYS_DeleteSemaphore(SYS_Id id);
186int SYS_SignalSemaphore(SYS_Id id);
187int SYS_WaitSemaphore(SYS_Id id, SYS_Timeout timeout);
188int SYS_ReferSemaphore(SYS_Id id, SYS_SemaphoreStatus *semaphoreStatus);
189
190int SYS_CreateFlag(SYS_Id id, const SYS_CreateFlagParams *params);
191int SYS_DeleteFlag(SYS_Id id);
192int SYS_SetFlag(SYS_Id id, SYS_FlagPattern setPattern);
193int SYS_ClearFlag(SYS_Id id, SYS_FlagPattern clearPattern);
194int SYS_WaitFlag(SYS_Id id, SYS_FlagPattern waitPattern, SYS_WaitMode waitMode, SYS_FlagPattern *flagPattern, SYS_Timeout timeout);
195int SYS_ReferFlag(SYS_Id id, SYS_FlagStatus *flagStatus);
196
197int SYS_CreateMailbox(SYS_Id id, const SYS_CreateMailboxParams *params);
198int SYS_DeleteMailbox(SYS_Id id);
199int SYS_SendMailbox(SYS_Id id, SYS_Message *message);
200int SYS_ReceiveMailbox(SYS_Id id, SYS_Message **message, SYS_Timeout timeout);
201int SYS_ReferMailbox(SYS_Id id, SYS_MailboxStatus *mailboxStatus);
202
203#if defined(CPU_CLUSTER_M0P) && defined(CONFIG_OS_PM_SUPPORT)
204int SYS_SignalSemaphorePowerCare(SYS_Id id);
205int SYS_WaitSemaphorePowerCare(SYS_Id id, SYS_Timeout timeout);
206int SYS_ReferSemaphorePowerCare(SYS_Id id, SYS_SemaphoreStatus *semaphoreStatus);
207
208int SYS_SetFlagPowerCare(SYS_Id id, SYS_FlagPattern setPattern);
209int SYS_ClearFlagPowerCare(SYS_Id id, SYS_FlagPattern clearPattern);
210int SYS_WaitFlagPowerCare(SYS_Id id, SYS_FlagPattern waitPattern, SYS_WaitMode waitMode, SYS_FlagPattern *flagPattern, SYS_Timeout timeout);
211int SYS_ReferFlagPowerCare(SYS_Id id, SYS_FlagStatus *flagStatus);
212
213int SYS_SendMailboxPowerCare(SYS_Id id, SYS_Message *message);
214int SYS_ReceiveMailboxPowerCare(SYS_Id id, SYS_Message **message, SYS_Timeout timeout);
215int SYS_ReferMailboxPowerCare(SYS_Id id, SYS_MailboxStatus *mailboxStatus);
216
217#endif /* defined(CPU_CLUSTER_M0P) && defined(CONFIG_OS_PM_SUPPORT) */
218
219/* Memory Pool Management Fucntions */
220void *SYS_AllocMemory(unsigned int size);
221void SYS_FreeMemory(void *ptr);
222void *SYS_AllocSharedMemory(unsigned int size);
223void SYS_FreeSharedMemory(void *ptr);
224int SYS_CreateMemoryPool(SYS_Id id, const SYS_CreateMemoryPoolParams *params);
225int SYS_DeleteMemoryPool(SYS_Id id);
226int SYS_GetMemoryBlock(SYS_Id id, void **block, SYS_Timeout timeout);
227int SYS_AcquireMemoryBlock(SYS_Id id, void *block);
228int SYS_ReleaseMemoryBlock(SYS_Id id, void *block);
229int SYS_ReferMemoryPool(SYS_Id id, SYS_MemoryPoolStatus *status);
230
231/* Time Management Functions */
232int SYS_GetTime(SYS_Time *time);
233int SYS_CreateCyclicHandler(SYS_CyclicHandler *desc, const SYS_CreateCyclicHandlerParams *params);
234int SYS_DeleteCyclicHandler(SYS_CyclicHandler desc);
235int SYS_StartCyclicHandler(SYS_CyclicHandler desc);
236int SYS_StopCyclicHandler(SYS_CyclicHandler desc);
237int SYS_GetCyclicHandlerArg(SYS_CyclicHandlerInfo info, void **arg);
238int SYS_ReferCyclicHandler(SYS_CyclicHandler desc, SYS_CyclicHandlerStatus *status);
239int SYS_CreateAlarmHandler(SYS_AlarmHandler *desc, const SYS_CreateAlarmHandlerParams *params);
240int SYS_DeleteAlarmHandler(SYS_AlarmHandler desc);
241int SYS_StartAlarmHandler(SYS_AlarmHandler desc, SYS_RelativeTime time);
242int SYS_StopAlarmHandler(SYS_AlarmHandler desc);
243int SYS_GetAlarmHandlerArg(SYS_AlarmHandlerInfo info, void **arg);
244int SYS_ReferAlarmHandler(SYS_AlarmHandler desc, SYS_AlarmHandlerStatus *status);
245
246/* System State Management Functions */
247int SYS_GetTaskDescriptor(SYS_Task *desc);
248int SYS_YieldTask(void);
249int SYS_DisableDispatch(void);
250int SYS_EnableDispatch(void);
251bool SYS_IsDispatchDisabled(void);
252int SYS_DisableInterrupt(int irqNum);
253int SYS_EnableInterrupt(int irqNum);
254void SYS_SaveInterruptMask(uint32_t *mask);
255void SYS_RestoreInterruptMask(uint32_t mask);
256bool SYS_GetInterruptMask(void);
257bool SYS_IsInTaskContext(void);
258int SYS_GetCpuId(void);
259int SYS_GetCpuClusterId(void);
260
261#endif /* _POSIX */
262
263#ifdef _POSIX /* _POSIX */
264int SYS_DisableDispatch(void);
265int SYS_EnableDispatch(void);
266int SYS_GetCpuId(void);
267#endif /* _POSIX */
268
269/* UINT tskstat */
270#define TTS_RUN (0x0001)
271#define TTS_RDY (0x0002)
272#define TTS_WAI (0x0004)
273
274/* TMP tmout */
275#define TMO_POL (0)
276#define TMO_FEVR (-1)
277
278/* UINT wfmode */
279#define TWF_ANDW (0x0000)
280#define TWF_ORW (0x0001)
281
282#define TA_CLR (0x0004)
283
284#define TSK_SELF (0)
285
286#ifdef __cplusplus
287}
288#endif /* __cplusplus */
289
290#endif /* _OS_WRAPPER_H_ */
Definition: os_wrapper.h:166
Definition: os_wrapper.h:162
Definition: os_wrapper.h:150
Definition: os_wrapper.h:154
Definition: os_wrapper.h:158
Definition: os_wrapper.h:135
Definition: os_wrapper.h:128
Definition: os_wrapper.h:113
Definition: os_wrapper.h:118
Definition: os_wrapper.h:122
Definition: os_wrapper.h:107
Definition: os_wrapper.h:99
Definition: os_wrapper.h:146
Definition: os_wrapper.h:141