[En-Nut-Discussion] Run-time or compile-time configurable devices?

Ulrich Prinz ulrich.prinz at googlemail.com
Thu Jan 5 10:53:15 CET 2012


Hi!

Am 04.01.2012 18:52, schrieb Uwe Bonnes:
> Hello Ulrich,
> 
> to make a long discussion short:
> 
>>>>>> "Ulrich" == Ulrich Prinz <ulrich.prinz at googlemail.com> writes:
> 
> 
>     Ulrich> Right, accessing the NutRegisterDevice( &DEV_UART4...  causes
>     Ulrich> the linker to see that this device is addressed and therefore
>     Ulrich> the code must be linked.
> 
> #define  TIM_Init(timer ) \
>     ((timer) == (NUTTIMER2))?(CM3MEM(CM3BBSET(CM3ADDR(RCC_BASE, RCC_TypeDef, APB1ENR), _BI32(RCC_APB1Periph_TIM2))) = 1) \
>     :((timer) == (NUTTIMER3))?(CM3MEM(CM3BBSET(CM3ADDR(RCC_BASE, RCC_TypeDef, APB1ENR), _BI32(RCC_APB1Periph_TIM3))) = 1) \
>     :((timer) == (NUTTIMER4))?(CM3MEM(CM3BBSET(CM3ADDR(RCC_BASE, RCC_TypeDef, APB1ENR), _BI32(RCC_APB1Periph_TIM4))) = 1) \
>     :((timer) == (NUTTIMER5))?(CM3MEM(CM3BBSET(CM3ADDR(RCC_BASE, RCC_TypeDef, APB1ENR), _BI32(RCC_APB1Periph_TIM5))) = 1) \
>     :((timer) == (NUTTIMER6))?(CM3MEM(CM3BBSET(CM3ADDR(RCC_BASE, RCC_TypeDef, APB1ENR), _BI32(RCC_APB1Periph_TIM6))) = 1) \
>     :((timer) == (NUTTIMER7))?(CM3MEM(CM3BBSET(CM3ADDR(RCC_BASE, RCC_TypeDef, APB1ENR), _BI32(RCC_APB1Periph_TIM7))) = 1) :0
>   
> For TIM_Init() this only means smaller code, but if you think of e.g. some
> function like TIM_IntRegister(timer, pfnHandler), a compile time definition
> like
> 
> #define TIM_IntRegister(timer, pfnHandler) \
>     ((timer) == (NUTTIMER2))?IntRegister(TIM2_IRQn, pfnHandler)         \
>     :((timer) == (NUTTIMER3))?IntRegister(TIM3_IRQn, pfnHandler)        \
>     :((timer) == (NUTTIMER4))?IntRegister(TIM4_IRQn, pfnHandler)        \
>     :((timer) == (NUTTIMER5))?IntRegister(TIM5_IRQn, pfnHandler)        \
>     :((timer) == (NUTTIMER6))?IntRegister(TIM6_IRQn, pfnHandler)        \
>     :((timer) == (NUTTIMER7))?IntRegister(TIM7_IRQn, pfnHandler):0
> 
> will save code and runtime, as setting of some interrupt happen quite
> often. I used this already to successfully bitbang a one-wire device with a
> timer on a STM32F107 device.
> 

Ok, this looks crazy... I like it :)

But may be we could return -1 in case of error instead of 0.

Afaik, 0 and up means good, <0 means bad.

The only things that needs to be remembered is, that not all devices
have the full number of timers. But in this case some #ifdef could split
the lines.

Best regards
Ulrich



More information about the En-Nut-Discussion mailing list