os_port_none.c
Go to the documentation of this file.
1 /**
2  * @file os_port_none.c
3  * @brief RTOS-less environment
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 //Switch to the appropriate trace level
28 #define TRACE_LEVEL TRACE_LEVEL_OFF
29 
30 //Dependencies
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include "os_port.h"
34 #include "os_port_none.h"
35 #include "debug.h"
36 
37 //Platform-specific dependencies
38 #if defined(__linux__) || defined(__FreeBSD__)
39  #include <sys/time.h>
40 #elif defined(_WIN32)
41  #include <windows.h>
42 #endif
43 
44 //Tick count
46 
47 
48 /**
49  * @brief Kernel initialization
50  **/
51 
52 void osInitKernel(void)
53 {
54  //Initialize tick count
55  systemTicks = 0;
56 }
57 
58 
59 /**
60  * @brief Start kernel
61  **/
62 
63 void osStartKernel(void)
64 {
65 }
66 
67 
68 /**
69  * @brief Create a new task
70  * @param[in] name A name identifying the task
71  * @param[in] taskCode Pointer to the task entry function
72  * @param[in] param A pointer to a variable to be passed to the task
73  * @param[in] stackSize The initial size of the stack, in words
74  * @param[in] priority The priority at which the task should run
75  * @return If the function succeeds, the return value is a pointer to the
76  * new task. If the function fails, the return value is NULL
77  **/
78 
80  void *param, size_t stackSize, int_t priority)
81 {
82  //Return a non-NULL pointer
83  return (OsTask *) (-1);
84 }
85 
86 
87 /**
88  * @brief Delete a task
89  * @param[in] task Pointer to the task to be deleted
90  **/
91 
92 void osDeleteTask(OsTask *task)
93 {
94 }
95 
96 
97 /**
98  * @brief Delay routine
99  * @param[in] delay Amount of time for which the calling task should block
100  **/
101 
103 {
104 }
105 
106 
107 /**
108  * @brief Yield control to the next task
109  **/
110 
111 void osSwitchTask(void)
112 {
113 }
114 
115 
116 /**
117  * @brief Suspend scheduler activity
118  **/
119 
121 {
122 }
123 
124 
125 /**
126  * @brief Resume scheduler activity
127  **/
128 
130 {
131 }
132 
133 
134 /**
135  * @brief Create an event object
136  * @param[in] event Pointer to the event object
137  * @return The function returns TRUE if the event object was successfully
138  * created. Otherwise, FALSE is returned
139  **/
140 
142 {
143  //Force the event to the nonsignaled state
144  *event = FALSE;
145  //Event successfully created
146  return TRUE;
147 }
148 
149 
150 /**
151  * @brief Delete an event object
152  * @param[in] event Pointer to the event object
153  **/
154 
155 void osDeleteEvent(OsEvent *event)
156 {
157 }
158 
159 
160 /**
161  * @brief Set the specified event object to the signaled state
162  * @param[in] event Pointer to the event object
163  **/
164 
165 void osSetEvent(OsEvent *event)
166 {
167  //Set the specified event to the signaled state
168  *event = TRUE;
169 }
170 
171 
172 /**
173  * @brief Set the specified event object to the nonsignaled state
174  * @param[in] event Pointer to the event object
175  **/
176 
177 void osResetEvent(OsEvent *event)
178 {
179  //Force the specified event to the nonsignaled state
180  *event = FALSE;
181 }
182 
183 
184 /**
185  * @brief Wait until the specified event is in the signaled state
186  * @param[in] event Pointer to the event object
187  * @param[in] timeout Timeout interval
188  * @return The function returns TRUE if the state of the specified object is
189  * signaled. FALSE is returned if the timeout interval elapsed
190  **/
191 
193 {
194  //Check whether the specified event is set
195  if(*event)
196  {
197  //Clear event
198  *event = FALSE;
199  //The event is in the signaled state
200  return TRUE;
201  }
202  else
203  {
204  //The event is not in the signaled state
205  return FALSE;
206  }
207 }
208 
209 
210 /**
211  * @brief Set an event object to the signaled state from an interrupt service routine
212  * @param[in] event Pointer to the event object
213  * @return TRUE if setting the event to signaled state caused a task to unblock
214  * and the unblocked task has a priority higher than the currently running task
215  **/
216 
218 {
219  //Set the specified event to the signaled state
220  *event = TRUE;
221  //A higher priority task has been woken?
222  return FALSE;
223 }
224 
225 
226 /**
227  * @brief Create a semaphore object
228  * @param[in] semaphore Pointer to the semaphore object
229  * @param[in] count The maximum count for the semaphore object. This value
230  * must be greater than zero
231  * @return The function returns TRUE if the semaphore was successfully
232  * created. Otherwise, FALSE is returned
233  **/
234 
236 {
237  //Create a semaphore
238  *semaphore = count;
239  //The semaphore was successfully created
240  return TRUE;
241 }
242 
243 
244 /**
245  * @brief Delete a semaphore object
246  * @param[in] semaphore Pointer to the semaphore object
247  **/
248 
250 {
251 }
252 
253 
254 /**
255  * @brief Wait for the specified semaphore to be available
256  * @param[in] semaphore Pointer to the semaphore object
257  * @param[in] timeout Timeout interval
258  * @return The function returns TRUE if the semaphore is available. FALSE is
259  * returned if the timeout interval elapsed
260  **/
261 
263 {
264  //Check whether the specified semaphore is available
265  if(*semaphore > 0)
266  {
267  //Decrement semaphore value
268  *semaphore -= 1;
269  //The semaphore is available
270  return TRUE;
271  }
272  else
273  {
274  //The semaphore is not available
275  return FALSE;
276  }
277 }
278 
279 
280 /**
281  * @brief Release the specified semaphore object
282  * @param[in] semaphore Pointer to the semaphore object
283  **/
284 
286 {
287  //Release the semaphore
288  *semaphore += 1;
289 }
290 
291 
292 /**
293  * @brief Create a mutex object
294  * @param[in] mutex Pointer to the mutex object
295  * @return The function returns TRUE if the mutex was successfully
296  * created. Otherwise, FALSE is returned
297  **/
298 
300 {
301  //The mutex was successfully created
302  return TRUE;
303 }
304 
305 
306 /**
307  * @brief Delete a mutex object
308  * @param[in] mutex Pointer to the mutex object
309  **/
310 
311 void osDeleteMutex(OsMutex *mutex)
312 {
313 }
314 
315 
316 /**
317  * @brief Acquire ownership of the specified mutex object
318  * @param[in] mutex Pointer to the mutex object
319  **/
320 
322 {
323 }
324 
325 
326 /**
327  * @brief Release ownership of the specified mutex object
328  * @param[in] mutex Pointer to the mutex object
329  **/
330 
332 {
333 }
334 
335 
336 /**
337  * @brief Retrieve system time
338  * @return Number of milliseconds elapsed since the system was last started
339  **/
340 
342 {
343  systime_t time;
344 
345 #if defined(__linux__) || defined(__FreeBSD__)
346  struct timeval tv;
347  //Get current time
348  gettimeofday(&tv, NULL);
349  //Convert resulting value to milliseconds
350  time = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
351 #elif defined(_WIN32)
352  //Get current tick count
353  time = GetTickCount();
354 #else
355  //Get current tick count
356  time = systemTicks;
357 #endif
358 
359  //Convert system ticks to milliseconds
360  return OS_SYSTICKS_TO_MS(time);
361 }
362 
363 
364 /**
365  * @brief Allocate a memory block
366  * @param[in] size Bytes to allocate
367  * @return A pointer to the allocated memory block or NULL if
368  * there is insufficient memory available
369  **/
370 
371 void *osAllocMem(size_t size)
372 {
373  void *p;
374 
375  //Allocate a memory block
376  p = malloc(size);
377 
378  //Debug message
379  TRACE_DEBUG("Allocating %" PRIuSIZE " bytes at 0x%08" PRIXPTR "\r\n", size, (uintptr_t) p);
380 
381  //Return a pointer to the newly allocated memory block
382  return p;
383 }
384 
385 
386 /**
387  * @brief Release a previously allocated memory block
388  * @param[in] p Previously allocated memory block to be freed
389  **/
390 
391 void osFreeMem(void *p)
392 {
393  //Make sure the pointer is valid
394  if(p != NULL)
395  {
396  //Debug message
397  TRACE_DEBUG("Freeing memory at 0x%08" PRIXPTR "\r\n", (uintptr_t) p);
398 
399  //Free memory block
400  free(p);
401  }
402 }
uint16_t priority
Definition: dns_common.h:219
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
Create a semaphore object.
Definition: os_port_none.c:235
void osDelayTask(systime_t delay)
Delay routine.
Definition: os_port_none.c:102
uint32_t systime_t
Definition: compiler_port.h:44
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
Definition: os_port_none.c:321
char char_t
Definition: compiler_port.h:41
uint32_t time
void osDeleteSemaphore(OsSemaphore *semaphore)
Delete a semaphore object.
Definition: os_port_none.c:249
Debugging facilities.
uint8_t p
Definition: ndp.h:295
void osDeleteTask(OsTask *task)
Delete a task.
Definition: os_port_none.c:92
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
Definition: os_port_none.c:217
RTOS-less environment.
void osFreeMem(void *p)
Release a previously allocated memory block.
Definition: os_port_none.c:391
bool_t osCreateEvent(OsEvent *event)
Create an event object.
Definition: os_port_none.c:141
Event object.
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
Definition: os_port_none.c:165
#define TRUE
Definition: os_port.h:48
bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout)
Wait for the specified semaphore to be available.
Definition: os_port_none.c:262
void osSwitchTask(void)
Yield control to the next task.
Definition: os_port_none.c:111
Task object.
signed int int_t
Definition: compiler_port.h:42
void osInitKernel(void)
Kernel initialization.
Definition: os_port_none.c:52
char_t name[]
void osSuspendAllTasks(void)
Suspend scheduler activity.
Definition: os_port_none.c:120
RTOS abstraction layer.
void osStartKernel(void)
Start kernel.
Definition: os_port_none.c:63
Timeout structure.
Definition: bsd_socket.h:251
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
Definition: os_port_none.c:331
void osResumeAllTasks(void)
Resume scheduler activity.
Definition: os_port_none.c:129
void(* OsTaskCode)(void *param)
Task routine.
int32_t tv_sec
Definition: bsd_socket.h:253
void osDeleteEvent(OsEvent *event)
Delete an event object.
Definition: os_port_none.c:155
void * osAllocMem(size_t size)
Allocate a memory block.
Definition: os_port_none.c:371
unsigned int uint_t
Definition: compiler_port.h:43
#define OS_SYSTICKS_TO_MS(n)
#define PRIuSIZE
Definition: compiler_port.h:72
OsTask * osCreateTask(const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
Create a new task.
Definition: os_port_none.c:79
Mutex object.
systime_t osGetSystemTime(void)
Retrieve system time.
Definition: os_port_none.c:341
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
Definition: os_port_none.c:311
void osReleaseSemaphore(OsSemaphore *semaphore)
Release the specified semaphore object.
Definition: os_port_none.c:285
systime_t systemTicks
Definition: os_port_none.c:45
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
Definition: os_port_none.c:192
Semaphore object.
#define FALSE
Definition: os_port.h:44
int bool_t
Definition: compiler_port.h:47
void osResetEvent(OsEvent *event)
Set the specified event object to the nonsignaled state.
Definition: os_port_none.c:177
int32_t tv_usec
Definition: bsd_socket.h:254
#define TRACE_DEBUG(...)
Definition: debug.h:98
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
Definition: os_port_none.c:299