📄 maca_indirect_polling.c
字号:
*******************************************************************************************************/
//-------------------------------------------------------------------------------------------------------
// void mipDataRequestTimeoutTask(MAC_TASK_INFO *pTask)
//
// DESCRIPTION:
// This task is run when no valid response has been received after a data request. The task makes
// the callback to the higher layer.
//
// TASK DATA:
// 0
//-------------------------------------------------------------------------------------------------------
void mipDataRequestTimeoutTask(MAC_TASK_INFO *pTask) {
MAC_STATE_TYPE oldState;
ENABLE_FIFOP_INT();
// The data request has failed, so stop listening
mrxDecrOnCounter();
oldState = macInfo.state;
macSetState(MAC_STATE_DEFAULT);
// Remove the task
mschRemoveTask(pTask->priority, 0);
// Notify the higher layer...
switch (oldState) {
case MAC_STATE_MANUAL_DATA_REQUEST_SENT: mlmePollConfirm(NO_DATA); break;
case MAC_STATE_ASSOC_DATA_REQUEST_SENT: mlmeAssociateConfirm(0xFFFF, NO_DATA); break;
default: break;
}
} // mipDataRequestTimeoutTask
//-------------------------------------------------------------------------------------------------------
// void mipDataRequestTimeout(void)
//
// DESCRIPTION:
// This timeout will occur when no response has been received after a data request.
//-------------------------------------------------------------------------------------------------------
void mipDataRequestTimeout(void) {
if (!mschAddTask(mschReserveTask(), MAC_TASK_PRI_HIGH, mipDataRequestTimeoutTask, 0)) {
mtimSetCallback(mipDataRequestTimeout, 10);
}
} // mipDataRequestTimeout
//-------------------------------------------------------------------------------------------------------
// MAC_STATE_TYPE mipCancelDataRequestTimeout(void)
//
// DESCRIPTION:
// Cancels the data request timeout. This function should be used when a valid or invalid "indirect
// packet" has been received. The MAC state is set back to the default state.
//
// RETURN VALUE:
// MAC_STATE_TYPE
// The MAC state before resetting it to MAC_STATE_DEFAULT
//-------------------------------------------------------------------------------------------------------
MAC_STATE_TYPE mipCancelDataRequestTimeout(void) {
MAC_STATE_TYPE macState = MAC_STATE_DEFAULT;
if (mtimCancelCallback(mipDataRequestTimeout)) {
mrxDecrOnCounter();
DISABLE_GLOBAL_INT();
macState = macInfo.state;
macSetState(MAC_STATE_DEFAULT);
ENABLE_GLOBAL_INT();
}
return macState;
} // mipCancelDataRequestTimeout
/*******************************************************************************************************
*******************************************************************************************************
************************** ASSOCIATION RESPONSE POLLING **************************
*******************************************************************************************************
*******************************************************************************************************/
//-------------------------------------------------------------------------------------------------------
// MAC_ENUM mipTransmitAssocDataRequest(void)
//
// DESCRIPTION:
// Tranmits an the data request packet that follows a successful association request packet. This
// packet is transmitted when the data is indicated in the beacon pending list, or the response
// time has passed.
//
// RETURN VALUE:
// BOOL
// The association request was transmitted
//-------------------------------------------------------------------------------------------------------
MAC_ENUM mipTransmitAssocDataRequest(void) {
BOOL securityEnable;
#if MAC_OPT_SECURITY
securityEnable = GET_MF(MF_SECURE_ASSOC);
#else
securityEnable = FALSE;
#endif
// Set automatic polling mode
if (!macSetState(MAC_STATE_TX_ASSOC_DATA_REQUEST)) return SUCCESS;
// Transmit the data request
if (mpib.macCoordShortAddress < 0xFFFE) {
return mipTransmitDataRequest(AM_SHORT_16, mpib.macPANId, (ADDRESS*) &mpib.macCoordShortAddress, securityEnable);
} else {
return mipTransmitDataRequest(AM_EXTENDED_64, mpib.macPANId, (ADDRESS*) &mpib.macCoordExtendedAddress, securityEnable);
}
} // mipTransmitAssocDataRequest
//-------------------------------------------------------------------------------------------------------
// void mipPollAssociateResponseTask(MAC_TASK_INFO *pTask)
//
// DESCRIPTION:
// This task makes sure that a data request is transmitted in the association procedure. If the
// transmission couldn't be initiated, this task will be rescheduled.
//
// TASK DATA:
// 0
//-------------------------------------------------------------------------------------------------------
void mipPollAssociateResponseTask(MAC_TASK_INFO *pTask) {
// We should not wait for the association response to be indicated in the beacon pending list, because there's no
// guarantee that it will ever appear there (the coordinator could for instance be out of resources when the
// association request is received)! If the association response is not polled, the MAC state machine (macInfo.state)
// will lock up (and probably the higher layer too).
if (macInfo.state == MAC_STATE_ASSOC_REQUEST_SENT) {
if (mipTransmitAssocDataRequest() == RESOURCE_SHORTAGE) {
// Reschedule this task if there was a lack of resources (TX packet or task)
mschRescheduleTask(pTask, 0);
return;
}
}
// Done! Remove this task
mschRemoveTask(pTask->priority, MSCH_KEEP_TASK_IN_PROGRESS_BM);
} // mipPollAssociateResponse
//-------------------------------------------------------------------------------------------------------
// void mipPollAssociateResponse(void)
//
// DESCRIPTION:
// This timeout function creates the task responsible for polling the association response.
//-------------------------------------------------------------------------------------------------------
void mipPollAssociateResponse(void) {
if (!mschAddTask(mschReserveTask(), MAC_TASK_PRI_LOW, mipPollAssociateResponseTask, 0)) {
mtimSetCallback(mipPollAssociateResponse, MIP_RETRY_ASSOCIATION_RESPONSE_POLLING_TIMEOUT);
}
} // mipPollAssociateResponse
/*******************************************************************************************************
* Revision history:
*
* $Log: mac_indirect_polling.c,v $
* Revision 1.12 2005/02/02 15:08:14 thl
* Added functionality for pan id conflict according to IEEE802.15.4-2003
*
* Revision 1.11 2004/11/18 15:07:57 thl
* Added support for pending frame bit in outgoing data frames.
* Only apply to outgoing data frames and wherer the address matches
* one or more packet in the indirect packet quee.
*
* Revision 1.10 2004/11/10 09:33:13 thl
* Fixed a number of bugs according to: MAC software check lists.xls
*
* Revision 1.9 2004/08/13 13:04:46 jol
* CC2420 MAC Release v0.7
*
*
*******************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -