退出debug之后Timer精度变差
时间:10-02
整理:3721RD
点击:
Hi,
大家好。我在试着用Timer模块来定时发送一个报文。在连接ICE,进入debug模式之后,一切都是正常,从sniffer上面能看到每10ms能收到一个包。但是当IAR退出debug模式之后,就变成每隔200ms~300ms左右才能收到一个包了。如果再次进入debug模式,又恢复成10ms了。MSA_SEND_PERIOD_EVENT是我创建的timer发送的事件。
我在Sample那个例程的基础上做了一点点改动。
大家帮我看看到底哪里有问题?我也试过把runMode改为PeriodContinue,但是也还是不行。
static void MSA_Init(void)
{
UInt msaWaitPeriod = MSA_WAIT_PERIOD * 1000 / Clock_tickPeriod;
UInt msaLed4Period = MSA_LED4_INITIAL_PERIOD * 1000 / Clock_tickPeriod;
UInt msaSendTimerPeriod = MSA_WAIT_PERIOD * 1000; // In microseconds.
Error_Block eb;
Error_init(&eb);
// Create Timer
Timer_Params_init(&msaSendTimerParams);
msaSendTimerParams.arg = (UArg)MSA_SEND_PERIOD_EVENT;
msaSendTimerParams.period = 10000;
msaSendTimerParams.periodType = Timer_PeriodType_MICROSECS;
//msaSendTimerParams.periodType = Timer_PeriodType_COUNTS;
msaSendTimerParams.runMode = Timer_RunMode_ONESHOT;
msaSendTimerParams.startMode = Timer_StartMode_AUTO;
timerHandle = Timer_create(Timer_ANY, MSA_ClockFxn, &msaSendTimerParams, &eb);
// msaSendTimerId = 1;
// Timer_construct(&msaSendTimer, msaSendTimerId, MSA_ClockFxn, &msaSendTimerParams, NULL);
/* Open LED PIN driver */
//ledPinHandle = PIN_open(&ledPinState, ledPinTable);
/* Initialize clock wait parameters */
//Clock_Params_init(&msaSendParams);
/* Create a one-shot wait timer */
//msaSendParams.period = 0;
//msaSendParams.startFlag = FALSE;
//msaSendParams.arg = (UArg)MSA_SEND_EVENT;
//Clock_construct(&msaSend, MSA_ClockFxn, msaWaitPeriod, &msaSendParams);
/* Initialize clock poll parameters */
Clock_Params_init(&msaPollParams);
/* Create a periodic poll timer */
msaPollParams.period = msaWaitPeriod;
msaPollParams.startFlag = FALSE;
msaPollParams.arg = (UArg)MSA_POLL_EVENT;
Clock_construct(&msaPoll, MSA_ClockFxn, msaWaitPeriod, &msaPollParams);
/* Initialize clock poll parameters */
Clock_Params_init(&msaLed4Params);
/* Create a periodic poll timer */
msaLed4Params.period = msaLed4Period;
msaLed4Params.startFlag = TRUE;
msaLed4Params.arg = (UArg)MSA_LED4_EVENT;
Clock_construct(&msaLed4, MSA_ClockFxn, msaLed4Period, &msaLed4Params);
/* Setup parameters for debounce timeout */
//Clock_Params_init(&msaKeyParams);
//msaKeyParams.period = 0;
//msaKeyParams.startFlag = false;
/* Keycallback for keys */
//Clock_construct(&msaKey, MSA_keyCB, KEY_DEBOUNCE_TIMEOUT, &msaKeyParams);
/* Initialize keys */
MSA_initKeys();
/* Register the current thread as an ICall dispatcher application
* so that the application can send and receive messages.
*/
ICall_registerApp(&macAppEntity, &sem);
/* Send a MAC init message */
MAC_Init();
/* initialize MAC features */
#ifdef MSA_FFD
MAC_InitCoord();
#else
MAC_InitDevice();
#endif
/* Reset the MAC */
MAC_MlmeResetReq(TRUE);
/* Initialize MAC beacon */
#ifdef MSA_FFD
MAC_InitBeaconCoord();
#else
MAC_InitBeaconDevice();
#endif
#ifdef FEATURE_MAC_SECURITY
/* Initialize the security part of the application */
MSA_SecurityInit();
#endif /* FEATURE_MAC_SECURITY */
/* Initialize the data packet */
for (uint_least8_t i=MSA_HEADER_LENGTH; i<MSA_PACKET_LENGTH; i++)
{
msa_Data1[i] = i-MSA_HEADER_LENGTH;
}
/* Initialize the echo packet */
for (uint_least8_t j=0; j<MSA_ECHO_LENGTH; j++)
{
msa_Data2[j] = 0xEE;
}
msa_BeaconOrder = MSA_MAC_BEACON_ORDER;
msa_SuperFrameOrder = MSA_MAC_SUPERFRAME_ORDER;
#if defined( USE_FPGA )
/* Send a fake UP key for FPGA to start the association */
MSA_HandleKeys(Board_KEY_UP);
#endif /* USE_FPGA */
}
static void MSA_Process(void)
{
static uint8 index;
static uint8 sequence;
/* Forever loop */
for (;;)
{
ICall_ServiceEnum stackid;
ICall_EntityID dest;
TimacMSG_MacCbackEvent_t *pMsg;
uint16_t events;
//for(int i=0;i<1000000;i++);
/* Wait for response message */
if (ICall_wait(ICALL_TIMEOUT_FOREVER) == ICALL_ERRNO_SUCCESS)
{
/* Retrieve the response message */
if (ICall_fetchServiceMsg(&stackid, &dest, (void **) &pMsg)
== ICALL_ERRNO_SUCCESS)
{
if ((stackid == ICALL_SERVICE_CLASS_TIMAC) &&
(dest == macAppEntity ))
{
MSA_ProcessEvent(pMsg);
}
if (pMsg)
{
ICall_freeMsg(pMsg);
}
}
{
UInt key = Hwi_disable();
events = msa_events;
msa_events = 0;
Hwi_restore(key);
}
if(events & MSA_POLL_EVENT)
{
MSA_McpsPollReq();
}
if(events & MSA_LED4_EVENT)
{
PIN_setOutputValue(ledPinHandle, Board_LED4, !PIN_getOutputValue(Board_LED4));
}
if(events & MSA_KEY_EVENT)
{
MSA_HandleKeys(keys);
keys = 0;
}
if(events & MSA_SEND_PERIOD_EVENT)
{
Timer_start(timerHandle);
MSA_McpsDataReq((uint8*)msa_Data1,80,
msa_DeviceRecord[index].isDirectMsg,
msa_DeviceRecord[index].devShortAddr );
}
if(events & MSA_SEND_EVENT)
{
/* Do it again */
if (msa_State == MSA_SEND_STATE)
{
/* Start sending */
if (msa_IsCoordinator)
{
if (MSA_PACKET_LENGTH >= MSA_HEADER_LENGTH)
{
/* Coordinator sending to devices. Use the associated list of device to send out msg */
msa_Data1[0] = MSA_PACKET_LENGTH;
msa_Data1[1] = HI_UINT16(msa_DeviceRecord[index].devShortAddr);
msa_Data1[2] = LO_UINT16(msa_DeviceRecord[index].devShortAddr);
msa_Data1[3] = sequence;
}
/*
MSA_McpsDataReq((uint8*)msa_Data1,
MSA_PACKET_LENGTH,
msa_DeviceRecord[index].isDirectMsg,
msa_DeviceRecord[index].devShortAddr );
*/
/* Reset the index if it reaches the current number of associated devices */
if (++index == msa_NumOfDevices)
{
index = 0;
}
}
else
{
if (MSA_PACKET_LENGTH >= MSA_HEADER_LENGTH)
{
/* Device sending to coordinator */
msa_Data1[0] = MSA_PACKET_LENGTH;
msa_Data1[1] = HI_UINT16(msa_CoordShortAddr);
msa_Data1[2] = LO_UINT16(msa_CoordShortAddr);
msa_Data1[3] = sequence;
}
/* MSA_McpsDataReq((uint8*)msa_Data1,
MSA_PACKET_LENGTH,
TRUE,
msa_CoordShortAddr );
*/
}
#if defined (NV_RESTORE) && defined (FEATURE_MAC_SECURITY)
msa_keyTable[0].frameCounter++;
if(msa_keyTable[0].frameCounter % 1000 == 0)
{
nv_write(MAC_NV_KEY_TABLE, 0, sizeof(msa_keyTable), &msa_keyTable);
}
#endif /* defined (NV_RESTORE) && defined (FEATURE_MAC_SECURITY) */
if (sequence++ == 0xFF)
{
sequence = 0;
}
PIN_setOutputValue(ledPinHandle, Board_LED1, !PIN_getOutputValue(Board_LED1));
}
}
}
}
}
忘了说了,我现在用的芯片是CC2650
建议用I/O翻转输出的方式,测试下timer的定时功能是否正确,然后再去无线数据的发送部分。
