version 2.8
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.org/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 typedef cyg_bool_t bool_t;
22 typedef cyg_int8 int8_t;
23 typedef cyg_uint8 uint8_t;
24 typedef cyg_int16 int16_t;
25 typedef cyg_uint16 uint16_t;
26 typedef cyg_int32 int32_t;
27 typedef cyg_uint32 uint32_t;
28 typedef cyg_uint32 size_t;
29 
30 #define TRUE -1
31 #define FALSE 0
32 #define TIME_IMMEDIATE 0
33 #define TIME_INFINITE 0xFFFFFFFF
34 
35 typedef cyg_ucount32 delaytime_t;
36 typedef cyg_tick_count_t systemticks_t;
37 typedef cyg_count32 semcount_t;
38 typedef void threadreturn_t;
39 typedef cyg_addrword_t threadpriority_t;
40 typedef cyg_handle_t gfxThreadHandle;
41 
42 #define MAX_SEMAPHORE_COUNT 0x7FFFFFFF
43 #define LOW_PRIORITY (CYGNUM_KERNEL_SCHED_PRIORITIES-2)
44 #define NORMAL_PRIORITY (CYGNUM_KERNEL_SCHED_PRIORITIES/2)
45 #define HIGH_PRIORITY 0
46 
47 #define DECLARE_THREAD_STACK(name, sz) struct { cyg_thread t; unsigned char stk[(sz) & ~3]; } name[1]
48 #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(cyg_addrword_t param)
49 #define THREAD_RETURN(retval)
50 
51 typedef struct {
52  cyg_sem_t sem;
53  semcount_t limit;
54  } gfxSem;
55 
56 typedef cyg_mutex_t gfxMutex;
57 
58 
59 /*===========================================================================*/
60 /* Function declarations. */
61 /*===========================================================================*/
62 
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 
67 #define gfxSystemTicks() cyg_current_time()
68 #define gfxExit() exit(0)
69 #define gfxHalt(msg) exit(-1)
70 #define gfxYield() cyg_thread_yield()
71 
72 #define gfxMillisecondsToTicks(ms) (((ms)*(CYGNUM_HAL_RTC_DENOMINATOR*1000))/(CYGNUM_HAL_RTC_NUMERATOR/1000))
73 void gfxSleepMilliseconds(delaytime_t ms);
74 void gfxSleepMicroseconds(delaytime_t ms);
75 
76 #define gfxAlloc(sz) malloc(sz)
77 #define gfxFree(ptr) free(ptr)
78 #define gfxRealloc(ptr, oldsz, newsz) realloc(ptr, newsz)
79 
80 #define gfxSystemLock() cyg_scheduler_lock()
81 #define gfxSystemUnlock() cyg_scheduler_unlock()
82 
83 #define gfxMutexInit(pmutex) cyg_mutex_init(pmutex)
84 #define gfxMutexExit(pmutex) cyg_mutex_unlock(pmutex)
85 #define gfxMutexDestroy(pmutex) cyg_mutex_destroy(pmutex)
86 #define gfxMutexEnter(pmutex) cyg_mutex_lock(pmutex)
87 
88 void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
89 void gfxSemDestroy(gfxSem *psem);
90 bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
91 bool_t gfxSemWaitI(gfxSem *psem);
92 void gfxSemSignal(gfxSem *psem);
93 void gfxSemSignalI(gfxSem *psem);
94 
95 gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
96 #define gfxThreadWait(thread) NOTIMPLEMENTED_YET
97 #define gfxThreadMe() cyg_thread_self()
98 #define gfxThreadClose(thread) (void)thread
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif /* GFX_USE_OS_ECOS */
105 #endif /* _GOS_ECOS_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.
void gfxSleepMicroseconds(delaytime_t us)
Put the current thread to sleep for the specified period in microseconds.
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 gfxSleepMilliseconds(delaytime_t ms)
Put the current thread to sleep for the specified period in milliseconds.
bool_t gfxSemWaitI(gfxSem *psem)
Test if a wait on a semaphore can be satisfied immediately.