简体   繁体   中英

nrf51 timer driver code bugs

I'm currently trying to make an application using the nrf51 development kit & I'm trying to use the timer driver, when I induled the C & H files of the driver I got some error :

static const nrf_drv_timer_config_t m_default_config[] = {// here it told me there is error #1
 #if (TIMER0_ENABLED == 1)
NRF_DRV_TIMER_DEFAULT_CONFIG(0),
#endif
#if (TIMER1_ENABLED == 1)
NRF_DRV_TIMER_DEFAULT_CONFIG(1),
#endif
#if (TIMER2_ENABLED == 1)
NRF_DRV_TIMER_DEFAULT_CONFIG(2)
#endif
};

// here it told me there is error #2

ret_code_t nrf_drv_timer_init(nrf_drv_timer_t const * const p_instance,
                          nrf_drv_timer_config_t const * p_config,
                          nrf_timer_event_handler_t timer_event_handler)
{
ASSERT((p_instance->instance_id) < TIMER_INSTANCE_NUMBER);
ASSERT(TIMER_IS_BIT_WIDTH_VALID(p_instance->instance_id, p_config->bit_width));

if (m_cb[p_instance->instance_id].state != NRF_DRV_STATE_UNINITIALIZED)
{
    return NRF_ERROR_INVALID_STATE; // timer already initialized
} 

if (p_config == NULL)
{
    p_config = &m_default_config[p_instance->instance_id];
}

#ifdef SOFTDEVICE_PRESENT
if (p_instance->p_reg == NRF_TIMER0)
{
    return NRF_ERROR_INVALID_PARAM;
}
#endif    

nrf_drv_common_irq_enable(p_instance->irq, p_config->interrupt_priority);

mp_contexts[p_instance->instance_id] = p_config->p_context;

if (timer_event_handler != NULL)
{
    m_timer_event_handlers[p_instance->instance_id] = timer_event_handler;
}
else
{
    return NRF_ERROR_INVALID_PARAM;
}

nrf_timer_mode_set(p_instance->p_reg, p_config->mode);
nrf_timer_bit_width_set(p_instance->p_reg, p_config->bit_width);
nrf_timer_frequency_set(p_instance->p_reg, p_config->frequency);

m_cb[p_instance->instance_id].state = NRF_DRV_STATE_INITIALIZED;

return NRF_SUCCESS;
}

the error #1 says that "an empty initializer is invalid for an array with unspecified bound" the error #2 says that it expected an expression

I till now didn't use any of these functions in the main.c code, I'm just added the header files that will be used further.

Error 1: Apparently neither of TIMERx_ENABLED is 1, so the array will be empty. As it is const , there is no chance to initialize it later. That would also result in an array of zero elements, which is not allowed. Easiest might be to have an #else clause with a single null entry. However, I suspect you have to configure the stuff for your system first. Read the documentation.

Error 2: might be a follow up error, or one of the custom types are not defined - hard to say without more info, or the location the error is reported is simply not that of the actual error, or ... . Best is to fix the first error, then try again for error 2.

If you are using examples from nordic then the defines are either in nrf_drv_config.h or in the sdk_config.h for new versions of the nordic sdk.

You have to enable the timers by changing the TIMER_ENABLED define to 1. Then do the same for the timers you want to use.

You could make these defines yourself as other people have suggested.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM