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-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_POSIX_H
30 #define _OS_PORT_POSIX_H
31 
32 //Dependencies
33 #include <pthread.h>
34 #include <semaphore.h>
35 
36 //Task priority (normal)
37 #ifndef OS_TASK_PRIORITY_NORMAL
38  #define OS_TASK_PRIORITY_NORMAL 0
39 #endif
40 
41 //Task priority (high)
42 #ifndef OS_TASK_PRIORITY_HIGH
43  #define OS_TASK_PRIORITY_HIGH 0
44 #endif
45 
46 //Milliseconds to system ticks
47 #ifndef OS_MS_TO_SYSTICKS
48  #define OS_MS_TO_SYSTICKS(n) (n)
49 #endif
50 
51 //System ticks to milliseconds
52 #ifndef OS_SYSTICKS_TO_MS
53  #define OS_SYSTICKS_TO_MS(n) (n)
54 #endif
55 
56 //Task prologue
57 #define osEnterTask()
58 //Interrupt service routine prologue
59 #define osEnterIsr()
60 //Interrupt service routine epilogue
61 #define osExitIsr(flag)
62 
63 //C++ guard
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 
69 /**
70  * @brief Task object
71  **/
72 
73 typedef void OsTask;
74 
75 
76 /**
77  * @brief Event object
78  **/
79 
80 typedef sem_t OsEvent;
81 
82 
83 /**
84  * @brief Semaphore object
85  **/
86 
87 typedef sem_t OsSemaphore;
88 
89 
90 /**
91  * @brief Mutex object
92  **/
93 
94 typedef pthread_mutex_t OsMutex;
95 
96 
97 /**
98  * @brief Task routine
99  **/
100 
101 typedef void (*OsTaskCode)(void *param);
102 
103 
104 //Kernel management
105 void osInitKernel(void);
106 void osStartKernel(void);
107 
108 //Task management
109 OsTask *osCreateTask(const char_t *name, OsTaskCode taskCode,
110  void *param, size_t stackSize, int_t priority);
111 
112 void osDeleteTask(OsTask *task);
113 void osDelayTask(systime_t delay);
114 void osSwitchTask(void);
115 void osSuspendAllTasks(void);
116 void osResumeAllTasks(void);
117 
118 //Event management
120 void osDeleteEvent(OsEvent *event);
121 void osSetEvent(OsEvent *event);
122 void osResetEvent(OsEvent *event);
123 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
125 
126 //Semaphore management
127 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
128 void osDeleteSemaphore(OsSemaphore *semaphore);
129 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
130 void osReleaseSemaphore(OsSemaphore *semaphore);
131 
132 //Mutex management
134 void osDeleteMutex(OsMutex *mutex);
135 void osAcquireMutex(OsMutex *mutex);
136 void osReleaseMutex(OsMutex *mutex);
137 
138 //System time
140 
141 //Memory management
142 void *osAllocMem(size_t size);
143 void osFreeMem(void *p);
144 
145 //C++ guard
146 #ifdef __cplusplus
147 }
148 #endif
149 
150 #endif
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
int bool_t
Definition: compiler_port.h:49
bool_t osCreateEvent(OsEvent *event)
Create an event 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 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.
Definition: os_port_posix.h:94
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.
Task object.
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.
void OsTask
Task object.
Definition: os_port_posix.h:73
void(* OsTaskCode)(void *param)
Task routine.
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
sem_t OsEvent
Event object.
Definition: os_port_posix.h:80
Mutex object.
OsTask * osCreateTask(const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
Create a new task.
char char_t
Definition: compiler_port.h:43
void osResumeAllTasks(void)
Resume scheduler activity.
void osSuspendAllTasks(void)
Suspend scheduler activity.
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 osDeleteTask(OsTask *task)
Delete a task.
void osDeleteEvent(OsEvent *event)
Delete an event object.
void osFreeMem(void *p)
Release a previously allocated memory block.
void osSwitchTask(void)
Yield control to the next task.
unsigned int uint_t
Definition: compiler_port.h:45
uint16_t priority
Definition: dns_common.h:221
sem_t OsSemaphore
Semaphore object.
Definition: os_port_posix.h:87
uint32_t systime_t
Definition: compiler_port.h:46
void osStartKernel(void)
Start kernel.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.