version 2.8
gos_zephyr.h
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_zepyhr.h
10  * @brief GOS - Operating System Support header file for Zephyr RTOS.
11  * Zephyr SDK 0.9.1
12  */
13 
14 #ifndef _GOS_ZEPHYR_H
15 #define _GOS_ZEPHYR_H
16 
17 #if GFX_USE_OS_ZEPHYR
18 
19 // #include <stdbool.h>
20 // #include <stdint.h>
21 
22 #include <zephyr.h>
23 
24  /*===========================================================================*/
25  /* Type definitions */
26  /*===========================================================================*/
27 
28  typedef bool bool_t;
29  typedef s8_t int8_t;
30  typedef u8_t uint8_t;
31  typedef s16_t int16_t;
32  typedef u16_t uint16_t;
33  typedef s32_t int32_t;
34  typedef u32_t uint32_t;
35 
36  // typedef unsigned long size_t;
37  typedef s32_t delaytime_t;
38  typedef u32_t systemticks_t;
39  typedef u32_t semcount_t;
40  typedef void threadreturn_t;
41  typedef int threadpriority_t;
42 
43  #define DECLARE_THREAD_FUNCTION(fnName, param)\
44  threadreturn_t fnName(void* param, void* p2, void* p3)
45 
46  #define DECLARE_THREAD_STACK(name, sz)\
47  K_THREAD_STACK_DEFINE(name, sz)
48 
49  #define THREAD_RETURN(retval) return
50 
51  // #define FALSE 0
52  // #define TRUE 1
53  #define TIME_IMMEDIATE K_NO_WAIT
54  #define TIME_INFINITE K_FOREVER
55  #define MAX_SEMAPHORE_COUNT ((semcount_t)(((unsigned long)((semcount_t)(-1))) >> 1))
56  #define LOW_PRIORITY CONFIG_NUM_PREEMPT_PRIORITIES-1
57  #define NORMAL_PRIORITY 1
58  #define HIGH_PRIORITY 0
59 
60  typedef struct k_sem gfxSem;
61 
62  typedef struct k_mutex gfxMutex;
63 
64  typedef k_tid_t gfxThreadHandle;
65 
66  /*===========================================================================*/
67  /* Function declarations. */
68  /*===========================================================================*/
69 
70  #ifdef __cplusplus
71  extern "C" {
72  #endif
73 
74  #define gfxHalt(msg) do{}while(0)
75  #define gfxExit() do{}while(0)
76 
77  // Don't forget to set CONFIG_HEAP_MEM_POOL_SIZE
78  #define gfxAlloc(sz) k_malloc(sz)
79  #define gfxFree(ptr) k_free(ptr)
80  #define gfxRealloc(ptr, oldsz, newsz) do{}while(0)
81 
82  #define gfxYield() k_yield()
83  #define gfxSleepMilliseconds(ms) k_sleep(ms)
84  #define gfxSleepMicroseconds(us) do{}while(0)
85  #define gfxMillisecondsToTicks(ms) CONFIG_SYS_CLOCK_TICKS_PER_SEC*ms/1000
86  systemticks_t gfxSystemTicks();
87 
88  #define gfxSystemLock() k_sched_lock()
89  #define gfxSystemUnlock() k_sched_unlock()
90 
91  #define gfxMutexInit(pmutex) k_mutex_init(pmutex)
92  #define gfxMutexDestroy(pmutex) do{}while(0)
93  #define gfxMutexEnter(pmutex) k_mutex_lock(pmutex, K_FOREVER)
94  #define gfxMutexExit(pmutex) k_mutex_unlock(pmutex)
95 
96  #define gfxSemInit(psem, val, limit) k_sem_init(psem, val, limit)
97  #define gfxSemDestroy(psem) do{}while(0)
98  #define gfxSemWait(psem, ms) (k_sem_take(psem, ms) == 0) ? TRUE : FALSE
99  #define gfxSemWaitI(psem) (k_sem_take(psem, K_NO_WAIT) == 0) ? TRUE : FALSE
100  #define gfxSemSignal(psem) k_sem_give(psem)
101  #define gfxSemSignalI(psem) k_sem_give(psem)
102  #define gfxSemCounter(psem) k_sem_count_get(psem)
103  #define gfxSemCounterI(psem) k_sem_count_get(psem)
104 
105  #define gfxThreadCreate(stackarea, stacksz, prio, fn, param)\
106  k_thread_spawn(stackarea, stacksz, fn, param, NULL, NULL, prio, 0, K_NO_WAIT)
107  #define gfxThreadWait(thread) 0
108  #define gfxThreadMe() k_current_get()
109  #define gfxThreadClose(thread) k_thread_abort(thread)
110 
111  #ifdef __cplusplus
112  }
113  #endif
114 
115 #endif /* GFX_USE_OS_ZEPHYR */
116 #endif /* _GOS_H */
117 /** @} */
void * gfxThreadHandle
A thread handle.
Definition: gos.h:117
systemticks_t gfxSystemTicks(void)
Get the current operating system tick time.
A semaphore.
Definition: gos.h:105
A mutex.
Definition: gos.h:111