为了能够精确在每250us发送一次数据,我采用了RTC CH2通道进行定时,然后再主程序中进行radio发送。现在问题是:
1)单独的RTC 程序测试没有问题,通过GPIO电平翻转,可以测试到约250us时刻翻转;
2)单独的射频发送测试没有问题,可通过频谱分析仪测试到发送的信号;
3)将两个合并使用时,则定时器中断可以正常进入;但是射频发送无法进行。
请问,是RTC的使用与RADIO发送冲突了吗?还是使用方法不对导致的?
****************************以下是主程序部分*********************************************************
/*定时器中断处理函数*/
void RTCtimer_int_hanlder(uintptr_t arg)
{
GPIO_toggle(Board_GPIO_LED0);
send_flag = 1;
}
/*
* ======== adcThread ========
*/
void *adcThread(void *arg0)
{
ADC_Handle adc;
ADC_Params params;
/* Call driver init functions */
RTC_timerCreate(RTCtimer_int_hanlder);
GPIO_init();
ADC_init();
RF_tx_init();
ADC_Params_init(¶ms);
/*配置GPIO*/
GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
adc = ADC_open(Board_ADC0, ¶ms);
if (adc == NULL) {
while (1);
}
while(1)
{
/*ADC_convert(adc, &adcValue);*/
if(send_flag == 1)
{
send_flag = 0;
dataNumber++;
RF_tx_data(adcValue, dataNumber);
}
}
****************************定时器程序*********************************************************
typedef struct _RTC_Obj {
RTC_Fxn tickFxn;
} RTC_Obj;
static HwiP_Struct RTC_hwiStruct;
static RTC_Obj RTC_handle;
static uint32_t delay_ticks = (uint32_t)(0.00025*FACTOR_SEC_TO_COMP_VAL_FORMAT); /*定时间隔*/
void RTC_init(void)
{
/*关闭并重置RTC*/
AONRTCDisable();
AONRTCReset();
HWREG(AON_RTC_BASE + AON_RTC_O_SYNC) = 1;
/* read sync register to complete reset */
HWREG(AON_RTC_BASE + AON_RTC_O_SYNC);
/*清除RTC事件*/
AONRTCEventClear(AON_RTC_CH2);
IntPendClear(INT_AON_RTC_COMB);
HWREG(AON_RTC_BASE + AON_RTC_O_SYNC);
}
void RTC_intFxn(uintptr_t arg)
{
/* clear the RTC event */
AONRTCEventClear(AON_RTC_CH2);
RTC_handle.tickFxn(NULL);
}
void RTC_start(void)
{
uintptr_t key;
key = HwiP_disable();
/* reset timer */
AONRTCReset();
AONRTCEventClear(AON_RTC_CH2);
IntPendClear(INT_AON_RTC_COMB);
/*设置比较值大小*/
AONRTCModeCh2Set(AON_RTC_MODE_CH2_CONTINUOUS);
AONRTCCompareValueSet(AON_RTC_CH2, delay_ticks);
AONRTCIncValueCh2Set(delay_ticks);
AONEventMcuWakeUpSet(AON_EVENT_MCU_WU0, AON_EVENT_RTC_CH2);
AONRTCChannelEnable(AON_RTC_CH2);
AONRTCCombinedEventConfig(AON_RTC_CH2);
AONRTCEnable();
/*退出临界区*/
HwiP_restore(key);
}
void RTC_timerCreate(RTC_Fxn timer_fxn)
{
uintptr_t hwiKey;
/*进入临界区*/
hwiKey = HwiP_disable();
HwiP_Params hwiParams;
HwiP_Params_init(&hwiParams);
hwiParams.priority = INT_PRI_LEVEL4;
HwiP_construct(&RTC_hwiStruct, INT_AON_RTC_COMB, RTC_intFxn, &hwiParams);
RTC_init();
/*退出临界区*/
HwiP_restore(hwiKey);
RTC_handle.tickFxn = timer_fxn;
RTC_start();
}
****************************射频发送*********************************************************
void RF_tx_init(void)
{
RF_Params rfParams;
RF_Params_init(&rfParams);
if( RFQueue_defineQueue(&dataQueue,
txDataEntryBuffer,
sizeof(txDataEntryBuffer),
NUM_DATA_ENTRIES,
MAX_LENGTH + NUM_APPENDED_BYTES))
{
/* Failed to allocate space for all data entries */
while(true);
}
RF_cmdTxHS.pQueue = &dataQueue;
currentDataEntry = (rfc_dataEntryGeneral_t*)&txDataEntryBuffer;
currentDataEntry->length = PAYLOAD_LENGTH;
pPacket = ¤tDataEntry->data;
RF_cmdFs_preDef.frequency = 0x0364; //0x364:868Mhz, 0x0393: 915 MHz
RF_cmdFs_preDef.fractFreq = 0x0000;
/* Request access to the radio */
rfHandle = RF_open(&rfObject, &RF_prop_hsm, (RF_RadioSetup*)&RF_cmdRadioSetup_hsm, &rfParams);
/* Set the frequency */
RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs_preDef, RF_PriorityNormal, NULL, 0);
}
void RF_tx_data(uint16_t playload, uint16_t seqNumber)
{
/* Create packet with incrementing sequence number and random payload */
pPacket[0]= (uint8_t)(seqNumber >> 8);
pPacket[1]= (uint8_t)(seqNumber++);
/* pPacket[2]= (uint8_t)(playload >> 8);
pPacket[3]= (uint8_t)(playload);*/
/* Send packet */
RF_EventMask terminationReason = RF_postCmd(rfHandle, (RF_Op*)&RF_cmdTxHS,
RF_PriorityNormal, NULL, 0);
}