【问题标题】:nrf51 timer driver code bugsnrf51 计时器驱动程序代码错误
【发布时间】:2015-08-30 09:22:29
【问题描述】:

我目前正在尝试使用 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 代码中使用任何这些函数,我只是添加了将进一步使用的头文件。

【问题讨论】:

    标签: c keil nrf51


    【解决方案1】:

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

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

    【讨论】:

    • 我会尝试在 main.c 代码中初始化它们,然后看看它是否已修复.. 感谢您的帮助
    • 再说一遍:你不能初始化const,除非你定义它。但是,如果这有助于/是解决方案,请记住支持/接受。
    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-28
      • 2022-01-28
      • 2012-07-01
      • 2013-08-14
      • 2021-02-13
      • 1970-01-01
      • 2021-12-25
      相关资源
      最近更新 更多