From 46c0e6255e9d3013ce6308cd1fa494d6550fa80e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 12 Aug 2014 16:05:36 +0000 Subject: Added chSysConditionalLock() and chSysConditionalUnlock() functions to RT and NIL. Improved debug documentation. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7166 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/nil/include/nil.h | 10 ++++++---- os/nil/src/nil.c | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) (limited to 'os/nil') diff --git a/os/nil/include/nil.h b/os/nil/include/nil.h index 109f99533..47f93af0b 100644 --- a/os/nil/include/nil.h +++ b/os/nil/include/nil.h @@ -587,21 +587,21 @@ typedef struct { #define chSysEnable() port_enable() /** - * @brief Enters the kernel lock mode. + * @brief Enters the kernel lock state. * * @special */ #define chSysLock() port_lock() /** - * @brief Leaves the kernel lock mode. + * @brief Leaves the kernel lock state. * * @special */ #define chSysUnlock() port_unlock() /** - * @brief Enters the kernel lock mode from within an interrupt handler. + * @brief Enters the kernel lock state from within an interrupt handler. * @note This API may do nothing on some architectures, it is required * because on ports that support preemptable interrupt handlers * it is required to raise the interrupt mask to the same level of @@ -615,7 +615,7 @@ typedef struct { #define chSysLockFromISR() port_lock_from_isr() /** - * @brief Leaves the kernel lock mode from within an interrupt handler. + * @brief Leaves the kernel lock state from within an interrupt handler. * * @note This API may do nothing on some architectures, it is required * because on ports that support preemptable interrupt handlers @@ -835,6 +835,8 @@ extern "C" { void chSysInit(void); void chSysHalt(const char *reason); void chSysTimerHandlerI(void); + void chSysConditionalLock(void); + void chSysConditionalUnlock(void); syssts_t chSysGetStatusAndLockX(void); void chSysRestoreStatusX(syssts_t sts); thread_t *chSchReadyI(thread_t *tp, msg_t msg); diff --git a/os/nil/src/nil.c b/os/nil/src/nil.c index 3462b735a..48f640b09 100644 --- a/os/nil/src/nil.c +++ b/os/nil/src/nil.c @@ -218,6 +218,32 @@ void chSysTimerHandlerI(void) { #endif } +/** + * @brief Conditionally enters the kernel lock state. + * @note Can be called without previous knowledge of the current lock state. + * The final state is "s-locked". + * + * @special + */ +void chSysConditionalLock(void) { + + if (port_irq_enabled(port_get_irq_status())) + chSysLock(); +} + +/** + * @brief Conditionally leaves the kernel lock state. + * @note Can be called without previous knowledge of the current lock state. + * The final state is "normal". + * + * @special + */ +void chSysConditionalUnlock(void) { + + if (!port_irq_enabled(port_get_irq_status())) + chSysUnlock(); +} + /** * @brief Returns the execution status and enters a critical zone. * @details This functions enters into a critical zone and can be called -- cgit v1.2.3