version 2.8
gos_cmsis2.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_cmsis2.h
10  * @brief GOS - Operating System Support header file for CMSIS 2.0 RTOS.
11  */
12 
13 #ifndef _GOS_CMSIS2_H
14 #define _GOS_CMSIS2_H
15 
16 #if GFX_USE_OS_CMSIS2
17 
18 #include <stdbool.h>
19 #include "cmsis_os2.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_t threadpriority_t;
38 
39 #define MAX_SEMAPHORE_COUNT 65535UL
40 #define LOW_PRIORITY osPriorityLow
41 #define NORMAL_PRIORITY osPriorityNormal
42 #define HIGH_PRIORITY osPriorityHigh
43 
44 typedef osSemaphoreId_t gfxSem;
45 
46 typedef osMutexId_t gfxMutex;
47 
48 typedef osThreadId_t gfxThreadHandle;
49 
50 #define DECLARE_THREAD_STACK(name, sz) uint8_t name[1]; // Some compilers don't allow zero sized arrays. Let's waste one byte
51 #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void* param)
52 #define THREAD_RETURN(retval)
53 
54 /*===========================================================================*/
55 /* Function declarations. */
56 /*===========================================================================*/
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 #define gfxExit() os_error(0)
63 #define gfxHalt(msg) os_error(1)
64 #define gfxSystemTicks() osKernelGetSysTimerCount()
65 #define gfxMillisecondsToTicks(ms) (1000*(ms)/osKernelGetTickFreq())
66 #define gfxSystemLock() osKernelLock()
67 #define gfxSystemUnlock() osKernelUnlock()
68 #define gfxSleepMilliseconds(ms) osDelay(ms)
69 
70 void gfxMutexInit(gfxMutex* pmutex);
71 #define gfxMutexDestroy(pmutex) osMutexDelete(*(pmutex))
72 #define gfxMutexEnter(pmutex) osMutexAcquire(*(pmutex), TIME_INFINITE)
73 #define gfxMutexExit(pmutex) osMutexRelease(*(pmutex))
74 
75 void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit);
76 #define gfxSemDestroy(psem) osSemaphoreDelete(*(psem))
77 bool_t gfxSemWait(gfxSem* psem, delaytime_t ms);
78 #define gfxSemWaitI(psem) gfxSemWait((psem), 0)
79 #define gfxSemSignal(psem) osSemaphoreRelease(*(psem))
80 #define gfxSemSignalI(psem) osSemaphoreRelease(*(psem))
81 
82 gfxThreadHandle gfxThreadCreate(void* stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void* param);
83 #define gfxYield() osThreadYield()
84 #define gfxThreadMe() osThreadGetId()
85 #define gfxThreadClose(thread) {}
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 /*===========================================================================*/
92 /* Use the generic heap handling */
93 /*===========================================================================*/
94 
95 #define GOS_NEED_X_HEAP TRUE
96 #include "gos_x_heap.h"
97 
98 #endif /* GFX_USE_OS_CMSIS */
99 #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.
bool_t gfxSemWait(gfxSem *psem, delaytime_t ms)
Wait on a semaphore.
A semaphore.
Definition: gos.h:105
#define DECLARE_THREAD_FUNCTION(fnName, param)
Declare a thread function.
Definition: gos.h:62
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.