µGFX library fork

gos_ecos.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #include "../../gfx.h"
  8. #if GFX_USE_OS_ECOS
  9. void _gosInit(void)
  10. {
  11. #if !GFX_OS_NO_INIT
  12. #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"
  13. #endif
  14. #if !GFX_OS_INIT_NO_WARNING
  15. #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT
  16. #warning "GOS: Operating System initialization has been turned off. Make sure you call cyg_scheduler_start() before gfxInit() in your application!"
  17. #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO
  18. COMPILER_WARNING("GOS: Operating System initialization has been turned off. Make sure you call cyg_scheduler_start() before gfxInit() in your application!")
  19. #endif
  20. #endif
  21. }
  22. void _gosPostInit(void)
  23. {
  24. }
  25. void _gosDeinit(void)
  26. {
  27. /* ToDo */
  28. }
  29. void gfxSleepMilliseconds(delaytime_t ms)
  30. {
  31. switch(ms) {
  32. case TIME_IMMEDIATE: cyg_thread_yield(); return;
  33. case TIME_INFINITE: cyg_thread_suspend(cyg_thread_self()); return;
  34. default: cyg_thread_delay(gfxMillisecondsToTicks(ms)); return;
  35. }
  36. }
  37. void gfxSleepMicroseconds(delaytime_t ms)
  38. {
  39. switch(ms) {
  40. case TIME_IMMEDIATE: return;
  41. case TIME_INFINITE: cyg_thread_suspend(cyg_thread_self()); return;
  42. default: cyg_thread_delay(gfxMillisecondsToTicks(ms/1000)); return;
  43. }
  44. }
  45. void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit)
  46. {
  47. if (val > limit)
  48. val = limit;
  49. psem->limit = limit;
  50. cyg_semaphore_init(&psem->sem, val);
  51. }
  52. void gfxSemDestroy(gfxSem *psem)
  53. {
  54. cyg_semaphore_destroy(&psem->sem);
  55. }
  56. bool_t gfxSemWait(gfxSem *psem, delaytime_t ms)
  57. {
  58. switch(ms) {
  59. case TIME_IMMEDIATE: return cyg_semaphore_trywait(&psem->sem);
  60. case TIME_INFINITE: return cyg_semaphore_wait(&psem->sem);
  61. default: return cyg_semaphore_timed_wait(&psem->sem, gfxMillisecondsToTicks(ms)+cyg_current_time());
  62. }
  63. }
  64. bool_t gfxSemWaitI(gfxSem *psem)
  65. {
  66. return cyg_semaphore_trywait(&psem->sem);
  67. }
  68. void gfxSemSignal(gfxSem *psem)
  69. {
  70. if (psem->limit == MAX_SEMAPHORE_COUNT)
  71. cyg_semaphore_post(&psem->sem);
  72. else {
  73. cyg_scheduler_lock();
  74. if (gfxSemCounterI(psem) < psem->limit)
  75. cyg_semaphore_post(&psem->sem);
  76. cyg_scheduler_unlock();
  77. }
  78. }
  79. void gfxSemSignalI(gfxSem *psem)
  80. {
  81. if (psem->limit == MAX_SEMAPHORE_COUNT || gfxSemCounterI(psem) < psem->limit)
  82. cyg_semaphore_post(&psem->sem);
  83. }
  84. semcount_t gfxSemCounterI(gfxSem *psem) {
  85. semcount_t cnt;
  86. cyg_semaphore_peek(&psem->sem, &cnt);
  87. return cnt;
  88. }
  89. gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param)
  90. {
  91. gfxThreadHandle th;
  92. if (!stackarea) {
  93. if (!stacksz) stacksz = CYGNUM_HAL_STACK_SIZE_TYPICAL;
  94. if (!(stackarea = gfxAlloc(stacksz+sizeof(cyg_thread))))
  95. return 0;
  96. }
  97. if (!stacksz)
  98. return 0;
  99. cyg_thread_create(prio, fn, param, "uGFX", (((cyg_thread *)stackarea)+1), stacksz, &th, (cyg_thread *)stackarea);
  100. cyg_thread_resume(th);
  101. return th;
  102. }
  103. #endif /* GFX_USE_OS_ECOS */