-
Notifications
You must be signed in to change notification settings - Fork 15
/
os_port_windows.h
194 lines (151 loc) · 3.89 KB
/
os_port_windows.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
* @file os_port_windows.h
* @brief RTOS abstraction layer (Windows)
*
* @section License
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @author Oryx Embedded SARL (www.oryx-embedded.com)
* @version 2.4.4
**/
#ifndef _OS_PORT_WINDOWS_H
#define _OS_PORT_WINDOWS_H
//Invalid task identifier
#define OS_INVALID_TASK_ID NULL
//Self task identifier
#define OS_SELF_TASK_ID NULL
//Task priority (normal)
#ifndef OS_TASK_PRIORITY_NORMAL
#define OS_TASK_PRIORITY_NORMAL 0
#endif
//Task priority (high)
#ifndef OS_TASK_PRIORITY_HIGH
#define OS_TASK_PRIORITY_HIGH 0
#endif
//Milliseconds to system ticks
#ifndef OS_MS_TO_SYSTICKS
#define OS_MS_TO_SYSTICKS(n) (n)
#endif
//System ticks to milliseconds
#ifndef OS_SYSTICKS_TO_MS
#define OS_SYSTICKS_TO_MS(n) (n)
#endif
//Retrieve 64-bit system time (not implemented)
#ifndef osGetSystemTime64
#define osGetSystemTime64() osGetSystemTime()
#endif
//Task prologue
#define osEnterTask()
//Task epilogue
#define osExitTask()
//Interrupt service routine prologue
#define osEnterIsr()
//Interrupt service routine epilogue
#define osExitIsr(flag)
//C++ guard
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief System time
**/
typedef uint32_t systime_t;
/**
* @brief Task identifier
**/
typedef void *OsTaskId;
/**
* @brief Task parameters
**/
typedef struct
{
size_t stackSize;
uint_t priority;
} OsTaskParameters;
/**
* @brief Event object
**/
typedef struct
{
void *handle;
} OsEvent;
/**
* @brief Semaphore object
**/
typedef struct
{
void *handle;
} OsSemaphore;
/**
* @brief Mutex object
**/
typedef struct
{
void *handle;
} OsMutex;
/**
* @brief Task routine
**/
typedef void (*OsTaskCode)(void *arg);
//Default task parameters
extern const OsTaskParameters OS_TASK_DEFAULT_PARAMS;
//Kernel management
void osInitKernel(void);
void osStartKernel(void);
//Task management
OsTaskId osCreateTask(const char_t *name, OsTaskCode taskCode, void *arg,
const OsTaskParameters *params);
void osDeleteTask(OsTaskId taskId);
void osDelayTask(systime_t delay);
void osSwitchTask(void);
void osSuspendAllTasks(void);
void osResumeAllTasks(void);
//Event management
bool_t osCreateEvent(OsEvent *event);
void osDeleteEvent(OsEvent *event);
void osSetEvent(OsEvent *event);
void osResetEvent(OsEvent *event);
bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
bool_t osSetEventFromIsr(OsEvent *event);
//Semaphore management
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
void osDeleteSemaphore(OsSemaphore *semaphore);
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
void osReleaseSemaphore(OsSemaphore *semaphore);
//Mutex management
bool_t osCreateMutex(OsMutex *mutex);
void osDeleteMutex(OsMutex *mutex);
void osAcquireMutex(OsMutex *mutex);
void osReleaseMutex(OsMutex *mutex);
//System time
systime_t osGetSystemTime(void);
//Memory management
void *osAllocMem(size_t size);
void osFreeMem(void *p);
//Miscellaneous definitions
#define strlwr _strlwr
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define strtok_r(str, delim, p) strtok(str, delim)
//C++ guard
#ifdef __cplusplus
}
#endif
#endif