From 16e2a55bf42f532404cddd8ddbc7cbee38c39572 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sat, 2 Sep 2017 16:35:10 +0000 Subject: Made PAL callback and wait APIs independent from each other. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10543 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/hal_pal.h | 338 +++++++++++++++++----------- os/hal/ports/STM32/LLD/GPIOv1/hal_pal_lld.c | 34 +-- os/hal/ports/STM32/LLD/GPIOv1/hal_pal_lld.h | 13 +- os/hal/ports/STM32/LLD/GPIOv2/hal_pal_lld.c | 30 +-- os/hal/ports/STM32/LLD/GPIOv2/hal_pal_lld.h | 11 +- os/hal/ports/STM32/LLD/GPIOv3/hal_pal_lld.c | 30 +-- os/hal/ports/STM32/LLD/GPIOv3/hal_pal_lld.h | 11 +- os/hal/ports/STM32/STM32F0xx/stm32_isr.c | 10 +- os/hal/ports/STM32/STM32F1xx/stm32_isr.c | 2 +- os/hal/ports/STM32/STM32F37x/stm32_isr.c | 2 +- os/hal/ports/STM32/STM32F3xx/stm32_isr.c | 4 +- os/hal/ports/STM32/STM32F4xx/stm32_isr.c | 4 +- os/hal/ports/STM32/STM32F7xx/stm32_isr.c | 4 +- os/hal/ports/STM32/STM32L0xx/stm32_isr.c | 10 +- os/hal/ports/STM32/STM32L1xx/stm32_isr.c | 4 +- os/hal/ports/STM32/STM32L4xx/stm32_isr.c | 4 +- os/hal/src/hal_pal.c | 36 +++ testhal/STM32/multi/PAL/main.c | 45 +++- 18 files changed, 374 insertions(+), 218 deletions(-) diff --git a/os/hal/include/hal_pal.h b/os/hal/include/hal_pal.h index a0ef91b37..3514b7ffe 100644 --- a/os/hal/include/hal_pal.h +++ b/os/hal/include/hal_pal.h @@ -117,6 +117,14 @@ * @name PAL configuration options * @{ */ +/** + * @brief Enables synchronous APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(PAL_USE_CALLBACKS) || defined(__DOXYGEN__) +#define PAL_USE_CALLBACKS TRUE +#endif + /** * @brief Enables synchronous APIs. * @note Disabling this option saves both code and data space. @@ -149,6 +157,7 @@ typedef struct { */ threads_queue_t threads; #endif +#if PAL_USE_CALLBACKS || defined(__DOXYGEN__) /** * @brief Event callback. */ @@ -157,6 +166,7 @@ typedef struct { * @brief Event callback argument. */ void *arg; +#endif } palevent_t; #include "hal_pal_lld.h" @@ -235,10 +245,73 @@ typedef struct { #define IOBUS_DECL(name, port, width, offset) \ IOBus name = _IOBUS_DATA(name, port, width, offset) +#if PAL_USE_CALLBACKS || PAL_USE_WAIT || defined(__DOXYGEN__) /** * @name Low level driver helper macros * @{ */ +#if (PAL_USE_CALLBACKS && PAL_USE_WAIT) || defined(__DOXYGEN__) +/** + * @brief Initializes a PAL event object. + * + * @param[in] e event index + * + * @notapi + */ +#define _pal_init_event(e) \ + do { \ + osalThreadQueueObjectInit(&_pal_events[e].threads); \ + _pal_events[e].cb = NULL; \ + _pal_events[e].arg = NULL; \ + } while (false) +#endif /* PAL_USE_CALLBACKS && PAL_USE_WAIT */ + +#if PAL_USE_CALLBACKS && !PAL_USE_WAIT +#define _pal_init_event(e) \ + do { \ + _pal_events[e].cb = NULL; \ + _pal_events[e].arg = NULL; \ + } while (false) +#endif /* PAL_USE_CALLBACKS && !PAL_USE_WAIT */ + +#if !PAL_USE_CALLBACKS && PAL_USE_WAIT +#define _pal_init_event(e) \ + do { \ + osalThreadQueueObjectInit(&_pal_events[e].threads); \ + } while (false) +#endif /* !PAL_USE_CALLBACKS && PAL_USE_WAIT */ + +#if (PAL_USE_CALLBACKS && PAL_USE_WAIT) || defined(__DOXYGEN__) +/** + * @brief Clears a PAL event object. + * + * @param[in] e event index + * + * @notapi + */ +#define _pal_clear_event(e) \ + do { \ + osalThreadDequeueAllI(&_pal_events[pad].threads, MSG_RESET); \ + _pal_events[e].cb = NULL; \ + _pal_events[e].arg = NULL; \ + } while (false) +#endif /* PAL_USE_CALLBACKS && PAL_USE_WAIT */ + +#if PAL_USE_CALLBACKS && !PAL_USE_WAIT +#define _pal_clear_event(e) \ + do { \ + _pal_events[e].cb = NULL; \ + _pal_events[e].arg = NULL; \ + } while (false) +#endif /* PAL_USE_CALLBACKS && !PAL_USE_WAIT */ + +#if !PAL_USE_CALLBACKS && PAL_USE_WAIT +#define _pal_clear_event(e) \ + do { \ + osalThreadDequeueAllI(&_pal_events[pad].threads, MSG_RESET); \ + } while (false) +#endif /* !PAL_USE_CALLBACKS && PAL_USE_WAIT */ + /** * @brief Common ISR code. * @note This macro is meant to be used in the low level drivers @@ -248,7 +321,7 @@ typedef struct { * * @notapi */ -#if PAL_USE_WAIT || defined(__DOXYGEN__) +#if (PAL_USE_CALLBACKS && PAL_USE_WAIT) || defined(__DOXYGEN__) #define _pal_isr_code(e) do { \ if (_pal_events[e].cb != NULL) { \ _pal_events[e].cb(_pal_events[e].arg); \ @@ -257,60 +330,26 @@ typedef struct { osalThreadDequeueAllI(&_pal_events[e].threads, MSG_OK); \ osalSysUnlockFromISR(); \ } while (false) -#else +#endif /* PAL_USE_CALLBACKS && PAL_USE_WAIT */ + +#if PAL_USE_CALLBACKS && !PAL_USE_WAIT #define _pal_isr_code(e) do { \ if (_pal_events[e].cb != NULL) { \ _pal_events[e].cb(_pal_events[e].arg); \ } \ } while (false) -#endif +#endif /* PAL_USE_CALLBACKS && !PAL_USE_WAIT */ -/** - * @brief PAL event setup. - * @note This macro is meant to be used in the low level drivers - * implementation only. - * - * @param[in] e event index - * @param[in] c callback pointer - * @param[in] a callback argument - * - * @notapi - */ -#if PAL_USE_WAIT || defined(__DOXYGEN__) -#define _pal_set_event(e, c, a) { \ - osalThreadQueueObjectInit(&_pal_events[e].threads); \ - _pal_events[e].cb = c; \ - _pal_events[e].arg = a; \ -} -#else -#define _pal_set_event(e, c, a) { \ - _pal_events[e].cb = c; \ - _pal_events[e].arg = a; \ -} -#endif +#if (!PAL_USE_CALLBACKS && PAL_USE_WAIT) || defined(__DOXYGEN__) +#define _pal_isr_code(e) do { \ + osalSysLockFromISR(); \ + osalThreadDequeueAllI(&_pal_events[e].threads, MSG_OK); \ + osalSysUnlockFromISR(); \ +} while (false) +#endif /* !PAL_USE_CALLBACKS && PAL_USE_WAIT */ -/** - * @brief PAL event clear. - * @note This macro is meant to be used in the low level drivers - * implementation only. - * - * @param[in] e event index - * - * @notapi - */ -#if PAL_USE_WAIT || defined(__DOXYGEN__) -#define _pal_clear_event(e) { \ - osalThreadDequeueAllI(&_pal_events[e].threads, MSG_RESET); \ - _pal_events[e].cb = NULL; \ - _pal_events[e].arg = NULL; \ -} -#else -#define _pal_clear_event(e) { \ - _pal_events[e].cb = NULL; \ - _pal_events[e].arg = NULL; \ -} -#endif /** @} */ +#endif /* PAL_USE_CALLBACKS || PAL_USE_WAIT */ /** * @name Macro Functions @@ -627,78 +666,6 @@ typedef struct { #define palSetPadMode(port, pad, mode) pal_lld_setpadmode(port, pad, mode) #endif -/** - * @brief Pad event enable. - * @details This function programs an event callback in the specified mode. - * @note Programming an unknown or unsupported mode is silently ignored. - * - * @param[in] port port identifier - * @param[in] pad pad number within the port - * @param[in] mode pad event mode - * @param[in] callback event callback function - * @param[in] arg callback argument - * - * @iclass - */ -#if !defined(pal_lld_enablepadevent) || defined(__DOXYGEN__) -#define palEnablePadEventI(port, pad, mode, callback, arg) -#else -#define palEnablePadEventI(port, pad, mode, callback, arg) \ - pal_lld_enablepadevent(port, pad, mode, callback, arg) -#endif - -/** - * @brief Pad event disable. - * @details This function disables previously programmed event callbacks. - * - * @param[in] port port identifier - * @param[in] pad pad number within the port - * - * @iclass - */ -#if !defined(pal_lld_disablepadevent) || defined(__DOXYGEN__) -#define palDisablePadEventI(port, pad) -#else -#define PadDisablepalEventI(port, pad) \ - pal_lld_disablepadevent(port, pad) -#endif - -/** - * @brief Pad event enable. - * @details This function programs an event callback in the specified mode. - * @note Programming an unknown or unsupported mode is silently ignored. - * - * @param[in] port port identifier - * @param[in] pad pad number within the port - * @param[in] mode pad event mode - * @param[in] callback event callback function - * @param[in] arg callback argument - * - * @api - */ -#define palEnablePadEvent(port, pad, mode, callback, arg) \ - do { \ - osalSysLock(); \ - palEnablePadEventI(port, pad, mode, callback, arg); \ - osalSysUnlock(); \ - } while (false) - -/** - * @brief Pad event disable. - * @details This function disables previously programmed event callbacks. - * - * @param[in] port port identifier - * @param[in] pad pad number within the port - * - * @api - */ -#define palDisablePadEvent(port, pad) \ - do { \ - osalSysLock(); \ - palisablePadDEventI(port, pad); \ - osalSysUnlock(); \ - } while (false) - /** * @brief Reads an input line logic state. * @note The function can be called from any context. @@ -810,26 +777,93 @@ typedef struct { #define palSetLineMode(line, mode) pal_lld_setlinemode(line, mode) #endif +#if PAL_USE_CALLBACKS || PAL_USE_WAIT || defined(__DOXYGEN__) +/** + * @brief Pad event enable. + * @note Programming an unknown or unsupported mode is silently ignored. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + * @param[in] mode pad event mode + * + * @iclass + */ +#if !defined(pal_lld_enablepadevent) || defined(__DOXYGEN__) +#define palEnablePadEventI(port, pad, mode) +#else +#define palEnablePadEventI(port, pad, mode) \ + pal_lld_enablepadevent(port, pad, mode) +#endif + +/** + * @brief Pad event disable. + * @details This function also disables previously programmed event callbacks. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + * + * @iclass + */ +#if !defined(pal_lld_disablepadevent) || defined(__DOXYGEN__) +#define palDisablePadEventI(port, pad) +#else +#define PadDisablepalEventI(port, pad) \ + pal_lld_disablepadevent(port, pad) +#endif + +/** + * @brief Pad event enable. + * @note Programming an unknown or unsupported mode is silently ignored. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + * @param[in] mode pad event mode + * + * @api + */ +#define palEnablePadEvent(port, pad, mode) \ + do { \ + osalSysLock(); \ + palEnablePadEventI(port, pad, mode); \ + osalSysUnlock(); \ + } while (false) + +/** + * @brief Pad event disable. + * @details This function also disables previously programmed event callbacks. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + * + * @api + */ +#define palDisablePadEvent(port, pad) \ + do { \ + osalSysLock(); \ + palisablePadDEventI(port, pad); \ + osalSysUnlock(); \ + } while (false) + /** * @brief Line event enable. + * @note Programming an unknown or unsupported mode is silently ignored. * * @param[in] line line identifier * @param[in] mode line event mode - * @param[in] callback event callback function - * @param[in] arg callback argument * * @iclass */ #if !defined(pal_lld_enablelineevent) || defined(__DOXYGEN__) -#define palEnableLineEventI(line, mode, callback, arg) \ - palEnablePadEventI(PAL_PORT(line), PAL_PAD(line), mode, callback, arg) +#define palEnableLineEventI(line, mode) \ + palEnablePadEventI(PAL_PORT(line), PAL_PAD(line), mode) #else -#define palEnableLineEventI(line, mode, callback, arg) \ - pal_lld_enablelineevent(line, mode, callback, arg) +#define palEnableLineEventI(line, mode) \ + pal_lld_enablelineevent(line, mode) #endif /** * @brief Line event disable. + * @details This function also disables previously programmed event callbacks. * * @param[in] line line identifier * @@ -844,35 +878,73 @@ typedef struct { /** * @brief Line event enable. + * @note Programming an unknown or unsupported mode is silently ignored. * * @param[in] line line identifier * @param[in] mode line event mode - * @param[in] callback event callback function - * @param[in] arg callback argument * * @api */ -#define palEnableLineEvent(line, mode, callback, arg) \ +#define palEnableLineEvent(line, mode) \ do { \ osalSysLock(); \ - palEnableLineEventI(line, mode, callback, arg); \ + palEnableLineEventI(line, mode); \ osalSysUnlock(); \ } while (false) /** * @brief Line event disable. + * @details This function also disables previously programmed event callbacks. * * @param[in] line line identifier * * @api */ -#define paDisableLineEvent(line) \ +#define palDisableLineEvent(line) \ do { \ osalSysLock(); \ palDisableLineEventI(line); \ osalSysUnlock(); \ } while (false) +#endif /* PAL_USE_CALLBACKS || PAL_USE_WAIT */ + +#if PAL_USE_CALLBACKS || defined(__DOXYGEN__) +/** + * @brief Associates a callback to a pad. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + * @param[in] mode pad event mode + * @param[in] callback event callback function + * @param[in] arg callback argument + * + * @api + */ +#define palSetPadCallback(port, pad, cb, arg) \ + do { \ + osalSysLock(); \ + palSetPadCallbackI(port, pad, cb, arg); \ + osalSysUnlock(); \ + } while (false) + +/** + * @brief Associates a callback to a line. + * + * @param[in] line line identifier + * @param[in] callback event callback function + * @param[in] arg callback argument + * + * @iclass + */ +#define palSetLineCallback(line, cb, arg) \ + do { \ + osalSysLock(); \ + palSetLineCallbackI(line, cb, arg); \ + osalSysUnlock(); \ + } while (false) +#endif /* PAL_USE_CALLBACKS */ + #if PAL_USE_WAIT || defined(__DOXYGEN__) /** * @brief Waits for an edge on the specified port/pad. @@ -914,7 +986,6 @@ typedef struct { palWaitLineTimeoutS(line, timeout); \ osalSysUnlock(); \ } while (false) - #endif /* PAL_USE_WAIT */ /** @} */ @@ -929,6 +1000,11 @@ extern "C" { ioportmask_t palReadBus(IOBus *bus); void palWriteBus(IOBus *bus, ioportmask_t bits); void palSetBusMode(IOBus *bus, iomode_t mode); +#if PAL_USE_CALLBACKS || defined(__DOXYGEN__) + void palSetPadCallbackI(ioportid_t port, iopadid_t pad, + palcallback_t cb, void *arg); + void palSetLineCallbackI(ioline_t line, palcallback_t cb, void *arg); +#endif /* PAL_USE_CALLBACKS */ #if PAL_USE_WAIT || defined(__DOXYGEN__) msg_t palWaitPadTimeoutS(ioportid_t port, iopadid_t pad, systime_t timeout); msg_t palWaitLineTimeoutS(ioline_t line, systime_t timeout); diff --git a/os/hal/ports/STM32/LLD/GPIOv1/hal_pal_lld.c b/os/hal/ports/STM32/LLD/GPIOv1/hal_pal_lld.c index be8f7e829..84f0be664 100644 --- a/os/hal/ports/STM32/LLD/GPIOv1/hal_pal_lld.c +++ b/os/hal/ports/STM32/LLD/GPIOv1/hal_pal_lld.c @@ -80,6 +80,14 @@ palevent_t _pal_events[16]; */ void _pal_lld_init(const PALConfig *config) { +#if PAL_USE_CALLBACKS || PAL_USE_WAIT || defined(__DOXYGEN__) + unsigned i; + + for (i = 0; i < 16; i++) { + _pal_init_event(i); + } +#endif + /* * Enables the GPIO related clocks. */ @@ -183,24 +191,20 @@ void _pal_lld_setgroupmode(ioportid_t port, port->CRL = (port->CRL & ml) | crl; } +#if PAL_USE_CALLBACKS || PAL_USE_WAIT || defined(__DOXYGEN__) /** * @brief Pad event enable. - * @details This function programs an event callback in the specified mode. * @note Programming an unknown or unsupported mode is silently ignored. * * @param[in] port port identifier * @param[in] pad pad number within the port * @param[in] mode pad event mode - * @param[in] callback event callback function - * @param[in] arg callback argument * * @notapi */ void _pal_lld_enablepadevent(ioportid_t port, iopadid_t pad, - ioeventmode_t mode, - palcallback_t callback, - void *arg) { + ioeventmode_t mode) { uint32_t padmask, cridx, crmask, portidx; @@ -218,7 +222,7 @@ void _pal_lld_enablepadevent(ioportid_t port, crmask = ~(0xFU << (((uint32_t)pad & 3U) * 4U)); /* Port index is obtained assuming that GPIO ports are placed at regular - 0x400 intervalis in memory space. So far this is true for all devices.*/ + 0x400 intervals in memory space. So far this is true for all devices.*/ portidx = (uint32_t)port >> 10U; /* Port selection in SYSCFG.*/ @@ -237,14 +241,11 @@ void _pal_lld_enablepadevent(ioportid_t port, /* Programming interrupt and event registers.*/ EXTI->IMR |= padmask; EXTI->EMR &= ~padmask; - - /* Setting up callback and argument for this event.*/ - _pal_set_event(pad, callback, arg); } /** * @brief Pad event disable. - * @details This function disables previously programmed event callbacks. + * @details This function also disables previously programmed event callbacks. * * @param[in] port port identifier * @param[in] pad pad number within the port @@ -269,7 +270,7 @@ void _pal_lld_disablepadevent(ioportid_t port, iopadid_t pad) { croff = ((uint32_t)pad & 3U) * 4U; /* Port index is obtained assuming that GPIO ports are placed at regular - 0x400 intervalis in memory space. So far this is true for all devices.*/ + 0x400 intervals in memory space. So far this is true for all devices.*/ portidx = (uint32_t)port >> 10U; crport = (AFIO->EXTICR[cridx] >> croff) & 0xFU; @@ -282,11 +283,14 @@ void _pal_lld_disablepadevent(ioportid_t port, iopadid_t pad) { EXTI->RTSR = rtsr1 & ~padmask; EXTI->FTSR = ftsr1 & ~padmask; EXTI->PR = padmask; - - /* Clearing callback and argument for this event.*/ - _pal_clear_event(pad); } + +#if PAL_USE_CALLBACKS || PAL_USE_WAIT + /* Callback cleared and/or thread reset.*/ + _pal_clear_event(pad); +#endif } +#endif /* PAL_USE_CALLBACKS || PAL_USE_WAIT */ #endif /* HAL_USE_PAL */ diff --git a/os/hal/ports/STM32/LLD/GPIOv1/hal_pal_lld.h b/os/hal/ports/STM32/LLD/GPIOv1/hal_pal_lld.h index a20cea930..f7f1c2e81 100644 --- a/os/hal/ports/STM32/LLD/GPIOv1/hal_pal_lld.h +++ b/os/hal/ports/STM32/LLD/GPIOv1/hal_pal_lld.h @@ -368,19 +368,16 @@ typedef uint32_t iopadid_t; /** * @brief Pad event enable. - * @details This function programs an event callback in the specified mode. * @note Programming an unknown or unsupported mode is silently ignored. * * @param[in] port port identifier * @param[in] pad pad number within the port * @param[in] mode pad event mode - * @param[in] callback event callback function - * @param[in] arg callback argument * * @notapi */ -#define pal_lld_enablepadevent(port, pad, mode, callback, arg) \ - _pal_lld_enablepadevent(port, pad, mode, callback, arg) +#define pal_lld_enablepadevent(port, pad, mode) \ + _pal_lld_enablepadevent(port, pad, mode) /** * @brief Pad event disable. @@ -427,12 +424,12 @@ extern "C" { void _pal_lld_setgroupmode(ioportid_t port, ioportmask_t mask, iomode_t mode); +#if PAL_USE_CALLBACKS || PAL_USE_WAIT void _pal_lld_enablepadevent(ioportid_t port, iopadid_t pad, - ioeventmode_t mode, - palcallback_t callback, - void *arg); + ioeventmode_t mode); void _pal_lld_disablepadevent(ioportid_t port, iopadid_t pad); +#endif #ifdef __cplusplus } #endif diff --git a/os/hal/ports/STM32/LLD/GPIOv2/hal_pal_lld.c b/os/hal/ports/STM32/LLD/GPIOv2/hal_pal_lld.c index 70f769f02..ab6864474 100644 --- a/os/hal/ports/STM32/LLD/GPIOv2/hal_pal_lld.c +++ b/os/hal/ports/STM32/LLD/GPIOv2/hal_pal_lld.c @@ -92,6 +92,14 @@ static void initgpio(stm32_gpio_t *gpiop, const stm32_gpio_setup_t *config) { */ void _pal_lld_init(const PALConfig *config) { +#if PAL_USE_CALLBACKS || PAL_USE_WAIT || defined(__DOXYGEN__) + unsigned i; + + for (i = 0; i < 16; i++) { + _pal_init_event(i); + } +#endif + /* * Enables the GPIO related clocks. */ @@ -212,24 +220,20 @@ void _pal_lld_setgroupmode(ioportid_t port, } } +#if PAL_USE_CALLBACKS || PAL_USE_WAIT || defined(__DOXYGEN__) /** * @brief Pad event enable. - * @details This function programs an event callback in the specified mode. * @note Programming an unknown or unsupported mode is silently ignored. * * @param[in] port port identifier * @param[in] pad pad number within the port * @param[in] mode pad event mode - * @param[in] callback event callback function - * @param[in] arg callback argument * * @notapi */ void _pal_lld_enablepadevent(ioportid_t port, iopadid_t pad, - ioeventmode_t mode, - palcallback_t callback, - void *arg) { + ioeventmode_t mode) { uint32_t padmask, cridx, crmask, portidx; @@ -247,7 +251,7 @@ void _pal_lld_enablepadevent(ioportid_t port, crmask = ~(0xFU << (((uint32_t)pad & 3U) * 4U)); /* Port index is obtained assuming that GPIO ports are placed at regular - 0x400 intervalis in memory space. So far this is true for all devices.*/ + 0x400 intervals in memory space. So far this is true for all devices.*/ portidx = (uint32_t)port >> 10U; /* Port selection in SYSCFG.*/ @@ -266,9 +270,6 @@ void _pal_lld_enablepadevent(ioportid_t port, /* Programming interrupt and event registers.*/ EXTI->IMR |= padmask; EXTI->EMR &= ~padmask; - - /* Setting up callback and argument for this event.*/ - _pal_set_event(pad, callback, arg); } /** @@ -298,7 +299,7 @@ void _pal_lld_disablepadevent(ioportid_t port, iopadid_t pad) { croff = ((uint32_t)pad & 3U) * 4U; /* Port index is obtained assuming that GPIO ports are placed at regular - 0x400 intervalis in memory space. So far this is true for all devices.*/ + 0x400 intervals in memory space. So far this is true for all devices.*/ portidx = (uint32_t)port >> 10U; crport = (SYSCFG->EXTICR[cridx] >> croff) & 0xFU; @@ -312,10 +313,13 @@ void _pal_lld_disablepadevent(ioportid_t port, iopadid_t pad) { EXTI->FTSR = ftsr1 & ~padmask; EXTI->PR = padmask; - /* Clearing callback and argument for this event.*/ - _pal_clear_event(pad); +#if PAL_USE_CALLBACKS || PAL_USE_WAIT + /* Callback cleared and/or thread reset.*/ + _pal_clear_event(pad); +#endif } } +#endif /* PAL_USE_CALLBACKS || PAL_USE_WAIT */ #endif /* HAL_USE_PAL */ diff --git a/os/hal/ports/STM32/LLD/GPIOv2/hal_pal_lld.h b/os/hal/ports/STM32/LLD/GPIOv2/hal_pal_lld.h index 4a30a61a5..546c45045 100644 --- a/os/hal/ports/STM32/LLD/GPIOv2/hal_pal_lld.h +++ b/os/hal/ports/STM32/LLD/GPIOv2/hal_pal_lld.h @@ -551,19 +551,16 @@ typedef uint32_t iopadid_t; /** * @brief Pad event enable. - * @details This function programs an event callback in the specified mode. * @note Programming an unknown or unsupported mode is silently ignored. * * @param[in] port port identifier * @param[in] pad pad number within the port * @param[in] mode pad event mode - * @param[in] callback event callback function - * @param[in] arg callback argument * * @notapi */ -#define pal_lld_enablepadevent(port, pad, mode, callback, arg) \ - _pal_lld_enablepadevent(port, pad, mode, callback, arg) +#define pal_lld_enablepadevent(port, pad, mode) \ + _pal_lld_enablepadevent(port, pad, mode) /** * @brief Pad event disable. @@ -612,9 +609,7 @@ extern "C" { iomode_t mode); void _pal_lld_enablepadevent(ioportid_t port, iopadid_t pad, - ioeventmode_t mode, - palcallback_t callback, - void *arg); + ioeventmode_t mode); void _pal_lld_disablepadevent(ioportid_t port, iopadid_t pad); #ifdef __cplusplus } diff --git a/os/hal/ports/STM32/LLD/GPIOv3/hal_pal_lld.c b/os/hal/ports/STM32/LLD/GPIOv3/hal_pal_lld.c index 6c8a1ec2e..65f76a609 100644 --- a/os/hal/ports/STM32/LLD/GPIOv3/hal_pal_lld.c +++ b/os/hal/ports/STM32/LLD/GPIOv3/hal_pal_lld.c @@ -95,6 +95,14 @@ static void initgpio(stm32_gpio_t *gpiop, const stm32_gpio_setup_t *config) { */ void _pal_lld_init(const PALConfig *config) { +#if PAL_USE_CALLBACKS || PAL_USE_WAIT || defined(__DOXYGEN__) + unsigned i; + + for (i = 0; i < 16; i++) { + _pal_init_event(i); + } +#endif + /* * Enables the GPIO related clocks. */ @@ -208,24 +216,20 @@ void _pal_lld_setgroupmode(ioportid_t port, } } +#if PAL_USE_CALLBACKS || PAL_USE_WAIT || defined(__DOXYGEN__) /** * @brief Pad event enable. - * @details This function programs an event callback in the specified mode. * @note Programming an unknown or unsupported mode is silently ignored. * * @param[in] port port identifier * @param[in] pad pad number within the port * @param[in] mode pad event mode - * @param[in] callback event callback function - * @param[in] arg callback argument * * @notapi */ void _pal_lld_enablepadevent(ioportid_t port, iopadid_t pad, - ioeventmode_t mode, - palcallback_t callback, - void *arg) { + ioeventmode_t mode) { uint32_t padmask, cridx, crmask, portidx; @@ -243,7 +247,7 @@ void _pal_lld_enablepadevent(ioportid_t port, crmask = ~(0xFU << (((uint32_t)pad & 3U) * 4U)); /* Port index is obtained assuming that GPIO ports are placed at regular - 0x400 intervalis in memory space. So far this is true for all devices.*/ + 0x400 intervals in memory space. So far this is true for all devices.*/ portidx = (uint32_t)port >> 10U; /* Port selection in SYSCFG.*/ @@ -262,9 +266,6 @@ void _pal_lld_enablepadevent(ioportid_t port, /* Programming interrupt and event registers.*/ EXTI->IMR |= padmask; EXTI->EMR &= ~padmask; - - /* Setting up callback and argument for this event.*/ - _pal_set_event(pad, callback, arg); } /** @@ -294,7 +295,7 @@ void _pal_lld_disablepadevent(ioportid_t port, iopadid_t pad) { croff = ((uint32_t)pad & 3U) * 4U; /* Port index is obtained assuming that GPIO ports are placed at regular - 0x400 intervalis in memory space. So far this is true for all devices.*/ + 0x400 intervals in memory space. So far this is true for all devices.*/ portidx = (uint32_t)port >> 10U; crport = (SYSCFG->EXTICR[cridx] >> croff) & 0xFU; @@ -308,10 +309,13 @@ void _pal_lld_disablepadevent(ioportid_t port, iopadid_t pad) { EXTI->FTSR = ftsr1 & ~padmask; EXTI->PR = padmask; - /* Clearing callback and argument for this event.*/ - _pal_clear_event(pad); +#if PAL_USE_CALLBACKS || PAL_USE_WAIT + /* Callback cleared and/or thread reset.*/ + _pal_clear_event(pad); +#endif } } +#endif /* PAL_USE_CALLBACKS || PAL_USE_WAIT */ #endif /* HAL_USE_PAL */ diff --git a/os/hal/ports/STM32/LLD/GPIOv3/hal_pal_lld.h b/os/hal/ports/STM32/LLD/GPIOv3/hal_pal_lld.h index 7b423807e..c76fda1b0 100644 --- a/os/hal/ports/STM32/LLD/GPIOv3/hal_pal_lld.h +++ b/os/hal/ports/STM32/LLD/GPIOv3/hal_pal_lld.h @@ -563,19 +563,16 @@ typedef uint32_t iopadid_t; /** * @brief Pad event enable. - * @details This function programs an event callback in the specified mode. * @note Programming an unknown or unsupported mode is silently ignored. * * @param[in] port port identifier * @param[in] pad pad number within the port * @param[in] mode pad event mode - * @param[in] callback event callback function - * @param[in] arg callback argument * * @notapi */ -#define pal_lld_enablepadevent(port, pad, mode, callback, arg) \ - _pal_lld_enablepadevent(port, pad, mode, callback, arg) +#define pal_lld_enablepadevent(port, pad, mode) \ + _pal_lld_enablepadevent(port, pad, mode) /** * @brief Pad event disable. @@ -624,9 +621,7 @@ extern "C" { iomode_t mode); void _pal_lld_enablepadevent(ioportid_t port, iopadid_t pad, - ioeventmode_t mode, - palcallback_t callback, - void *arg); + ioeventmode_t mode); void _pal_lld_disablepadevent(ioportid_t port, iopadid_t pad); #ifdef __cplusplus } diff --git a/os/hal/ports/STM32/STM32F0xx/stm32_isr.c b/os/hal/ports/STM32/STM32F0xx/stm32_isr.c index 8397b7e51..12d931c44 100644 --- a/os/hal/ports/STM32/STM32F0xx/stm32_isr.c +++ b/os/hal/ports/STM32/STM32F0xx/stm32_isr.c @@ -51,7 +51,8 @@ /* Driver interrupt handlers. */ /*===========================================================================*/ -#if HAL_USE_PAL || defined(__DOXYGEN__) +#if (HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS)) || defined(__DOXYGEN__) +#if !defined(STM32_DISABLE_EXTI0_1_HANDLER) /** * @brief EXTI[0]...EXTI[1] interrupt handler. * @@ -71,7 +72,9 @@ OSAL_IRQ_HANDLER(Vector54) { OSAL_IRQ_EPILOGUE(); } +#endif +#if !defined(STM32_DISABLE_EXTI2_3_HANDLER) /** * @brief EXTI[2]...EXTI[3] interrupt handler. * @@ -91,7 +94,9 @@ OSAL_IRQ_HANDLER(Vector58) { OSAL_IRQ_EPILOGUE(); } +#endif +#if !defined(STM32_DISABLE_EXTI4_15_HANDLER) /** * @brief EXTI[4]...EXTI[15] interrupt handler. * @@ -123,8 +128,9 @@ OSAL_IRQ_HANDLER(Vector5C) { OSAL_IRQ_EPILOGUE(); } +#endif -#endif /* HAL_USE_PAL */ +#endif /* HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS) */ /*===========================================================================*/ /* Driver exported functions. */ diff --git a/os/hal/ports/STM32/STM32F1xx/stm32_isr.c b/os/hal/ports/STM32/STM32F1xx/stm32_isr.c index 4442a8456..813468553 100644 --- a/os/hal/ports/STM32/STM32F1xx/stm32_isr.c +++ b/os/hal/ports/STM32/STM32F1xx/stm32_isr.c @@ -51,7 +51,7 @@ /* Driver interrupt handlers. */ /*===========================================================================*/ -#if HAL_USE_PAL || defined(__DOXYGEN__) +#if (HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS))|| defined(__DOXYGEN__) #if !defined(STM32_DISABLE_EXTI0_HANDLER) /** * @brief EXTI[0] interrupt handler. diff --git a/os/hal/ports/STM32/STM32F37x/stm32_isr.c b/os/hal/ports/STM32/STM32F37x/stm32_isr.c index bfb969ce0..222bee1f7 100644 --- a/os/hal/ports/STM32/STM32F37x/stm32_isr.c +++ b/os/hal/ports/STM32/STM32F37x/stm32_isr.c @@ -51,7 +51,7 @@ /* Driver interrupt handlers. */ /*===========================================================================*/ -#if HAL_USE_PAL || defined(__DOXYGEN__) +#if (HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS))|| defined(__DOXYGEN__) #if !defined(STM32_DISABLE_EXTI0_HANDLER) /** * @brief EXTI[0] interrupt handler. diff --git a/os/hal/ports/STM32/STM32F3xx/stm32_isr.c b/os/hal/ports/STM32/STM32F3xx/stm32_isr.c index bfb969ce0..d9c27b8d2 100644 --- a/os/hal/ports/STM32/STM32F3xx/stm32_isr.c +++ b/os/hal/ports/STM32/STM32F3xx/stm32_isr.c @@ -51,7 +51,7 @@ /* Driver interrupt handlers. */ /*===========================================================================*/ -#if HAL_USE_PAL || defined(__DOXYGEN__) +#if (HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS)) || defined(__DOXYGEN__) #if !defined(STM32_DISABLE_EXTI0_HANDLER) /** * @brief EXTI[0] interrupt handler. @@ -210,7 +210,7 @@ OSAL_IRQ_HANDLER(VectorE0) { } #endif -#endif /* HAL_USE_PAL */ +#endif /* HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS) */ /*===========================================================================*/ /* Driver exported functions. */ diff --git a/os/hal/ports/STM32/STM32F4xx/stm32_isr.c b/os/hal/ports/STM32/STM32F4xx/stm32_isr.c index 9ee6ea16e..1b2126be3 100644 --- a/os/hal/ports/STM32/STM32F4xx/stm32_isr.c +++ b/os/hal/ports/STM32/STM32F4xx/stm32_isr.c @@ -51,7 +51,7 @@ /* Driver interrupt handlers. */ /*===========================================================================*/ -#if HAL_USE_PAL || defined(__DOXYGEN__) +#if (HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS)) || defined(__DOXYGEN__) #if !defined(STM32_DISABLE_EXTI0_HANDLER) /** * @brief EXTI[0] interrupt handler. @@ -210,7 +210,7 @@ OSAL_IRQ_HANDLER(VectorE0) { } #endif -#endif /* HAL_USE_PAL */ +#endif /* HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS) */ /*===========================================================================*/ /* Driver exported functions. */ diff --git a/os/hal/ports/STM32/STM32F7xx/stm32_isr.c b/os/hal/ports/STM32/STM32F7xx/stm32_isr.c index 447d389db..a51705a11 100644 --- a/os/hal/ports/STM32/STM32F7xx/stm32_isr.c +++ b/os/hal/ports/STM32/STM32F7xx/stm32_isr.c @@ -51,7 +51,7 @@ /* Driver interrupt handlers. */ /*===========================================================================*/ -#if HAL_USE_PAL || defined(__DOXYGEN__) +#if (HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS)) || defined(__DOXYGEN__) #if !defined(STM32_DISABLE_EXTI0_HANDLER) /** * @brief EXTI[0] interrupt handler. @@ -210,7 +210,7 @@ OSAL_IRQ_HANDLER(VectorE0) { } #endif -#endif /* HAL_USE_PAL */ +#endif /* HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS) */ /*===========================================================================*/ /* Driver exported functions. */ diff --git a/os/hal/ports/STM32/STM32L0xx/stm32_isr.c b/os/hal/ports/STM32/STM32L0xx/stm32_isr.c index 04c73d850..a471834cb 100644 --- a/os/hal/ports/STM32/STM32L0xx/stm32_isr.c +++ b/os/hal/ports/STM32/STM32L0xx/stm32_isr.c @@ -51,7 +51,8 @@ /* Driver interrupt handlers. */ /*===========================================================================*/ -#if HAL_USE_PAL || defined(__DOXYGEN__) +#if (HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS)) || defined(__DOXYGEN__) +#if !defined(STM32_DISABLE_EXTI0_1_HANDLER) /** * @brief EXTI[0]...EXTI[1] interrupt handler. * @@ -71,12 +72,14 @@ OSAL_IRQ_HANDLER(Vector54) { OSAL_IRQ_EPILOGUE(); } +#endif /** * @brief EXTI[2]...EXTI[3] interrupt handler. * * @isr */ +#if !defined(STM32_DISABLE_EXTI2_3_HANDLER) OSAL_IRQ_HANDLER(Vector58) { uint32_t pr; @@ -91,7 +94,9 @@ OSAL_IRQ_HANDLER(Vector58) { OSAL_IRQ_EPILOGUE(); } +#endif +#if !defined(STM32_DISABLE_EXTI4_15_HANDLER) /** * @brief EXTI[4]...EXTI[15] interrupt handler. * @@ -123,8 +128,9 @@ OSAL_IRQ_HANDLER(Vector5C) { OSAL_IRQ_EPILOGUE(); } +#endif -#endif /* HAL_USE_PAL */ +#endif /* HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS) */ /*===========================================================================*/ /* Driver exported functions. */ diff --git a/os/hal/ports/STM32/STM32L1xx/stm32_isr.c b/os/hal/ports/STM32/STM32L1xx/stm32_isr.c index 3682c5a8a..6d1a49d0b 100644 --- a/os/hal/ports/STM32/STM32L1xx/stm32_isr.c +++ b/os/hal/ports/STM32/STM32L1xx/stm32_isr.c @@ -51,7 +51,7 @@ /* Driver interrupt handlers. */ /*===========================================================================*/ -#if HAL_USE_PAL || defined(__DOXYGEN__) +#if (HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS)) || defined(__DOXYGEN__) #if !defined(STM32_DISABLE_EXTI0_HANDLER) /** * @brief EXTI[0] interrupt handler. @@ -210,7 +210,7 @@ OSAL_IRQ_HANDLER(VectorE0) { } #endif -#endif /* HAL_USE_PAL */ +#endif /* HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS) */ /*===========================================================================*/ /* Driver exported functions. */ diff --git a/os/hal/ports/STM32/STM32L4xx/stm32_isr.c b/os/hal/ports/STM32/STM32L4xx/stm32_isr.c index f10a7dd9d..f134dc9b3 100644 --- a/os/hal/ports/STM32/STM32L4xx/stm32_isr.c +++ b/os/hal/ports/STM32/STM32L4xx/stm32_isr.c @@ -51,7 +51,7 @@ /* Driver interrupt handlers. */ /*===========================================================================*/ -#if HAL_USE_PAL || defined(__DOXYGEN__) +#if (HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS)) || defined(__DOXYGEN__) #if !defined(STM32_DISABLE_EXTI0_HANDLER) /** * @brief EXTI[0] interrupt handler. @@ -210,7 +210,7 @@ OSAL_IRQ_HANDLER(VectorE0) { } #endif -#endif /* HAL_USE_PAL */ +#endif /* HAL_USE_PAL && (PAL_USE_WAIT || PAL_USE_CALLBACKS) */ /*===========================================================================*/ /* Driver exported functions. */ diff --git a/os/hal/src/hal_pal.c b/os/hal/src/hal_pal.c index 12b06abd0..9cffc6d69 100644 --- a/os/hal/src/hal_pal.c +++ b/os/hal/src/hal_pal.c @@ -117,6 +117,42 @@ void palSetBusMode(IOBus *bus, iomode_t mode) { palSetGroupMode(bus->portid, bus->mask, bus->offset, mode); } +#if PAL_USE_CALLBACKS || defined(__DOXYGEN__) +/** + * @brief Associates a callback to a port/pad. + * + * @param[in] port port identifier + * @param[in] pad pad number within the port + * @param[in] callback event callback function + * @param[in] arg callback argument + * + * @api + */ +void palSetPadCallbackI(ioportid_t port, iopadid_t pad, + palcallback_t cb, void *arg) { + + palevent_t *pep = pal_lld_get_pad_event(port, pad); + pep->cb = cb; + pep->arg = arg; +} + +/** + * @brief Associates a callback to a line. + * + * @param[in] line line identifier + * @param[in] callback event callback function + * @param[in] arg callback argument + * + * @api + */ +void palSetLineCallbackI(ioline_t line, palcallback_t cb, void *arg) { + + palevent_t *pep = pal_lld_get_line_event(line); + pep->cb = cb; + pep->arg = arg; +} +#endif /* PAL_USE_CALLBACKS */ + #if PAL_USE_WAIT || defined(__DOXYGEN__) /** * @brief Waits for an edge on the specified port/pad. diff --git a/testhal/STM32/multi/PAL/main.c b/testhal/STM32/multi/PAL/main.c index a5646c1b2..bc1489cb2 100644 --- a/testhal/STM32/multi/PAL/main.c +++ b/testhal/STM32/multi/PAL/main.c @@ -63,8 +63,7 @@ int main(void) { #endif /* Enabling events on both edges of the button line.*/ - palEnableLineEvent(PORTAB_LINE_BUTTON, PAL_EVENT_MODE_BOTH_EDGES, - NULL, NULL); + palEnableLineEvent(PORTAB_LINE_BUTTON, PAL_EVENT_MODE_BOTH_EDGES); /* * Normal main() thread activity. @@ -83,7 +82,9 @@ int main(void) { } } -#else /* !PAL_USE_WAIT */ +#endif /* PAL_USE_WAIT */ + +#if !PAL_USE_WAIT && PAL_USE_CALLBACKS static event_source_t button_pressed_event; static event_source_t button_released_event; @@ -132,8 +133,8 @@ int main(void) { #endif /* Enabling events on both edges of the button line.*/ - palEnableLineEvent(PORTAB_LINE_BUTTON, PAL_EVENT_MODE_BOTH_EDGES, - button_cb, NULL); + palEnableLineEvent(PORTAB_LINE_BUTTON, PAL_EVENT_MODE_BOTH_EDGES); + palSetLineCallback(PORTAB_LINE_BUTTON, button_cb, NULL); /* * Normal main() thread activity. @@ -150,5 +151,37 @@ int main(void) { } } } -#endif /* !PAL_USE_WAIT */ +#endif /* !PAL_USE_WAIT && PAL_USE_CALLBACKS */ + +#if !PAL_USE_WAIT && !PAL_USE_CALLBACKS +/* + * Application entry point. + */ +int main(void) { + /* + * System initializations. + * - HAL initialization, this also initializes the configured device drivers + * and performs the board-specific initializations. + * - Kernel initialization, the main() function becomes a thread and the + * RTOS is active. + */ + halInit(); + chSysInit(); + +#if defined(PORTAB_LINE_LED2) + /* + * Creates the blinker thread. + */ + chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); +#endif + + /* + * Normal main() thread activity. + */ + while (true) { + palToggleLine(PORTAB_LINE_LED1); + chThdSleepMilliseconds(500); + } +} +#endif /* !PAL_USE_WAIT && !PAL_USE_CALLBACKS */ -- cgit v1.2.3