📄 wuart_c.c
字号:
/****************************************************************************
*
* MODULE: Wireless UART
*
* COMPONENT: wuart_c.c,v
*
* VERSION:
*
* REVISION: 1.3
*
* DATED: 2006/11/09 12:57:10
*
* STATUS: Exp
*
* AUTHOR: Ian Morris
*
* DESCRIPTION
*
* CHANGE HISTORY:
*
* wuart_c.c,v
* Revision 1.3 2006/11/09 12:57:10 imorr
* Updated copyright information in file header
*
* Revision 1.2 2006/11/06 15:42:10 imorr
* Updated to use interrupt driven comms
*
* Revision 1.1 2006/08/24 14:58:35 imorr
* Initial version
*
*
*
* LAST MODIFIED BY: imorr
* $Modtime: $
*
*
****************************************************************************
*
* This software is owned by Jennic and/or its supplier and is protected
* under applicable copyright laws. All rights are reserved. We grant You,
* and any third parties, a license to use this software solely and
* exclusively on Jennic products. You, and any third parties must reproduce
* the copyright and warranty notice and any other legend of ownership on each
* copy or partial copy of the software.
*
* THIS SOFTWARE IS PROVIDED "AS IS". JENNIC MAKES NO WARRANTIES, WHETHER
* EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
* ACCURACY OR LACK OF NEGLIGENCE. JENNIC SHALL NOT, IN ANY CIRCUMSTANCES,
* BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, SPECIAL,
* INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER.
*
* Copyright Jennic Ltd 2005, 2006, 2007. All rights reserved
*
****************************************************************************/
/****************************************************************************/
/*** 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 <LedControl.h>
#include "config.h"
#include "serialq.h"
#include "uart.h"
#include "serial.h"
#include "gdb.h"
/****************************************************************************/
/*** Macro Definitions ***/
/****************************************************************************/
/****************************************************************************/
/*** Type Definitions ***/
/****************************************************************************/
/* System states with respect to screen display being shown */
typedef enum
{
E_STATE_INIT,
E_STATE_START_ENERGY_SCAN,
E_STATE_ENERGY_SCANNING,
E_STATE_START_COORDINATOR,
E_STATE_RUNNING_UART_APP
} teState;
/* Used to track an association between extended address and short address */
typedef struct
{
uint32 u32ExtAddrLo;
uint32 u32ExtAddrHi;
uint16 u16ShortAddr;
} tsAssocNodes;
/* All application data with scope within the entire file is kept here,
including all stored node data, GUI settings and current state */
typedef struct
{
struct
{
tsAssocNodes asAssocNodes[MAX_UART_NODES];
uint8 u8AssociatedNodes;
} sNode;
struct
{
teState eState;
uint8 u8Channel;
} sSystem;
} tsCoordData;
/****************************************************************************/
/*** Local Function Prototypes ***/
/****************************************************************************/
/****************************************************************************/
/*** Exported Variables ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Variables ***/
/****************************************************************************/
PRIVATE tsCoordData sCoordData;
PRIVATE uint8 u8TxFrameHandle = 0;
PRIVATE uint8 u8RxFrameHandle = 0;
PRIVATE void *pvMac;
PRIVATE MAC_Pib_s *psPib;
/****************************************************************************/
/*** Exported Functions ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Functions ***/
/****************************************************************************/
PRIVATE void vWUART_Init(void);
PRIVATE void vWUART_TxData(void);
PRIVATE void vProcessEventQueues(void);
PRIVATE void vStartCoordinator(void);
PRIVATE void vHandleNodeAssociation(MAC_MlmeDcfmInd_s *psMlmeInd);
PRIVATE void vProcessIncomingMlme(MAC_MlmeDcfmInd_s *psMlmeInd);
PRIVATE void vProcessIncomingData(MAC_McpsDcfmInd_s *psMcpsInd);
PRIVATE void vProcessIncomingHwEvent(AppQApiHwInd_s *psAHI_Ind);
PRIVATE void vTickTimerISR(uint32 u32Device, uint32 u32ItemBitmap);
PRIVATE void vStartEnergyScan(void);
PRIVATE void vHandleEnergyScanResponse(MAC_MlmeDcfmInd_s *psMlmeInd);
/****************************************************************************
*
* 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)
{
/* Debug hooks: include these regardless of whether debugging or not */
HAL_GDB_INIT();
HAL_BREAKPOINT();
vWUART_Init();
while(1)
{
vProcessEventQueues();
switch (sCoordData.sSystem.eState)
{
case E_STATE_INIT:
sCoordData.sSystem.u8Channel = CHANNEL_MIN;
sCoordData.sSystem.eState = E_STATE_START_ENERGY_SCAN;
break;
case E_STATE_START_ENERGY_SCAN:
vStartEnergyScan();
sCoordData.sSystem.eState = E_STATE_ENERGY_SCANNING;
break;
case E_STATE_ENERGY_SCANNING:
break;
case E_STATE_START_COORDINATOR:
vStartCoordinator();
sCoordData.sSystem.eState = E_STATE_RUNNING_UART_APP;
break;
case E_STATE_RUNNING_UART_APP:
break;
}
}
}
/****************************************************************************
*
* 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)
{
vLedInitRfd();
vLedControl(0,0);
vLedControl(1,0);
sCoordData.sNode.u8AssociatedNodes = 0;
/* 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 and short address in PIB (also sets match registers in hardware) */
MAC_vPibSetPanId(pvMac, PAN_ID);
MAC_vPibSetShortAddr(pvMac, COORD_ADDR);
/* Allow nodes to associate */
psPib->bAssociationPermit = 1;
/* Enable receiver to be on when idle */
MAC_vPibSetRxOnWhenIdle(pvMac, 1, FALSE);
/* 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)
{
switch(psMlmeInd->u8Type)
{
case MAC_MLME_IND_ASSOCIATE:
/* Only allow nodes to associate if network has been started */
if (sCoordData.sSystem.eState == E_STATE_RUNNING_UART_APP)
{
vHandleNodeAssociation(psMlmeInd);
}
break;
case MAC_MLME_DCFM_SCAN:
if (psMlmeInd->uParam.sDcfmScan.u8Status == MAC_ENUM_SUCCESS)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -