µGFX library fork

gos_cmsis.c 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #include <string.h>
  9. #if GFX_USE_OS_CMSIS
  10. void _gosHeapInit(void);
  11. void _gosInit(void)
  12. {
  13. #if !GFX_OS_NO_INIT
  14. osKernelInitialize();
  15. if (!osKernelRunning())
  16. osKernelStart();
  17. #elif !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 osKernelInitialize() and osKernelStart() 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 osKernelInitialize() and osKernelStart() before gfxInit() in your application!")
  22. #endif
  23. #endif
  24. // Set up the heap allocator
  25. _gosHeapInit();
  26. }
  27. void _gosPostInit(void)
  28. {
  29. }
  30. void _gosDeinit(void)
  31. {
  32. }
  33. void gfxMutexInit(gfxMutex* pmutex)
  34. {
  35. osMutexDef_t def;
  36. def.mutex = pmutex->mutex;
  37. pmutex->id = osMutexCreate(&def);
  38. }
  39. void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit)
  40. {
  41. osSemaphoreDef_t def;
  42. def.semaphore = psem->semaphore;
  43. if (val > limit) val = limit;
  44. psem->available = limit - val;
  45. psem->id = osSemaphoreCreate(&def, val);
  46. }
  47. void gfxSemDestroy(gfxSem* psem)
  48. {
  49. osSemaphoreDelete(psem->id);
  50. }
  51. bool_t gfxSemWait(gfxSem* psem, delaytime_t ms)
  52. {
  53. if (osSemaphoreWait(psem->id, ms) > 0) {
  54. psem->available++;
  55. return TRUE;
  56. }
  57. return FALSE;
  58. }
  59. bool_t gfxSemWaitI(gfxSem* psem)
  60. {
  61. return gfxSemWait(psem, 0);
  62. }
  63. void gfxSemSignal(gfxSem* psem)
  64. {
  65. gfxSemSignalI(psem);
  66. }
  67. void gfxSemSignalI(gfxSem* psem)
  68. {
  69. if (psem->available) {
  70. psem->available--;
  71. osSemaphoreRelease(psem->id);
  72. }
  73. }
  74. gfxThreadHandle gfxThreadCreate(void* stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void* param)
  75. {
  76. osThreadDef_t def;
  77. (void)stackarea;
  78. def.pthread = (os_pthread)fn;
  79. def.tpriority = prio;
  80. def.instances = 1;
  81. def.stacksize = stacksz;
  82. return osThreadCreate(&def, param);
  83. }
  84. threadreturn_t gfxThreadWait(gfxThreadHandle thread) {
  85. while(osThreadGetPriority(thread) == osPriorityError)
  86. gfxYield();
  87. }
  88. #endif /* GFX_USE_OS_CMSIS */