os_port_cmx_rtx.h
Go to the documentation of this file.
1 /**
2  * @file os_port_cmx_rtx.h
3  * @brief RTOS abstraction layer (CMX-RTX)
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_CMX_RTX_H
30 #define _OS_PORT_CMX_RTX_H
31 
32 //Dependencies
33 #include "cxfuncs.h"
34 
35 //Maximum number of semaphores that can be created
36 #ifndef OS_MAX_SEMAPHORES
37  #define OS_MAX_SEMAPHORES 64
38 #elif (OS_MAX_SEMAPHORES < 1 || OS_MAX_SEMAPHORES > 255)
39  #error OS_MAX_SEMAPHORES parameter is not valid
40 #endif
41 
42 //Invalid semaphore identifier
43 #define OS_INVALID_SEMAPHORE_ID 255
44 //Invalid task identifier
45 #define OS_INVALID_TASK_ID 0
46 //Self task identifier
47 #define OS_SELF_TASK_ID 0
48 
49 //Task priority (normal)
50 #ifndef OS_TASK_PRIORITY_NORMAL
51  #define OS_TASK_PRIORITY_NORMAL 3
52 #endif
53 
54 //Task priority (high)
55 #ifndef OS_TASK_PRIORITY_HIGH
56  #define OS_TASK_PRIORITY_HIGH 2
57 #endif
58 
59 //Milliseconds to system ticks
60 #ifndef OS_MS_TO_SYSTICKS
61  #define OS_MS_TO_SYSTICKS(n) (n)
62 #endif
63 
64 //System ticks to milliseconds
65 #ifndef OS_SYSTICKS_TO_MS
66  #define OS_SYSTICKS_TO_MS(n) (n)
67 #endif
68 
69 //Retrieve 64-bit system time (not implemented)
70 #ifndef osGetSystemTime64
71  #define osGetSystemTime64() osGetSystemTime()
72 #endif
73 
74 //Task prologue
75 #define osEnterTask()
76 //Task epilogue
77 #define osExitTask()
78 //Interrupt service routine prologue
79 #define osEnterIsr()
80 //Interrupt service routine epilogue
81 #define osExitIsr(flag)
82 
83 //C++ guard
84 #ifdef __cplusplus
85 extern "C" {
86 #endif
87 
88 
89 /**
90  * @brief System time
91  **/
92 
93 typedef uint32_t systime_t;
94 
95 
96 /**
97  * @brief Task identifier
98  **/
99 
100 typedef uint8_t OsTaskId;
101 
102 
103 /**
104  * @brief Task parameters
105  **/
106 
107 typedef struct
108 {
109  CMX_FP fp;
110  word32 *stack;
111  size_t stackSize;
114 
115 
116 /**
117  * @brief Event object
118  **/
119 
120 typedef struct
121 {
122  uint8_t id;
123 } OsEvent;
124 
125 
126 /**
127  * @brief Semaphore object
128  **/
129 
130 typedef struct
131 {
132  uint8_t id;
133 } OsSemaphore;
134 
135 
136 /**
137  * @brief Mutex object
138  **/
139 
140 typedef struct
141 {
142  uint8_t id;
143 } OsMutex;
144 
145 
146 /**
147  * @brief Task routine
148  **/
149 
150 typedef void (*OsTaskCode)(void *arg);
151 
152 
153 //Default task parameters
155 
156 //Kernel management
157 void osInitKernel(void);
158 void osStartKernel(void);
159 
160 //Task management
161 OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg,
162  const OsTaskParameters *params);
163 
164 void osDeleteTask(OsTaskId taskId);
165 void osDelayTask(systime_t delay);
166 void osSwitchTask(void);
167 void osSuspendAllTasks(void);
168 void osResumeAllTasks(void);
169 
170 //Event management
172 void osDeleteEvent(OsEvent *event);
173 void osSetEvent(OsEvent *event);
174 void osResetEvent(OsEvent *event);
175 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
177 
178 //Semaphore management
179 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
180 void osDeleteSemaphore(OsSemaphore *semaphore);
181 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
182 void osReleaseSemaphore(OsSemaphore *semaphore);
183 
184 //Mutex management
186 void osDeleteMutex(OsMutex *mutex);
187 void osAcquireMutex(OsMutex *mutex);
188 void osReleaseMutex(OsMutex *mutex);
189 
190 //System time
192 
193 //Memory management
194 void *osAllocMem(size_t size);
195 void osFreeMem(void *p);
196 
197 //C++ guard
198 #ifdef __cplusplus
199 }
200 #endif
201 
202 #endif
void osSuspendAllTasks(void)
Suspend scheduler activity.
int bool_t
Definition: compiler_port.h:53
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
uint8_t id
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
uint8_t p
Definition: ndp.h:300
Event object.
void osSwitchTask(void)
Yield control to the next task.
char_t name[]
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
Semaphore object.
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
void osInitKernel(void)
Kernel initialization.
void(* OsTaskCode)(void *arg)
Task routine.
void osStartKernel(void)
Start kernel.
mutex_t OsMutex
Mutex object.
const OsTaskParameters OS_TASK_DEFAULT_PARAMS
void osDeleteTask(OsTaskId taskId)
Delete a task.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg, const OsTaskParameters *params)
Create a task.
binary_semaphore_t OsEvent
Event object.
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
systime_t osGetSystemTime(void)
Retrieve system time.
Task parameters.
bool_t osCreateEvent(OsEvent *event)
Create an event object.
Mutex object.
uint32_t systime_t
System time.
char char_t
Definition: compiler_port.h:48
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
uint32_t systime_t
System time.
void * osAllocMem(size_t size)
Allocate a memory block.
void osFreeMem(void *p)
Release a previously allocated memory block.
thread_t * OsTaskId
Task identifier.
void osDeleteEvent(OsEvent *event)
Delete an event object.
void osDelayTask(systime_t delay)
Delay routine.
unsigned int uint_t
Definition: compiler_port.h:50
uint8_t OsTaskId
Task identifier.
uint16_t priority
Definition: dns_common.h:265
uint8_t id
void osResumeAllTasks(void)
Resume scheduler activity.
semaphore_t OsSemaphore
Semaphore object.