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  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  * @author Oryx Embedded SARL (www.oryx-embedded.com)
24  * @version 1.9.0
25  **/
26 
27 #ifndef _OS_PORT_POSIX_H
28 #define _OS_PORT_POSIX_H
29 
30 //Dependencies
31 #include <pthread.h>
32 #include <semaphore.h>
33 
34 //Task priority (normal)
35 #ifndef OS_TASK_PRIORITY_NORMAL
36  #define OS_TASK_PRIORITY_NORMAL 0
37 #endif
38 
39 //Task priority (high)
40 #ifndef OS_TASK_PRIORITY_HIGH
41  #define OS_TASK_PRIORITY_HIGH 0
42 #endif
43 
44 //Milliseconds to system ticks
45 #ifndef OS_MS_TO_SYSTICKS
46  #define OS_MS_TO_SYSTICKS(n) (n)
47 #endif
48 
49 //System ticks to milliseconds
50 #ifndef OS_SYSTICKS_TO_MS
51  #define OS_SYSTICKS_TO_MS(n) (n)
52 #endif
53 
54 //Enter interrupt service routine
55 #define osEnterIsr()
56 
57 //Leave interrupt service routine
58 #define osExitIsr(flag)
59 
60 //C++ guard
61 #ifdef __cplusplus
62  extern "C" {
63 #endif
64 
65 
66 /**
67  * @brief Task object
68  **/
69 
70 typedef void OsTask;
71 
72 
73 /**
74  * @brief Event object
75  **/
76 
77 typedef sem_t OsEvent;
78 
79 
80 /**
81  * @brief Semaphore object
82  **/
83 
84 typedef sem_t OsSemaphore;
85 
86 
87 /**
88  * @brief Mutex object
89  **/
90 
91 typedef pthread_mutex_t OsMutex;
92 
93 
94 /**
95  * @brief Task routine
96  **/
97 
98 typedef void (*OsTaskCode)(void *param);
99 
100 
101 //Kernel management
102 void osInitKernel(void);
103 void osStartKernel(void);
104 
105 //Task management
106 OsTask *osCreateTask(const char_t *name, OsTaskCode taskCode,
107  void *param, size_t stackSize, int_t priority);
108 
109 void osDeleteTask(OsTask *task);
110 void osDelayTask(systime_t delay);
111 void osSwitchTask(void);
112 void osSuspendAllTasks(void);
113 void osResumeAllTasks(void);
114 
115 //Event management
117 void osDeleteEvent(OsEvent *event);
118 void osSetEvent(OsEvent *event);
119 void osResetEvent(OsEvent *event);
120 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
122 
123 //Semaphore management
124 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
125 void osDeleteSemaphore(OsSemaphore *semaphore);
126 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
127 void osReleaseSemaphore(OsSemaphore *semaphore);
128 
129 //Mutex management
131 void osDeleteMutex(OsMutex *mutex);
132 void osAcquireMutex(OsMutex *mutex);
133 void osReleaseMutex(OsMutex *mutex);
134 
135 //System time
137 
138 //Memory management
139 void *osAllocMem(size_t size);
140 void osFreeMem(void *p);
141 
142 //C++ guard
143 #ifdef __cplusplus
144  }
145 #endif
146 
147 #endif
uint16_t priority
Definition: dns_common.h:219
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
uint32_t systime_t
Definition: compiler_port.h:44
void(* OsTaskCode)(void *param)
Task routine.
Definition: os_port_posix.h:98
char char_t
Definition: compiler_port.h:41
void osResumeAllTasks(void)
Resume scheduler activity.
uint8_t p
Definition: ndp.h:295
void osDeleteEvent(OsEvent *event)
Delete an event object.
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
void osDeleteTask(OsTask *task)
Delete a task.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
void OsTask
Task object.
Definition: os_port_posix.h:70
void * osAllocMem(size_t size)
Allocate a memory block.
sem_t OsSemaphore
Semaphore object.
Definition: os_port_posix.h:84
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
Event object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
void osSwitchTask(void)
Yield control to the next task.
void osSuspendAllTasks(void)
Suspend scheduler activity.
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
OsTask * osCreateTask(const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
Create a new task.
void osInitKernel(void)
Kernel initialization.
systime_t osGetSystemTime(void)
Retrieve system time.
Task object.
signed int int_t
Definition: compiler_port.h:42
char_t name[]
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
void osDelayTask(systime_t delay)
Delay routine.
void osFreeMem(void *p)
Release a previously allocated memory block.
void osStartKernel(void)
Start kernel.
pthread_mutex_t OsMutex
Mutex object.
Definition: os_port_posix.h:91
unsigned int uint_t
Definition: compiler_port.h:43
Mutex object.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
sem_t OsEvent
Event object.
Definition: os_port_posix.h:77
Semaphore object.
int bool_t
Definition: compiler_port.h:47
bool_t osCreateEvent(OsEvent *event)
Create an event object.
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.