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