?? wuart_e.c
字號:
{
MAC_RxFrameData_s *psFrame;
MAC_Addr_s *psAddr;
uint16 u16NodeAddr;
uint8 i;
// rmm char acBlankLine[] = " ";
psFrame = &psMcpsInd->uParam.sIndData.sFrame;
psAddr = &psFrame->sSrcAddr;
/* Check that this is a data frame */
if (psMcpsInd->u8Type == MAC_MCPS_IND_DATA)
{
/* Check that data is from UART node */
u16NodeAddr = psAddr->uAddr.u16Short;
if (u16NodeAddr == COORD_ADDR)
{
if (psFrame->au8Sdu[0] == u8RxFrameHandle)
{
u8RxFrameHandle++;
/* Copy frame data to serial buffer for output on UART */
for (i = 1; i < psFrame->u8SduLength; i++)
{
vSerial_TxChar(psFrame->au8Sdu[i]);
}
psFrame->au8Sdu[psFrame->u8SduLength] = 0; // Add a 'null' to the end of the data payload (required by the LcdWriteText function).
vLcdWriteText((char*)&psFrame->au8Sdu[1], 6, 0);
vLcdRefreshAll(); vLcdScrollUp(1); vLcdWriteText(acBlankLine, 6, 0);
}
/* Must have missed a frame */
else if (psFrame->au8Sdu[0] > u8RxFrameHandle)
{
u8RxFrameHandle = psFrame->au8Sdu[0] + 1;
/* Copy frame data to serial buffer for output on UART */
for (i = 1; i < psFrame->u8SduLength; i++)
{
vSerial_TxChar(psFrame->au8Sdu[i]);
}
psFrame->au8Sdu[psFrame->u8SduLength] = 0; // Add a 'null' to the end of the data payload (required by the LcdWriteText function).
vLcdWriteText((char*)&psFrame->au8Sdu[1], 6, 0);
vLcdRefreshAll(); vLcdScrollUp(1); vLcdWriteText(acBlankLine, 6, 0);
}
/* Must be the same frame as last time */
else if (psFrame->au8Sdu[0] < u8RxFrameHandle)
{
/* Dont do anything as we already have the data */
}
}
}
}
/****************************************************************************
*
* NAME: vProcessIncomingHwEvent
*
* DESCRIPTION:
* Process any hardware events.
*
* PARAMETERS: Name RW Usage
* psAHI_Ind
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
PRIVATE void vProcessIncomingHwEvent(AppQApiHwInd_s *psAHI_Ind)
{
/* If this is an event from UART0 */
if (psAHI_Ind->u32DeviceId == E_AHI_DEVICE_UART0)
{
/* If data has been received */
if ((psAHI_Ind->u32ItemBitmap & 0x000000FF) == E_AHI_UART_INT_RXDATA)
{
/* Process UART0 RX interrupt */
if (((psAHI_Ind->u32ItemBitmap & 0x0000FF00) >> 8) == 0x0D)
{
vWUART_TxData();
}
else
{
vUART_RxCharISR((psAHI_Ind->u32ItemBitmap & 0x0000FF00) >> 8);
}
}
else if (psAHI_Ind->u32ItemBitmap == E_AHI_UART_INT_TX)
{
/* Process UART0 TX interrupt */
vUART_TxCharISR();
}
}
}
/****************************************************************************
*
* NAME: vTickTimerISR
*
* DESCRIPTION:
*
*
* PARAMETERS: Name RW Usage
* None.
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
PRIVATE void vTickTimerISR(uint32 u32Device, uint32 u32ItemBitmap)
{
static uint8 u8ToggleCount;
/* Flash LED 1 to show we are alive */
if (u8ToggleCount++ & 0x40)
{
vLedControl(0, TRUE); }
else
{
vLedControl(0, FALSE); }
/* rmm
Commented out. Data now transmittd on the receipt of a CR
// Do this every 10ms to tx data received on hardware UART
if (sDeviceData.sSystem.eState == E_STATE_RUNNING)
{
vWUART_TxData();
}
*/
}
/****************************************************************************
*
* NAME: vStartActiveScan
*
* DESCRIPTION:
* Start a scan to search for a network to join.
*
* PARAMETERS: Name RW Usage
* None.
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
PRIVATE void vStartActiveScan(void)
{
MAC_MlmeReqRsp_s sMlmeReqRsp;
MAC_MlmeSyncCfm_s sMlmeSyncCfm;
sDeviceData.sSystem.eState = E_STATE_SCANNING;
/* Request scan */
sMlmeReqRsp.u8Type = MAC_MLME_REQ_SCAN;
sMlmeReqRsp.u8ParamLength = sizeof(MAC_MlmeReqScan_s);
sMlmeReqRsp.uParam.sReqScan.u8ScanType = MAC_MLME_SCAN_TYPE_ACTIVE;
sMlmeReqRsp.uParam.sReqScan.u32ScanChannels = SCAN_CHANNELS;
sMlmeReqRsp.uParam.sReqScan.u8ScanDuration = ACTIVE_SCAN_DURATION;
vAppApiMlmeRequest(&sMlmeReqRsp, &sMlmeSyncCfm);
}
/****************************************************************************
*
* NAME: vHandleActiveScanResponse
*
* DESCRIPTION:
* Handle the reponse generated by the stack as a result of the network scan.
*
* PARAMETERS: Name RW Usage
* psMlmeInd
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
PRIVATE void vHandleActiveScanResponse(MAC_MlmeDcfmInd_s *psMlmeInd)
{
MAC_PanDescr_s *psPanDesc;
int i;
/* Make sure it is what we're after */
if ((psMlmeInd->uParam.sDcfmScan.u8Status == MAC_ENUM_SUCCESS)
&& (psMlmeInd->uParam.sDcfmScan.u8ScanType == MAC_MLME_SCAN_TYPE_ACTIVE))
{
/* Determine which, if any, network contains demo coordinator.
Algorithm for determining which network to connect to is
beyond the scope of 802.15.4, and we use a simple approach
of matching the required PAN ID and short address, both of
which we already know */
i = 0;
while (i < psMlmeInd->uParam.sDcfmScan.u8ResultListSize)
{
psPanDesc = &psMlmeInd->uParam.sDcfmScan.uList.asPanDescr[i];
if ((psPanDesc->sCoord.u16PanId == PAN_ID)
&& (psPanDesc->sCoord.u8AddrMode == 2)
&& (psPanDesc->sCoord.uAddr.u16Short == COORD_ADDR))
{
/* Matched so start to synchronise and associate */
sDeviceData.sSystem.u8Channel = psPanDesc->u8LogicalChan;
vStartAssociate();
return;
}
i++;
}
}
/* Failed to find coordinator: keep trying */
vStartActiveScan();
}
/****************************************************************************
*
* NAME: vStartAssociate
*
* DESCRIPTION:
* Start the association process with the network coordinator.
*
* PARAMETERS: Name RW Usage
* None.
*
* RETURNS:
* None.
*
* NOTES:
* Assumes that a network has been found during the network scan.
****************************************************************************/
PRIVATE void vStartAssociate(void)
{
MAC_MlmeReqRsp_s sMlmeReqRsp;
MAC_MlmeSyncCfm_s sMlmeSyncCfm;
sDeviceData.sSystem.eState = E_STATE_ASSOCIATING;
/* Create associate request. We know short address and PAN ID of
coordinator as this is preset and we have checked that received
beacon matched this */
sMlmeReqRsp.u8Type = MAC_MLME_REQ_ASSOCIATE;
sMlmeReqRsp.u8ParamLength = sizeof(MAC_MlmeReqAssociate_s);
sMlmeReqRsp.uParam.sReqAssociate.u8LogicalChan = sDeviceData.sSystem.u8Channel;
sMlmeReqRsp.uParam.sReqAssociate.u8Capability = 0x80; /* We want short address, other features off */
sMlmeReqRsp.uParam.sReqAssociate.u8SecurityEnable = FALSE;
sMlmeReqRsp.uParam.sReqAssociate.sCoord.u8AddrMode = 2;
sMlmeReqRsp.uParam.sReqAssociate.sCoord.u16PanId = PAN_ID;
sMlmeReqRsp.uParam.sReqAssociate.sCoord.uAddr.u16Short = COORD_ADDR;
vAppApiMlmeRequest(&sMlmeReqRsp, &sMlmeSyncCfm);
}
/****************************************************************************
*
* NAME: vHandleAssociateResponse
*
* DESCRIPTION:
* Handle the response generated by the stack as a result of the associate
* start request.
*
* PARAMETERS: Name RW Usage
* psMlmeInd
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
PRIVATE void vHandleAssociateResponse(MAC_MlmeDcfmInd_s *psMlmeInd)
{
/* If successfully associated with network coordinator */
if (psMlmeInd->uParam.sDcfmAssociate.u8Status == MAC_ENUM_SUCCESS)
{
/* Store short address that we have been assigned */
sDeviceData.sSystem.u16ShortAddr = psMlmeInd->uParam.sDcfmAssociate.u16AssocShortAddr;
/* We are now in the running state */
sDeviceData.sSystem.eState = E_STATE_RUNNING;
/* Turn on LED 2 to show we have assocaited */
vLedControl(1, TRUE);
}
else
{
/* Try, try again */
vStartActiveScan();
}
}
/****************************************************************************
*
* NAME: vTxUARTData
*
* DESCRIPTION:
*
* PARAMETERS: Name RW Usage
* None.
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
PRIVATE void vWUART_TxData(void)
{
MAC_McpsReqRsp_s sMcpsReqRsp;
MAC_McpsSyncCfm_s sMcpsSyncCfm;
uint8 *pu8Payload, i = 0;
int16 i16RxChar;
i16RxChar = i16Serial_RxChar();
if (i16RxChar >= 0)
{
/* Create frame transmission request */
sMcpsReqRsp.u8Type = MAC_MCPS_REQ_DATA;
sMcpsReqRsp.u8ParamLength = sizeof(MAC_McpsReqData_s);
/* Set handle so we can match confirmation to request */
sMcpsReqRsp.uParam.sReqData.u8Handle = 1;
/* Use short address for source */
sMcpsReqRsp.uParam.sReqData.sFrame.sSrcAddr.u8AddrMode = 2;
sMcpsReqRsp.uParam.sReqData.sFrame.sSrcAddr.u16PanId = PAN_ID;
sMcpsReqRsp.uParam.sReqData.sFrame.sSrcAddr.uAddr.u16Short = sDeviceData.sSystem.u16ShortAddr;
/* Use short address for destination */
sMcpsReqRsp.uParam.sReqData.sFrame.sDstAddr.u8AddrMode = 2;
sMcpsReqRsp.uParam.sReqData.sFrame.sDstAddr.u16PanId = PAN_ID;
sMcpsReqRsp.uParam.sReqData.sFrame.sDstAddr.uAddr.u16Short = COORD_ADDR;
/* Frame requires ack but not security, indirect transmit or GTS */
sMcpsReqRsp.uParam.sReqData.sFrame.u8TxOptions = MAC_TX_OPTION_ACK;
pu8Payload = sMcpsReqRsp.uParam.sReqData.sFrame.au8Sdu;
pu8Payload[i++] = u8TxFrameHandle++;
pu8Payload[i++] = (uint8)i16RxChar;
while ((i16RxChar >= 0) && (i < MAX_DATA_PER_FRAME))
{
i16RxChar = i16Serial_RxChar();
if (i16RxChar >= 0)
{
/* Set payload data */
pu8Payload[i++] = (uint8)i16RxChar;
}
}
/* Set frame length */
sMcpsReqRsp.uParam.sReqData.sFrame.u8SduLength = i;
/* Request transmit */
vAppApiMcpsRequest(&sMcpsReqRsp, &sMcpsSyncCfm);
}
}
/****************************************************************************/
/*** END OF FILE ***/
/****************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -