Another attempt to get CMSIS semaphores correct.

This commit is contained in:
inmarket 2015-10-26 23:04:51 +10:00
parent bc32c99d1a
commit 267178254d
2 changed files with 17 additions and 9 deletions

View File

@ -43,9 +43,9 @@ void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit)
osSemaphoreDef_t def; osSemaphoreDef_t def;
def.semaphore = psem->semaphore; def.semaphore = psem->semaphore;
psem->id = osSemaphoreCreate(&def, limit); if (val > limit) val = limit;
while(val--) psem->available = limit - val;
osSemaphoreRelease(psem->id); psem->id = osSemaphoreCreate(&def, val);
} }
void gfxSemDestroy(gfxSem* psem) void gfxSemDestroy(gfxSem* psem)
@ -55,22 +55,29 @@ void gfxSemDestroy(gfxSem* psem)
bool_t gfxSemWait(gfxSem* psem, delaytime_t ms) bool_t gfxSemWait(gfxSem* psem, delaytime_t ms)
{ {
return osSemaphoreWait(psem->id, ms) > 0; if (osSemaphoreWait(psem->id, ms) == osOK) {
psem->available++;
return TRUE;
}
return FALSE;
} }
bool_t gfxSemWaitI(gfxSem* psem) bool_t gfxSemWaitI(gfxSem* psem)
{ {
return osSemaphoreWait(psem->id, 0) > 0; return gfxSemWait(psem, 0);
} }
void gfxSemSignal(gfxSem* psem) void gfxSemSignal(gfxSem* psem)
{ {
osSemaphoreRelease(psem->id); gfxSemSignalI(psem);
} }
void gfxSemSignalI(gfxSem* psem) void gfxSemSignalI(gfxSem* psem)
{ {
if (psem->available) {
psem->available--;
osSemaphoreRelease(psem->id); osSemaphoreRelease(psem->id);
}
} }
gfxThreadHandle gfxThreadCreate(void* stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void* param) gfxThreadHandle gfxThreadCreate(void* stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void* param)

View File

@ -44,6 +44,7 @@ typedef osPriority threadpriority_t;
typedef struct gfxSem { typedef struct gfxSem {
uint32_t semaphore[2]; uint32_t semaphore[2];
osSemaphoreId id; osSemaphoreId id;
semcount_t available;
} gfxSem; } gfxSem;
typedef struct gfxMutex { typedef struct gfxMutex {