1

現在、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 コードでこれらの関数を使用していませんでした。さらに使用するヘッダー ファイルを追加しただけです。

4

2 に答える 2

1

エラー 1: どうやらどちらもTIMERx_ENABLED1 ではないため、配列は空になります。そのままではconst、後で初期化する機会はありません。その結果、要素が 0 の配列になることもあり、これは許可されていません。最も簡単なのは#else、単一の null エントリを持つ句を使用することです。ただし、最初にシステム用に構成する必要があると思います。ドキュメントを読んでください。

エラー 2: フォローアップ エラーである可能性があるか、カスタム タイプの 1 つが定義されていない - 詳細情報なしでは言いにくいか、エラーが報告された場所が単に実際のエラーの場所ではない、または ... . 最善の方法は、最初のエラーを修正してから、エラー 2 について再試行することです。

于 2015-06-14T23:59:44.560 に答える