GOS updates
This commit is contained in:
parent
c2a4f9a5d6
commit
1c258a8273
15 changed files with 160 additions and 100 deletions
|
@ -24,15 +24,6 @@
|
|||
#include <wingdi.h>
|
||||
#include <assert.h>
|
||||
|
||||
/* Our threading model - ChibiOS or Win32 */
|
||||
#ifndef GDISP_THREAD_CHIBIOS
|
||||
#if GFX_USE_OS_WIN32
|
||||
#define GDISP_THREAD_CHIBIOS FALSE
|
||||
#else
|
||||
#define GDISP_THREAD_CHIBIOS TRUE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef GDISP_SCREEN_WIDTH
|
||||
#define GDISP_SCREEN_WIDTH 640
|
||||
#endif
|
||||
|
@ -45,7 +36,7 @@
|
|||
#include "ginput/lld/toggle.h"
|
||||
|
||||
const GToggleConfig GInputToggleConfigTable[GINPUT_TOGGLE_CONFIG_ENTRIES] = {
|
||||
{0, 0xFF, 0x00, PAL_MODE_INPUT},
|
||||
{0, 0xFF, 0x00, 0},
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -180,7 +171,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
|||
mousex = (coord_t)LOWORD(lParam);
|
||||
mousey = (coord_t)HIWORD(lParam);
|
||||
#if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
|
||||
ginputMouseWakeupI();
|
||||
ginputMouseWakeup();
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
|
@ -282,37 +273,22 @@ static void InitWindow(void) {
|
|||
isReady = TRUE;
|
||||
}
|
||||
|
||||
#if GDISP_THREAD_CHIBIOS
|
||||
static DECLARESTACK(waWindowThread, 1024);
|
||||
static threadreturn_t WindowThread(void *param) {
|
||||
(void)param;
|
||||
MSG msg;
|
||||
static DECLARE_THREAD_STACK(waWindowThread, 1024);
|
||||
static DECLARE_THREAD_FUNCTION(WindowThread, param) {
|
||||
(void)param;
|
||||
MSG msg;
|
||||
|
||||
InitWindow();
|
||||
do {
|
||||
gfxSleepMilliseconds(1);
|
||||
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
} while (msg.message != WM_QUIT);
|
||||
ExitProcess(0);
|
||||
return msg.wParam;
|
||||
}
|
||||
#else
|
||||
static DWORD WINAPI WindowThread(LPVOID param) {
|
||||
(void)param;
|
||||
MSG msg;
|
||||
|
||||
InitWindow();
|
||||
while(GetMessage(&msg, NULL, 0, 0) > 0) {
|
||||
InitWindow();
|
||||
do {
|
||||
gfxSleepMilliseconds(1);
|
||||
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
ExitProcess(0);
|
||||
return msg.wParam;
|
||||
}
|
||||
#endif
|
||||
} while (msg.message != WM_QUIT);
|
||||
ExitProcess(0);
|
||||
return msg.wParam;
|
||||
}
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
|
@ -331,7 +307,8 @@ static void InitWindow(void) {
|
|||
* @notapi
|
||||
*/
|
||||
bool_t gdisp_lld_init(void) {
|
||||
RECT rect;
|
||||
RECT rect;
|
||||
gfxThreadHandle hth;
|
||||
|
||||
/* Set the window dimensions */
|
||||
GetWindowRect(GetDesktopWindow(), &rect);
|
||||
|
@ -343,11 +320,11 @@ bool_t gdisp_lld_init(void) {
|
|||
wHeight = GDISP_SCREEN_HEIGHT;
|
||||
|
||||
/* Initialise the window */
|
||||
#if GDISP_THREAD_CHIBIOS
|
||||
gfxCreateThread(waWindowThread, sizeof(waWindowThread), HIGH_PRIORITY, WindowThread, 0);
|
||||
#else
|
||||
CreateThread(0, 0, WindowThread, 0, 0, 0);
|
||||
#endif
|
||||
if (!(hth = gfxThreadCreate(waWindowThread, sizeof(waWindowThread), HIGH_PRIORITY, WindowThread, 0))) {
|
||||
fprintf(stderr, "Cannot create window thread\n");
|
||||
exit(-1);
|
||||
}
|
||||
gfxThreadClose(hth);
|
||||
while (!isReady)
|
||||
Sleep(1);
|
||||
|
||||
|
@ -810,6 +787,9 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) {
|
|||
*/
|
||||
color_t gdisp_lld_get_pixel_color(coord_t x, coord_t y) {
|
||||
color_t color;
|
||||
#if GDISP_NEED_CONTROL
|
||||
coord_t t;
|
||||
#endif
|
||||
|
||||
#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
|
||||
// Clip pre orientation change
|
||||
|
@ -818,6 +798,8 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) {
|
|||
|
||||
#if GDISP_NEED_CONTROL
|
||||
switch(GDISP.Orientation) {
|
||||
case GDISP_ROTATE_0:
|
||||
break;
|
||||
case GDISP_ROTATE_90:
|
||||
t = GDISP.Height - 1 - y;
|
||||
y = x;
|
||||
|
|
|
@ -117,8 +117,8 @@ static void ProcessEvent(void) {
|
|||
|
||||
/* this is the X11 thread which keeps track of all events */
|
||||
#if GDISP_THREAD_CHIBIOS
|
||||
static DECLARESTACK(waXThread, 1024);
|
||||
static threadreturn_t ThreadX(void *arg) {
|
||||
static DECLARE_THREAD_STACK(waXThread, 1024);
|
||||
static DECLARE_THREAD_FUNCTION(ThreadX, arg) {
|
||||
(void)arg;
|
||||
|
||||
while(1) {
|
||||
|
@ -159,12 +159,12 @@ bool_t gdisp_lld_init(void)
|
|||
XSetWindowAttributes xa;
|
||||
XTextProperty WindowTitle;
|
||||
char * WindowTitleText;
|
||||
#if !GDISP_THREAD_CHIBIOS
|
||||
#if GDISP_THREAD_CHIBIOS
|
||||
gfxThreadHandle hth;
|
||||
#else
|
||||
pthread_attr_t thattr;
|
||||
pthread_t thid;
|
||||
#endif
|
||||
|
||||
#if !GDISP_THREAD_CHIBIOS
|
||||
XInitThreads();
|
||||
#endif
|
||||
|
||||
|
@ -228,16 +228,21 @@ bool_t gdisp_lld_init(void)
|
|||
ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
|
||||
|
||||
#if GDISP_THREAD_CHIBIOS
|
||||
if (!gfxCreateThread(waXThread, sizeof(waXThread), HIGH_PRIORITY, ThreadX, 0)) {
|
||||
if (!(hth = gfxThreadCreate(waXThread, sizeof(waXThread), HIGH_PRIORITY, ThreadX, 0))) {
|
||||
fprintf(stderr, "Cannot start X Thread\n");
|
||||
XCloseDisplay(dis);
|
||||
exit(0);
|
||||
}
|
||||
gfxThreadClose(hth);
|
||||
#else
|
||||
if (pthread_attr_init(&thattr)
|
||||
|| pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_DETACHED)
|
||||
|| pthread_create(&thid, &thattr, ThreadX, 0)) {
|
||||
fprintf(stderr, "Cannot start X Thread\n");
|
||||
XCloseDisplay(dis);
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
fprintf(stderr, "Cannot start X Thread\n");
|
||||
XCloseDisplay(dis);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Initialise the GDISP structure to match */
|
||||
GDISP.Orientation = GDISP_ROTATE_0;
|
||||
|
|
|
@ -35,6 +35,19 @@
|
|||
#define TRUE -1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Mark a function as deprecated.
|
||||
*/
|
||||
#ifndef DEPRECATED
|
||||
#if defined(__GNUC__) || defined(__MINGW32_) || defined(__CYGWIN__)
|
||||
#define DEPRECATED(msg) __attribute__((deprecated(msg)))
|
||||
#elif defined(_MSC_VER)
|
||||
#define DEPRECATED(msg) __declspec(deprecated(msg))
|
||||
#else
|
||||
#define DEPRECATED(msg)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* gfxconf.h is the user's project configuration for the GFX system. */
|
||||
#include "gfxconf.h"
|
||||
|
||||
|
@ -199,8 +212,8 @@ extern "C" {
|
|||
*/
|
||||
void gfxInit(void);
|
||||
|
||||
/* compatibility for old programs - throws a #warning */
|
||||
void gdispInit(void);
|
||||
/* Compatibility for old programs */
|
||||
void DEPRECATED("Use gfxInit() instead") gdispInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ typedef struct GToggleConfig_t {
|
|||
void *id;
|
||||
unsigned mask;
|
||||
unsigned invert;
|
||||
iomode_t mode;
|
||||
unsigned mode;
|
||||
} GToggleConfig;
|
||||
|
||||
/*===========================================================================*/
|
||||
|
|
|
@ -51,21 +51,21 @@ typedef cnt_t semcount_t;
|
|||
typedef msg_t threadreturn_t;
|
||||
typedef tprio_t threadpriority_t;
|
||||
|
||||
typedef threadreturn_t (*gfxThreadFunction)(void *param);
|
||||
|
||||
#define MAX_SEMAPHORE_COUNT ((semcount_t)(((unsigned long)((semcount_t)(-1))) >> 1))
|
||||
#define LOW_PRIORITY LOWPRIO
|
||||
#define NORMAL_PRIORITY NORMALPRIO
|
||||
#define HIGH_PRIORITY HIGHPRIO
|
||||
#define DECLARESTACK(name, sz) WORKING_AREA(name, sz);
|
||||
|
||||
#define DECLARE_THREAD_STACK(name, sz) WORKING_AREA(name, sz)
|
||||
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
|
||||
|
||||
typedef struct {
|
||||
Semaphore sem;
|
||||
semcount_t limit;
|
||||
} gfxSem;
|
||||
|
||||
#define gfxMutex Mutex
|
||||
typedef Mutex gfxMutex;
|
||||
typedef Thread * gfxThreadHandle;
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Function declarations. */
|
||||
|
@ -85,7 +85,7 @@ extern "C" {
|
|||
#define gfxSystemLock() chSysLock()
|
||||
#define gfxSystemUnlock() chSysUnlock()
|
||||
#define gfxMutexInit(pmutex) chMtxInit(pmutex)
|
||||
#define gfxMutexDestroy(pmutex) ;
|
||||
#define gfxMutexDestroy(pmutex) {}
|
||||
#define gfxMutexEnter(pmutex) chMtxLock(pmutex)
|
||||
#define gfxMutexExit(pmutex) chMtxUnlock()
|
||||
void gfxSleepMilliseconds(delaytime_t ms);
|
||||
|
@ -97,7 +97,10 @@ void gfxSemSignal(gfxSem *psem);
|
|||
void gfxSemSignalI(gfxSem *psem);
|
||||
#define gfxSemCounterI(psem) ((psem)->sem.s_cnt)
|
||||
#define gfxSemCounter(psem) ((psem)->sem.s_cnt)
|
||||
bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param);
|
||||
gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
|
||||
#define gfxThreadWait(thread) chThdWait(thread)
|
||||
#define gfxThreadMe() chThdSelf()
|
||||
#define gfxThreadClose(thread) {}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -61,10 +61,15 @@
|
|||
typedef short semcount_t;
|
||||
typedef int threadreturn_t;
|
||||
typedef int threadpriority_t;
|
||||
|
||||
/**
|
||||
* @brief A function for a new thread to execute.
|
||||
* @brief Declare a thread stack and function
|
||||
* @{
|
||||
*/
|
||||
typedef threadreturn_t (*gfxThreadFunction)(void *param);
|
||||
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
|
||||
#define DECLARE_THREAD_STACK(name, sz) uint8_t name[sz];
|
||||
/* @} */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
|
@ -80,7 +85,6 @@
|
|||
#define LOW_PRIORITY 0
|
||||
#define NORMAL_PRIORITY 1
|
||||
#define HIGH_PRIORITY 2
|
||||
#define DECLARESTACK(name, sz) uint8_t name[sz];
|
||||
/* @} */
|
||||
|
||||
/**
|
||||
|
@ -95,6 +99,12 @@
|
|||
*/
|
||||
typedef struct {} gfxMutex;
|
||||
|
||||
/**
|
||||
* @brief A thread handle
|
||||
* @note Your operating system will have a proper definition for this.
|
||||
*/
|
||||
typedef void * gfxThreadHandle;
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Function declarations. */
|
||||
/*===========================================================================*/
|
||||
|
@ -355,7 +365,7 @@
|
|||
|
||||
/**
|
||||
* @brief Start a new thread.
|
||||
* @return Return TRUE if the thread was started, FALSE on an error
|
||||
* @return Returns a thread handle if the thread was started, NULL on an error
|
||||
*
|
||||
* @param[in] stackarea A pointer to the area for the new threads stack or NULL to dynamically allocate it
|
||||
* @param[in] stacksz The size of the thread stack. 0 means the default operating system size although this
|
||||
|
@ -366,7 +376,38 @@
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param);
|
||||
gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
|
||||
|
||||
/**
|
||||
* @brief Wait for a thread to finish.
|
||||
* @return Returns the thread exit code.
|
||||
*
|
||||
* @param[in] thread The Thread Handle
|
||||
*
|
||||
* @note This will also close the thread handle as it is no longer useful
|
||||
* once the thread has ended.
|
||||
* @api
|
||||
*/
|
||||
threadreturn_t gfxThreadWait(gfxThreadHandle thread);
|
||||
|
||||
/**
|
||||
* @brief Get the current thread handle.
|
||||
* @return A thread handle
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
gfxThreadHandle gfxThreadMe(void);
|
||||
|
||||
/**
|
||||
* @brief Close the thread handle.
|
||||
*
|
||||
* @param[in] thread The Thread Handle
|
||||
*
|
||||
* @note This does not affect the thread, it just closes our handle to the thread.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
void gfxThreadClose(gfxThreadHandle thread);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@
|
|||
//#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
/* Stop cygwin from defining these types */
|
||||
#define __int8_t_defined
|
||||
|
||||
/**
|
||||
* size_t
|
||||
* TRUE, FALSE
|
||||
|
@ -45,10 +48,11 @@ typedef unsigned __int32 uint32_t;
|
|||
typedef DWORD delaytime_t;
|
||||
typedef DWORD systemticks_t;
|
||||
typedef LONG semcount_t;
|
||||
#define threadreturn_t DWORD WINAPI
|
||||
typedef DWORD threadreturn_t;
|
||||
typedef int threadpriority_t;
|
||||
|
||||
typedef threadreturn_t (*gfxThreadFunction)(void *param);
|
||||
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t WINAPI fnName(void *param)
|
||||
#define DECLARE_THREAD_STACK(name, sz) uint8_t name[0];
|
||||
|
||||
#define TIME_IMMEDIATE 0
|
||||
#define TIME_INFINITE INFINITE
|
||||
|
@ -56,10 +60,10 @@ typedef threadreturn_t (*gfxThreadFunction)(void *param);
|
|||
#define LOW_PRIORITY THREAD_PRIORITY_BELOW_NORMAL
|
||||
#define NORMAL_PRIORITY THREAD_PRIORITY_NORMAL
|
||||
#define HIGH_PRIORITY THREAD_PRIORITY_ABOVE_NORMAL
|
||||
#define DECLARESTACK(name, sz) uint8_t name[0];
|
||||
|
||||
typedef HANDLE gfxSem;
|
||||
typedef HANDLE gfxMutex;
|
||||
typedef HANDLE gfxThreadHandle;
|
||||
|
||||
#define gfxExit() ExitProcess(0)
|
||||
#define gfxAlloc(sz) malloc(sz)
|
||||
|
@ -77,6 +81,8 @@ typedef HANDLE gfxMutex;
|
|||
#define gfxSemSignal(psem) ReleaseSemaphore(*(psem), 1, NULL)
|
||||
#define gfxSemSignalI(psem) ReleaseSemaphore(*(psem), 1, NULL)
|
||||
#define gfxSemCounterI(psem) gfxSemCounter(psem)
|
||||
#define gfxThreadMe() GetCurrentThread()
|
||||
#define gfxThreadClose(thread) CloseHandle(thread)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Function declarations. */
|
||||
|
@ -92,7 +98,8 @@ bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
|
|||
semcount_t gfxSemCounter(gfxSem *pSem);
|
||||
void gfxSystemLock(void);
|
||||
void gfxSystemUnlock(void);
|
||||
bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param);
|
||||
gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
|
||||
threadreturn_t gfxThreadWait(gfxThreadHandle thread);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
typedef struct gfxQueueASync {
|
||||
struct gfxQueueASyncItem *head;
|
||||
struct gfxQueueASyncItem *tail;
|
||||
} gfxQueueAsync;
|
||||
} gfxQueueASync;
|
||||
typedef struct gfxQueueGSync {
|
||||
struct gfxQueueGSyncItem *head;
|
||||
struct gfxQueueGSyncItem *tail;
|
||||
|
@ -57,7 +57,7 @@ typedef struct gfxQueueFSync {
|
|||
struct gfxQueueFSyncItem *head;
|
||||
struct gfxQueueFSyncItem *tail;
|
||||
gfxSem sem;
|
||||
} gfxQueueGSync;
|
||||
} gfxQueueFSync;
|
||||
/* @} */
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
static gfxMutex gdispMsgsMutex;
|
||||
static gfxSem gdispMsgsSem;
|
||||
static gdisp_lld_msg_t gdispMsgs[GDISP_QUEUE_SIZE];
|
||||
static DECLARESTACK(waGDISPThread, GDISP_THREAD_STACK_SIZE);
|
||||
static DECLARE_THREAD_STACK(waGDISPThread, GDISP_THREAD_STACK_SIZE);
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
|
@ -47,7 +47,7 @@
|
|||
/*===========================================================================*/
|
||||
|
||||
#if GDISP_NEED_ASYNC
|
||||
static threadreturn_t GDISPThreadHandler(void *arg) {
|
||||
static DECLARE_THREAD_FUNCTION(GDISPThreadHandler, arg) {
|
||||
(void)arg;
|
||||
gdisp_lld_msg_t *pmsg;
|
||||
|
||||
|
@ -111,7 +111,8 @@
|
|||
}
|
||||
#elif GDISP_NEED_ASYNC
|
||||
void _gdispInit(void) {
|
||||
unsigned i;
|
||||
unsigned i;
|
||||
gfxThreadHandle hth;
|
||||
|
||||
/* Mark all the Messages as free */
|
||||
for(i=0; i < GDISP_QUEUE_SIZE; i++)
|
||||
|
@ -126,7 +127,8 @@
|
|||
gfxMutexInit(&gdispMsgsMutex);
|
||||
gfxSemInit(&gdispMsgsSem, GDISP_QUEUE_SIZE, GDISP_QUEUE_SIZE);
|
||||
|
||||
gfxCreateThread(waGDISPThread, sizeof(waGDISPThread), NORMAL_PRIORITY, GDISPThreadHandler, NULL);
|
||||
hth = gfxThreadCreate(waGDISPThread, sizeof(waGDISPThread), NORMAL_PRIORITY, GDISPThreadHandler, NULL);
|
||||
if (hth) gfxThreadClose(hth);
|
||||
|
||||
/* Initialise driver - synchronous */
|
||||
gfxMutexEnter(&gdispMutex);
|
||||
|
|
|
@ -170,7 +170,7 @@ void geventSendEvent(GSourceListener *psl) {
|
|||
|
||||
} else {
|
||||
// Wake up the listener
|
||||
if (gfxSemCounter(&psl->pListener->waitqueue) < 0)
|
||||
if (gfxSemCounter(&psl->pListener->waitqueue) <= 0)
|
||||
gfxSemSignal(&psl->pListener->waitqueue);
|
||||
gfxMutexExit(&geventMutex);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include "gfx.h"
|
||||
|
||||
void DEPRECATED("Use gfxInit() instead") gdispInit() { gfxInit(); }
|
||||
|
||||
/* These init functions are defined by each module but not published */
|
||||
extern void _gosInit(void);
|
||||
#if GFX_USE_GDISP && (GDISP_NEED_MULTITHREAD || GDISP_NEED_ASYNC)
|
||||
|
@ -105,10 +107,3 @@ void gfxInit(void) {
|
|||
_gaudoutInit();
|
||||
#endif
|
||||
}
|
||||
|
||||
void gdispInit(void) {
|
||||
#warning "gdispInit() is obsolete - please use gfxInit() instead"
|
||||
|
||||
gfxInit();
|
||||
}
|
||||
|
||||
|
|
|
@ -86,13 +86,14 @@ void gfxSemSignalI(gfxSem *psem) {
|
|||
chSemSignalI(&psem->sem);
|
||||
}
|
||||
|
||||
bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param) {
|
||||
gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param) {
|
||||
if (!stackarea) {
|
||||
if (!stacksz) stacksz = 256;
|
||||
return chThdCreateFromHeap(0, stacksz, prio, fn, param) != 0;
|
||||
return chThdCreateFromHeap(0, stacksz, prio, fn, param);
|
||||
}
|
||||
|
||||
return stacksz && chThdCreateStatic(stackarea, stacksz, prio, fn, param) != NULL;
|
||||
if (!stacksz) return NULL;
|
||||
return chThdCreateStatic(stackarea, stacksz, prio, fn, param);
|
||||
}
|
||||
|
||||
#endif /* GFX_USE_OS_CHIBIOS */
|
||||
|
|
|
@ -96,15 +96,24 @@ semcount_t gfxSemCounter(gfxSem *pSem) {
|
|||
return BasicInfo.CurrentCount;
|
||||
}
|
||||
|
||||
bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param) {
|
||||
(void) stackarea;
|
||||
gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param) {
|
||||
(void) stackarea;
|
||||
HANDLE thd;
|
||||
|
||||
if (!(thd = CreateThread(NULL, stacksz, fn, param, CREATE_SUSPENDED, NULL)))
|
||||
return FALSE;
|
||||
SetThreadPriority(thd, prio);
|
||||
ResumeThread(thd);
|
||||
return TRUE;
|
||||
return thd;
|
||||
}
|
||||
|
||||
threadreturn_t gfxThreadWait(gfxThreadHandle thread) {
|
||||
DWORD ret;
|
||||
|
||||
WaitForSingleObject(thread, INFINITE);
|
||||
GetExitCodeThread(thread, &ret);
|
||||
CloseHandle(thread);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* GFX_USE_OS_WIN32 */
|
||||
|
|
|
@ -26,16 +26,16 @@
|
|||
|
||||
/* This mutex protects access to our tables */
|
||||
static gfxMutex mutex;
|
||||
static bool_t haveThread = 0;
|
||||
static gfxThreadHandle hThread = 0;
|
||||
static GTimer *pTimerHead = 0;
|
||||
static gfxSem waitsem;
|
||||
static DECLARESTACK(waTimerThread, GTIMER_THREAD_WORKAREA_SIZE);
|
||||
static DECLARE_THREAD_STACK(waTimerThread, GTIMER_THREAD_WORKAREA_SIZE);
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
static threadreturn_t GTimerThreadHandler(void *arg) {
|
||||
static DECLARE_THREAD_FUNCTION(GTimerThreadHandler, arg) {
|
||||
(void)arg;
|
||||
GTimer *pt;
|
||||
systemticks_t tm;
|
||||
|
@ -131,8 +131,10 @@ void gtimerStart(GTimer *pt, GTimerFunction fn, void *param, bool_t periodic, de
|
|||
gfxMutexEnter(&mutex);
|
||||
|
||||
// Start our thread if not already going
|
||||
if (!haveThread)
|
||||
haveThread = gfxCreateThread(waTimerThread, sizeof(waTimerThread), HIGH_PRIORITY, GTimerThreadHandler, NULL);
|
||||
if (!hThread) {
|
||||
hThread = gfxThreadCreate(waTimerThread, sizeof(waTimerThread), HIGH_PRIORITY, GTimerThreadHandler, NULL);
|
||||
if (hThread) gfxThreadClose(hThread); // We never really need the handle again
|
||||
}
|
||||
|
||||
// Is this already scheduled?
|
||||
if (pt->flags & GTIMER_FLG_SCHEDULED) {
|
||||
|
|
|
@ -63,7 +63,7 @@ GHandle gwinCreateConsole(GConsoleObject *gc, coord_t x, coord_t y, coord_t widt
|
|||
return 0;
|
||||
gc->gwin.type = GW_CONSOLE;
|
||||
gwinSetFont(&gc->gwin, font);
|
||||
#if GFX_USE_OS_CHIBIOS
|
||||
#if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM
|
||||
gc->stream.vmt = &GWindowConsoleVMT;
|
||||
#endif
|
||||
gc->cx = 0;
|
||||
|
@ -193,7 +193,7 @@ void gwinPrintf(GHandle gh, const char *fmt, ...) {
|
|||
int i, precision, width;
|
||||
bool_t is_long, left_align;
|
||||
long l;
|
||||
#if CHPRINTF_USE_FLOAT
|
||||
#if GWIN_CONSOLE_USE_FLOAT
|
||||
float f;
|
||||
char tmpbuf[2*MAX_FILLER + 1];
|
||||
#else
|
||||
|
@ -286,7 +286,7 @@ void gwinPrintf(GHandle gh, const char *fmt, ...) {
|
|||
}
|
||||
p = ltoa_wd(p, l, 10, 0);
|
||||
break;
|
||||
#if CHPRINTF_USE_FLOAT
|
||||
#if GWIN_CONSOLE_USE_FLOAT
|
||||
case 'f':
|
||||
f = (float) va_arg(ap, double);
|
||||
if (f < 0) {
|
||||
|
|
Loading…
Add table
Reference in a new issue