version 2.8
gos_cmsis.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_cmsis.h
10  * @brief GOS - Operating System Support header file for CMSIS RTOS.
11  */
12 
13 #ifndef _GOS_CMSIS_H
14 #define _GOS_CMSIS_H
15 
16 #if GFX_USE_OS_CMSIS
17 
18 #include <stdbool.h>
19 #include "cmsis_os.h"
20 
21 #ifndef GFX_OS_HEAP_SIZE
22  #define GFX_OS_HEAP_SIZE 10240
23 #endif
24 
25 /*===========================================================================*/
26 /* Type definitions */
27 /*===========================================================================*/
28 
29 typedef bool bool_t;
30 
31 #define TIME_IMMEDIATE 0
32 #define TIME_INFINITE osWaitForever
33 typedef uint32_t delaytime_t;
34 typedef uint32_t systemticks_t;
35 typedef uint16_t semcount_t;
36 typedef void threadreturn_t;
37 typedef osPriority threadpriority_t;
38 
39 #define MAX_SEMAPHORE_COUNT osFeature_Semaphore
40 #define LOW_PRIORITY osPriorityLow
41 #define NORMAL_PRIORITY osPriorityNormal
42 #define HIGH_PRIORITY osPriorityHigh
43 
44 typedef struct gfxSem {
45  uint32_t semaphore[2];
46  osSemaphoreId id;
47  semcount_t available;
48 } gfxSem;
49 
50 typedef struct gfxMutex {
51  uint32_t mutex[4];
52  osMutexId id;
53 } gfxMutex;
54 
55 typedef osThreadId gfxThreadHandle;
56 
57 #define DECLARE_THREAD_STACK(name, sz) uint8_t name[1]; // Some compilers don't allow zero sized arrays. Let's waste one byte
58 #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void* param)
59 #define THREAD_RETURN(retval)
60 
61 /*===========================================================================*/
62 /* Function declarations. */
63 /*===========================================================================*/
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
69 #define gfxExit() os_error(0)
70 #define gfxHalt(msg) os_error(1)
71 #define gfxSystemTicks() osKernelSysTick()
72 #define gfxMillisecondsToTicks(ms) osKernelSysTickMicroSec(1000*ms)
73 #define gfxSystemLock() osKernelInitialize()
74 #define gfxSystemUnlock() osKernelStart()
75 #define gfxSleepMilliseconds(ms) osDelay(ms)
76 
77 void gfxMutexInit(gfxMutex* pmutex);
78 #define gfxMutexDestroy(pmutex) osMutexDelete((pmutex)->id)
79 #define gfxMutexEnter(pmutex) osMutexWait((pmutex)->id, TIME_INFINITE)
80 #define gfxMutexExit(pmutex) osMutexRelease((pmutex)->id)
81 
82 void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit);
83 void gfxSemDestroy(gfxSem* psem);
84 bool_t gfxSemWait(gfxSem* psem, delaytime_t ms);
85 bool_t gfxSemWaitI(gfxSem* psem);
86 void gfxSemSignal(gfxSem* psem);
87 void gfxSemSignalI(gfxSem* psem);
88 
89 gfxThreadHandle gfxThreadCreate(void* stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void* param);
90 #define gfxYield() osThreadYield()
91 #define gfxThreadMe() osThreadGetId()
92 #define gfxThreadClose(thread) {}
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 
98 /*===========================================================================*/
99 /* Use the generic heap handling */
100 /*===========================================================================*/
101 
102 #define GOS_NEED_X_HEAP TRUE
103 #include "gos_x_heap.h"
104 
105 #endif /* GFX_USE_OS_CMSIS */
106 #endif /* _GOS_CMSIS_H */
void * gfxThreadHandle
A thread handle.
Definition: gos.h:117
void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit)
Initialise a Counted Semaphore.
void gfxSemDestroy(gfxSem *psem)
Destroy 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
#define DECLARE_THREAD_FUNCTION(fnName, param)
Declare a thread function.
Definition: gos.h:62
void gfxSemSignal(gfxSem *psem)
Signal a semaphore.
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
void gfxMutexInit(gfxMutex *pmutex)
Initialise a mutex to protect a region of code from other threads.
bool_t gfxSemWaitI(gfxSem *psem)
Test if a wait on a semaphore can be satisfied immediately.