nrf5/hal/timer: Changing hardcoded hal timer instance base to a lookup, so that IRQ num can be detected automatically without the need of using struct param on it. Size of binary does not increase when using Os.

This commit is contained in:
Glenn Ruben Bakke 2017-04-30 19:42:19 +02:00
parent 7aa7bad78a
commit 7449f8d861
2 changed files with 25 additions and 26 deletions

View File

@ -30,31 +30,30 @@
#include "nrf.h"
#if NRF51
#define TIMER0 ((NRF_TIMER_Type *) NRF_TIMER0)
#define TIMER0_IRQ_NUM TIMER0_IRQn
#define TIMER1 ((NRF_TIMER_Type *) NRF_TIMER1)
#define TIMER1_IRQ_NUM TIMER1_IRQn
#define TIMER2 ((NRF_TIMER_Type *) NRF_TIMER2)
#define TIMER2_IRQ_NUM TIMER2_IRQn
#elif NRF52
#define TIMER0 ((NRF_TIMER_Type *) NRF_TIMER0)
#define TIMER0_IRQ_NUM TIMER0_IRQn
#define TIMER1 ((NRF_TIMER_Type *) NRF_TIMER1)
#define TIMER1_IRQ_NUM TIMER1_IRQn
#define TIMER2 ((NRF_TIMER_Type *) NRF_TIMER2)
#define TIMER2_IRQ_NUM TIMER2_IRQn
#define TIMER3 ((NRF_TIMER_Type *) NRF_TIMER3)
#define TIMER3_IRQ_NUM TIMER3_IRQn
#define TIMER4 ((NRF_TIMER_Type *) NRF_TIMER4)
#define TIMER4_IRQ_NUM TIMER4_IRQn
#else
#error "Device not supported."
#define TIMER_BASE_POINTERS (const uint32_t[]){NRF_TIMER0_BASE, \
NRF_TIMER1_BASE, \
NRF_TIMER2_BASE}
#define TIMER_IRQ_VALUES (const uint32_t[]){TIMER0_IRQn, \
TIMER1_IRQn, \
TIMER2_IRQn}
#endif
#if NRF52
#define TIMER_BASE_POINTERS (const uint32_t[]){NRF_TIMER0_BASE, \
NRF_TIMER1_BASE, \
NRF_TIMER1_BASE, \
NRF_TIMER1_BASE, \
NRF_TIMER2_BASE}
#define TIMER_IRQ_VALUES (const uint32_t[]){TIMER0_IRQn, \
TIMER1_IRQn, \
TIMER2_IRQn, \
TIMER3_IRQn, \
TIMER4_IRQn}
#endif
#define TIMER_BASE(x) ((NRF_TIMER_Type *)TIMER_BASE_POINTERS[x])
#define TIMER_IRQ_NUM(x) (TIMER_IRQ_VALUES[x])
/**
* @brief Timer Configuration Structure definition
*/

View File

@ -53,11 +53,11 @@ STATIC const machine_timer_obj_t machine_timer_obj[] = {
void timer_init0(void) {
// reset the Timer handles
memset(&TimerHandle0, 0, sizeof(Timer_HandleTypeDef));
TimerHandle0.instance = TIMER0;
TimerHandle0.instance = TIMER_BASE(0);
memset(&TimerHandle1, 0, sizeof(Timer_HandleTypeDef));
TimerHandle0.instance = TIMER1;
TimerHandle0.instance = TIMER_BASE(1);
memset(&TimerHandle2, 0, sizeof(Timer_HandleTypeDef));
TimerHandle0.instance = TIMER2;
TimerHandle0.instance = TIMER_BASE(2);
}
STATIC int timer_find(mp_obj_t id) {