version 2.8
gos_ecos.c
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 #include "../../gfx.h"
9 
10 #if GFX_USE_OS_ECOS
11 
12 void _gosInit(void)
13 {
14  #if !GFX_OS_NO_INIT
15  #error "GOS: Operating System initialization for eCos is not yet implemented in uGFX. Please set GFX_OS_NO_INIT to TRUE in your gfxconf.h"
16  #endif
17  #if !GFX_OS_INIT_NO_WARNING
18  #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT
19  #warning "GOS: Operating System initialization has been turned off. Make sure you call cyg_scheduler_start() before gfxInit() in your application!"
20  #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO
21  COMPILER_WARNING("GOS: Operating System initialization has been turned off. Make sure you call cyg_scheduler_start() before gfxInit() in your application!")
22  #endif
23  #endif
24 }
25 
26 void _gosPostInit(void)
27 {
28 }
29 
30 void _gosDeinit(void)
31 {
32  /* ToDo */
33 }
34 
35 void gfxSleepMilliseconds(delaytime_t ms)
36 {
37  switch(ms) {
38  case TIME_IMMEDIATE: cyg_thread_yield(); return;
39  case TIME_INFINITE: cyg_thread_suspend(cyg_thread_self()); return;
40  default: cyg_thread_delay(gfxMillisecondsToTicks(ms)); return;
41  }
42 }
43 
44 void gfxSleepMicroseconds(delaytime_t ms)
45 {
46  switch(ms) {
47  case TIME_IMMEDIATE: return;
48  case TIME_INFINITE: cyg_thread_suspend(cyg_thread_self()); return;
49  default: cyg_thread_delay(gfxMillisecondsToTicks(ms/1000)); return;
50  }
51 }
52 
53 void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit)
54 {
55  if (val > limit)
56  val = limit;
57 
58  psem->limit = limit;
59  cyg_semaphore_init(&psem->sem, val);
60 }
61 
62 void gfxSemDestroy(gfxSem *psem)
63 {
64  cyg_semaphore_destroy(&psem->sem);
65 }
66 
67 bool_t gfxSemWait(gfxSem *psem, delaytime_t ms)
68 {
69  switch(ms) {
70  case TIME_IMMEDIATE: return cyg_semaphore_trywait(&psem->sem);
71  case TIME_INFINITE: return cyg_semaphore_wait(&psem->sem);
72  default: return cyg_semaphore_timed_wait(&psem->sem, gfxMillisecondsToTicks(ms)+cyg_current_time());
73  }
74 }
75 
76 bool_t gfxSemWaitI(gfxSem *psem)
77 {
78  return cyg_semaphore_trywait(&psem->sem);
79 }
80 
81 void gfxSemSignal(gfxSem *psem)
82 {
83  if (psem->limit == MAX_SEMAPHORE_COUNT)
84  cyg_semaphore_post(&psem->sem);
85  else {
86  cyg_scheduler_lock();
87  if (cyg_semaphore_peek(&psem->sem, &cnt) < psem->limit)
88  cyg_semaphore_post(&psem->sem);
89  cyg_scheduler_unlock();
90  }
91 }
92 
93 void gfxSemSignalI(gfxSem *psem)
94 {
95  if (psem->limit == MAX_SEMAPHORE_COUNT || cyg_semaphore_peek(&psem->sem, &cnt) < psem->limit)
96  cyg_semaphore_post(&psem->sem);
97 }
98 
99 gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param)
100 {
101  gfxThreadHandle th;
102 
103  if (!stackarea) {
104  if (!stacksz) stacksz = CYGNUM_HAL_STACK_SIZE_TYPICAL;
105  if (!(stackarea = gfxAlloc(stacksz+sizeof(cyg_thread))))
106  return 0;
107  }
108 
109  if (!stacksz)
110  return 0;
111 
112  cyg_thread_create(prio, fn, param, "uGFX", (((cyg_thread *)stackarea)+1), stacksz, &th, (cyg_thread *)stackarea);
113  cyg_thread_resume(th);
114  return th;
115 }
116 
117 #endif /* GFX_USE_OS_ECOS */
void * gfxThreadHandle
A thread handle.
Definition: gos.h:117
void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit)
Initialise a Counted Semaphore.
systemticks_t gfxMillisecondsToTicks(delaytime_t ms)
Convert a given number of millseconds to a number of operating system ticks.
void gfxSemDestroy(gfxSem *psem)
Destroy a Counted Semaphore.
void * gfxAlloc(size_t sz)
Allocate memory.
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.
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.