version 2.8
gos_freertos.h
Go to the documentation of this file.
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.org/license.html
6  */
7 
8 /**
9  * @file src/gos/gos_freertos.h
10  * @brief GOS - Operating System Support header file for FreeRTOS.
11  */
12 
13 #ifndef _GOS_FREERTOS_H
14 #define _GOS_FREERTOS_H
15 
16 #if GFX_USE_OS_FREERTOS
17 
18 #include "FreeRTOS.h"
19 #include "FreeRTOSConfig.h"
20 #include "semphr.h"
21 #include "task.h"
22 
23 /*===========================================================================*/
24 /* Type definitions */
25 /*===========================================================================*/
26 
27 /* Additional types are required when FreeRTOS 7.x is used */
28 #if !defined(tskKERNEL_VERSION_MAJOR) && !tskKERNEL_VERSION_MAJOR == 8
29  typedef signed char int8_t
30  typedef unsigned char uint8_t
31  typedef signed int int16_t
32  typedef unsigned int uint16_t
33  typedef signed long int int32_t
34  typedef unsigned long int uint32_t
35  typedef signed long long int int64_t
36  typedef unsigned long long int uint64_t
37 #endif
38 
39 /**
40  * bool_t,
41  * int8_t, uint8_t,
42  * int16_t, uint16_t,
43  * int32_t, uint32_t,
44  * size_t
45  * TRUE, FALSE
46  * are already defined by FreeRTOS
47  */
48 #define TIME_IMMEDIATE 0
49 #define TIME_INFINITE ((delaytime_t)-1)
50 typedef int8_t bool_t;
51 typedef uint32_t delaytime_t;
52 typedef portTickType systemticks_t;
53 typedef int32_t semcount_t;
54 typedef void threadreturn_t;
55 typedef portBASE_TYPE threadpriority_t;
56 
57 #define MAX_SEMAPHORE_COUNT ((semcount_t)(((unsigned long)((semcount_t)(-1))) >> 1))
58 #define LOW_PRIORITY 0
59 #define NORMAL_PRIORITY configMAX_PRIORITIES/2
60 #define HIGH_PRIORITY configMAX_PRIORITIES-1
61 
62 /* FreeRTOS will allocate the stack when creating the thread */
63 #define DECLARE_THREAD_STACK(name, sz) uint8_t name[1]
64 #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
65 #define THREAD_RETURN(retval)
66 
67 typedef xSemaphoreHandle gfxSem;
68 typedef xSemaphoreHandle gfxMutex;
69 typedef xTaskHandle gfxThreadHandle;
70 
71 /*===========================================================================*/
72 /* Function declarations. */
73 /*===========================================================================*/
74 
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78 
79 #define gfxHalt(msg) {while(1);}
80 #define gfxExit() {while(1);}
81 #define gfxAlloc(sz) pvPortMalloc(sz)
82 #define gfxFree(ptr) vPortFree(ptr)
83 #define gfxYield() taskYIELD()
84 #define gfxSystemTicks() xTaskGetTickCount()
85 #define gfxMillisecondsToTicks(ms) ((systemticks_t)((ms) / portTICK_PERIOD_MS))
86 #define gfxSystemLock() taskENTER_CRITICAL()
87 #define gfxSystemUnlock() taskEXIT_CRITICAL()
88 
89 void gfxMutexInit(gfxMutex* s);
90 #define gfxMutexDestroy(pmutex) vSemaphoreDelete(*(pmutex))
91 #define gfxMutexEnter(pmutex) xSemaphoreTake(*(pmutex),portMAX_DELAY)
92 #define gfxMutexExit(pmutex) xSemaphoreGive(*(pmutex))
93 
94 void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz);
95 void gfxSleepMilliseconds(delaytime_t ms);
96 void gfxSleepMicroseconds(delaytime_t ms);
97 
98 void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit);
99 #define gfxSemDestroy(psem) vSemaphoreDelete(*(psem))
100 bool_t gfxSemWait(gfxSem* psem, delaytime_t ms);
101 bool_t gfxSemWaitI(gfxSem* psem);
102 void gfxSemSignal(gfxSem* psem);
103 void gfxSemSignalI(gfxSem* psem);
104 gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
105 
106 #define gfxThreadMe() xTaskGetCurrentTaskHandle()
107 #if INCLUDE_eTaskGetState == 1
108  threadreturn_t gfxThreadWait(gfxThreadHandle thread);
109 #endif
110 #define gfxThreadClose(thread)
111 
112 #ifdef __cplusplus
113 }
114 #endif
115 
116 #endif /* GFX_USE_OS_FREERTOS */
117 #endif /* _GOS_CHIBIOS_H */
void * gfxThreadHandle
A thread handle.
Definition: gos.h:117
void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit)
Initialise a Counted Semaphore.
bool_t gfxSemWait(gfxSem *psem, delaytime_t ms)
Wait on a semaphore.
void gfxSemSignalI(gfxSem *psem)
Signal a semaphore.
A semaphore.
Definition: gos.h:105
void * gfxRealloc(void *ptr, size_t oldsz, size_t newsz)
Re-allocate memory.
#define DECLARE_THREAD_FUNCTION(fnName, param)
Declare a thread function.
Definition: gos.h:62
void gfxSemSignal(gfxSem *psem)
Signal a semaphore.
void gfxSleepMicroseconds(delaytime_t us)
Put the current thread to sleep for the specified period in microseconds.
gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn), p), void *param)
Start a new thread.
A mutex.
Definition: gos.h:111
threadreturn_t gfxThreadWait(gfxThreadHandle thread)
Wait for a thread to finish.
void gfxMutexInit(gfxMutex *pmutex)
Initialise a mutex to protect a region of code from other threads.
void gfxSleepMilliseconds(delaytime_t ms)
Put the current thread to sleep for the specified period in milliseconds.
bool_t gfxSemWaitI(gfxSem *psem)
Test if a wait on a semaphore can be satisfied immediately.