os_port_embos.h
Go to the documentation of this file.
1 /**
2  * @file os_port_embos.h
3  * @brief RTOS abstraction layer (Segger embOS)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 2.4.4
27  **/
28 
29 #ifndef _OS_PORT_EMBOS_H
30 #define _OS_PORT_EMBOS_H
31 
32 //Dependencies
33 #include "rtos.h"
34 
35 //Invalid task identifier
36 #define OS_INVALID_TASK_ID NULL
37 //Self task identifier
38 #define OS_SELF_TASK_ID NULL
39 
40 //Task priority (normal)
41 #ifndef OS_TASK_PRIORITY_NORMAL
42  #define OS_TASK_PRIORITY_NORMAL 1
43 #endif
44 
45 //Task priority (high)
46 #ifndef OS_TASK_PRIORITY_HIGH
47  #define OS_TASK_PRIORITY_HIGH 2
48 #endif
49 
50 //Milliseconds to system ticks
51 #ifndef OS_MS_TO_SYSTICKS
52  #define OS_MS_TO_SYSTICKS(n) (n)
53 #endif
54 
55 //System ticks to milliseconds
56 #ifndef OS_SYSTICKS_TO_MS
57  #define OS_SYSTICKS_TO_MS(n) (n)
58 #endif
59 
60 //Retrieve 64-bit system time (not implemented)
61 #ifndef osGetSystemTime64
62  #define osGetSystemTime64() osGetSystemTime()
63 #endif
64 
65 //Task prologue
66 #define osEnterTask()
67 //Task epilogue
68 #define osExitTask()
69 //Interrupt service routine prologue
70 #define osEnterIsr() OS_EnterNestableInterrupt()
71 //Interrupt service routine epilogue
72 #define osExitIsr(flag) OS_LeaveNestableInterrupt()
73 
74 //C++ guard
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78 
79 
80 /**
81  * @brief System time
82  **/
83 
84 typedef uint32_t systime_t;
85 
86 
87 /**
88  * @brief Task identifier
89  **/
90 
91 typedef OS_TASK *OsTaskId;
92 
93 
94 /**
95  * @brief Task parameters
96  **/
97 
98 typedef struct
99 {
100  OS_TASK *tcb;
101  uint32_t *stack;
102  size_t stackSize;
105 
106 
107 /**
108  * @brief Event object
109  **/
110 
111 typedef OS_EVENT OsEvent;
112 
113 
114 /**
115  * @brief Semaphore object
116  **/
117 
118 typedef OS_CSEMA OsSemaphore;
119 
120 
121 /**
122  * @brief Mutex object
123  **/
124 
125 typedef OS_RSEMA OsMutex;
126 
127 
128 /**
129  * @brief Task routine
130  **/
131 
132 typedef void (*OsTaskCode)(void *arg);
133 
134 
135 //Default task parameters
137 
138 //Kernel management
139 void osInitKernel(void);
140 void osStartKernel(void);
141 
142 //Task management
143 OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg,
144  const OsTaskParameters *params);
145 
146 void osDeleteTask(OsTaskId taskId);
147 void osDelayTask(systime_t delay);
148 void osSwitchTask(void);
149 void osSuspendAllTasks(void);
150 void osResumeAllTasks(void);
151 
152 //Event management
154 void osDeleteEvent(OsEvent *event);
155 void osSetEvent(OsEvent *event);
156 void osResetEvent(OsEvent *event);
157 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
159 
160 //Semaphore management
161 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
162 void osDeleteSemaphore(OsSemaphore *semaphore);
163 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
164 void osReleaseSemaphore(OsSemaphore *semaphore);
165 
166 //Mutex management
168 void osDeleteMutex(OsMutex *mutex);
169 void osAcquireMutex(OsMutex *mutex);
170 void osReleaseMutex(OsMutex *mutex);
171 
172 //System time
174 
175 //Memory management
176 void *osAllocMem(size_t size);
177 void osFreeMem(void *p);
178 
179 //C++ guard
180 #ifdef __cplusplus
181 }
182 #endif
183 
184 #endif
void osResumeAllTasks(void)
Resume scheduler activity.
OS_RSEMA OsMutex
Mutex object.
int bool_t
Definition: compiler_port.h:53
void osSuspendAllTasks(void)
Suspend scheduler activity.
void osInitKernel(void)
Kernel initialization.
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
uint8_t p
Definition: ndp.h:300
void osFreeMem(void *p)
Release a previously allocated memory block.
Event object.
OS_EVENT OsEvent
Event object.
char_t name[]
OS_CSEMA OsSemaphore
Semaphore object.
Semaphore object.
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
const OsTaskParameters OS_TASK_DEFAULT_PARAMS
bool_t osCreateEvent(OsEvent *event)
Create an event object.
void osDeleteTask(OsTaskId taskId)
Delete a task.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
Task parameters.
void(* OsTaskCode)(void *arg)
Task routine.
uint32_t systime_t
System time.
Definition: os_port_embos.h:84
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
Mutex object.
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
uint32_t systime_t
System time.
char char_t
Definition: compiler_port.h:48
OS_TASK * OsTaskId
Task identifier.
Definition: os_port_embos.h:91
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg, const OsTaskParameters *params)
Create a task.
void osStartKernel(void)
Start kernel.
systime_t osGetSystemTime(void)
Retrieve system time.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
void osDelayTask(systime_t delay)
Delay routine.
void osSwitchTask(void)
Yield control to the next task.
thread_t * OsTaskId
Task identifier.
unsigned int uint_t
Definition: compiler_port.h:50
void * osAllocMem(size_t size)
Allocate a memory block.
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
uint16_t priority
Definition: dns_common.h:265
void osDeleteEvent(OsEvent *event)
Delete an event object.
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.