From 855065f2390b698ef6e1e68a7a75535230b3e1e8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 6 Oct 2014 13:25:45 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7379 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/ports/ARMCMx/cmsis_os/cmsis_os.c | 55 ++++++++++++++++++++++++++++++++++ os/rt/ports/ARMCMx/cmsis_os/cmsis_os.h | 27 +++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/os/rt/ports/ARMCMx/cmsis_os/cmsis_os.c b/os/rt/ports/ARMCMx/cmsis_os/cmsis_os.c index f8c8c3311..d8aa35cb5 100644 --- a/os/rt/ports/ARMCMx/cmsis_os/cmsis_os.c +++ b/os/rt/ports/ARMCMx/cmsis_os/cmsis_os.c @@ -220,6 +220,61 @@ osStatus osTimerDelete (osTimerId timer_id) { return osOK; } +/** + * @brief Send signals. + */ +int32_t osSignalSet(osThreadId thread_id, int32_t signals) { + int32_t oldsignals; + + syssts_t sts = chSysGetStatusAndLockX(); + oldsignals = (int32_t)thread_id->p_epending; + chEvtSignalI((thread_t *)thread_id, (eventmask_t)signals); + chSysRestoreStatusX(sts); + + return oldsignals; +} + +/** + * @brief Clear signals. + */ +int32_t osSignalClear(osThreadId thread_id, int32_t signals) { + eventmask_t m; + + chSysLock(); + + m = thread_id->p_epending & (eventmask_t)signals; + thread_id->p_epending &= ~(eventmask_t)signals; + + chSysUnlock(); + + return (int32_t)m; +} + +/** + * @brief Wait for signals. + */ +osEvent osSignalWait(int32_t signals, uint32_t millisec) { + osEvent event; + + systime_t timeout = millisec == osWaitForever ? TIME_INFINITE : + (systime_t)millisec; + + if (signals == 0) + event.value.signals = (uint32_t)chEvtWaitAnyTimeout((eventmask_t)signals, + timeout); + else + event.value.signals = (uint32_t)chEvtWaitAllTimeout((eventmask_t)signals, + timeout); + + /* Type of event.*/ + if (event.value.signals == 0) + event.status = osEventTimeout; + else + event.status = osEventSignal; + + return event; +} + /** * @brief Create a semaphore. * @note @p semaphore_def is not used. diff --git a/os/rt/ports/ARMCMx/cmsis_os/cmsis_os.h b/os/rt/ports/ARMCMx/cmsis_os/cmsis_os.h index 5c15fc3be..3151a8f39 100644 --- a/os/rt/ports/ARMCMx/cmsis_os/cmsis_os.h +++ b/os/rt/ports/ARMCMx/cmsis_os/cmsis_os.h @@ -105,6 +105,14 @@ #error "CMSIS RTOS requires CH_CFG_USE_MEMPOOLS" #endif +#if !CH_CFG_USE_EVENTS +#error "CMSIS RTOS requires CH_CFG_USE_EVENTS" +#endif + +#if !CH_CFG_USE_EVENTS_TIMEOUT +#error "CMSIS RTOS requires CH_CFG_USE_EVENTS_TIMEOUT" +#endif + #if !CH_CFG_USE_SEMAPHORES #error "CMSIS RTOS requires CH_CFG_USE_SEMAPHORES" #endif @@ -196,6 +204,22 @@ typedef binary_semaphore_t *osMutexId; */ typedef semaphore_t *osSemaphoreId; +/** + * @brief Type of an event. + */ +typedef struct { + osStatus status; + union { + uint32_t v; + void *p; + int32_t signals; + } value; +/* union { + osMailQId mail_id; + osMessageQId message_id; + } def;*/ +} osEvent; + /** * @brief Type of a thread definition block. */ @@ -324,6 +348,9 @@ extern "C" { osStatus osTimerStart (osTimerId timer_id, uint32_t millisec); osStatus osTimerStop (osTimerId timer_id); osStatus osTimerDelete (osTimerId timer_id); + int32_t osSignalSet (osThreadId thread_id, int32_t signals); + int32_t osSignalClear (osThreadId thread_id, int32_t signals); + osEvent osSignalWait (int32_t signals, uint32_t millisec); osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count); int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec); -- cgit v1.2.3