µGFX  2.9
version 2.9
gos_ecos.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.io/license.html
6  */
7 
8 #ifndef _GOS_ECOS_H
9 #define _GOS_ECOS_H
10 
11 #if GFX_USE_OS_ECOS
12 
13 #include <cyg/hal/hal_arch.h>
14 #include <cyg/kernel/kapi.h>
15 #include <stdlib.h>
16 
17 /*===========================================================================*/
18 /* Type definitions */
19 /*===========================================================================*/
20 
21 #define gDelayNone 0
22 #define gDelayForever 0xFFFFFFFF
23 
24 typedef cyg_ucount32 gDelay;
25 typedef cyg_tick_count_t gTicks;
26 typedef cyg_count32 gSemcount;
27 typedef void gThreadreturn;
28 typedef cyg_addrword_t gThreadpriority;
29 typedef cyg_handle_t gThread;
30 
31 #define gSemMaxCount 0x7FFFFFFF
32 #define gThreadpriorityLow (CYGNUM_KERNEL_SCHED_PRIORITIES-2)
33 #define gThreadpriorityNormal (CYGNUM_KERNEL_SCHED_PRIORITIES/2)
34 #define gThreadpriorityHigh 0
35 
36 #define GFX_THREAD_STACK(name, sz) struct { cyg_thread t; unsigned char stk[(sz) & ~3]; } name[1]
37 #define GFX_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(cyg_addrword_t param)
38 #define gfxThreadReturn(retval) return
39 
40 typedef struct {
41  cyg_sem_t sem;
42  gSemcount limit;
43  } gSem;
44 
45 typedef cyg_mutex_t gMutex;
46 
47 
48 /*===========================================================================*/
49 /* Function declarations. */
50 /*===========================================================================*/
51 
52 #define gfxSystemTicks() cyg_current_time()
53 #define gfxExit() exit(0)
54 #define gfxHalt(msg) exit(-1)
55 #define gfxYield() cyg_thread_yield()
56 
57 #define gfxMillisecondsToTicks(ms) (((ms)*(CYGNUM_HAL_RTC_DENOMINATOR*1000))/(CYGNUM_HAL_RTC_NUMERATOR/1000))
58 void gfxSleepMilliseconds(gDelay ms);
59 void gfxSleepMicroseconds(gDelay ms);
60 
61 #define gfxAlloc(sz) malloc(sz)
62 #define gfxFree(ptr) free(ptr)
63 #define gfxRealloc(ptr, oldsz, newsz) realloc(ptr, newsz)
64 
65 #define gfxSystemLock() cyg_scheduler_lock()
66 #define gfxSystemUnlock() cyg_scheduler_unlock()
67 
68 #define gfxMutexInit(pmutex) cyg_mutex_init(pmutex)
69 #define gfxMutexExit(pmutex) cyg_mutex_unlock(pmutex)
70 #define gfxMutexDestroy(pmutex) cyg_mutex_destroy(pmutex)
71 #define gfxMutexEnter(pmutex) cyg_mutex_lock(pmutex)
72 
73 void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit);
74 void gfxSemDestroy(gSem *psem);
75 gBool gfxSemWait(gSem *psem, gDelay ms);
76 gBool gfxSemWaitI(gSem *psem);
77 void gfxSemSignal(gSem *psem);
78 void gfxSemSignalI(gSem *psem);
79 
80 gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void *param);
81 #define gfxThreadWait(thread) NOTIMPLEMENTED_YET
82 #define gfxThreadMe() cyg_thread_self()
83 #define gfxThreadClose(thread) (void)thread
84 
85 #endif /* GFX_USE_OS_ECOS */
86 #endif /* _GOS_ECOS_H */
void gfxSemSignal(gSem *psem)
Signal a semaphore.
void * gThread
A thread handle.
Definition: gos.h:116
#define GFX_THREAD_FUNCTION(fnName, param)
Declare a thread function.
Definition: gos.h:73
gBool gfxSemWait(gSem *psem, gDelay ms)
Wait on a semaphore.
void gfxSleepMicroseconds(gDelay us)
Put the current thread to sleep for the specified period in microseconds.
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn), p), void *param)
Start a new thread.
gBool gfxSemWaitI(gSem *psem)
Test if a wait on a semaphore can be satisfied immediately.
void gfxSemDestroy(gSem *psem)
Destroy a Counted Semaphore.
void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit)
Initialise a Counted Semaphore.
void gfxSemSignalI(gSem *psem)
Signal a semaphore.
void gfxSleepMilliseconds(gDelay ms)
Put the current thread to sleep for the specified period in milliseconds.
A mutex.
Definition: gos.h:110
A semaphore.
Definition: gos.h:104