This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf51422 timer driver

I'm currently trying to make an application using the development kit & I'm trying to use the timer driver, when I induled the C & H files of the driver I got an 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.

Parents
  • Which if TIMER0_ENABLED, TIMER1_ENABLED or TIMER2_ENABLED defines did you set to 1? None of them perhaps? In which case you have no enabled timers and that's an empty array (not that I agree an empty initializer is invalid for an array with unspecified bounds, but it looks like whatever compiler you use doesn't care for it.).

    Define one or more of them, otherwise the timer module is pretty useless anyway.

Reply
  • Which if TIMER0_ENABLED, TIMER1_ENABLED or TIMER2_ENABLED defines did you set to 1? None of them perhaps? In which case you have no enabled timers and that's an empty array (not that I agree an empty initializer is invalid for an array with unspecified bounds, but it looks like whatever compiler you use doesn't care for it.).

    Define one or more of them, otherwise the timer module is pretty useless anyway.

Children
No Data
Related