os_port_windows.h
Go to the documentation of this file.
1 /**
2  * @file os_port_windows.h
3  * @brief RTOS abstraction layer (Windows)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2023 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.2.4
27  **/
28 
29 #ifndef _OS_PORT_WINDOWS_H
30 #define _OS_PORT_WINDOWS_H
31 
32 //Use dynamic memory allocation for tasks
33 #define OS_STATIC_TASK_SUPPORT DISABLED
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 0
43 #endif
44 
45 //Task priority (high)
46 #ifndef OS_TASK_PRIORITY_HIGH
47  #define OS_TASK_PRIORITY_HIGH 0
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 //Retrieve 64-bit system time (not implemented)
61 #ifndef osGetSystemTime64
62  #define osGetSystemTime64() osGetSystemTime()
63 #endif
64 
65 //Task prologue
66 #define osEnterTask()
67 //Task epilogue
68 #define osExitTask()
69 //Interrupt service routine prologue
70 #define osEnterIsr()
71 //Interrupt service routine epilogue
72 #define osExitIsr(flag)
73 
74 //C++ guard
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78 
79 
80 /**
81  * @brief System time
82  **/
83 
84 typedef uint32_t systime_t;
85 
86 
87 /**
88  * @brief Task identifier
89  **/
90 
91 typedef void *OsTaskId;
92 
93 
94 /**
95  * @brief Event object
96  **/
97 
98 typedef struct
99 {
100  void *handle;
101 } OsEvent;
102 
103 
104 /**
105  * @brief Semaphore object
106  **/
107 
108 typedef struct
109 {
110  void *handle;
111 } OsSemaphore;
112 
113 
114 /**
115  * @brief Mutex object
116  **/
117 
118 typedef struct
119 {
120  void *handle;
121 } OsMutex;
122 
123 
124 /**
125  * @brief Task routine
126  **/
127 
128 typedef void (*OsTaskCode)(void *param);
129 
130 
131 //Kernel management
132 void osInitKernel(void);
133 void osStartKernel(void);
134 
135 //Task management
136 OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode,
137  void *param, size_t stackSize, int_t priority);
138 
139 void osDeleteTask(OsTaskId taskId);
140 void osDelayTask(systime_t delay);
141 void osSwitchTask(void);
142 void osSuspendAllTasks(void);
143 void osResumeAllTasks(void);
144 
145 //Event management
147 void osDeleteEvent(OsEvent *event);
148 void osSetEvent(OsEvent *event);
149 void osResetEvent(OsEvent *event);
150 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
152 
153 //Semaphore management
154 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
155 void osDeleteSemaphore(OsSemaphore *semaphore);
156 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
157 void osReleaseSemaphore(OsSemaphore *semaphore);
158 
159 //Mutex management
161 void osDeleteMutex(OsMutex *mutex);
162 void osAcquireMutex(OsMutex *mutex);
163 void osReleaseMutex(OsMutex *mutex);
164 
165 //System time
167 
168 //Memory management
169 void *osAllocMem(size_t size);
170 void osFreeMem(void *p);
171 
172 //Miscellaneous definitions
173 #define strlwr _strlwr
174 #define strcasecmp _stricmp
175 #define strncasecmp _strnicmp
176 #define strtok_r(str, delim, p) strtok(str, delim)
177 
178 //C++ guard
179 #ifdef __cplusplus
180 }
181 #endif
182 
183 #endif
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
int bool_t
Definition: compiler_port.h:53
uint32_t systime_t
System time.
signed int int_t
Definition: compiler_port.h:49
uint8_t p
Definition: ndp.h:298
Event object.
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.
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
Create a task.
char_t name[]
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
Semaphore object.
void osDelayTask(systime_t delay)
Delay routine.
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
void osInitKernel(void)
Kernel initialization.
void * handle
mutex_t OsMutex
Mutex object.
void * handle
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
binary_semaphore_t OsEvent
Event object.
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
void * OsTaskId
Task identifier.
bool_t osCreateEvent(OsEvent *event)
Create an event object.
void osSwitchTask(void)
Yield control to the next task.
void osFreeMem(void *p)
Release a previously allocated memory block.
void osSuspendAllTasks(void)
Suspend scheduler activity.
void osDeleteTask(OsTaskId taskId)
Delete a task.
Mutex object.
uint32_t systime_t
System time.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
char char_t
Definition: compiler_port.h:48
systime_t osGetSystemTime(void)
Retrieve system time.
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
void osResumeAllTasks(void)
Resume scheduler activity.
void * osAllocMem(size_t size)
Allocate a memory block.
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
void osDeleteEvent(OsEvent *event)
Delete an event object.
thread_t * OsTaskId
Task identifier.
unsigned int uint_t
Definition: compiler_port.h:50
void(* OsTaskCode)(void *param)
Task routine.
uint16_t priority
Definition: dns_common.h:249
void osStartKernel(void)
Start kernel.
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
semaphore_t OsSemaphore
Semaphore object.