Hello,
I am using nrf51 SDK version 10.0.0 along with the nRF51822, and I believe I have found an issue with a macro that is supposed to check the correctness of a bit width setting for a certain timer.
Context: I am trying to init a nrf_drv_timer instance with TIMER2, on 8 bit mode. According to the nRF51822 product specification v3.3, this timer supports both 8 or 16 bit width.
The init fails on the bit-width validation in the file nrf_drv_timer.c, on line 46:
ASSERT(TIMER_IS_BIT_WIDTH_VALID(p_instance->instance_id, p_config->bit_width));
Here is the definition of this macro:
/**
* @brief Macro for validating correctness of BIT_WIDTH setting.
*/
#define TIMER_IS_BIT_WIDTH_VALID(instance_id, mode) \
(((instance_id>0) && (mode>NRF_TIMER_BIT_WIDTH_16)) ? false : true)
I my case,
- the instance_id for TIMER2 is 1, because my nrf_drv_config.h disables TIMER0.
- the mode parameter is NRF_TIMER_BIT_WIDTH_8
The assert triggers because NRF_TIMER_BIT_WIDTH_8 is greater than NRF_TIMER_BIT_WIDTH_16. Is this intended?
My understanding of the goal of this validation is to ensure that a bit width of more than 16 bits is not used with a timer other than TIMER0.
If so, then the test is not appropriate, because :
- The instance_id of any timer can be 0, depending on nrf_drv_config.h. In my case the instance id of TIMER1 is 0, and TIMER1 only supports 8 or 16 bit widths.
- The value of NRF_TIMER_BIT_WIDTH_16 is 0 and NRF_TIMER_BIT_WIDTH_8 is 1. (reason for this shown below)
nrf_timer.h
/**
* @enum nrf_timer_bit_width_t
* @brief Timer bit width.
*/
typedef enum
{
NRF_TIMER_BIT_WIDTH_8 = TIMER_BITMODE_BITMODE_08Bit, /**< Timer bit width 8 bit. */
NRF_TIMER_BIT_WIDTH_16 = TIMER_BITMODE_BITMODE_16Bit, /**< Timer bit width 16 bit. */
NRF_TIMER_BIT_WIDTH_24 = TIMER_BITMODE_BITMODE_24Bit, /**< Timer bit width 24 bit. */
NRF_TIMER_BIT_WIDTH_32 = TIMER_BITMODE_BITMODE_32Bit /**< Timer bit width 32 bit. */
} nrf_timer_bit_width_t;
nrf51_bitfields.h
#define TIMER_BITMODE_BITMODE_16Bit (0x00UL) /*!< 16-bit timer behaviour. */
#define TIMER_BITMODE_BITMODE_08Bit (0x01UL) /*!< 8-bit timer behaviour. */
#define TIMER_BITMODE_BITMODE_24Bit (0x02UL) /*!< 24-bit timer behaviour. */
#define TIMER_BITMODE_BITMODE_32Bit (0x03UL) /*!< 32-bit timer behaviour. */
Am I right to believe there is an issue with this validation? Please enlighten me if there is something I totally missed.