os_port_zephyr.h
Go to the documentation of this file.
1 /**
2  * @file os_port_zephyr.h
3  * @brief RTOS abstraction layer (Zephyr)
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_ZEPHYR_H
30 #define _OS_PORT_ZEPHYR_H
31 
32 //Dependencies
33 #include <zephyr/kernel.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 (CONFIG_NUM_PREEMPT_PRIORITIES - 1)
43 #endif
44 
45 //Task priority (high)
46 #ifndef OS_TASK_PRIORITY_HIGH
47  #define OS_TASK_PRIORITY_HIGH (CONFIG_NUM_PREEMPT_PRIORITIES - 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 //Task prologue
61 #define osEnterTask()
62 //Task epilogue
63 #define osExitTask()
64 
65 //Interrupt service routine prologue
66 #ifndef osEnterIsr
67  #define osEnterIsr()
68 #endif
69 
70 //Interrupt service routine epilogue
71 #ifndef osExitIsr
72  #define osExitIsr(flag) (void) flag
73 #endif
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 k_tid_t OsTaskId;
93 
94 
95 /**
96  * @brief Task parameters
97  **/
98 
99 typedef struct
100 {
101  struct k_thread *tcb;
102  k_thread_stack_t *stack;
103  size_t stackSize;
106 
107 
108 /**
109  * @brief Event object
110  **/
111 
112 typedef struct k_sem OsEvent;
113 
114 
115 /**
116  * @brief Semaphore object
117  **/
118 
119 typedef struct k_sem OsSemaphore;
120 
121 
122 /**
123  * @brief Mutex object
124  **/
125 
126 typedef struct k_mutex 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 uint64_t osGetSystemTime64(void);
176 
177 //Memory management
178 void *osAllocMem(size_t size);
179 void osFreeMem(void *p);
180 
181 //C++ guard
182 #ifdef __cplusplus
183 }
184 #endif
185 
186 #endif
int bool_t
Definition: compiler_port.h:53
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
void osStartKernel(void)
Start kernel.
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg, const OsTaskParameters *params)
Create a task.
uint8_t p
Definition: ndp.h:300
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
Event object.
void osDeleteTask(OsTaskId taskId)
Delete a task.
struct k_thread * tcb
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
void osSwitchTask(void)
Yield control to the next task.
char_t name[]
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
void(* OsTaskCode)(void *arg)
Task routine.
void osDelayTask(systime_t delay)
Delay routine.
Semaphore object.
k_tid_t OsTaskId
Task identifier.
void osSuspendAllTasks(void)
Suspend scheduler activity.
uint32_t systime_t
System time.
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
Task parameters.
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
void osResumeAllTasks(void)
Resume scheduler activity.
bool_t osCreateEvent(OsEvent *event)
Create an event object.
void osFreeMem(void *p)
Release a previously allocated memory block.
Mutex object.
void osDeleteEvent(OsEvent *event)
Delete an event object.
uint32_t systime_t
System time.
char char_t
Definition: compiler_port.h:48
systime_t osGetSystemTime(void)
Retrieve system time.
k_thread_stack_t * stack
void osInitKernel(void)
Kernel initialization.
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
void * osAllocMem(size_t size)
Allocate a memory block.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
thread_t * OsTaskId
Task identifier.
unsigned int uint_t
Definition: compiler_port.h:50
uint64_t osGetSystemTime64(void)
Retrieve 64-bit system time.
uint16_t priority
Definition: dns_common.h:265
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
const OsTaskParameters OS_TASK_DEFAULT_PARAMS
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.