nrf51计时器驱动程序代码错误

时间:2015-06-14 23:48:24

标签: c keil nrf51

我目前正在尝试使用nrf51开发套件&我试图使用定时器驱动程序,当我引导C&驱动程序的H文件我收到了一些错误:

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;
}

错误#1表示&#34;空的初始值设定项对于未指定绑定的数组无效#34; 错误#2表示它预期表达式

到目前为止,我还没有在main.c代码中使用任何这些函数,我只是添加了将要进一步使用的头文件。

2 个答案:

答案 0 :(得分:1)

错误1:显然TIMERx_ENABLED都不是1,因此数组将为空。因为它是const,所以以后没有机会对其进行初始化。这也会导致零元素数组,这是不允许的。最简单的可能是具有单个空条目的#else子句。但是,我怀疑你必须先为你的系统配置东西。阅读文档。

错误2:可能是一个跟进错误,或者没有定义其中一个自定义类型 - 很难说没有更多信息,或报告错误的位置根本不是实际错误的位置,或者...... 。最好是修复第一个错误,然后再次尝试错误2。

答案 1 :(得分:1)

如果您使用的是nordic中的示例,那么定义可以在nrf_drv_config.h中,也可以在sdk_config.h中用于新版本的nordic sdk。

您必须通过将TIMER_ENABLED定义更改为1来启用计时器。然后对要使用的计时器执行相同操作。

你可以像其他人建议的那样自己定义这些。