Skip to content

events: Adopt osEventFlags from RTX 5 #4571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions events/equeue/equeue_mbed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,29 @@ void equeue_mutex_unlock(equeue_mutex_t *m) {
#ifdef MBED_CONF_RTOS_PRESENT

int equeue_sema_create(equeue_sema_t *s) {
MBED_STATIC_ASSERT(sizeof(equeue_sema_t) >= sizeof(Semaphore),
"The equeue_sema_t must fit the class Semaphore");
new (s) Semaphore(0);
return 0;
osEventFlagsAttr_t attr;
memset(&attr, 0, sizeof(attr));
attr.cb_mem = &s->mem;
attr.cb_size = sizeof(s->mem);

s->id = osEventFlagsNew(&attr);
return !s->id ? -1 : 0;
}

void equeue_sema_destroy(equeue_sema_t *s) {
reinterpret_cast<Semaphore*>(s)->~Semaphore();
osEventFlagsDelete(s->id);
}

void equeue_sema_signal(equeue_sema_t *s) {
reinterpret_cast<Semaphore*>(s)->release();
osEventFlagsSet(s->id, 1);
}

bool equeue_sema_wait(equeue_sema_t *s, int ms) {
if (ms < 0) {
ms = osWaitForever;
}

return (reinterpret_cast<Semaphore*>(s)->wait(ms) > 0);
return (osEventFlagsWait(s->id, 1, osFlagsWaitAny, ms) == 1);
}

#else
Expand Down
8 changes: 7 additions & 1 deletion events/equeue/equeue_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ extern "C" {
// Platform includes
#if defined(EQUEUE_PLATFORM_POSIX)
#include <pthread.h>
#elif defined(EQUEUE_PLATFORM_MBED)
#include "cmsis_os2.h"
#include "rtx_lib.h"
#endif


Expand Down Expand Up @@ -112,7 +115,10 @@ typedef struct equeue_sema {
bool signal;
} equeue_sema_t;
#elif defined(EQUEUE_PLATFORM_MBED) && defined(MBED_CONF_RTOS_PRESENT)
typedef unsigned equeue_sema_t[9];
typedef struct equeue_sema {
osEventFlagsId_t id;
os_event_flags_t mem;
} equeue_sema_t;
#elif defined(EQUEUE_PLATFORM_MBED)
typedef volatile int equeue_sema_t;
#endif
Expand Down