os_port_chibios.h
Go to the documentation of this file.
1 /**
2  * @file os_port_chibios.h
3  * @brief RTOS abstraction layer (ChibiOS/RT)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 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 1.9.6
27  **/
28 
29 #ifndef _OS_PORT_CHIBIOS_H
30 #define _OS_PORT_CHIBIOS_H
31 
32 //Dependencies
33 #include "ch.h"
34 
35 //Maximum number of tasks that can be dynamically created
36 #ifndef OS_PORT_MAX_TASKS
37  #define OS_PORT_MAX_TASKS 16
38 #elif (OS_PORT_MAX_TASKS < 1)
39  #error OS_PORT_MAX_TASKS parameter is not valid
40 #endif
41 
42 //Task priority (normal)
43 #ifndef OS_TASK_PRIORITY_NORMAL
44  #define OS_TASK_PRIORITY_NORMAL NORMALPRIO
45 #endif
46 
47 //Task priority (high)
48 #ifndef OS_TASK_PRIORITY_HIGH
49  #define OS_TASK_PRIORITY_HIGH HIGHPRIO
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 //Task prologue
63 #define osEnterTask()
64 //Interrupt service routine prologue
65 #define osEnterIsr() CH_IRQ_PROLOGUE(); chSysLockFromISR()
66 //Interrupt service routine epilogue
67 #define osExitIsr(flag) chSysUnlockFromISR(); CH_IRQ_EPILOGUE()
68 
69 //Check kernel version
70 #if (CH_KERNEL_MAJOR < 3)
71  #define thread_t Thread
72  #define semaphore_t Semaphore
73  #define binary_semaphore_t BinarySemaphore
74  #define mutex_t Mutex
75  #define chThdTerminatedX chThdTerminated
76  #define chSemObjectInit chSemInit
77  #define chBSemObjectInit chBSemInit
78  #define chMtxObjectInit chMtxInit
79  #define chVTGetSystemTime chTimeNow
80  #define chSysLockFromISR chSysLockFromIsr
81  #define chSysUnlockFromISR chSysUnlockFromIsr
82  #define THD_WORKING_AREA_SIZE THD_WA_SIZE
83  #define MSG_OK RDY_OK
84 #endif
85 
86 //C++ guard
87 #ifdef __cplusplus
88 extern "C" {
89 #endif
90 
91 
92 /**
93  * @brief Task object
94  **/
95 
96 typedef struct
97 {
99 } OsTask;
100 
101 
102 /**
103  * @brief Event object
104  **/
105 
107 
108 
109 /**
110  * @brief Semaphore object
111  **/
112 
114 
115 
116 /**
117  * @brief Mutex object
118  **/
119 
120 typedef mutex_t OsMutex;
121 
122 
123 /**
124  * @brief Task routine
125  **/
126 
127 typedef void (*OsTaskCode)(void *param);
128 
129 
130 //Kernel management
131 void osInitKernel(void);
132 void osStartKernel(void);
133 
134 //Task management
135 bool_t osCreateStaticTask(OsTask *task, const char_t *name, OsTaskCode taskCode,
136  void *param, void *stack, size_t stackSize, int_t priority);
137 
138 OsTask *osCreateTask(const char_t *name, OsTaskCode taskCode,
139  void *param, size_t stackSize, int_t priority);
140 
141 void osDeleteTask(OsTask *task);
142 void osDelayTask(systime_t delay);
143 void osSwitchTask(void);
144 void osSuspendAllTasks(void);
145 void osResumeAllTasks(void);
146 
147 //Event management
149 void osDeleteEvent(OsEvent *event);
150 void osSetEvent(OsEvent *event);
151 void osResetEvent(OsEvent *event);
152 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
154 
155 //Semaphore management
156 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
157 void osDeleteSemaphore(OsSemaphore *semaphore);
158 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
159 void osReleaseSemaphore(OsSemaphore *semaphore);
160 
161 //Mutex management
163 void osDeleteMutex(OsMutex *mutex);
164 void osAcquireMutex(OsMutex *mutex);
165 void osReleaseMutex(OsMutex *mutex);
166 
167 //System time
169 
170 //Memory management
171 void *osAllocMem(size_t size);
172 void osFreeMem(void *p);
173 
174 //C++ guard
175 #ifdef __cplusplus
176 }
177 #endif
178 
179 #endif
systime_t osGetSystemTime(void)
Retrieve system time.
int bool_t
Definition: compiler_port.h:49
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
signed int int_t
Definition: compiler_port.h:44
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
uint8_t p
Definition: ndp.h:298
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
Event object.
void osFreeMem(void *p)
Release a previously allocated memory block.
void osSwitchTask(void)
Yield control to the next task.
char_t name[]
void osStartKernel(void)
Start kernel.
Semaphore object.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
#define OsTask
Task object.
#define binary_semaphore_t
mutex_t OsMutex
Mutex object.
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
binary_semaphore_t OsEvent
Event object.
Task object.
void osResumeAllTasks(void)
Resume scheduler activity.
void osDeleteEvent(OsEvent *event)
Delete an event object.
void osDeleteTask(OsTask *task)
Delete a task.
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
#define mutex_t
#define thread_t
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
bool_t osCreateStaticTask(OsTask *task, const char_t *name, OsTaskCode taskCode, void *param, void *stack, size_t stackSize, int_t priority)
Create a static task.
Mutex object.
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
void osSuspendAllTasks(void)
Suspend scheduler activity.
char char_t
Definition: compiler_port.h:43
void * osAllocMem(size_t size)
Allocate a memory block.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
void osDelayTask(systime_t delay)
Delay routine.
void(* OsTaskCode)(void *param)
Task routine.
bool_t osCreateEvent(OsEvent *event)
Create an event object.
void osInitKernel(void)
Kernel initialization.
OsTask * osCreateTask(const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
Create a new task.
thread_t * tp
unsigned int uint_t
Definition: compiler_port.h:45
uint16_t priority
Definition: dns_common.h:221
#define semaphore_t
uint32_t systime_t
Definition: compiler_port.h:46
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
semaphore_t OsSemaphore
Semaphore object.