Browse Source

Tidy u gfxSem, gfxMutex and various Macros by converting to new types gSem, gMutex etc

release/v2.9
inmarket 3 years ago
parent
commit
8a9ed5195b
  1. 8
      changelog.txt
  2. 8
      demos/3rdparty/notepad-2/notepadApp.c
  3. 6
      demos/3rdparty/notepad-2/notepadCore.c
  4. 2
      demos/applications/combo/bounce.c
  5. 2
      demos/applications/combo/mandelbrot.c
  6. 4
      demos/games/justget10/jg10.c
  7. 4
      demos/games/minesweeper/mines.c
  8. 2
      demos/games/tetris/tetris.c
  9. 4
      demos/tools/uGFXnetDisplay/main.c
  10. 4
      drivers/multiple/X/gdisp_lld_X.c
  11. 6
      drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c
  12. 2
      drivers/multiple/uGFXnetESP8266/gdisp_lld_uGFXnetESP8266.cpp
  13. 2
      ffconf.h
  14. 2
      src/gadc/gadc.c
  15. 4
      src/gaudio/gaudio.c
  16. 2
      src/gdisp/gdisp_driver.h
  17. 8
      src/gevent/gevent.c
  18. 4
      src/gevent/gevent.h
  19. 10
      src/gfile/gfile_fatfs_wrapper.c
  20. 61
      src/gos/gos.h
  21. 14
      src/gos/gos_chibios.c
  22. 40
      src/gos/gos_chibios.h
  23. 16
      src/gos/gos_cmsis.c
  24. 40
      src/gos/gos_cmsis.h
  25. 10
      src/gos/gos_cmsis2.c
  26. 28
      src/gos/gos_cmsis2.h
  27. 18
      src/gos/gos_ecos.c
  28. 32
      src/gos/gos_ecos.h
  29. 16
      src/gos/gos_freertos.c
  30. 30
      src/gos/gos_freertos.h
  31. 20
      src/gos/gos_linux.c
  32. 40
      src/gos/gos_linux.h
  33. 12
      src/gos/gos_osx.c
  34. 32
      src/gos/gos_osx.h
  35. 22
      src/gos/gos_qt.cpp
  36. 44
      src/gos/gos_qt.h
  37. 6
      src/gos/gos_rawrtos.c
  38. 24
      src/gos/gos_rawrtos.h
  39. 6
      src/gos/gos_win32.c
  40. 22
      src/gos/gos_win32.h
  41. 18
      src/gos/gos_x_threads.c
  42. 40
      src/gos/gos_x_threads.h
  43. 20
      src/gos/gos_zephyr.h
  44. 4
      src/gqueue/gqueue.c
  45. 6
      src/gqueue/gqueue.h
  46. 12
      src/gtimer/gtimer.c
  47. 4
      src/gwin/gwin_wm.c

8
changelog.txt

@ -18,8 +18,8 @@ CHANGE: Added types gI8, gU8 .. gI32, gU32 to replace V2.x int8_t etc
CHANGE: Added type gBool to replace V2.x bool_t, and values gTrue/gFalse to replace TRUE/FALSE
CHANGE: Added type gDelay to replace V2.x delaytime_t and values gDelayNone/gDelayForever to replace TIME_IMMEDIATE/TIME_INFINITE
CHANGE: Added type gTicks to replace V2.x systemticks_t
CHANGE: Added type gThread to replace V2.x gfxThreadHandle
CHANGE: Added type gThreadreturn to replace V2.x threadreturn_t
CHANGE: Added type gThread to replace V2.x gfxThreadHandle and macros GFX_THREAD_FUNCTION/STACK to replace DECLARE_THREAD_FUNCTION & DECLARE_THREAD_STACK
CHANGE: Added type gThreadreturn to replace V2.x threadreturn_t and pseudo function gfxThreadReturn() to replace THREAD_RETURN()
CHANGE: Added type gThreadpriority to replace V2.x threadpriority_t and values gThreadpriorityLow/Normal/High to replace LOW_/NORMAL_/HIGH_PRIORITY
CHANGE: Added type gPoint to replace V2.x point and point_t
CHANGE: Added type gCoord to replace V2.x coord_t
@ -31,7 +31,9 @@ CHANGE: Added type gPowermode to replace V2.x powermode_t, and values gP
CHANGE: Added type gJustify to replace V2.x justify_t, and values gJustifyXXX replace justifyXXX
CHANGE: Added type gFontmetric to replace V2.x fontmetric_t, and values gFontXXX replace fontXXX
CHANGE: Added type gOrientation to replace V2.x orientation_t, and values gOrientationX replace GDISP_ROTATE_X
CHANGE: Added macros JUSTIFYMASK_HORIZONTAL, JUSTIFYMASK_VERTICAL to replace macros JUSTIFYMASK_LEFTRIGHT, JUSTIFYMASK_TOPBOTTOM
CHANGE: Added type gSem to replace V2.x gfxSem, and values gSemMaxCount replace MAX_SEMAPHORE_COUNT
CHANGE: Added type gMutex to replace V2.x gfxMutex
CHANGE: Added macros JUSTIFYMASK_HORIZONTAL, JUSTIFYMASK_VERTICAL to replace V2.x macros JUSTIFYMASK_LEFTRIGHT, JUSTIFYMASK_TOPBOTTOM
FEATURE: Added types gPtr, gPtrDiff and gAny
FEATURE: Added type gMemSize and config macro GFX_MEM_LT64K
FEATURE: Added type gFileSize

8
demos/3rdparty/notepad-2/notepadApp.c

@ -2,7 +2,7 @@
* File: notepadApp.c
*
* This file is a part of the Notepad demo application for ChibiOS/GFX
* Copyright © 2013, Kumar Abhishek [abhishek.kakkar@edaboard.com].
* Copyright 2013, Kumar Abhishek [abhishek.kakkar@edaboard.com].
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -70,7 +70,7 @@ static int selColorIndex = 0, selPenWidth = 1, tbMode = 1;
static NColorScheme nCurColorScheme;
static DECLARE_THREAD_FUNCTION(notepadThread, param);
static GFX_THREAD_FUNCTION(notepadThread, param);
// Custom drawing functions for the buttons
static void nbtnColorBarDraw(GHandle gh, gBool enabled, gBool isdown, const char *txt, const GButtonDrawStyle *pstyle, void *param) {
@ -311,8 +311,8 @@ static void drawVButtons(void) {
gwinButtonDraw(H(btnFill));
}
static DECLARE_THREAD_STACK(waNotepadThread, NPAD_THD_WA_SIZE);
static DECLARE_THREAD_FUNCTION(notepadThread, param) {
static GFX_THREAD_STACK(waNotepadThread, NPAD_THD_WA_SIZE);
static GFX_THREAD_FUNCTION(notepadThread, param) {
GEventMouse *pem;
GEventGWinButton *peb;

6
demos/3rdparty/notepad-2/notepadCore.c

@ -2,7 +2,7 @@
* File: notepadCore.c
*
* This file is a part of the Notepad demo application for ChibiOS/GFX
* Copyright © 2013, Kumar Abhishek [abhishek.kakkar@edaboard.com].
* Copyright 2013, Kumar Abhishek [abhishek.kakkar@edaboard.com].
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -43,7 +43,7 @@
(ev.y >= ncoreDrawingArea->y) && (ev.y <= (ncoreDrawingArea->y + ncoreDrawingArea->height)))
/* This is the drawing core */
static DECLARE_THREAD_STACK(waDrawThread, NCORE_THD_STACK_SIZE);
static GFX_THREAD_STACK(waDrawThread, NCORE_THD_STACK_SIZE);
static gU8 nPenWidth = 1;
static gU8 nMode = NCORE_MODE_DRAW;
@ -127,7 +127,7 @@ static void draw_line(gCoord x0, gCoord y0, gCoord x1, gCoord y1) {
}
/* Core thread */
static DECLARE_THREAD_FUNCTION(ncoreDrawThread, msg) {
static GFX_THREAD_FUNCTION(ncoreDrawThread, msg) {
GEventMouse ev, evPrev;
gCoord dx, dy;

2
demos/applications/combo/bounce.c

@ -62,7 +62,7 @@ static gThread thread;
#define FLOORCOLOR HTML2COLOR(0x606060)
#define SHADOWALPHA (255-255*0.2)
static DECLARE_THREAD_FUNCTION(task, param) {
static GFX_THREAD_FUNCTION(task, param) {
gCoord width, height, x, y, radius, ballx, bally, dx, floor;
gCoord minx, miny, maxx, maxy, winx, winy;
gCoord ballcx, ballcy;

2
demos/applications/combo/mandelbrot.c

@ -66,7 +66,7 @@ static void mandelbrot(float x1, float y1, float x2, float y2) {
}
}
static DECLARE_THREAD_FUNCTION(task, param) {
static GFX_THREAD_FUNCTION(task, param) {
float cx, cy;
float zoom = 1.0f;
(void) param;

4
demos/games/justget10/jg10.c

@ -223,7 +223,7 @@ static void printCongrats(void) {
gdispDrawString(JG10_TOTAL_FIELD_WIDTH+((gdispGetWidth()-JG10_TOTAL_FIELD_WIDTH)/2)-(gdispGetStringWidth(pps_str, font)/2), (gdispGetHeight()/2)+20, pps_str, font, GFX_RED);
}
static DECLARE_THREAD_FUNCTION(thdJg10, msg) {
static GFX_THREAD_FUNCTION(thdJg10, msg) {
(void)msg;
gU16 x,y;
while (!jg10GameOver) {
@ -273,7 +273,7 @@ static DECLARE_THREAD_FUNCTION(thdJg10, msg) {
}
}
}
THREAD_RETURN(0);
gfxThreadReturn(0);
}
static void initField(void) {

4
demos/games/minesweeper/mines.c

@ -192,7 +192,7 @@ static void openEmptyNodes(void)
}
}
static DECLARE_THREAD_FUNCTION(thdMines, msg)
static GFX_THREAD_FUNCTION(thdMines, msg)
{
(void)msg;
gU16 x,y, delay;
@ -245,7 +245,7 @@ static DECLARE_THREAD_FUNCTION(thdMines, msg)
}
}
}
THREAD_RETURN(0);
gfxThreadReturn(0);
}
static void printGameOver(void)

2
demos/games/tetris/tetris.c

@ -427,7 +427,7 @@ static void goLeft(void) {
}
}
static DECLARE_THREAD_FUNCTION(thdTetris, arg) {
static GFX_THREAD_FUNCTION(thdTetris, arg) {
(void)arg;
gU8 i;
while (!tetrisGameOver) {

4
demos/tools/uGFXnetDisplay/main.c

@ -182,8 +182,8 @@ static gBool sendpkt(gU16 *pkt, int len) {
* We do the send in a single transaction to prevent it getting interspersed with
* any reply we need to send on the main thread.
*/
static DECLARE_THREAD_STACK(waNetThread, 512);
static DECLARE_THREAD_FUNCTION(NetThread, param) {
static GFX_THREAD_STACK(waNetThread, 512);
static GFX_THREAD_FUNCTION(NetThread, param) {
GEventMouse *pem;
gU16 cmd[2];
gU16 lbuttons;

4
drivers/multiple/X/gdisp_lld_X.c

@ -270,8 +270,8 @@ static void ProcessEvent(GDisplay *g, xPriv *priv) {
}
/* this is the X11 thread which keeps track of all events */
static DECLARE_THREAD_STACK(waXThread, 1024);
static DECLARE_THREAD_FUNCTION(ThreadX, arg) {
static GFX_THREAD_STACK(waXThread, 1024);
static GFX_THREAD_FUNCTION(ThreadX, arg) {
GDisplay *g;
(void)arg;

6
drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c

@ -168,7 +168,7 @@ typedef struct netPriv {
static gThread hThread;
#if GDISP_GFXNET_UNSAFE_SOCKETS
static gfxMutex uGFXnetMutex;
static gMutex uGFXnetMutex;
#define MUTEX_INIT gfxMutexInit(&uGFXnetMutex)
#define MUTEX_ENTER gfxMutexEnter(&uGFXnetMutex)
#define MUTEX_EXIT gfxMutexExit(&uGFXnetMutex)
@ -318,8 +318,8 @@ static gBool rxdata(SOCKET_TYPE fd) {
return gTrue;
}
static DECLARE_THREAD_STACK(waNetThread, 512);
static DECLARE_THREAD_FUNCTION(NetThread, param) {
static GFX_THREAD_STACK(waNetThread, 512);
static GFX_THREAD_FUNCTION(NetThread, param) {
SOCKET_TYPE listenfd, fdmax, i, clientfd;
socklen_t len;
fd_set master, read_fds;

2
drivers/multiple/uGFXnetESP8266/gdisp_lld_uGFXnetESP8266.cpp

@ -126,7 +126,7 @@ typedef struct netPriv {
} netPriv;
#if GDISP_GFXNET_UNSAFE_SOCKETS
static gfxMutex uGFXnetMutex;
static gMutex uGFXnetMutex;
#define MUTEX_INIT gfxMutexInit(&uGFXnetMutex)
#define MUTEX_ENTER gfxMutexEnter(&uGFXnetMutex)
#define MUTEX_EXIT gfxMutexExit(&uGFXnetMutex)

2
ffconf.h

@ -244,7 +244,7 @@
#define FF_FS_REENTRANT 0
#define FF_FS_TIMEOUT 1000
#define FF_SYNC_t gfxSem
#define FF_SYNC_t gSem
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
/ module itself. Note that regardless of this option, file access to different
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()

2
src/gadc/gadc.c

@ -25,7 +25,7 @@ typedef struct NonTimerData_t {
GADCCallbackFunction callback;
union {
void *param;
gfxSem sigdone;
gSem sigdone;
};
GadcNonTimerJob job;
} NonTimerData;

4
src/gaudio/gaudio.c

@ -13,8 +13,8 @@
#include "gaudio_driver_play.h"
static gfxQueueASync playList;
static gfxSem playComplete;
static gU16 playFlags;
static gSem playComplete;
static gU16 playFlags;
#define PLAYFLG_USEEVENTS 0x0001
#define PLAYFLG_PLAYING 0x0002
#define PLAYFLG_ISINIT 0x0004

2
src/gdisp/gdisp_driver.h

@ -338,7 +338,7 @@ struct GDisplay {
// Multithread Mutex
#if GDISP_NEED_MULTITHREAD
gfxMutex mutex;
gMutex mutex;
#endif
// Software clipping

8
src/gevent/gevent.c

@ -20,7 +20,7 @@
#define GLISTENER_WITHSOURCE 0x0002 // The source is currently using the buffer
/* This mutex protects access to our tables */
static gfxMutex geventMutex;
static gMutex geventMutex;
/* Our table of listener/source pairs */
static GSourceListener Assignments[GEVENT_MAX_SOURCE_LISTENERS];
@ -62,9 +62,9 @@ void _geventDeinit(void)
}
void geventListenerInit(GListener *pl) {
gfxSemInit(&pl->waitqueue, 0, MAX_SEMAPHORE_COUNT); // Next wait'er will block
pl->callback = 0; // No callback active
pl->event.type = GEVENT_NULL; // Always safety
gfxSemInit(&pl->waitqueue, 0, gSemMaxCount); // Next wait'er will block
pl->callback = 0; // No callback active
pl->event.type = GEVENT_NULL; // Always safety
pl->flags = 0;
}

4
src/gevent/gevent.h

@ -55,8 +55,8 @@ typedef void (*GEventCallbackFn)(void *param, GEvent *pe);
// The Listener Object
typedef struct GListener {
gfxSem waitqueue; // Private: Semaphore for the listener to wait on.
gU16 flags; // Private: Flags for operation
gSem waitqueue; // Private: Semaphore for the listener to wait on.
gU16 flags; // Private: Flags for operation
GEventCallbackFn callback; // Private: Call back Function
void *param; // Private: Parameter for the callback function.
GEvent event; // Public: The event object into which the event information is stored.

10
src/gfile/gfile_fatfs_wrapper.c

@ -20,7 +20,7 @@
/*------------------------------------------------------------------------*/
/* Static array of Synchronization Objects */
/*------------------------------------------------------------------------*/
static gfxSem ff_sem[_VOLUMES];
static gSem ff_sem[_VOLUMES];
/*------------------------------------------------------------------------*/
/* Create a Synchronization Object */
@ -28,7 +28,7 @@
int ff_cre_syncobj(BYTE vol, _SYNC_t *sobj)
{
*sobj = ff_sem[vol];
gfxSemInit(sobj, 1, MAX_SEMAPHORE_COUNT);
gfxSemInit(sobj, 1, gSemMaxCount);
return 1;
}
@ -38,7 +38,7 @@
/*------------------------------------------------------------------------*/
int ff_del_syncobj(_SYNC_t sobj)
{
gfxSemDestroy( (gfxSem*)&sobj );
gfxSemDestroy( (gSem*)&sobj );
return 1;
}
@ -48,7 +48,7 @@
/*------------------------------------------------------------------------*/
int ff_req_grant(_SYNC_t sobj)
{
if (gfxSemWait( (gfxSem*)&sobj, (gDelay)_FS_TIMEOUT) )
if (gfxSemWait( (gSem*)&sobj, (gDelay)_FS_TIMEOUT) )
return gTrue;
return gFalse;
}
@ -58,7 +58,7 @@
/*------------------------------------------------------------------------*/
void ff_rel_grant(_SYNC_t sobj)
{
gfxSemSignal( (gfxSem*)&sobj );
gfxSemSignal( (gSem*)&sobj );
}
#endif /* _FS_REENTRANT */

61
src/gos/gos.h

@ -48,7 +48,7 @@
* @note GFX_TYPE_64 is set to GFXON or GFXOFF by the compiler detector. It is not a user configuration macro.
* @{
*/
typedef long long gI64;
typedef long long gI64;
typedef unsigned long long gU64;
/** @} */
@ -70,7 +70,7 @@
* @param[in] fnName The name of the function
* @param[in] param A custom parameter that is passed to the function
*/
#define DECLARE_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void *param)
#define GFX_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void *param)
/**
* @brief Declare a thread stack
@ -82,17 +82,7 @@
* Many platforms will round the size to ensure correct stack alignment.
* Other platforms may entirely ignore the suggested size.
*/
#define DECLARE_THREAD_STACK(name, sz) gU8 name[sz];
/*
* @brief Return from a thread
*
* @details Some underlying operating systems allow to return a value from a thread while others don't.
* For systems that don't allow to return a value from a thread function this call is simply ignored.
*
* @param[in] reval The value which should be returned
*/
#define THREAD_RETURN(retval) return retval
#define GFX_THREAD_STACK(name, sz) gU8 name[sz];
/**
* @name Various platform (and operating system) constants
@ -101,7 +91,7 @@
*/
#define gDelayNone 0
#define gDelayForever ((gDelay)-1)
#define MAX_SEMAPHORE_COUNT ((gSemcount)(((unsigned long)((gSemcount)(-1))) >> 1))
#define gSemMaxCount ((gSemcount)(((unsigned long)((gSemcount)(-1))) >> 1))
#define gThreadpriorityLow 0
#define gThreadpriorityNormal 1
#define gThreadpriorityHigh 2
@ -111,13 +101,13 @@
* @brief A semaphore
* @note Your operating system will have a proper definition for this structure
*/
typedef struct {} gfxSem;
typedef struct {} gSem;
/**
* @brief A mutex
* @note Your operating system will have a proper definition for this structure
*/
typedef struct {} gfxMutex;
typedef struct {} gMutex;
/**
* @brief A thread handle
@ -297,7 +287,7 @@
*
* @api
*/
void gfxMutexInit(gfxMutex *pmutex);
void gfxMutexInit(gMutex *pmutex);
/**
* @brief Destroy a Mutex.
@ -306,7 +296,7 @@
*
* @api
*/
void gfxMutexDestroy(gfxMutex *pmutex);
void gfxMutexDestroy(gMutex *pmutex);
/**
* @brief Enter the critical code region protected by the mutex.
@ -316,7 +306,7 @@
*
* @api
*/
void gfxMutexEnter(gfxMutex *pmutex);
void gfxMutexEnter(gMutex *pmutex);
/**
* @brief Exit the critical code region protected by the mutex.
@ -326,7 +316,7 @@
*
* @api
*/
void gfxMutexExit(gfxMutex *pmutex);
void gfxMutexExit(gMutex *pmutex);
/**
* @brief Initialise a Counted Semaphore
@ -344,7 +334,7 @@
*
* @api
*/
void gfxSemInit(gfxSem *psem, gSemcount val, gSemcount limit);
void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit);
/**
* @brief Destroy a Counted Semaphore
@ -355,7 +345,7 @@
*
* @api
*/
void gfxSemDestroy(gfxSem *psem);
void gfxSemDestroy(gSem *psem);
/**
* @brief Wait on a semaphore
@ -368,7 +358,7 @@
*
* @api
*/
gBool gfxSemWait(gfxSem *psem, gDelay ms);
gBool gfxSemWait(gSem *psem, gDelay ms);
/**
* @brief Test if a wait on a semaphore can be satisfied immediately
@ -380,7 +370,7 @@
* @iclass
* @api
*/
gBool gfxSemWaitI(gfxSem *psem);
gBool gfxSemWaitI(gSem *psem);
/**
* @brief Signal a semaphore
@ -392,7 +382,7 @@
*
* @api
*/
void gfxSemSignal(gfxSem *psem);
void gfxSemSignal(gSem *psem);
/**
* @brief Signal a semaphore
@ -405,7 +395,7 @@
* @iclass
* @api
*/
void gfxSemSignalI(gfxSem *psem);
void gfxSemSignalI(gSem *psem);
/**
* @brief Start a new thread.
@ -420,7 +410,7 @@
*
* @api
*/
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void *param);
/**
* @brief Wait for a thread to finish.
@ -453,6 +443,17 @@
*/
void gfxThreadClose(gThread thread);
/*
* @brief Return from a thread
*
* @details Some underlying operating systems allow to return a value from a thread while others don't.
* For systems that don't allow to return a value from a thread function this call is simply ignored.
* @pre This pseudo function can only be called within the main body of the thread function (not a sub-function)
*
* @param[in] reval The value which should be returned
*/
#define gfxThreadReturn(retval) return retval
/**
* All the above was just for the doxygen documentation. All the implementation of the above
* (without any of the documentation overheads) is in the files below.
@ -502,11 +503,17 @@
#endif
typedef gTicks systemticks_t;
typedef gThread gfxThreadHandle;
#define DECLARE_THREAD_FUNCTION GFX_THREAD_FUNCTION
#define DECLARE_THREAD_STACK GFX_THREAD_STACK
typedef gThreadreturn threadreturn_t;
#define THREAD_RETURN gfxThreadReturn
typedef gThreadpriority threadpriority_t;
#define LOW_PRIORITY gThreadpriorityLow
#define NORMAL_PRIORITY gThreadpriorityNormal
#define HIGH_PRIORITY gThreadpriorityHigh
typedef gSem gfxSem;
#define MAX_SEMAPHORE_COUNT gSemMaxCount
typedef gMutex gfxMutex;
#endif
#endif /* _GOS_H */

14
src/gos/gos_chibios.c

@ -99,7 +99,7 @@ void gfxSleepMicroseconds(gDelay ms)
}
}
void gfxSemInit(gfxSem *psem, gSemcount val, gSemcount limit)
void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit)
{
if (val > limit)
val = limit;
@ -113,12 +113,12 @@ void gfxSemInit(gfxSem *psem, gSemcount val, gSemcount limit)
#endif
}
void gfxSemDestroy(gfxSem *psem)
void gfxSemDestroy(gSem *psem)
{
chSemReset(&psem->sem, 1);
}
gBool gfxSemWait(gfxSem *psem, gDelay ms)
gBool gfxSemWait(gSem *psem, gDelay ms)
{
#if CH_KERNEL_MAJOR <= 2
switch(ms) {
@ -135,7 +135,7 @@ gBool gfxSemWait(gfxSem *psem, gDelay ms)
#endif
}
gBool gfxSemWaitI(gfxSem *psem)
gBool gfxSemWaitI(gSem *psem)
{
#if CH_KERNEL_MAJOR <= 3
if (psem->sem.s_cnt <= 0)
@ -148,7 +148,7 @@ gBool gfxSemWaitI(gfxSem *psem)
return gTrue;
}
void gfxSemSignal(gfxSem *psem)
void gfxSemSignal(gSem *psem)
{
chSysLock();
@ -164,7 +164,7 @@ void gfxSemSignal(gfxSem *psem)
chSysUnlock();
}
void gfxSemSignalI(gfxSem *psem)
void gfxSemSignalI(gSem *psem)
{
#if CH_KERNEL_MAJOR <= 3
if (psem->sem.s_cnt < psem->limit)
@ -175,7 +175,7 @@ void gfxSemSignalI(gfxSem *psem)
#endif
}
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param)
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void *param)
{
if (!stackarea) {
if (!stacksz) stacksz = 256;

40
src/gos/gos_chibios.h

@ -38,33 +38,33 @@ typedef cnt_t gSemcount;
typedef msg_t gThreadreturn;
typedef tprio_t gThreadpriority;
#define MAX_SEMAPHORE_COUNT ((gSemcount)(((unsigned long)((gSemcount)(-1))) >> 1))
#define gThreadpriorityLow LOWPRIO
#define gThreadpriorityNormal NORMALPRIO
#define gThreadpriorityHigh HIGHPRIO
#define gSemMaxCount ((gSemcount)(((unsigned long)((gSemcount)(-1))) >> 1))
#define gThreadpriorityLow LOWPRIO
#define gThreadpriorityNormal NORMALPRIO
#define gThreadpriorityHigh HIGHPRIO
#define DECLARE_THREAD_STACK(name, sz) WORKING_AREA(name, sz)
#define DECLARE_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void *param)
#define THREAD_RETURN(retval) return retval
#define GFX_THREAD_STACK(name, sz) WORKING_AREA(name, sz)
#define GFX_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void *param)
#define gfxThreadReturn(retval) return retval
#if CH_KERNEL_MAJOR <= 2
typedef struct {
Semaphore sem;
gSemcount limit;
} gfxSem;
} gSem;
typedef Mutex gfxMutex;
typedef Mutex gMutex;
typedef Thread* gThread;
#else
#undef DECLARE_THREAD_STACK
#define DECLARE_THREAD_STACK(a, b) THD_WORKING_AREA(a, b)
#undef GFX_THREAD_STACK
#define GFX_THREAD_STACK(a, b) THD_WORKING_AREA(a, b)
typedef struct {
semaphore_t sem;
gSemcount limit;
} gfxSem;
} gSem;
typedef mutex_t gfxMutex;
typedef mutex_t gMutex;
typedef thread_t* gThread;
#endif
@ -104,13 +104,13 @@ typedef tprio_t gThreadpriority;
void *gfxRealloc(void *ptr, gMemSize oldsz, gMemSize newsz);
void gfxSleepMilliseconds(gDelay ms);
void gfxSleepMicroseconds(gDelay ms);
void gfxSemInit(gfxSem *psem, gSemcount val, gSemcount limit);
void gfxSemDestroy(gfxSem *psem);
gBool gfxSemWait(gfxSem *psem, gDelay ms);
gBool gfxSemWaitI(gfxSem *psem);
void gfxSemSignal(gfxSem *psem);
void gfxSemSignalI(gfxSem *psem);
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit);
void gfxSemDestroy(gSem *psem);
gBool gfxSemWait(gSem *psem, gDelay ms);
gBool gfxSemWaitI(gSem *psem);
void gfxSemSignal(gSem *psem);
void gfxSemSignalI(gSem *psem);
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void *param);
#define gfxThreadWait(thread) chThdWait(thread)
#define gfxThreadMe() chThdSelf()
#define gfxThreadClose(thread) (void)thread

16
src/gos/gos_cmsis.c

@ -38,7 +38,7 @@ void _gosDeinit(void)
{
}
void gfxMutexInit(gfxMutex* pmutex)
void gfxMutexInit(gMutex* pmutex)
{
osMutexDef_t def;
def.mutex = pmutex->mutex;
@ -46,7 +46,7 @@ void gfxMutexInit(gfxMutex* pmutex)
pmutex->id = osMutexCreate(&def);
}
void gfxSemInit(gfxSem* psem, gSemcount val, gSemcount limit)
void gfxSemInit(gSem* psem, gSemcount val, gSemcount limit)
{
osSemaphoreDef_t def;
def.semaphore = psem->semaphore;
@ -56,12 +56,12 @@ void gfxSemInit(gfxSem* psem, gSemcount val, gSemcount limit)
psem->id = osSemaphoreCreate(&def, val);
}
void gfxSemDestroy(gfxSem* psem)
void gfxSemDestroy(gSem* psem)
{
osSemaphoreDelete(psem->id);
}
gBool gfxSemWait(gfxSem* psem, gDelay ms)
gBool gfxSemWait(gSem* psem, gDelay ms)
{
if (osSemaphoreWait(psem->id, ms) > 0) {
psem->available++;
@ -70,17 +70,17 @@ gBool gfxSemWait(gfxSem* psem, gDelay ms)
return gFalse;
}
gBool gfxSemWaitI(gfxSem* psem)
gBool gfxSemWaitI(gSem* psem)
{
return gfxSemWait(psem, 0);
}
void gfxSemSignal(gfxSem* psem)
void gfxSemSignal(gSem* psem)
{
gfxSemSignalI(psem);
}
void gfxSemSignalI(gfxSem* psem)
void gfxSemSignalI(gSem* psem)
{
if (psem->available) {
psem->available--;
@ -88,7 +88,7 @@ void gfxSemSignalI(gfxSem* psem)
}
}
gThread gfxThreadCreate(void* stackarea, gMemSize stacksz, gThreadpriority prio, DECLARE_THREAD_FUNCTION((*fn),p), void* param)
gThread gfxThreadCreate(void* stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void* param)
{
osThreadDef_t def;

40
src/gos/gos_cmsis.h

@ -27,33 +27,33 @@
#define gDelayNone 0
#define gDelayForever osWaitForever
typedef gU32 gDelay;
typedef gU32 gTicks;
typedef gU16 gSemcount;
typedef gU32 gDelay;
typedef gU32 gTicks;
typedef gU16 gSemcount;
typedef void gThreadreturn;
typedef osPriority gThreadpriority;
#define MAX_SEMAPHORE_COUNT osFeature_Semaphore
#define gSemMaxCount osFeature_Semaphore
#define gThreadpriorityLow osPriorityLow
#define gThreadpriorityNormal osPriorityNormal
#define gThreadpriorityNormal osPriorityNormal
#define gThreadpriorityHigh osPriorityHigh
typedef struct gfxSem {
typedef struct gSem {
gU32 semaphore[2];
osSemaphoreId id;
gSemcount available;
} gfxSem;
} gSem;
typedef struct gfxMutex {
typedef struct gMutex {
gU32 mutex[4];
osMutexId id;
} gfxMutex;
} gMutex;
typedef osThreadId gThread;
#define DECLARE_THREAD_STACK(name, sz) gU8 name[1]; // Some compilers don't allow zero sized arrays. Let's waste one byte
#define DECLARE_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void* param)
#define THREAD_RETURN(retval)
#define GFX_THREAD_STACK(name, sz) gU8 name[1]; // Some compilers don't allow zero sized arrays. Let's waste one byte
#define GFX_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void* param)
#define gfxThreadReturn(retval) return
/*===========================================================================*/
/* Function declarations. */
@ -67,19 +67,19 @@ typedef osThreadId gThread;
#define gfxSystemUnlock() osKernelStart()
#define gfxSleepMilliseconds(ms) osDelay(ms)
void gfxMutexInit(gfxMutex* pmutex);
void gfxMutexInit(gMutex* pmutex);
#define gfxMutexDestroy(pmutex) osMutexDelete((pmutex)->id)
#define gfxMutexEnter(pmutex) osMutexWait((pmutex)->id, gDelayForever)
#define gfxMutexExit(pmutex) osMutexRelease((pmutex)->id)
void gfxSemInit(gfxSem* psem, gSemcount val, gSemcount limit);
void gfxSemDestroy(gfxSem* psem);
gBool gfxSemWait(gfxSem* psem, gDelay ms);
gBool gfxSemWaitI(gfxSem* psem);
void gfxSemSignal(gfxSem* psem);
void gfxSemSignalI(gfxSem* psem);
void gfxSemInit(gSem* psem, gSemcount val, gSemcount limit);
void gfxSemDestroy(gSem* psem);
gBool gfxSemWait(gSem* psem, gDelay ms);
gBool gfxSemWaitI(gSem* psem);
void gfxSemSignal(gSem* psem);
void gfxSemSignalI(gSem* psem);
gThread gfxThreadCreate(void* stackarea, gMemSize stacksz, gThreadpriority prio, DECLARE_THREAD_FUNCTION((*fn),p), void* param);
gThread gfxThreadCreate(void* stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void* param);
#define gfxYield() osThreadYield()
#define gfxThreadMe() osThreadGetId()
#define gfxThreadClose(thread) {}

10
src/gos/gos_cmsis2.c

@ -31,7 +31,7 @@ void _gosInit(void)
}
#if !GFX_OS_NO_INIT && GFX_OS_CALL_UGFXMAIN
static DECLARE_THREAD_FUNCTION(startUGFX_CMSIS2, p) {
static GFX_THREAD_FUNCTION(startUGFX_CMSIS2, p) {
(void) p;
uGFXMain();
}
@ -59,24 +59,24 @@ void _gosDeinit(void)
{
}
void gfxMutexInit(gfxMutex* pmutex)
void gfxMutexInit(gMutex* pmutex)
{
*pmutex = osMutexNew(NULL);
}
void gfxSemInit(gfxSem* psem, gSemcount val, gSemcount limit)
void gfxSemInit(gSem* psem, gSemcount val, gSemcount limit)
{
*psem = osSemaphoreNew(limit, val, NULL);
}
gBool gfxSemWait(gfxSem* psem, gDelay ms)
gBool gfxSemWait(gSem* psem, gDelay ms)
{
if (osSemaphoreAcquire(*psem, gfxMillisecondsToTicks(ms)) == osOK)
return gTrue;
return gFalse;
}
gThread gfxThreadCreate(void* stackarea, gMemSize stacksz, gThreadpriority prio, DECLARE_THREAD_FUNCTION((*fn),p), void* param)
gThread gfxThreadCreate(void* stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void* param)
{
osThreadAttr_t def;

28
src/gos/gos_cmsis2.h

@ -27,26 +27,26 @@
#define gDelayNone 0
#define gDelayForever osWaitForever
typedef gU32 gDelay;
typedef gU32 gTicks;
typedef gU16 gSemcount;
typedef gU32 gDelay;
typedef gU32 gTicks;
typedef gU16 gSemcount;
typedef void gThreadreturn;
typedef osPriority_t gThreadpriority;
#define MAX_SEMAPHORE_COUNT 65535UL
#define gSemMaxCount 65535UL
#define gThreadpriorityLow osPriorityLow
#define gThreadpriorityNormal osPriorityNormal
#define gThreadpriorityNormal osPriorityNormal
#define gThreadpriorityHigh osPriorityHigh
typedef osSemaphoreId_t gfxSem;
typedef osSemaphoreId_t gSem;
typedef osMutexId_t gfxMutex;
typedef osMutexId_t gMutex;
typedef osThreadId_t gThread;
#define DECLARE_THREAD_STACK(name, sz) gU8 name[1]; // Some compilers don't allow zero sized arrays. Let's waste one byte
#define DECLARE_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void* param)
#define THREAD_RETURN(retval)
#define GFX_THREAD_STACK(name, sz) gU8 name[1]; // Some compilers don't allow zero sized arrays. Let's waste one byte
#define GFX_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void* param)
#define gfxThreadReturn(retval) return
/*===========================================================================*/
/* Function declarations. */
@ -60,19 +60,19 @@ typedef osThreadId_t gThread;
#define gfxSystemUnlock() osKernelUnlock()
#define gfxSleepMilliseconds(ms) osDelay(ms)
void gfxMutexInit(gfxMutex* pmutex);
void gfxMutexInit(gMutex* pmutex);
#define gfxMutexDestroy(pmutex) osMutexDelete(*(pmutex))
#define gfxMutexEnter(pmutex) osMutexAcquire(*(pmutex), gDelayForever)
#define gfxMutexExit(pmutex) osMutexRelease(*(pmutex))
void gfxSemInit(gfxSem* psem, gSemcount val, gSemcount limit);
void gfxSemInit(gSem* psem, gSemcount val, gSemcount limit);
#define gfxSemDestroy(psem) osSemaphoreDelete(*(psem))
gBool gfxSemWait(gfxSem* psem, gDelay ms);
gBool gfxSemWait(gSem* psem, gDelay ms);
#define gfxSemWaitI(psem) gfxSemWait((psem), 0)
#define gfxSemSignal(psem) osSemaphoreRelease(*(psem))
#define gfxSemSignalI(psem) osSemaphoreRelease(*(psem))
gThread gfxThreadCreate(void* stackarea, gMemSize stacksz, gThreadpriority prio, DECLARE_THREAD_FUNCTION((*fn),p), void* param);
gThread gfxThreadCreate(void* stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void* param);
#define gfxYield() osThreadYield()
#define gfxThreadMe() osThreadGetId()
#define gfxThreadClose(thread) {}

18
src/gos/gos_ecos.c

@ -50,7 +50,7 @@ void gfxSleepMicroseconds(gDelay ms)
}
}
void gfxSemInit(gfxSem *psem, gSemcount val, gSemcount limit)
void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit)
{
if (val > limit)
val = limit;
@ -59,12 +59,12 @@ void gfxSemInit(gfxSem *psem, gSemcount val, gSemcount limit)
cyg_semaphore_init(&psem->sem, val);
}
void gfxSemDestroy(gfxSem *psem)
void gfxSemDestroy(gSem *psem)
{
cyg_semaphore_destroy(&psem->sem);
}
gBool gfxSemWait(gfxSem *psem, gDelay ms)
gBool gfxSemWait(gSem *psem, gDelay ms)
{
switch(ms) {
case gDelayNone: return cyg_semaphore_trywait(&psem->sem);
@ -73,14 +73,14 @@ gBool gfxSemWait(gfxSem *psem, gDelay ms)
}
}
gBool gfxSemWaitI(gfxSem *psem)
gBool gfxSemWaitI(gSem *psem)
{
return cyg_semaphore_trywait(&psem->sem);
}
void gfxSemSignal(gfxSem *psem)
void gfxSemSignal(gSem *psem)
{
if (psem->limit == MAX_SEMAPHORE_COUNT)
if (psem->limit == gSemMaxCount)
cyg_semaphore_post(&psem->sem);
else {
cyg_scheduler_lock();
@ -90,13 +90,13 @@ void gfxSemSignal(gfxSem *psem)
}
}
void gfxSemSignalI(gfxSem *psem)
void gfxSemSignalI(gSem *psem)
{
if (psem->limit == MAX_SEMAPHORE_COUNT || cyg_semaphore_peek(&psem->sem, &cnt) < psem->limit)
if (psem->limit == gSemMaxCount || cyg_semaphore_peek(&psem->sem, &cnt) < psem->limit)
cyg_semaphore_post(&psem->sem);
}
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param)
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void *param)
{
gThread th;

32
src/gos/gos_ecos.h

@ -28,21 +28,21 @@ typedef void gThreadreturn;
typedef cyg_addrword_t gThreadpriority;
typedef cyg_handle_t gThread;
#define MAX_SEMAPHORE_COUNT 0x7FFFFFFF
#define gThreadpriorityLow (CYGNUM_KERNEL_SCHED_PRIORITIES-2)
#define gThreadpriorityNormal (CYGNUM_KERNEL_SCHED_PRIORITIES/2)
#define gThreadpriorityHigh 0
#define gSemMaxCount 0x7FFFFFFF
#define gThreadpriorityLow (CYGNUM_KERNEL_SCHED_PRIORITIES-2)
#define gThreadpriorityNormal (CYGNUM_KERNEL_SCHED_PRIORITIES/2)
#define gThreadpriorityHigh 0
#define DECLARE_THREAD_STACK(name, sz) struct { cyg_thread t; unsigned char stk[(sz) & ~3]; } name[1]
#define DECLARE_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(cyg_addrword_t param)
#define THREAD_RETURN(retval)
#define GFX_THREAD_STACK(name, sz) struct { cyg_thread t; unsigned char stk[(sz) & ~3]; } name[1]
#define GFX_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(cyg_addrword_t param)
#define gfxThreadReturn(retval) return
typedef struct {
cyg_sem_t sem;
gSemcount limit;
} gfxSem;
} gSem;
typedef cyg_mutex_t gfxMutex;
typedef cyg_mutex_t gMutex;
/*===========================================================================*/
@ -70,14 +70,14 @@ void gfxSleepMicroseconds(gDelay ms);
#define gfxMutexDestroy(pmutex) cyg_mutex_destroy(pmutex)
#define gfxMutexEnter(pmutex) cyg_mutex_lock(pmutex)
void gfxSemInit(gfxSem *psem, gSemcount val, gSemcount limit);
void gfxSemDestroy(gfxSem *psem);
gBool gfxSemWait(gfxSem *psem, gDelay ms);
gBool gfxSemWaitI(gfxSem *psem);
void gfxSemSignal(gfxSem *psem);
void gfxSemSignalI(gfxSem *psem);
void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit);
void gfxSemDestroy(gSem *psem);
gBool gfxSemWait(gSem *psem, gDelay ms);
gBool gfxSemWaitI(gSem *psem);
void gfxSemSignal(gSem *psem);
void gfxSemSignalI(gSem *psem);
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void *param);
#define gfxThreadWait(thread) NOTIMPLEMENTED_YET
#define gfxThreadMe() cyg_thread_self()
#define gfxThreadClose(thread) (void)thread

16
src/gos/gos_freertos.c

@ -42,7 +42,7 @@ void _gosInit(void)
}
#if !GFX_OS_NO_INIT && GFX_OS_CALL_UGFXMAIN
static DECLARE_THREAD_FUNCTION(startUGFX_FreeRTOS, p) {
static GFX_THREAD_FUNCTION(startUGFX_FreeRTOS, p) {
(void) p;
uGFXMain();
}
@ -98,7 +98,7 @@ void gfxSleepMicroseconds(gDelay ms)
// vUsDelay(ms%1000);
}
void gfxMutexInit(gfxMutex *pmutex)
void gfxMutexInit(gMutex *pmutex)
{
*pmutex = xSemaphoreCreateMutex();
#if GFX_FREERTOS_USE_TRACE
@ -106,7 +106,7 @@ void gfxMutexInit(gfxMutex *pmutex)
#endif
}
void gfxSemInit(gfxSem* psem, gSemcount val, gSemcount limit)
void gfxSemInit(gSem* psem, gSemcount val, gSemcount limit)
{
if (val > limit)
val = limit;
@ -117,14 +117,14 @@ void gfxSemInit(gfxSem* psem, gSemcount val, gSemcount limit)
#endif
}
gBool gfxSemWait(gfxSem* psem, gDelay ms)
gBool gfxSemWait(gSem* psem, gDelay ms)
{
if (xSemaphoreTake(*psem, gfxMillisecondsToTicks(ms)) == pdPASS)
return gTrue;
return gFalse;
}
gBool gfxSemWaitI(gfxSem* psem)
gBool gfxSemWaitI(gSem* psem)
{
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
@ -133,20 +133,20 @@ gBool gfxSemWaitI(gfxSem* psem)
return gFalse;
}
void gfxSemSignal(gfxSem* psem)
void gfxSemSignal(gSem* psem)
{
xSemaphoreGive(*psem);
taskYIELD();
}
void gfxSemSignalI(gfxSem* psem)
void gfxSemSignalI(gSem* psem)
{
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(*psem,&xHigherPriorityTaskWoken);
}
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param)
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void *param)
{
gThread task;
(void) stackarea;

30
src/gos/gos_freertos.h

@ -26,24 +26,24 @@
#define gDelayNone 0
#define gDelayForever ((gDelay)-1)
typedef gU32 gDelay;
typedef gU32 gDelay;
typedef portTickType gTicks;
typedef gI32 gSemcount;
typedef void gThreadreturn;
typedef portBASE_TYPE gThreadpriority;
#define MAX_SEMAPHORE_COUNT ((gSemcount)(((unsigned long)((gSemcount)(-1))) >> 1))
#define gSemMaxCount ((gSemcount)(((unsigned long)((gSemcount)(-1))) >> 1))
#define gThreadpriorityLow 0
#define gThreadpriorityNormal configMAX_PRIORITIES/2
#define gThreadpriorityNormal configMAX_PRIORITIES/2
#define gThreadpriorityHigh configMAX_PRIORITIES-1
/* FreeRTOS will allocate the stack when creating the thread */
#define DECLARE_THREAD_STACK(name, sz) gU8 name[1]
#define DECLARE_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void *param)
#define THREAD_RETURN(retval)
#define GFX_THREAD_STACK(name, sz) gU8 name[1]
#define GFX_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void *param)
#define gfxThreadReturn(retval) return
typedef xSemaphoreHandle gfxSem;
typedef xSemaphoreHandle gfxMutex;
typedef xSemaphoreHandle gSem;
typedef xSemaphoreHandle gMutex;
typedef xTaskHandle gThread;
/*===========================================================================*/
@ -60,7 +60,7 @@ typedef xTaskHandle gThread;
#define gfxSystemLock() taskENTER_CRITICAL()
#define gfxSystemUnlock() taskEXIT_CRITICAL()
void gfxMutexInit(gfxMutex* s);
void gfxMutexInit(gMutex* s);
#define gfxMutexDestroy(pmutex) vSemaphoreDelete(*(pmutex))
#define gfxMutexEnter(pmutex) xSemaphoreTake(*(pmutex),portMAX_DELAY)
#define gfxMutexExit(pmutex) xSemaphoreGive(*(pmutex))
@ -69,13 +69,13 @@ void *gfxRealloc(void *ptr, gMemSize oldsz, gMemSize newsz);
void gfxSleepMilliseconds(gDelay ms);
void gfxSleepMicroseconds(gDelay ms);
void gfxSemInit(gfxSem* psem, gSemcount val, gSemcount limit);
void gfxSemInit(gSem* psem, gSemcount val, gSemcount limit);
#define gfxSemDestroy(psem) vSemaphoreDelete(*(psem))
gBool gfxSemWait(gfxSem* psem, gDelay ms);
gBool gfxSemWaitI(gfxSem* psem);
void gfxSemSignal(gfxSem* psem);
void gfxSemSignalI(gfxSem* psem);
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
gBool gfxSemWait(gSem* psem, gDelay ms);
gBool gfxSemWaitI(gSem* psem);
void gfxSemSignal(gSem* psem);
void gfxSemSignalI(gSem* psem);
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void *param);
#define gfxThreadMe() xTaskGetCurrentTaskHandle()
#if INCLUDE_eTaskGetState == 1

20
src/gos/gos_linux.c

@ -25,7 +25,7 @@
#define linuxyield() pthread_yield()
#endif
static gfxMutex SystemMutex;
static gMutex SystemMutex;
void _gosInit(void)
{
@ -109,7 +109,7 @@ gTicks gfxSystemTicks(void) {
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
}
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param) {
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void *param) {
gThread th;
(void) stackarea;
(void) stacksz;
@ -138,14 +138,14 @@ gThreadreturn gfxThreadWait(gThread thread) {
}
#if GFX_USE_POSIX_SEMAPHORES
void gfxSemInit(gfxSem *pSem, gSemcount val, gSemcount limit) {
void gfxSemInit(gSem *pSem, gSemcount val, gSemcount limit) {
pSem->max = limit;
sem_init(&pSem->sem, 0, val);
}
void gfxSemDestroy(gfxSem *pSem) {
void gfxSemDestroy(gSem *pSem) {
sem_destroy(&pSem->sem);
}
gBool gfxSemWait(gfxSem *pSem, gDelay ms) {
gBool gfxSemWait(gSem *pSem, gDelay ms) {
switch (ms) {
case gDelayForever:
return sem_wait(&pSem->sem) ? gFalse : gTrue;
@ -164,7 +164,7 @@ gThreadreturn gfxThreadWait(gThread thread) {
}
}
}
void gfxSemSignal(gfxSem *pSem) {
void gfxSemSignal(gSem *pSem) {
int res;
res = 0;
@ -173,7 +173,7 @@ gThreadreturn gfxThreadWait(gThread thread) {
sem_post(&pSem->sem);
}
#else
void gfxSemInit(gfxSem *pSem, gSemcount val, gSemcount limit) {
void gfxSemInit(gSem *pSem, gSemcount val, gSemcount limit) {
pthread_mutex_init(&pSem->mtx, 0);
pthread_cond_init(&pSem->cond, 0);
pthread_mutex_lock(&pSem->mtx);
@ -181,11 +181,11 @@ gThreadreturn gfxThreadWait(gThread thread) {
pSem->max = limit;
pthread_mutex_unlock(&pSem->mtx);
}
void gfxSemDestroy(gfxSem *pSem) {
void gfxSemDestroy(gSem *pSem) {
pthread_mutex_destroy(&pSem->mtx);
pthread_cond_destroy(&pSem->cond);
}
gBool gfxSemWait(gfxSem *pSem, gDelay ms) {
gBool gfxSemWait(gSem *pSem, gDelay ms) {
pthread_mutex_lock(&pSem->mtx);
switch (ms) {
@ -226,7 +226,7 @@ gThreadreturn gfxThreadWait(gThread thread) {
pthread_mutex_unlock(&pSem->mtx);
return gTrue;
}
void gfxSemSignal(gfxSem *pSem) {
void gfxSemSignal(gSem *pSem) {
pthread_mutex_lock(&pSem->mtx);
if (pSem->cnt < pSem->max) {

40
src/gos/gos_linux.h

@ -28,12 +28,12 @@ typedef void * gThreadreturn;
typedef unsigned long gDelay;
typedef pthread_t gThread;
typedef int gThreadpriority;
typedef gU32 gSemcount;
typedef pthread_mutex_t gfxMutex;
typedef gU32 gSemcount;
typedef pthread_mutex_t gMutex;
#define DECLARE_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void *param)
#define DECLARE_THREAD_STACK(name, sz) gU8 name[0];
#define THREAD_RETURN(retval) return retval
#define GFX_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void *param)
#define GFX_THREAD_STACK(name, sz) gU8 name[0];
#define gfxThreadReturn(retval) return retval
#define gfxExit() exit(0)
#define gfxAlloc(sz) malloc(sz)
@ -49,25 +49,25 @@ typedef pthread_mutex_t gfxMutex;
#define gfxSemWaitI(psem) gfxSemWait(psem, gDelayNone)
#define gfxSemSignalI(psem) gfxSemSignal(psem)
#define gDelayNone 0
#define gDelayForever ((gDelay)-1)
#define MAX_SEMAPHORE_COUNT ((gSemcount)-1)
#define gThreadpriorityLow 10
#define gThreadpriorityNormal 0
#define gThreadpriorityHigh -10
#define gDelayNone 0
#define gDelayForever ((gDelay)-1)
#define gSemMaxCount ((gSemcount)-1)
#define gThreadpriorityLow 10
#define gThreadpriorityNormal 0
#define gThreadpriorityHigh -10
#if GFX_USE_POSIX_SEMAPHORES
typedef struct gfxSem {
typedef struct gSem {
sem_t sem;
gSemcount max;
} gfxSem;
} gSem;
#else
typedef struct gfxSem {
typedef struct gSem {
pthread_mutex_t mtx;
pthread_cond_t cond;
gSemcount cnt;
gSemcount max;
} gfxSem;
} gSem;
#endif
/*===========================================================================*/
@ -81,11 +81,11 @@ void gfxSleepMicroseconds(gDelay ms);
gTicks gfxSystemTicks(void);
void gfxSystemLock(void);
void gfxSystemUnlock(void);
void gfxSemInit(gfxSem *psem, gSemcount val, gSemcount limit);
void gfxSemDestroy(gfxSem *psem);
gBool gfxSemWait(gfxSem *psem, gDelay ms);
void gfxSemSignal(gfxSem *psem);
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit);
void gfxSemDestroy(gSem *psem);
gBool gfxSemWait(gSem *psem, gDelay ms);
void gfxSe