forked from rtlabs-com/osal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosal.c
More file actions
224 lines (185 loc) · 3.72 KB
/
osal.c
File metadata and controls
224 lines (185 loc) · 3.72 KB
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*********************************************************************
* _ _ _
* _ __ | |_ _ | | __ _ | |__ ___
* | '__|| __|(_)| | / _` || '_ \ / __|
* | | | |_ _ | || (_| || |_) |\__ \
* |_| \__|(_)|_| \__,_||_.__/ |___/
*
* www.rt-labs.com
* Copyright 2017 rt-labs AB, Sweden.
*
* This software is licensed under the terms of the BSD 3-clause
* license. See the file LICENSE distributed with this software for
* full license information.
********************************************************************/
#include "osal.h"
void * os_malloc (size_t size)
{
return malloc (size);
}
void os_free (void * ptr)
{
free (ptr);
}
os_thread_t * os_thread_create (
const char * name,
uint32_t priority,
size_t stacksize,
void (*entry) (void * arg),
void * arg)
{
return task_spawn (name, entry, priority, stacksize, arg);
}
os_mutex_t * os_mutex_create (void)
{
return mtx_create();
}
void os_mutex_lock (os_mutex_t * mutex)
{
mtx_lock (mutex);
}
void os_mutex_unlock (os_mutex_t * mutex)
{
mtx_unlock (mutex);
}
void os_mutex_destroy (os_mutex_t * mutex)
{
mtx_destroy (mutex);
}
void os_usleep (uint32_t us)
{
task_delay (tick_from_ms (us / 1000));
}
uint32_t os_get_current_time_us (void)
{
return 1000 * tick_to_ms (tick_get());
}
os_tick_t os_tick_current (void)
{
return tick_get();
}
os_tick_t os_tick_from_us (uint32_t us)
{
return tick_from_ms (us / 1000);
}
void os_tick_sleep (os_tick_t tick)
{
task_delay (tick);
}
os_sem_t * os_sem_create (size_t count)
{
return sem_create (count);
}
bool os_sem_wait (os_sem_t * sem, uint32_t time)
{
int tmo = 0;
if (time != OS_WAIT_FOREVER)
{
tmo = sem_wait_tmo (sem, tick_from_ms (time));
}
else
{
sem_wait (sem);
}
return tmo;
}
void os_sem_signal (os_sem_t * sem)
{
sem_signal (sem);
}
void os_sem_destroy (os_sem_t * sem)
{
sem_destroy (sem);
}
os_event_t * os_event_create (void)
{
return flags_create (0);
}
bool os_event_wait (os_event_t * event, uint32_t mask, uint32_t * value, uint32_t time)
{
int tmo = 0;
if (time != OS_WAIT_FOREVER)
{
tmo = flags_wait_any_tmo (event, mask, tick_from_ms (time), value);
}
else
{
flags_wait_any (event, mask, value);
}
*value = *value & mask;
return tmo;
}
void os_event_set (os_event_t * event, uint32_t value)
{
flags_set (event, value);
}
void os_event_clr (os_event_t * event, uint32_t value)
{
flags_clr (event, value);
}
void os_event_destroy (os_event_t * event)
{
flags_destroy (event);
}
os_mbox_t * os_mbox_create (size_t size)
{
return mbox_create (size);
}
bool os_mbox_fetch (os_mbox_t * mbox, void ** msg, uint32_t time)
{
int tmo = 0;
if (time != OS_WAIT_FOREVER)
{
tmo = mbox_fetch_tmo (mbox, msg, tick_from_ms (time));
}
else
{
mbox_fetch (mbox, msg);
}
return tmo;
}
bool os_mbox_post (os_mbox_t * mbox, void * msg, uint32_t time)
{
int tmo = 0;
if (time != OS_WAIT_FOREVER)
{
tmo = mbox_post_tmo (mbox, msg, tick_from_ms (time));
}
else
{
mbox_post (mbox, msg);
}
return tmo;
}
void os_mbox_destroy (os_mbox_t * mbox)
{
mbox_destroy (mbox);
}
os_timer_t * os_timer_create (
uint32_t us,
void (*fn) (os_timer_t *, void * arg),
void * arg,
bool oneshot)
{
return tmr_create (
tick_from_ms (us / 1000),
fn,
arg,
(oneshot) ? TMR_ONCE : TMR_CYCL);
}
void os_timer_set (os_timer_t * timer, uint32_t us)
{
tmr_set (timer, tick_from_ms (us / 1000));
}
void os_timer_start (os_timer_t * timer)
{
tmr_start (timer);
}
void os_timer_stop (os_timer_t * timer)
{
tmr_stop (timer);
}
void os_timer_destroy (os_timer_t * timer)
{
tmr_destroy (timer);
}