The official µGFX library repository.

gos_chibios.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #ifndef _GOS_CHIBIOS_H
  8. #define _GOS_CHIBIOS_H
  9. #if GFX_USE_OS_CHIBIOS
  10. // This shouldn't be needed but some people are complaining
  11. // about TRUE/FALSE redefinition so we fix it here.
  12. #undef TRUE
  13. #undef FALSE
  14. #include "ch.h"
  15. #include "hal.h"
  16. /*===========================================================================*/
  17. /* Type definitions */
  18. /*===========================================================================*/
  19. /**
  20. * bool_t,
  21. * int8_t, uint8_t,
  22. * int16_t, uint16_t,
  23. * int32_t, uint32_t,
  24. * size_t
  25. * TRUE, FALSE
  26. * TIME_IMMEDIATE, TIME_INFINITE
  27. * are already defined by ChibiOS
  28. */
  29. #if !defined(FALSE)
  30. #define FALSE 0
  31. #endif
  32. #if !defined(TRUE)
  33. #define TRUE -1
  34. #endif
  35. #if (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4)
  36. typedef char bool_t;
  37. #endif
  38. typedef systime_t delaytime_t;
  39. typedef systime_t systemticks_t;
  40. typedef cnt_t semcount_t;
  41. typedef msg_t threadreturn_t;
  42. typedef tprio_t threadpriority_t;
  43. #define MAX_SEMAPHORE_COUNT ((semcount_t)(((unsigned long)((semcount_t)(-1))) >> 1))
  44. #define LOW_PRIORITY LOWPRIO
  45. #define NORMAL_PRIORITY NORMALPRIO
  46. #define HIGH_PRIORITY HIGHPRIO
  47. #define DECLARE_THREAD_STACK(name, sz) WORKING_AREA(name, sz)
  48. #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
  49. #define THREAD_RETURN(retval) return retval
  50. #if CH_KERNEL_MAJOR == 2
  51. typedef struct {
  52. Semaphore sem;
  53. semcount_t limit;
  54. } gfxSem;
  55. typedef Mutex gfxMutex;
  56. typedef Thread* gfxThreadHandle;
  57. #elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4)
  58. #undef DECLARE_THREAD_STACK
  59. #define DECLARE_THREAD_STACK(a, b) THD_WORKING_AREA(a, b)
  60. typedef struct {
  61. semaphore_t sem;
  62. semcount_t limit;
  63. } gfxSem;
  64. typedef mutex_t gfxMutex;
  65. typedef thread_t* gfxThreadHandle;
  66. #endif
  67. /*===========================================================================*/
  68. /* Function declarations. */
  69. /*===========================================================================*/
  70. #ifdef __cplusplus
  71. extern "C" {
  72. #endif
  73. // First the kernel version specific ones
  74. #if CH_KERNEL_MAJOR == 2
  75. #define gfxSystemTicks() chTimeNow()
  76. #define gfxMutexInit(pmutex) chMtxInit(pmutex)
  77. #define gfxMutexExit(pmutex) chMtxUnlock()
  78. #define gfxExit() chSysHalt()
  79. #define gfxHalt(msg) { chDbgPanic(msg); chSysHalt(); }
  80. #elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4)
  81. #define gfxSystemTicks() chVTGetSystemTimeX()
  82. #define gfxMutexInit(pmutex) chMtxObjectInit(pmutex)
  83. #define gfxMutexExit(pmutex) chMtxUnlock(pmutex)
  84. #define gfxExit() osalSysHalt("gfx_exit")
  85. #define gfxHalt(msg) { chSysHalt(msg); }
  86. #endif
  87. #define gfxAlloc(sz) chHeapAlloc(0, sz)
  88. #define gfxFree(ptr) chHeapFree(ptr)
  89. #define gfxYield() chThdYield()
  90. #define gfxMillisecondsToTicks(ms) MS2ST(ms)
  91. #define gfxSystemLock() chSysLock()
  92. #define gfxSystemUnlock() chSysUnlock()
  93. #define gfxMutexDestroy(pmutex) (void)pmutex
  94. #define gfxMutexEnter(pmutex) chMtxLock(pmutex)
  95. void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz);
  96. void gfxSleepMilliseconds(delaytime_t ms);
  97. void gfxSleepMicroseconds(delaytime_t ms);
  98. void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
  99. void gfxSemDestroy(gfxSem *psem);
  100. bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
  101. bool_t gfxSemWaitI(gfxSem *psem);
  102. void gfxSemSignal(gfxSem *psem);
  103. void gfxSemSignalI(gfxSem *psem);
  104. #if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3)
  105. #define gfxSemCounterI(psem) ((psem)->sem.s_cnt)
  106. #define gfxSemCounter(psem) ((psem)->sem.s_cnt)
  107. #elif (CH_KERNEL_MAJOR == 4)
  108. #define gfxSemCounterI(psem) ((psem)->sem.cnt)
  109. #define gfxSemCounter(psem) ((psem)->sem.cnt)
  110. #endif
  111. gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
  112. #define gfxThreadWait(thread) chThdWait(thread)
  113. #define gfxThreadMe() chThdSelf()
  114. #define gfxThreadClose(thread) (void)thread
  115. #ifdef __cplusplus
  116. }
  117. #endif
  118. #endif /* GFX_USE_OS_CHIBIOS */
  119. #endif /* _GOS_CHIBIOS_H */