繁体   English   中英

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

[英]nrf51 timer driver code bugs

我目前正在尝试使用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说“空的初始化程序对于具有未指定绑定的数组无效”,错误#2说它期望使用表达式

到目前为止,我在main.c代码中未使用任何这些功能,只是添加了将进一步使用的头文件。

错误1:显然TIMERx_ENABLED为1,因此该数组将为空。 由于它是const ,因此以后没有机会对其进行初始化。 那也将导致零元素的数组,这是不允许的。 最简单的方法是使#else子句具有单个空条目。 但是,我怀疑您必须先为系统配置这些内容。 阅读文档。

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

如果您使用的是北欧的示例,那么对于北欧sdk的新版本,定义位于nrf_drv_config.h或sdk_config.h中。

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

您可以按照其他人的建议自行定义。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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