📄 wuart_e.c
字号:
/****************************************************************************
*
* MODULE: wuart_e.c
*
* COMPONENT: $RCSfile: $
*
* VERSION: $Name: $
*
* REVISION: $Revision: $
*
* DATED: $Date: $
*
* STATUS: $State: $
*
* AUTHOR: Ian Morris
*
* DESCRIPTION
*
* CHANGE HISTORY:
*
* $Log: $
*
*
* LAST MODIFIED BY: $Author: $
* $Modtime: $
*
*
****************************************************************************
*
* (c) Copyright 2000 JENNIC Ltd
*
****************************************************************************/
/****************************************************************************/
/*** Include files ***/
/****************************************************************************/
#include <jendefs.h>
#include <AppHardwareApi.h>
#include <AppQueueApi.h>
#include <mac_sap.h>
#include <mac_pib.h>
#include <string.h>
#include <AppApi.h>
#include <LcdDriver.h>
#include "config.h"
#include "serialq.h"
#include "uart.h"
#include "serial.h"
/****************************************************************************/
/*** Macro Definitions ***/
/****************************************************************************/
/****************************************************************************/
/*** Type Definitions ***/
/****************************************************************************/
/* State machine states */
typedef enum
{
E_STATE_OFF,
E_STATE_SCANNING,
E_STATE_ASSOCIATING,
E_STATE_RUNNING,
} teState;
/* All application data with scope within the entire file is kept here,
including all stored node data */
typedef struct
{
struct
{
teState eState;
uint8 u8Channel;
uint16 u16ShortAddr;
} sSystem;
} tsDeviceData;
/****************************************************************************/
/*** Local Function Prototypes ***/
/****************************************************************************/
/****************************************************************************/
/*** Exported Variables ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Variables ***/
/****************************************************************************/
PRIVATE tsDeviceData sDeviceData;
uint8 u8TxFrameHandle = 0;
uint8 u8RxFrameHandle = 0;
bool_t bToggle;
uint16 u16TestCount = 0;
PRIVATE void *pvMac;
PRIVATE MAC_Pib_s *psPib;
/****************************************************************************/
/*** Exported Functions ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Functions ***/
/****************************************************************************/
PRIVATE void vWUART_Init(void);
PRIVATE void vStartActiveScan(void);
PRIVATE void vStartAssociate(void);
PRIVATE void vProcessEventQueues(void);
PRIVATE void vProcessIncomingMlme(MAC_MlmeDcfmInd_s *psMlmeInd);
PRIVATE void vProcessIncomingData(MAC_McpsDcfmInd_s *psMcpsInd);
PRIVATE void vProcessIncomingHwEvent(AppQApiHwInd_s *psAHI_Ind);
PRIVATE void vHandleActiveScanResponse(MAC_MlmeDcfmInd_s *psMlmeInd);
PRIVATE void vHandleAssociateResponse(MAC_MlmeDcfmInd_s *psMlmeInd);
PRIVATE void vWUART_TxData(void);
PRIVATE void vTickTimerISR(uint32 u32Device, uint32 u32ItemBitmap);
/****************************************************************************
*
* NAME: AppColdStart
*
* DESCRIPTION:
*
* PARAMETERS: Name RW Usage
* None.
*
* RETURNS:
* None.
*
* NOTES:
* Entry point for a power on reset or wake from sleep mode.
****************************************************************************/
PUBLIC void AppColdStart(void)
{
vWUART_Init();
vStartActiveScan();
while(1)
{
vProcessEventQueues();
}
}
/****************************************************************************
*
* NAME: AppWarmStart
*
* DESCRIPTION:
* Entry point for a wake from sleep mode with the memory contents held. We
* are not using this mode and so should never get here.
*
* PARAMETERS: Name RW Usage
* None.
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
PUBLIC void AppWarmStart(void)
{
AppColdStart();
}
/****************************************************************************
*
* NAME: vWUART_Init
*
* DESCRIPTION:
* Initialises stack and hardware, sets non-default values in the 802.15.4
* PIB.
*
* PARAMETERS: Name RW Usage
* None.
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
PRIVATE void vWUART_Init(void)
{
LED_INIT;
LED_1_OFF;
LED_2_OFF;
sDeviceData.sSystem.eState = E_STATE_OFF;
/* Initialise stack and hardware interfaces. We aren't using callbacks
at all, just monitoring the upward queues in a loop */
(void)u32AppQApiInit(NULL, NULL, NULL);
(void)u32AHI_Init();
pvMac = pvAppApiGetMacHandle();
psPib = MAC_psPibGetHandle(pvMac);
/* Set Pan ID in PIB (also sets match register in hardware) */
MAC_vPibSetPanId(pvMac, PAN_ID);
/* Enable receiver to be on when idle */
MAC_vPibSetRxOnWhenIdle(pvMac, 1, FALSE);
/* rmm
Initialise the Lcd Display
*/
vLcdResetDefault(); // LCD Default settings
vLcdClear(); // Clear Shadow memory
vLcdRefreshAll(); // Copy Shadowe mem to Lcd
/* Initialise the serial port and rx/tx queues */
vSerial_Init();
/* Initialise tick timer to give 10ms interrupt */
vAHI_TickTimerConfigure(E_AHI_TICK_TIMER_DISABLE);
vAHI_TickTimerWrite(0);
vAHI_TickTimerInit(vTickTimerISR);
vAHI_TickTimerInterval(TICK_PERIOD_COUNT);
vAHI_TickTimerConfigure(E_AHI_TICK_TIMER_RESTART);
vAHI_TickTimerIntEnable(TRUE);
}
/****************************************************************************
*
* NAME: vProcessEventQueues
*
* DESCRIPTION:
* Check each of the three event queues and process and items found.
*
* PARAMETERS: Name RW Usage
* None.
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
PRIVATE void vProcessEventQueues(void)
{
MAC_MlmeDcfmInd_s *psMlmeInd;
MAC_McpsDcfmInd_s *psMcpsInd;
AppQApiHwInd_s *psAHI_Ind;
/* Check for anything on the MCPS upward queue */
do
{
psMcpsInd = psAppQApiReadMcpsInd();
if (psMcpsInd != NULL)
{
vProcessIncomingData(psMcpsInd);
vAppQApiReturnMcpsIndBuffer(psMcpsInd);
}
} while (psMcpsInd != NULL);
/* Check for anything on the MLME upward queue */
do
{
psMlmeInd = psAppQApiReadMlmeInd();
if (psMlmeInd != NULL)
{
vProcessIncomingMlme(psMlmeInd);
vAppQApiReturnMlmeIndBuffer(psMlmeInd);
}
} while (psMlmeInd != NULL);
/* Check for anything on the AHI upward queue */
do
{
psAHI_Ind = psAppQApiReadHwInd();
if (psAHI_Ind != NULL)
{
vProcessIncomingHwEvent(psAHI_Ind);
vAppQApiReturnHwIndBuffer(psAHI_Ind);
}
} while (psAHI_Ind != NULL);
}
/****************************************************************************
*
* NAME: vProcessIncomingMlme
*
* DESCRIPTION:
* Process any incoming managment events from the stack.
*
* PARAMETERS: Name RW Usage
* psMlmeInd
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
PRIVATE void vProcessIncomingMlme(MAC_MlmeDcfmInd_s *psMlmeInd)
{
/* We respond to several MLME indications and confirmations, depending
on mode */
switch (psMlmeInd->u8Type)
{
/* Deferred confirmation that the scan is complete */
case MAC_MLME_DCFM_SCAN:
/* Only respond to this if scanning */
if (sDeviceData.sSystem.eState == E_STATE_SCANNING)
{
vHandleActiveScanResponse(psMlmeInd);
}
break;
/* Deferred confirmation that the association process is complete */
case MAC_MLME_DCFM_ASSOCIATE:
/* Only respond to this if associating */
if (sDeviceData.sSystem.eState == E_STATE_ASSOCIATING)
{
vHandleAssociateResponse(psMlmeInd);
}
break;
default:
break;
}
}
/****************************************************************************
*
* NAME: vProcessIncomingData
*
* DESCRIPTION:
* Process incoming data events from the stack.
*
* PARAMETERS: Name RW Usage
* psMcpsInd
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
PRIVATE void vProcessIncomingData(MAC_McpsDcfmInd_s *psMcpsInd)
{
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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -