From 424f88606831bf8645716b9cfce831b468cfca75 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Thu, 31 Aug 2017 14:04:24 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10514 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/hal_pal.h | 66 ++++++++++++++++++++++ os/hal/ports/STM32/STM32L4xx/hal_lld.c | 4 ++ os/hal/ports/STM32/STM32L4xx/stm32_isr.c | 4 +- os/hal/ports/STM32/STM32L4xx/stm32_isr.h | 4 +- testhal/STM32/multi/PAL/.project | 5 -- .../multi/PAL/cfg-stm32l476_discovery/portab.h | 6 +- testhal/STM32/multi/PAL/main.c | 52 ++++++++++++++--- testhal/STM32/multi/USB_CDC/.project | 5 -- 8 files changed, 121 insertions(+), 25 deletions(-) diff --git a/os/hal/include/hal_pal.h b/os/hal/include/hal_pal.h index 6e305340e..ede48c470 100644 --- a/os/hal/include/hal_pal.h +++ b/os/hal/include/hal_pal.h @@ -607,6 +607,42 @@ typedef struct { 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 palPadEnableEvent(port, pad, mode, callback, arg) \ + do { \ + osalSysLock(); \ + palPadEnableEventI(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 palPadDisableEvent(port, pad) \ + do { \ + osalSysLock(); \ + palPadDisableEventI(port, pad); \ + osalSysUnlock(); \ + } while (false) + /** * @brief Reads an input line logic state. * @note The function can be called from any context. @@ -750,6 +786,36 @@ typedef struct { #define palLineDisableEventI(line) pal_lld_linedisableevent(line) #endif +/** + * @brief Line event enable. + * + * @param[in] line line identifier + * @param[in] mode line event mode + * @param[in] callback event callback function + * @param[in] arg callback argument + * + * @api + */ +#define palLineEnableEvent(line, mode, callback, arg) \ + do { \ + osalSysLock(); \ + palLineEnableEventI(line, mode, callback, arg); \ + osalSysUnlock(); \ + } while (false) + +/** + * @brief Line event disable. + * + * @param[in] line line identifier + * + * @api + */ +#define palLineDisableEvent(line) \ + do { \ + osalSysLock(); \ + palLineDisableEventI(line); \ + osalSysUnlock(); \ + } while (false) /** @} */ /*===========================================================================*/ diff --git a/os/hal/ports/STM32/STM32L4xx/hal_lld.c b/os/hal/ports/STM32/STM32L4xx/hal_lld.c index f02d2a3ba..d87f9b336 100644 --- a/os/hal/ports/STM32/STM32L4xx/hal_lld.c +++ b/os/hal/ports/STM32/STM32L4xx/hal_lld.c @@ -123,10 +123,14 @@ void hal_lld_init(void) { /* Initializes the backup domain.*/ hal_lld_backup_domain_init(); + /* DMA subsystems initialization.*/ #if defined(STM32_DMA_REQUIRED) dmaInit(); #endif + /* IRQ subsystem initialization.*/ + irqInit(); + /* Programmable voltage detector enable.*/ #if STM32_PVD_ENABLE PWR->CR2 = PWR_CR2_PVDE | (STM32_PLS & STM32_PLS_MASK); diff --git a/os/hal/ports/STM32/STM32L4xx/stm32_isr.c b/os/hal/ports/STM32/STM32L4xx/stm32_isr.c index 5fc69894c..71907f00c 100644 --- a/os/hal/ports/STM32/STM32L4xx/stm32_isr.c +++ b/os/hal/ports/STM32/STM32L4xx/stm32_isr.c @@ -327,7 +327,7 @@ OSAL_IRQ_HANDLER(Vector140) { * * @notapi */ -void stm32_irq_enable(void) { +void irqInit(void) { #if HAL_USE_PAL || HAL_USE_EXT nvicEnableVector(EXTI0_IRQn, STM32_IRQ_EXTI0_PRIORITY); @@ -352,7 +352,7 @@ void stm32_irq_enable(void) { * * @notapi */ -void stm32_irq_disable(void) { +void irqDeinit(void) { #if HAL_USE_PAL || HAL_USE_EXT nvicDisableVector(EXTI0_IRQn); diff --git a/os/hal/ports/STM32/STM32L4xx/stm32_isr.h b/os/hal/ports/STM32/STM32L4xx/stm32_isr.h index 1cd5cc19d..76538a0a6 100644 --- a/os/hal/ports/STM32/STM32L4xx/stm32_isr.h +++ b/os/hal/ports/STM32/STM32L4xx/stm32_isr.h @@ -141,8 +141,8 @@ #ifdef __cplusplus extern "C" { #endif - void stm32_irq_enable(void); - void stm32_irq_disable(void); + void irqInit(void); + void irqDeinit(void); #ifdef __cplusplus } #endif diff --git a/testhal/STM32/multi/PAL/.project b/testhal/STM32/multi/PAL/.project index a50e94f93..f08c2332f 100644 --- a/testhal/STM32/multi/PAL/.project +++ b/testhal/STM32/multi/PAL/.project @@ -76,11 +76,6 @@ org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - - board - 2 - CHIBIOS/os/hal/boards/ST_STM32L476_DISCOVERY - os 2 diff --git a/testhal/STM32/multi/PAL/cfg-stm32l476_discovery/portab.h b/testhal/STM32/multi/PAL/cfg-stm32l476_discovery/portab.h index b5d68b86b..a887e3190 100644 --- a/testhal/STM32/multi/PAL/cfg-stm32l476_discovery/portab.h +++ b/testhal/STM32/multi/PAL/cfg-stm32l476_discovery/portab.h @@ -29,9 +29,9 @@ /* Module constants. */ /*===========================================================================*/ -#define PORTAB_BLINK_LED1 LINE_LED_GREEN -#define PORTAB_BLINK_LED2 LINE_LED_RED -#define PORTAB_BLINK_BUTTON LINE_JOY_DOWN +#define PORTAB_LINE_LED1 LINE_LED_GREEN +#define PORTAB_LINE_LED2 LINE_LED_RED +#define PORTAB_LINE_BUTTON LINE_JOY_CENTER /*===========================================================================*/ /* Module pre-compile time settings. */ diff --git a/testhal/STM32/multi/PAL/main.c b/testhal/STM32/multi/PAL/main.c index c57a75f02..81d520cc5 100644 --- a/testhal/STM32/multi/PAL/main.c +++ b/testhal/STM32/multi/PAL/main.c @@ -22,28 +22,46 @@ /* Generic code. */ /*===========================================================================*/ -#if defined(PORTAB_BLINK_LED2) +#if defined(PORTAB_LINE_LED2) /* * LED blinker thread, times are in milliseconds. */ static THD_WORKING_AREA(waThread1, 128); static THD_FUNCTION(Thread1, arg) { - (void)arg; chRegSetThreadName("blinker"); while (true) { - palClearLine(PORTAB_BLINK_LED2); - chThdSleepMilliseconds(500); - palSetLine(PORTAB_BLINK_LED2); - chThdSleepMilliseconds(500); + systime_t time = palReadLine(PORTAB_LINE_BUTTON) == PAL_LOW ? 500 : 250; + palClearLine(PORTAB_LINE_LED2); + chThdSleepMilliseconds(time); + palSetLine(PORTAB_LINE_LED2); + chThdSleepMilliseconds(time); } } #endif +event_source_t button_pressed_event; +event_source_t button_released_event; + +static void button_cb(void *arg) { + + (void)arg; + + chSysLockFromISR(); + if (palReadLine(PORTAB_LINE_BUTTON) == PAL_LOW) { + chEvtBroadcastI(&button_released_event); + } + else { + chEvtBroadcastI(&button_pressed_event); + } + chSysUnlockFromISR(); +} + /* * Application entry point. */ int main(void) { + event_listener_t el0, el1; /* * System initializations. @@ -55,17 +73,35 @@ int main(void) { halInit(); chSysInit(); -#if defined(PORTAB_BLINK_LED2) + /* Events initialization and registration.*/ + chEvtObjectInit(&button_pressed_event); + chEvtObjectInit(&button_released_event); + chEvtRegister(&button_pressed_event, &el0, 0); + chEvtRegister(&button_released_event, &el1, 1); + +#if defined(PORTAB_LINE_LED2) /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); #endif + /* Enabling callback on both edges of the button line.*/ + palLineEnableEvent(PORTAB_LINE_BUTTON, PAL_EVENT_MODE_BOTH_EDGES, + button_cb, NULL); + /* * Normal main() thread activity. */ while (true) { - chThdSleepMilliseconds(1000); + eventmask_t events; + + events = chEvtWaitOne(EVENT_MASK(0) | EVENT_MASK(1)); + if (events & EVENT_MASK(0)) { + palSetLine(PORTAB_LINE_LED1); + } + if (events & EVENT_MASK(1)) { + palClearLine(PORTAB_LINE_LED1); + } } } diff --git a/testhal/STM32/multi/USB_CDC/.project b/testhal/STM32/multi/USB_CDC/.project index 1f29e2777..d2ce0172b 100644 --- a/testhal/STM32/multi/USB_CDC/.project +++ b/testhal/STM32/multi/USB_CDC/.project @@ -76,11 +76,6 @@ org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - - board - 2 - CHIBIOS/os/hal/boards/ST_STM32L476_DISCOVERY - os 2 -- cgit v1.2.3