µGFX  2.9
version 2.9
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.io/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 GFXON 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(gDelay ms)
36 {
37  switch(ms) {
38  case gDelayNone: cyg_thread_yield(); return;
39  case gDelayForever: cyg_thread_suspend(cyg_thread_self()); return;
40  default: cyg_thread_delay(gfxMillisecondsToTicks(ms)); return;
41  }
42 }
43 
44 void gfxSleepMicroseconds(gDelay ms)
45 {
46  switch(ms) {
47  case gDelayNone: return;
48  case gDelayForever: cyg_thread_suspend(cyg_thread_self()); return;
49  default: cyg_thread_delay(gfxMillisecondsToTicks(ms/1000)); return;
50  }
51 }
52 
53 void gfxSemInit(gSem *psem, gSemcount val, gSemcount 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(gSem *psem)
63 {
64  cyg_semaphore_destroy(&psem->sem);
65 }
66 
67 gBool gfxSemWait(gSem *psem, gDelay ms)
68 {
69  switch(ms) {
70  case gDelayNone: return cyg_semaphore_trywait(&psem->sem);
71  case gDelayForever: return cyg_semaphore_wait(&psem->sem);
72  default: return cyg_semaphore_timed_wait(&psem->sem, gfxMillisecondsToTicks(ms)+cyg_current_time());
73  }
74 }
75 
76 gBool gfxSemWaitI(gSem *psem)
77 {
78  return cyg_semaphore_trywait(&psem->sem);
79 }
80 
81 void gfxSemSignal(gSem *psem)
82 {
83  if (psem->limit == gSemMaxCount)
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(gSem *psem)
94 {
95  if (psem->limit == gSemMaxCount || cyg_semaphore_peek(&psem->sem, &cnt) < psem->limit)
96  cyg_semaphore_post(&psem->sem);
97 }
98 
99 gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void *param)
100 {
101  gThread 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 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
gTicks gfxMillisecondsToTicks(gDelay ms)
Convert a given number of millseconds to a number of operating system ticks.
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.
void * gfxAlloc(gMemSize sz)
Allocate memory.
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 semaphore.
Definition: gos.h:104