aboutsummaryrefslogtreecommitdiffstats
path: root/src/gos/gos_zephyr.h
blob: 1bfccf8b5b61ec78fc684bdee0a0418fedca465f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * This file is subject to the terms of the GFX License. If a copy of
 * the license was not distributed with this file, you can obtain one at:
 *
 *              http://ugfx.org/license.html
 */

#ifndef _GOS_ZEPHYR_H
#define _GOS_ZEPHYR_H

#if GFX_USE_OS_ZEPHYR

#include <zephyr.h>

/*===========================================================================*/
/* Type definitions                                                          */
/*===========================================================================*/

typedef s32_t 	gDelay;
typedef u32_t	gTicks;
typedef u32_t	gSemcount;
typedef void	gThreadreturn;
typedef int	gThreadpriority;

#define DECLARE_THREAD_FUNCTION(fnName, param)\
	gThreadreturn fnName(void* param, void* p2, void* p3)

#define DECLARE_THREAD_STACK(name, sz)\
	K_THREAD_STACK_DEFINE(name, sz)

#define THREAD_RETURN(retval)		return

#define TIME_IMMEDIATE			K_NO_WAIT
#define TIME_INFINITE			K_FOREVER
#define MAX_SEMAPHORE_COUNT		((gSemcount)(((unsigned long)((gSemcount)(-1))) >> 1))
#define LOW_PRIORITY			CONFIG_NUM_PREEMPT_PRIORITIES-1
#define NORMAL_PRIORITY			1
#define HIGH_PRIORITY			0

typedef struct k_sem gfxSem;

typedef struct k_mutex gfxMutex;

typedef k_tid_t gfxThreadHandle;

/*===========================================================================*/
/* Function declarations.                                                    */
/*===========================================================================*/

#define gfxHalt(msg)	do{}while(0)
#define gfxExit()		do{}while(0)

// Don't forget to set CONFIG_HEAP_MEM_POOL_SIZE
#define gfxAlloc(sz)					k_malloc(sz)
#define gfxFree(ptr)					k_free(ptr)
#define gfxRealloc(ptr, oldsz, newsz)	do{}while(0)

#define gfxYield()						k_yield()
#define gfxSleepMilliseconds(ms)		k_sleep(ms)
#define gfxSleepMicroseconds(us)		do{}while(0)
#define gfxMillisecondsToTicks(ms)		CONFIG_SYS_CLOCK_TICKS_PER_SEC*ms/1000
gTicks gfxSystemTicks();

#define gfxSystemLock()					k_sched_lock()
#define gfxSystemUnlock()				k_sched_unlock()

#define gfxMutexInit(pmutex)			k_mutex_init(pmutex)
#define gfxMutexDestroy(pmutex)			do{}while(0)
#define gfxMutexEnter(pmutex)			k_mutex_lock(pmutex, K_FOREVER)
#define gfxMutexExit(pmutex)			k_mutex_unlock(pmutex)

#define gfxSemInit(psem, val, limit) 	k_sem_init(psem, val, limit)
#define gfxSemDestroy(psem)				do{}while(0)
#define gfxSemWait(psem, ms)  			(k_sem_take(psem, ms) == 0) ? gTrue : gFalse
#define gfxSemWaitI(psem) 				(k_sem_take(psem, K_NO_WAIT) == 0) ? gTrue : gFalse
#define gfxSemSignal(psem)				k_sem_give(psem)
#define gfxSemSignalI(psem)				k_sem_give(psem)
#define gfxSemCounter(psem)				k_sem_count_get(psem)
#define gfxSemCounterI(psem)			k_sem_count_get(psem)

#define gfxThreadCreate(stackarea, stacksz, prio, fn, param)\
	k_thread_spawn(stackarea, stacksz, fn, param, NULL, NULL, prio, 0, K_NO_WAIT)
#define gfxThreadWait(thread)			0
#define gfxThreadMe()					k_current_get()
#define gfxThreadClose(thread)			k_thread_abort(thread)

#endif /* GFX_USE_OS_ZEPHYR */
#endif /* _GOS_H */
/** @} */