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-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_WINDOWS_H
30 #define _OS_PORT_WINDOWS_H
31 
32 //Invalid task identifier
33 #define OS_INVALID_TASK_ID NULL
34 //Self task identifier
35 #define OS_SELF_TASK_ID NULL
36 
37 //Task priority (normal)
38 #ifndef OS_TASK_PRIORITY_NORMAL
39  #define OS_TASK_PRIORITY_NORMAL 0
40 #endif
41 
42 //Task priority (high)
43 #ifndef OS_TASK_PRIORITY_HIGH
44  #define OS_TASK_PRIORITY_HIGH 0
45 #endif
46 
47 //Milliseconds to system ticks
48 #ifndef OS_MS_TO_SYSTICKS
49  #define OS_MS_TO_SYSTICKS(n) (n)
50 #endif
51 
52 //System ticks to milliseconds
53 #ifndef OS_SYSTICKS_TO_MS
54  #define OS_SYSTICKS_TO_MS(n) (n)
55 #endif
56 
57 //Retrieve 64-bit system time (not implemented)
58 #ifndef osGetSystemTime64
59  #define osGetSystemTime64() osGetSystemTime()
60 #endif
61 
62 //Task prologue
63 #define osEnterTask()
64 //Task epilogue
65 #define osExitTask()
66 //Interrupt service routine prologue
67 #define osEnterIsr()
68 //Interrupt service routine epilogue
69 #define osExitIsr(flag)
70 
71 //C++ guard
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75 
76 
77 /**
78  * @brief System time
79  **/
80 
81 typedef uint32_t systime_t;
82 
83 
84 /**
85  * @brief Task identifier
86  **/
87 
88 typedef void *OsTaskId;
89 
90 
91 /**
92  * @brief Task parameters
93  **/
94 
95 typedef struct
96 {
97  size_t stackSize;
100 
101 
102 /**
103  * @brief Event object
104  **/
105 
106 typedef struct
107 {
108  void *handle;
109 } OsEvent;
110 
111 
112 /**
113  * @brief Semaphore object
114  **/
115 
116 typedef struct
117 {
118  void *handle;
119 } OsSemaphore;
120 
121 
122 /**
123  * @brief Mutex object
124  **/
125 
126 typedef struct
127 {
128  void *handle;
129 } OsMutex;
130 
131 
132 /**
133  * @brief Task routine
134  **/
135 
136 typedef void (*OsTaskCode)(void *arg);
137 
138 
139 //Default task parameters
141 
142 //Kernel management
143 void osInitKernel(void);
144 void osStartKernel(void);
145 
146 //Task management
147 OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg,
148  const OsTaskParameters *params);
149 
150 void osDeleteTask(OsTaskId taskId);
151 void osDelayTask(systime_t delay);
152 void osSwitchTask(void);
153 void osSuspendAllTasks(void);
154 void osResumeAllTasks(void);
155 
156 //Event management
158 void osDeleteEvent(OsEvent *event);
159 void osSetEvent(OsEvent *event);
160 void osResetEvent(OsEvent *event);
161 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
163 
164 //Semaphore management
165 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
166 void osDeleteSemaphore(OsSemaphore *semaphore);
167 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
168 void osReleaseSemaphore(OsSemaphore *semaphore);
169 
170 //Mutex management
172 void osDeleteMutex(OsMutex *mutex);
173 void osAcquireMutex(OsMutex *mutex);
174 void osReleaseMutex(OsMutex *mutex);
175 
176 //System time
178 
179 //Memory management
180 void *osAllocMem(size_t size);
181 void osFreeMem(void *p);
182 
183 //Miscellaneous definitions
184 #define strlwr _strlwr
185 #define strcasecmp _stricmp
186 #define strncasecmp _strnicmp
187 #define strtok_r(str, delim, p) strtok(str, delim)
188 
189 //C++ guard
190 #ifdef __cplusplus
191 }
192 #endif
193 
194 #endif
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
int bool_t
Definition: compiler_port.h:53
uint32_t systime_t
System time.
void(* OsTaskCode)(void *arg)
Task routine.
uint8_t p
Definition: ndp.h:300
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.
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
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg, const OsTaskParameters *params)
Create a task.
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.
Task parameters.
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.
const OsTaskParameters OS_TASK_DEFAULT_PARAMS
thread_t * OsTaskId
Task identifier.
unsigned int uint_t
Definition: compiler_port.h:50
uint16_t priority
Definition: dns_common.h:265
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.