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