The official µGFX library repository.

gos_linux.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_LINUX_H
  8. #define _GOS_LINUX_H
  9. #if GFX_USE_OS_LINUX
  10. // We don't put this in the general sys_options.h as it is Linux specific.
  11. #ifndef GFX_USE_POSIX_SEMAPHORES
  12. #define GFX_USE_POSIX_SEMAPHORES TRUE
  13. #endif
  14. #include <sys/types.h>
  15. #include <stdlib.h>
  16. #include <stdint.h>
  17. #include <pthread.h>
  18. #if GFX_USE_POSIX_SEMAPHORES
  19. #include <semaphore.h>
  20. #endif
  21. /* Already defined int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, size_t */
  22. typedef int8_t bool_t;
  23. typedef unsigned long systemticks_t;
  24. typedef void * threadreturn_t;
  25. typedef unsigned long delaytime_t;
  26. typedef pthread_t gfxThreadHandle;
  27. typedef int threadpriority_t;
  28. typedef uint32_t semcount_t;
  29. typedef pthread_mutex_t gfxMutex;
  30. #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
  31. #define DECLARE_THREAD_STACK(name, sz) uint8_t name[0];
  32. #define THREAD_RETURN(retval) return retval
  33. #define gfxExit() exit(0)
  34. #define gfxAlloc(sz) malloc(sz)
  35. #define gfxRealloc(p,osz,nsz) realloc(p, nsz)
  36. #define gfxFree(ptr) free(ptr)
  37. #define gfxMillisecondsToTicks(ms) (ms)
  38. #define gfxThreadMe() pthread_self()
  39. #define gfxThreadClose(th) (void)th
  40. #define gfxMutexInit(pmtx) pthread_mutex_init(pmtx, 0)
  41. #define gfxMutexDestroy(pmtx) pthread_mutex_destroy(pmtx)
  42. #define gfxMutexEnter(pmtx) pthread_mutex_lock(pmtx)
  43. #define gfxMutexExit(pmtx) pthread_mutex_unlock(pmtx)
  44. #define gfxSemWaitI(psem) gfxSemWait(psem, TIME_IMMEDIATE)
  45. #define gfxSemSignalI(psem) gfxSemSignal(psem)
  46. #define TIME_IMMEDIATE 0
  47. #define TIME_INFINITE ((delaytime_t)-1)
  48. #define MAX_SEMAPHORE_COUNT ((semcount_t)-1)
  49. #define LOW_PRIORITY 10
  50. #define NORMAL_PRIORITY 0
  51. #define HIGH_PRIORITY -10
  52. #if GFX_USE_POSIX_SEMAPHORES
  53. typedef struct gfxSem {
  54. sem_t sem;
  55. semcount_t max;
  56. } gfxSem;
  57. #define gfxSemCounterI(psem) gfxSemCounter(psem)
  58. #else
  59. typedef struct gfxSem {
  60. pthread_mutex_t mtx;
  61. pthread_cond_t cond;
  62. semcount_t cnt;
  63. semcount_t max;
  64. } gfxSem;
  65. #define gfxSemCounterI(psem) ((psem)->cnt)
  66. #endif
  67. /*===========================================================================*/
  68. /* Function declarations. */
  69. /*===========================================================================*/
  70. #ifdef __cplusplus
  71. extern "C" {
  72. #endif
  73. void gfxYield(void);
  74. void gfxHalt(const char *msg);
  75. void gfxSleepMilliseconds(delaytime_t ms);
  76. void gfxSleepMicroseconds(delaytime_t ms);
  77. systemticks_t gfxSystemTicks(void);
  78. void gfxSystemLock(void);
  79. void gfxSystemUnlock(void);
  80. void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
  81. void gfxSemDestroy(gfxSem *psem);
  82. bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
  83. void gfxSemSignal(gfxSem *psem);
  84. semcount_t gfxSemCounter(gfxSem *pSem);
  85. gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
  86. threadreturn_t gfxThreadWait(gfxThreadHandle thread);
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90. #endif /* GFX_USE_OS_LINUX */
  91. #endif /* _GOS_LINUX_H */