Repository: incubator-mynewt-core Updated Branches: refs/heads/develop f739293e2 -> ece980672
MYNEWT-401: HAL timer init API modification The changes are due to a modification of the hal timer API. We decided that the configuration through the syscfg method was not desirable and it was not consistent with other hals. Thus, we modified hal_timer_init() to take a void *cfg and added a hal_timer_config() to make it operate like the other HALs. There are examples of configurations in most of the bsps for those who want to see how to configure the platform specific *cfg that is passed to hal_timer_init(). Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ece98067 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ece98067 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ece98067 Branch: refs/heads/develop Commit: ece980672d4b7e41c560107c667f6ffcb54d3e9d Parents: f739293 Author: William San Filippo <wi...@runtime.io> Authored: Tue Nov 1 15:55:41 2016 -0700 Committer: William San Filippo <wi...@runtime.io> Committed: Tue Nov 1 16:11:59 2016 -0700 ---------------------------------------------------------------------- hw/bsp/arduino_primo_nrf52/src/os_bsp.c | 21 ++++ hw/bsp/arduino_primo_nrf52/syscfg.yml | 15 --- hw/bsp/bmd300eval/src/os_bsp.c | 21 ++++ hw/bsp/bmd300eval/syscfg.yml | 15 --- hw/bsp/nrf51-arduino_101/src/os_bsp.c | 13 ++ hw/bsp/nrf51-arduino_101/syscfg.yml | 9 -- hw/bsp/nrf51-blenano/src/os_bsp.c | 13 ++ hw/bsp/nrf51-blenano/syscfg.yml | 9 -- hw/bsp/nrf51dk-16kbram/src/os_bsp.c | 13 ++ hw/bsp/nrf51dk-16kbram/syscfg.yml | 9 -- hw/bsp/nrf51dk/src/os_bsp.c | 13 ++ hw/bsp/nrf51dk/syscfg.yml | 9 -- hw/bsp/nrf52dk/src/os_bsp.c | 21 ++++ hw/bsp/nrf52dk/syscfg.yml | 15 --- hw/bsp/nucleo-f401re/src/hal_bsp.c | 5 + hw/bsp/nucleo-f401re/syscfg.yml | 10 +- hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c | 5 + hw/bsp/olimex_stm32-e407_devboard/syscfg.yml | 8 -- hw/bsp/rb-nano2/src/os_bsp.c | 21 ++++ hw/bsp/rb-nano2/syscfg.yml | 15 --- hw/bsp/stm32f4discovery/src/hal_bsp.c | 5 +- hw/hal/include/hal/hal_timer.h | 13 +- hw/mcu/nordic/nrf51xxx/src/hal_timer.c | 115 +++++++++++------- hw/mcu/nordic/nrf52xxx/src/hal_timer.c | 126 ++++++++++++-------- hw/mcu/stm/stm32f4xx/src/hal_timer.c | 78 +++++++----- kernel/os/src/os_cputime.c | 2 +- 26 files changed, 362 insertions(+), 237 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/arduino_primo_nrf52/src/os_bsp.c ---------------------------------------------------------------------- diff --git a/hw/bsp/arduino_primo_nrf52/src/os_bsp.c b/hw/bsp/arduino_primo_nrf52/src/os_bsp.c index 7a47ea7..3bf58e2 100644 --- a/hw/bsp/arduino_primo_nrf52/src/os_bsp.c +++ b/hw/bsp/arduino_primo_nrf52/src/os_bsp.c @@ -89,6 +89,27 @@ hal_bsp_init(void) nrf_drv_spis_config_t spi_cfg = NRF_DRV_SPIS_DEFAULT_CONFIG(0); #endif +#if MYNEWT_VAL(TIMER_0) + rc = hal_timer_init(0, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_1) + rc = hal_timer_init(1, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_2) + rc = hal_timer_init(2, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_3) + rc = hal_timer_init(3, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_4) + rc = hal_timer_init(4, NULL); + assert(rc == 0); +#endif + /* Set cputime to count at 1 usec increments */ rc = os_cputime_init(MYNEWT_VAL(CLOCK_FREQ)); assert(rc == 0); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/arduino_primo_nrf52/syscfg.yml ---------------------------------------------------------------------- diff --git a/hw/bsp/arduino_primo_nrf52/syscfg.yml b/hw/bsp/arduino_primo_nrf52/syscfg.yml index 178b9a2..3c13258 100644 --- a/hw/bsp/arduino_primo_nrf52/syscfg.yml +++ b/hw/bsp/arduino_primo_nrf52/syscfg.yml @@ -87,33 +87,18 @@ syscfg.defs: TIMER_0: description: 'NRF52 Timer 0' value: 0 - TIMER_0_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_1: description: 'NRF52 Timer 1' value: 0 - TIMER_1_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_2: description: 'NRF52 Timer 2' value: 0 - TIMER_2_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_3: description: 'NRF52 Timer 3' value: 0 - TIMER_3_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_4: description: 'NRF52 Timer 4' value: 0 - TIMER_4_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' syscfg.vals: CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/bmd300eval/src/os_bsp.c ---------------------------------------------------------------------- diff --git a/hw/bsp/bmd300eval/src/os_bsp.c b/hw/bsp/bmd300eval/src/os_bsp.c index ec153d0..755f39d 100644 --- a/hw/bsp/bmd300eval/src/os_bsp.c +++ b/hw/bsp/bmd300eval/src/os_bsp.c @@ -86,6 +86,27 @@ hal_bsp_init(void) nrf_drv_spis_config_t spi_cfg = NRF_DRV_SPIS_DEFAULT_CONFIG(0); #endif +#if MYNEWT_VAL(TIMER_0) + rc = hal_timer_init(0, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_1) + rc = hal_timer_init(1, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_2) + rc = hal_timer_init(2, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_3) + rc = hal_timer_init(3, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_4) + rc = hal_timer_init(4, NULL); + assert(rc == 0); +#endif + /* Set cputime to count at 1 usec increments */ rc = os_cputime_init(MYNEWT_VAL(CLOCK_FREQ)); assert(rc == 0); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/bmd300eval/syscfg.yml ---------------------------------------------------------------------- diff --git a/hw/bsp/bmd300eval/syscfg.yml b/hw/bsp/bmd300eval/syscfg.yml index 68b32ed..a84f75f 100644 --- a/hw/bsp/bmd300eval/syscfg.yml +++ b/hw/bsp/bmd300eval/syscfg.yml @@ -75,33 +75,18 @@ syscfg.defs: TIMER_0: description: 'NRF52 Timer 0' value: 1 - TIMER_0_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_1: description: 'NRF52 Timer 1' value: 0 - TIMER_1_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_2: description: 'NRF52 Timer 2' value: 0 - TIMER_2_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_3: description: 'NRF52 Timer 3' value: 0 - TIMER_3_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_4: description: 'NRF52 Timer 4' value: 0 - TIMER_4_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' syscfg.vals: CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/nrf51-arduino_101/src/os_bsp.c ---------------------------------------------------------------------- diff --git a/hw/bsp/nrf51-arduino_101/src/os_bsp.c b/hw/bsp/nrf51-arduino_101/src/os_bsp.c index 9991022..d0bb24d 100644 --- a/hw/bsp/nrf51-arduino_101/src/os_bsp.c +++ b/hw/bsp/nrf51-arduino_101/src/os_bsp.c @@ -55,6 +55,19 @@ hal_bsp_init(void) assert(rc == 0); #endif +#if MYNEWT_VAL(TIMER_0) + rc = hal_timer_init(0, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_1) + rc = hal_timer_init(1, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_2) + rc = hal_timer_init(2, NULL); + assert(rc == 0); +#endif + /* Set cputime to count at 1 usec increments */ rc = os_cputime_init(MYNEWT_VAL(CLOCK_FREQ)); assert(rc == 0); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/nrf51-arduino_101/syscfg.yml ---------------------------------------------------------------------- diff --git a/hw/bsp/nrf51-arduino_101/syscfg.yml b/hw/bsp/nrf51-arduino_101/syscfg.yml index 97b213d..eba942a 100644 --- a/hw/bsp/nrf51-arduino_101/syscfg.yml +++ b/hw/bsp/nrf51-arduino_101/syscfg.yml @@ -68,21 +68,12 @@ syscfg.defs: TIMER_0: description: 'NRF51 Timer 0' value: 1 - TIMER_0_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_1: description: 'NRF51 Timer 1' value: 0 - TIMER_1_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_2: description: 'NRF51 Timer 2' value: 0 - TIMER_2_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' syscfg.vals: CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/nrf51-blenano/src/os_bsp.c ---------------------------------------------------------------------- diff --git a/hw/bsp/nrf51-blenano/src/os_bsp.c b/hw/bsp/nrf51-blenano/src/os_bsp.c index 371a6ed..f18fb0b 100644 --- a/hw/bsp/nrf51-blenano/src/os_bsp.c +++ b/hw/bsp/nrf51-blenano/src/os_bsp.c @@ -68,6 +68,19 @@ hal_bsp_init(void) nrf_drv_spis_config_t spi_cfg = NRF_DRV_SPIS_DEFAULT_CONFIG(1); #endif +#if MYNEWT_VAL(TIMER_0) + rc = hal_timer_init(0, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_1) + rc = hal_timer_init(1, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_2) + rc = hal_timer_init(2, NULL); + assert(rc == 0); +#endif + /* Set cputime to count at 1 usec increments */ rc = os_cputime_init(MYNEWT_VAL(CLOCK_FREQ)); assert(rc == 0); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/nrf51-blenano/syscfg.yml ---------------------------------------------------------------------- diff --git a/hw/bsp/nrf51-blenano/syscfg.yml b/hw/bsp/nrf51-blenano/syscfg.yml index 048c781..39e8098 100644 --- a/hw/bsp/nrf51-blenano/syscfg.yml +++ b/hw/bsp/nrf51-blenano/syscfg.yml @@ -65,21 +65,12 @@ syscfg.defs: TIMER_0: description: 'NRF51 Timer 0' value: 1 - TIMER_0_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_1: description: 'NRF51 Timer 1' value: 0 - TIMER_1_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_2: description: 'NRF51 Timer 2' value: 0 - TIMER_2_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' syscfg.vals: CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/nrf51dk-16kbram/src/os_bsp.c ---------------------------------------------------------------------- diff --git a/hw/bsp/nrf51dk-16kbram/src/os_bsp.c b/hw/bsp/nrf51dk-16kbram/src/os_bsp.c index 107cb61..0694129 100644 --- a/hw/bsp/nrf51dk-16kbram/src/os_bsp.c +++ b/hw/bsp/nrf51dk-16kbram/src/os_bsp.c @@ -73,6 +73,19 @@ hal_bsp_init(void) nrf_drv_spis_config_t spi_cfg = NRF_DRV_SPIS_DEFAULT_CONFIG(1); #endif +#if MYNEWT_VAL(TIMER_0) + rc = hal_timer_init(0, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_1) + rc = hal_timer_init(1, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_2) + rc = hal_timer_init(2, NULL); + assert(rc == 0); +#endif + /* Set cputime to count at 1 usec increments */ rc = os_cputime_init(MYNEWT_VAL(CLOCK_FREQ)); assert(rc == 0); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/nrf51dk-16kbram/syscfg.yml ---------------------------------------------------------------------- diff --git a/hw/bsp/nrf51dk-16kbram/syscfg.yml b/hw/bsp/nrf51dk-16kbram/syscfg.yml index 7381af0..627db0f 100644 --- a/hw/bsp/nrf51dk-16kbram/syscfg.yml +++ b/hw/bsp/nrf51dk-16kbram/syscfg.yml @@ -65,21 +65,12 @@ syscfg.defs: TIMER_0: description: 'NRF51 Timer 0' value: 1 - TIMER_0_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_1: description: 'NRF51 Timer 1' value: 0 - TIMER_1_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_2: description: 'NRF51 Timer 2' value: 0 - TIMER_2_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' I2C_0: description: 'NRF51 I2C (TWI) interface 0' http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/nrf51dk/src/os_bsp.c ---------------------------------------------------------------------- diff --git a/hw/bsp/nrf51dk/src/os_bsp.c b/hw/bsp/nrf51dk/src/os_bsp.c index afaeb8c..68b9b1a 100644 --- a/hw/bsp/nrf51dk/src/os_bsp.c +++ b/hw/bsp/nrf51dk/src/os_bsp.c @@ -74,6 +74,19 @@ hal_bsp_init(void) nrf_drv_spis_config_t spi_cfg = NRF_DRV_SPIS_DEFAULT_CONFIG(1); #endif +#if MYNEWT_VAL(TIMER_0) + rc = hal_timer_init(0, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_1) + rc = hal_timer_init(1, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_2) + rc = hal_timer_init(2, NULL); + assert(rc == 0); +#endif + /* Set cputime to count at 1 usec increments */ rc = os_cputime_init(MYNEWT_VAL(CLOCK_FREQ)); assert(rc == 0); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/nrf51dk/syscfg.yml ---------------------------------------------------------------------- diff --git a/hw/bsp/nrf51dk/syscfg.yml b/hw/bsp/nrf51dk/syscfg.yml index 17d9213..14ab883 100644 --- a/hw/bsp/nrf51dk/syscfg.yml +++ b/hw/bsp/nrf51dk/syscfg.yml @@ -65,21 +65,12 @@ syscfg.defs: TIMER_0: description: 'NRF51 Timer 0' value: 1 - TIMER_0_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_1: description: 'NRF51 Timer 1' value: 0 - TIMER_1_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_2: description: 'NRF51 Timer 2' value: 0 - TIMER_2_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' I2C_0: description: 'NRF51 I2C (TWI) interface 0' http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/nrf52dk/src/os_bsp.c ---------------------------------------------------------------------- diff --git a/hw/bsp/nrf52dk/src/os_bsp.c b/hw/bsp/nrf52dk/src/os_bsp.c index 14ce441..ecbee85 100644 --- a/hw/bsp/nrf52dk/src/os_bsp.c +++ b/hw/bsp/nrf52dk/src/os_bsp.c @@ -92,6 +92,27 @@ hal_bsp_init(void) nrf_drv_spis_config_t spi_cfg = NRF_DRV_SPIS_DEFAULT_CONFIG(0); #endif +#if MYNEWT_VAL(TIMER_0) + rc = hal_timer_init(0, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_1) + rc = hal_timer_init(1, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_2) + rc = hal_timer_init(2, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_3) + rc = hal_timer_init(3, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_4) + rc = hal_timer_init(4, NULL); + assert(rc == 0); +#endif + /* Set cputime to count at 1 usec increments */ rc = os_cputime_init(MYNEWT_VAL(CLOCK_FREQ)); assert(rc == 0); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/nrf52dk/syscfg.yml ---------------------------------------------------------------------- diff --git a/hw/bsp/nrf52dk/syscfg.yml b/hw/bsp/nrf52dk/syscfg.yml index 3abc759..8f1bb0e 100644 --- a/hw/bsp/nrf52dk/syscfg.yml +++ b/hw/bsp/nrf52dk/syscfg.yml @@ -54,33 +54,18 @@ syscfg.defs: TIMER_0: description: 'NRF52 Timer 0' value: 1 - TIMER_0_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_1: description: 'NRF52 Timer 1' value: 0 - TIMER_1_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_2: description: 'NRF52 Timer 2' value: 0 - TIMER_2_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_3: description: 'NRF52 Timer 3' value: 0 - TIMER_3_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_4: description: 'NRF52 Timer 4' value: 0 - TIMER_4_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' I2C_0: description: 'NRF52 I2C (TWI) interface 0' http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/nucleo-f401re/src/hal_bsp.c ---------------------------------------------------------------------- diff --git a/hw/bsp/nucleo-f401re/src/hal_bsp.c b/hw/bsp/nucleo-f401re/src/hal_bsp.c index e80fb7e..0d2b2eb 100644 --- a/hw/bsp/nucleo-f401re/src/hal_bsp.c +++ b/hw/bsp/nucleo-f401re/src/hal_bsp.c @@ -26,6 +26,7 @@ #include <hal/hal_gpio.h> #include <hal/hal_flash_int.h> #include <hal/hal_i2c.h> +#include <hal/hal_timer.h> #if MYNEWT_VAL(SPI_0_MASTER) || MYNEWT_VAL(SPI_0_SLAVE) #include <hal/hal_spi.h> #endif @@ -129,6 +130,10 @@ hal_bsp_init(void) rc = hal_i2c_init(0, &i2c_cfg0); assert(rc == 0); #endif + +#if MYNEWT_VAL(TIMER_0) + hal_timer_init(0, TIM9); +#endif } /** http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/nucleo-f401re/syscfg.yml ---------------------------------------------------------------------- diff --git a/hw/bsp/nucleo-f401re/syscfg.yml b/hw/bsp/nucleo-f401re/syscfg.yml index 021a913..c27ed47 100644 --- a/hw/bsp/nucleo-f401re/syscfg.yml +++ b/hw/bsp/nucleo-f401re/syscfg.yml @@ -6,7 +6,7 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, @@ -50,14 +50,6 @@ syscfg.defs: description: 'TIMER_0' value: 0 - TIMER_0_INTERRUPT_PRIORITY: - description: 'Interrupt priority for HAL timer 0' - value: 1 - - TIMER_0_UNIT: - description: 'MCU timer unit assigned as HAL timer0' - value: TIM9 - syscfg.vals: REBOOT_LOG_FLASH_AREA: FLASH_AREA_REBOOT_LOG CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c ---------------------------------------------------------------------- diff --git a/hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c b/hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c index 446b72b..5ea6b16 100644 --- a/hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c +++ b/hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c @@ -39,6 +39,7 @@ #include "stm32f4xx_hal_adc.h" #include <adc_stm32f4/adc_stm32f4.h> #include <hal/hal_i2c.h> +#include <hal/hal_timer.h> #include <mcu/stm32f4xx_mynewt_hal.h> #if MYNEWT_VAL(SPI_0_MASTER) || MYNEWT_VAL(SPI_0_SLAVE) #include <hal/hal_spi.h> @@ -320,5 +321,9 @@ hal_bsp_init(void) rc = hal_i2c_init(0, &i2c_cfg0); assert(rc == 0); #endif + +#if MYNEWT_VAL(TIMER_0) + hal_timer_init(0, TIM9); +#endif } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/olimex_stm32-e407_devboard/syscfg.yml ---------------------------------------------------------------------- diff --git a/hw/bsp/olimex_stm32-e407_devboard/syscfg.yml b/hw/bsp/olimex_stm32-e407_devboard/syscfg.yml index 5f0cf16..20dd4e1 100644 --- a/hw/bsp/olimex_stm32-e407_devboard/syscfg.yml +++ b/hw/bsp/olimex_stm32-e407_devboard/syscfg.yml @@ -45,14 +45,6 @@ syscfg.defs: description: 'TIMER_0' value: 0 - TIMER_0_INTERRUPT_PRIORITY: - description: 'Interrupt priority for HAL timer 0' - value: 1 - - TIMER_0_UNIT: - description: 'MCU timer unit assigned as HAL timer0' - value: TIM9 - syscfg.vals: REBOOT_LOG_FLASH_AREA: FLASH_AREA_REBOOT_LOG CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/rb-nano2/src/os_bsp.c ---------------------------------------------------------------------- diff --git a/hw/bsp/rb-nano2/src/os_bsp.c b/hw/bsp/rb-nano2/src/os_bsp.c index 7da5d1e..cbf622f 100644 --- a/hw/bsp/rb-nano2/src/os_bsp.c +++ b/hw/bsp/rb-nano2/src/os_bsp.c @@ -60,6 +60,27 @@ hal_bsp_init(void) { int rc; +#if MYNEWT_VAL(TIMER_0) + rc = hal_timer_init(0, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_1) + rc = hal_timer_init(1, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_2) + rc = hal_timer_init(2, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_3) + rc = hal_timer_init(3, NULL); + assert(rc == 0); +#endif +#if MYNEWT_VAL(TIMER_4) + rc = hal_timer_init(4, NULL); + assert(rc == 0); +#endif + /* Set cputime to count at 1 usec increments */ rc = os_cputime_init(MYNEWT_VAL(CLOCK_FREQ)); assert(rc == 0); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/rb-nano2/syscfg.yml ---------------------------------------------------------------------- diff --git a/hw/bsp/rb-nano2/syscfg.yml b/hw/bsp/rb-nano2/syscfg.yml index 8f8fa81..f1c2581 100644 --- a/hw/bsp/rb-nano2/syscfg.yml +++ b/hw/bsp/rb-nano2/syscfg.yml @@ -70,33 +70,18 @@ syscfg.defs: TIMER_0: description: 'NRF52 Timer 0' value: 1 - TIMER_0_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_1: description: 'NRF52 Timer 1' value: 0 - TIMER_1_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_2: description: 'NRF52 Timer 2' value: 0 - TIMER_2_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_3: description: 'NRF52 Timer 3' value: 0 - TIMER_3_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' TIMER_4: description: 'NRF52 Timer 4' value: 0 - TIMER_4_INTERRUPT_PRIORITY: - description: 'TBD' - value: '((1 << __NVIC_PRIO_BITS) - 1)' syscfg.vals: CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/bsp/stm32f4discovery/src/hal_bsp.c ---------------------------------------------------------------------- diff --git a/hw/bsp/stm32f4discovery/src/hal_bsp.c b/hw/bsp/stm32f4discovery/src/hal_bsp.c index d170b35..696ecb8 100644 --- a/hw/bsp/stm32f4discovery/src/hal_bsp.c +++ b/hw/bsp/stm32f4discovery/src/hal_bsp.c @@ -27,6 +27,7 @@ #include <hal/hal_bsp.h> #include <hal/hal_gpio.h> #include <hal/hal_flash_int.h> +#include <hal/hal_timer.h> #include <stm32f407xx.h> #include <stm32f4xx_hal_gpio_ex.h> @@ -92,7 +93,9 @@ hal_bsp_init(void) OS_DEV_INIT_PRIMARY, 0, uart_hal_init, (void *)&uart_cfg[0]); assert(rc == 0); #endif - +#if MYNEWT_VAL(TIMER_0) + hal_timer_init(0, TIM9); +#endif } /** http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/hal/include/hal/hal_timer.h ---------------------------------------------------------------------- diff --git a/hw/hal/include/hal/hal_timer.h b/hw/hal/include/hal/hal_timer.h index 95f134b..c0a1cff 100644 --- a/hw/hal/include/hal/hal_timer.h +++ b/hw/hal/include/hal/hal_timer.h @@ -47,16 +47,19 @@ struct hal_timer TAILQ_ENTRY(hal_timer) link; /* Queue linked list structure */ }; -/* - * Initialize a HW timer at the given frequency and start it. If the exact - * frequency is not obtainable the closest obtainable frequency is set. - */ -int hal_timer_init(int timer_num, uint32_t freq_hz); +/* Initialize a HW timer. */ +int hal_timer_init(int timer_num, void *cfg); /* Un-initialize a HW timer. */ int hal_timer_deinit(int timer_num); /* + * Config a HW timer at the given frequency and start it. If the exact + * frequency is not obtainable the closest obtainable frequency is set. + */ +int hal_timer_config(int timer_num, uint32_t freq_hz); + +/* * Returns the resolution of the HW timer. NOTE: the frequency may not be * obtainable so the caller can use this to determine the resolution. * Returns resolution in nanoseconds. A return value of 0 indicates an invalid http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/mcu/nordic/nrf51xxx/src/hal_timer.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_timer.c b/hw/mcu/nordic/nrf51xxx/src/hal_timer.c index 5a5aa7c..45e4ac5 100644 --- a/hw/mcu/nordic/nrf51xxx/src/hal_timer.c +++ b/hw/mcu/nordic/nrf51xxx/src/hal_timer.c @@ -357,65 +357,36 @@ nrf51_timer2_irq_handler(void) /** * hal timer init * - * Initialize (and start) a timer to run at the desired frequency. + * Initialize platform specific timer items * - * @param timer_num - * @param freq_hz + * @param timer_num Timer number to initialize + * @param cfg Pointer to platform specific configuration * - * @return int + * @return int 0: success; error code otherwise */ int -hal_timer_init(int timer_num, uint32_t freq_hz) +hal_timer_init(int timer_num, void *cfg) { int rc; - uint8_t prescaler; uint8_t irq_num; - uint32_t ctx; - uint32_t div; - uint32_t min_delta; - uint32_t max_delta; - uint32_t prio; struct nrf51_hal_timer *bsptimer; NRF_TIMER_Type *hwtimer; hal_timer_irq_handler_t irq_isr; NRF51_HAL_TIMER_RESOLVE(timer_num, bsptimer); - /* Set timer to desired frequency */ - div = NRF51_MAX_TIMER_FREQ / freq_hz; - - /* Largest prescaler is 2^9 and must make sure frequency not too high */ - if (bsptimer->tmr_enabled || (div == 0) || (div > 512)) { + /* If timer is enabled do not allow init */ + if (bsptimer->tmr_enabled) { rc = EINVAL; goto err; } - if (div == 1) { - prescaler = 0; - } else { - /* Find closest prescaler */ - for (prescaler = 1; prescaler < 10; ++prescaler) { - if (div <= (1 << prescaler)) { - min_delta = div - (1 << (prescaler - 1)); - max_delta = (1 << prescaler) - div; - if (min_delta < max_delta) { - prescaler -= 1; - } - break; - } - } - } - - /* Now set the actual frequency */ - bsptimer->tmr_freq = NRF51_MAX_TIMER_FREQ / (1 << prescaler); - switch (timer_num) { #if MYNEWT_VAL(TIMER_0) case 0: irq_num = TIMER0_IRQn; hwtimer = NRF_TIMER0; irq_isr = nrf51_timer0_irq_handler; - prio = MYNEWT_VAL(TIMER_0_INTERRUPT_PRIORITY); break; #endif #if MYNEWT_VAL(TIMER_1) @@ -424,7 +395,6 @@ hal_timer_init(int timer_num, uint32_t freq_hz) hwtimer = NRF_TIMER1; irq_isr = nrf51_timer1_irq_handler; bsptimer->tmr_16bit = 1; - prio = MYNEWT_VAL(TIMER_1_INTERRUPT_PRIORITY); break; #endif #if MYNEWT_VAL(TIMER_2) @@ -433,11 +403,9 @@ hal_timer_init(int timer_num, uint32_t freq_hz) hwtimer = NRF_TIMER2; irq_isr = nrf51_timer2_irq_handler; bsptimer->tmr_16bit = 1; - prio = MYNEWT_VAL(TIMER_2_INTERRUPT_PRIORITY); break; #endif default: - prio = 0; hwtimer = NULL; break; } @@ -449,6 +417,70 @@ hal_timer_init(int timer_num, uint32_t freq_hz) bsptimer->tmr_reg = hwtimer; bsptimer->tmr_irq_num = irq_num; + + /* Disable IRQ, set priority and set vector in table */ + NVIC_DisableIRQ(irq_num); + NVIC_SetPriority(irq_num, (1 << __NVIC_PRIO_BITS) - 1); + NVIC_SetVector(irq_num, (uint32_t)irq_isr); + + return 0; + +err: + return rc; +} + +/** + * hal timer config + * + * Configure a timer to run at the desired frequency. This starts the timer. + * + * @param timer_num + * @param freq_hz + * + * @return int + */ +int +hal_timer_config(int timer_num, uint32_t freq_hz) +{ + int rc; + uint8_t prescaler; + uint32_t ctx; + uint32_t div; + uint32_t min_delta; + uint32_t max_delta; + struct nrf51_hal_timer *bsptimer; + NRF_TIMER_Type *hwtimer; + + NRF51_HAL_TIMER_RESOLVE(timer_num, bsptimer); + + /* Set timer to desired frequency */ + div = NRF51_MAX_TIMER_FREQ / freq_hz; + + /* Largest prescaler is 2^9 and must make sure frequency not too high */ + if (bsptimer->tmr_enabled || (div == 0) || (div > 512) || + (bsptimer->tmr_reg == NULL)) { + rc = EINVAL; + goto err; + } + + if (div == 1) { + prescaler = 0; + } else { + /* Find closest prescaler */ + for (prescaler = 1; prescaler < 10; ++prescaler) { + if (div <= (1 << prescaler)) { + min_delta = div - (1 << (prescaler - 1)); + max_delta = (1 << prescaler) - div; + if (min_delta < max_delta) { + prescaler -= 1; + } + break; + } + } + } + + /* Now set the actual frequency */ + bsptimer->tmr_freq = NRF51_MAX_TIMER_FREQ / (1 << prescaler); bsptimer->tmr_enabled = 1; /* disable interrupts */ @@ -465,6 +497,7 @@ hal_timer_init(int timer_num, uint32_t freq_hz) } } } + hwtimer = bsptimer->tmr_reg; /* Stop the timer first */ hwtimer->TASKS_STOP = 1; @@ -488,9 +521,7 @@ hal_timer_init(int timer_num, uint32_t freq_hz) hwtimer->TASKS_START = 1; /* Set isr in vector table and enable interrupt */ - NVIC_SetPriority(irq_num, prio); - NVIC_SetVector(irq_num, (uint32_t)irq_isr); - NVIC_EnableIRQ(irq_num); + NVIC_EnableIRQ(bsptimer->tmr_irq_num); __HAL_ENABLE_INTERRUPTS(ctx); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/mcu/nordic/nrf52xxx/src/hal_timer.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_timer.c b/hw/mcu/nordic/nrf52xxx/src/hal_timer.c index 1db2e37..396ba45 100644 --- a/hw/mcu/nordic/nrf52xxx/src/hal_timer.c +++ b/hw/mcu/nordic/nrf52xxx/src/hal_timer.c @@ -296,65 +296,36 @@ nrf52_timer4_irq_handler(void) /** * hal timer init * - * Initialize (and start) a timer to run at the desired frequency. + * Initialize platform specific timer items * - * @param timer_num - * @param freq_hz + * @param timer_num Timer number to initialize + * @param cfg Pointer to platform specific configuration * - * @return int + * @return int 0: success; error code otherwise */ int -hal_timer_init(int timer_num, uint32_t freq_hz) +hal_timer_init(int timer_num, void *cfg) { int rc; - uint8_t prescaler; uint8_t irq_num; - uint32_t ctx; - uint32_t div; - uint32_t min_delta; - uint32_t max_delta; - uint32_t prio; struct nrf52_hal_timer *bsptimer; NRF_TIMER_Type *hwtimer; hal_timer_irq_handler_t irq_isr; NRF52_HAL_TIMER_RESOLVE(timer_num, bsptimer); - /* Set timer to desired frequency */ - div = NRF52_MAX_TIMER_FREQ / freq_hz; - - /* Largest prescaler is 2^9 and must make sure frequency not too high */ - if (bsptimer->tmr_enabled || (div == 0) || (div > 512)) { + /* If timer is enabled do not allow init */ + if (bsptimer->tmr_enabled) { rc = EINVAL; goto err; } - if (div == 1) { - prescaler = 0; - } else { - /* Find closest prescaler */ - for (prescaler = 1; prescaler < 10; ++prescaler) { - if (div <= (1 << prescaler)) { - min_delta = div - (1 << (prescaler - 1)); - max_delta = (1 << prescaler) - div; - if (min_delta < max_delta) { - prescaler -= 1; - } - break; - } - } - } - - /* Now set the actual frequency */ - bsptimer->tmr_freq = NRF52_MAX_TIMER_FREQ / (1 << prescaler); - switch (timer_num) { #if MYNEWT_VAL(TIMER_0) case 0: irq_num = TIMER0_IRQn; hwtimer = NRF_TIMER0; irq_isr = nrf52_timer0_irq_handler; - prio = MYNEWT_VAL(TIMER_0_INTERRUPT_PRIORITY); break; #endif #if MYNEWT_VAL(TIMER_1) @@ -362,7 +333,6 @@ hal_timer_init(int timer_num, uint32_t freq_hz) irq_num = TIMER1_IRQn; hwtimer = NRF_TIMER1; irq_isr = nrf52_timer1_irq_handler; - prio = MYNEWT_VAL(TIMER_1_INTERRUPT_PRIORITY); break; #endif #if MYNEWT_VAL(TIMER_2) @@ -370,7 +340,6 @@ hal_timer_init(int timer_num, uint32_t freq_hz) irq_num = TIMER2_IRQn; hwtimer = NRF_TIMER2; irq_isr = nrf52_timer2_irq_handler; - prio = MYNEWT_VAL(TIMER_2_INTERRUPT_PRIORITY); break; #endif #if MYNEWT_VAL(TIMER_3) @@ -378,7 +347,6 @@ hal_timer_init(int timer_num, uint32_t freq_hz) irq_num = TIMER3_IRQn; hwtimer = NRF_TIMER3; irq_isr = nrf52_timer3_irq_handler; - prio = MYNEWT_VAL(TIMER_3_INTERRUPT_PRIORITY); break; #endif #if MYNEWT_VAL(TIMER_4) @@ -386,12 +354,10 @@ hal_timer_init(int timer_num, uint32_t freq_hz) irq_num = TIMER4_IRQn; hwtimer = NRF_TIMER4; irq_isr = nrf52_timer4_irq_handler; - prio = MYNEWT_VAL(TIMER_4_INTERRUPT_PRIORITY); break; #endif default: hwtimer = NULL; - prio = 0; break; } @@ -402,6 +368,74 @@ hal_timer_init(int timer_num, uint32_t freq_hz) bsptimer->tmr_reg = hwtimer; bsptimer->tmr_irq_num = irq_num; + + /* Disable IRQ, set priority and set vector in table */ + NVIC_DisableIRQ(irq_num); + NVIC_SetPriority(irq_num, (1 << __NVIC_PRIO_BITS) - 1); + NVIC_SetVector(irq_num, (uint32_t)irq_isr); + + return 0; + +err: + return rc; +} + +/** + * hal timer config + * + * Configure a timer to run at the desired frequency. This starts the timer. + * + * @param timer_num + * @param freq_hz + * + * @return int + */ +int +hal_timer_config(int timer_num, uint32_t freq_hz) +{ + int rc; + uint8_t prescaler; + uint32_t ctx; + uint32_t div; + uint32_t min_delta; + uint32_t max_delta; + struct nrf52_hal_timer *bsptimer; + NRF_TIMER_Type *hwtimer; + + NRF52_HAL_TIMER_RESOLVE(timer_num, bsptimer); + + /* Set timer to desired frequency */ + div = NRF52_MAX_TIMER_FREQ / freq_hz; + + /* + * Largest prescaler is 2^9 and must make sure frequency not too high. + * If hwtimer is NULL it means that the timer was not initialized prior + * to call. + */ + if (bsptimer->tmr_enabled || (div == 0) || (div > 512) || + (bsptimer->tmr_reg == NULL)) { + rc = EINVAL; + goto err; + } + + if (div == 1) { + prescaler = 0; + } else { + /* Find closest prescaler */ + for (prescaler = 1; prescaler < 10; ++prescaler) { + if (div <= (1 << prescaler)) { + min_delta = div - (1 << (prescaler - 1)); + max_delta = (1 << prescaler) - div; + if (min_delta < max_delta) { + prescaler -= 1; + } + break; + } + } + } + + /* Now set the actual frequency */ + bsptimer->tmr_freq = NRF52_MAX_TIMER_FREQ / (1 << prescaler); bsptimer->tmr_enabled = 1; /* disable interrupts */ @@ -417,6 +451,7 @@ hal_timer_init(int timer_num, uint32_t freq_hz) } } } + hwtimer = bsptimer->tmr_reg; /* Stop the timer first */ hwtimer->TASKS_STOP = 1; @@ -431,10 +466,7 @@ hal_timer_init(int timer_num, uint32_t freq_hz) /* Start the timer */ hwtimer->TASKS_START = 1; - /* Set isr in vector table and enable interrupt */ - NVIC_SetPriority(irq_num, prio); - NVIC_SetVector(irq_num, (uint32_t)irq_isr); - NVIC_EnableIRQ(irq_num); + NVIC_EnableIRQ(bsptimer->tmr_irq_num); __HAL_ENABLE_INTERRUPTS(ctx); @@ -467,9 +499,9 @@ hal_timer_deinit(int timer_num) hwtimer = bsptimer->tmr_reg; hwtimer->INTENCLR = NRF_TIMER_INT_MASK(NRF_TIMER_CC_INT); hwtimer->TASKS_STOP = 1; - __HAL_ENABLE_INTERRUPTS(ctx); - bsptimer->tmr_enabled = 0; + bsptimer->tmr_reg = NULL; + __HAL_ENABLE_INTERRUPTS(ctx); err: return rc; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/hw/mcu/stm/stm32f4xx/src/hal_timer.c ---------------------------------------------------------------------- diff --git a/hw/mcu/stm/stm32f4xx/src/hal_timer.c b/hw/mcu/stm/stm32f4xx/src/hal_timer.c index 6c912f1..5f9fcac 100644 --- a/hw/mcu/stm/stm32f4xx/src/hal_timer.c +++ b/hw/mcu/stm/stm32f4xx/src/hal_timer.c @@ -43,14 +43,10 @@ struct stm32f4_hal_tmr { }; #if MYNEWT_VAL(TIMER_0) -struct stm32f4_hal_tmr stm32f4_tmr0 = { - .sht_regs = MYNEWT_VAL(TIMER_0_UNIT) -}; +struct stm32f4_hal_tmr stm32f4_tmr0; #endif #if MYNEWT_VAL(TIMER_1) -struct stm32f4_hal_tmr stm32f4_tmr1 = { - .sht_regs = MYNEWT_VAL(TIMER_1_UNIT) -}; +struct stm32f4_hal_tmr stm32f4_tmr1; #endif static struct stm32f4_hal_tmr *stm32f4_tmr_devs[STM32F4_HAL_TIMER_MAX] = { @@ -147,9 +143,9 @@ stm32f4_tmr1_irq(void) #endif static void -stm32f4_tmr_reg_irq(IRQn_Type irqn, uint32_t prio, uint32_t func) +stm32f4_tmr_reg_irq(IRQn_Type irqn, uint32_t func) { - NVIC_SetPriority(irqn, prio); + NVIC_SetPriority(irqn, (1 << __NVIC_PRIO_BITS) - 1); NVIC_SetVector(irqn, func); NVIC_EnableIRQ(irqn); } @@ -198,19 +194,16 @@ static void stm32f4_hw_setup(int num, TIM_TypeDef *regs) { uint32_t func; - uint32_t prio; switch (num) { #if MYNEWT_VAL(TIMER_0) case 0: func = (uint32_t)stm32f4_tmr0_irq; - prio = MYNEWT_VAL(TIMER_0_INTERRUPT_PRIORITY); break; #endif #if MYNEWT_VAL(TIMER_1) case 1: func = (uint32_t)stm32f4_tmr1_irq; - prio = MYNEWT_VAL(TIMER_1_INTERRUPT_PRIORITY); break; #endif default: @@ -220,33 +213,33 @@ stm32f4_hw_setup(int num, TIM_TypeDef *regs) #ifdef TIM1 if (regs == TIM1) { - stm32f4_tmr_reg_irq(TIM1_CC_IRQn, prio, func); - stm32f4_tmr_reg_irq(TIM1_UP_TIM10_IRQn, prio, func); + stm32f4_tmr_reg_irq(TIM1_CC_IRQn, func); + stm32f4_tmr_reg_irq(TIM1_UP_TIM10_IRQn, func); __HAL_RCC_TIM1_CLK_ENABLE(); } #endif #ifdef TIM8 if (regs == TIM8) { - stm32f4_tmr_reg_irq(TIM8_CC_IRQn, prio, func); - stm32f4_tmr_reg_irq(TIM8_UP_TIM13_IRQn, prio, func); + stm32f4_tmr_reg_irq(TIM8_CC_IRQn, func); + stm32f4_tmr_reg_irq(TIM8_UP_TIM13_IRQn, func); __HAL_RCC_TIM8_CLK_ENABLE(); } #endif #ifdef TIM9 if (regs == TIM9) { - stm32f4_tmr_reg_irq(TIM1_BRK_TIM9_IRQn, prio, func); + stm32f4_tmr_reg_irq(TIM1_BRK_TIM9_IRQn, func); __HAL_RCC_TIM9_CLK_ENABLE(); } #endif #ifdef TIM10 if (regs == TIM10) { - stm32f4_tmr_reg_irq(TIM1_UP_TIM10_IRQn, prio, func); + stm32f4_tmr_reg_irq(TIM1_UP_TIM10_IRQn, func); __HAL_RCC_TIM10_CLK_ENABLE(); } #endif #ifdef TIM11 if (regs == TIM11) { - stm32f4_tmr_reg_irq(TIM1_TRG_COM_TIM11_IRQn, prio, func); + stm32f4_tmr_reg_irq(TIM1_TRG_COM_TIM11_IRQn, func); __HAL_RCC_TIM11_CLK_ENABLE(); } #endif @@ -285,7 +278,44 @@ stm32f4_hw_setdown(TIM_TypeDef *regs) /** * hal timer init * - * Initialize (and start) a timer to run at the desired frequency. + * Initialize platform specific timer items + * + * @param timer_num Timer number to initialize + * @param cfg Pointer to platform specific configuration + * + * @return int 0: success; error code otherwise + */ +int +hal_timer_init(int num, void *cfg) +{ + struct stm32f4_hal_tmr *tmr; + + if (num >= STM32F4_HAL_TIMER_MAX || !(tmr = stm32f4_tmr_devs[num]) || + (cfg == NULL)) { + return -1; + } + + tmr->sht_regs = (TIM_TypeDef *)cfg; + + if (!IS_TIM_CC1_INSTANCE(tmr->sht_regs)) { + return -1; + } + + stm32f4_hw_setup(num, tmr->sht_regs); + + /* + * Stop the timers at debugger. XXX Which TIM? + */ + DBGMCU->APB1FZ |= 0x1ff; /* TIM2 - TIM7, TIM12-TIM14 */ + DBGMCU->APB2FZ |= 0x70003; /* TIM1, TIM8-TIM11 */ + + return 0; +} + +/** + * hal timer config + * + * Configure a timer to run at the desired frequency. This starts the timer. * * @param timer_num * @param freq_hz @@ -293,7 +323,7 @@ stm32f4_hw_setdown(TIM_TypeDef *regs) * @return int */ int -hal_timer_init(int num, uint32_t freq_hz) +hal_timer_config(int num, uint32_t freq_hz) { struct stm32f4_hal_tmr *tmr; TIM_Base_InitTypeDef init; @@ -317,14 +347,6 @@ hal_timer_init(int num, uint32_t freq_hz) init.ClockDivision = TIM_CLOCKDIVISION_DIV1; init.CounterMode = TIM_COUNTERMODE_UP; - stm32f4_hw_setup(num, tmr->sht_regs); - - /* - * Stop the timers at debugger. XXX Which TIM? - */ - DBGMCU->APB1FZ |= 0x1ff; /* TIM2 - TIM7, TIM12-TIM14 */ - DBGMCU->APB2FZ |= 0x70003; /* TIM1, TIM8-TIM11 */ - /* * Set up to count overflow interrupts. */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ece98067/kernel/os/src/os_cputime.c ---------------------------------------------------------------------- diff --git a/kernel/os/src/os_cputime.c b/kernel/os/src/os_cputime.c index e67a2f8..067f1a1 100644 --- a/kernel/os/src/os_cputime.c +++ b/kernel/os/src/os_cputime.c @@ -50,7 +50,7 @@ os_cputime_init(uint32_t clock_freq) /* Set the ticks per microsecond. */ g_os_cputime.ticks_per_usec = clock_freq / 1000000U; - rc = hal_timer_init(MYNEWT_VAL(OS_CPUTIME_TIMER_NUM), clock_freq); + rc = hal_timer_config(MYNEWT_VAL(OS_CPUTIME_TIMER_NUM), clock_freq); return rc; }