Another attempt to get CMSIS semaphores correct.
This commit is contained in:
parent
bc32c99d1a
commit
267178254d
@ -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)
|
||||||
{
|
{
|
||||||
osSemaphoreRelease(psem->id);
|
if (psem->available) {
|
||||||
|
psem->available--;
|
||||||
|
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)
|
||||||
|
@ -42,8 +42,9 @@ typedef osPriority threadpriority_t;
|
|||||||
#define HIGH_PRIORITY osPriorityHigh
|
#define HIGH_PRIORITY osPriorityHigh
|
||||||
|
|
||||||
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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user