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