?? wuart_c.c
字號:
/****************************************************************************
*
* MODULE: wuart_c.c
*
* COMPONENT: $RCSfile: wuart_c.c,v $
*
* VERSION: $Name: $
*
* REVISION: $Revision: 1.1 $
*
* DATED: $Date: 2008/01/30 09:52:07 $
*
* STATUS: $State: Exp $
*
* AUTHOR: Ian Morris
*
* DESCRIPTION
*
* CHANGE HISTORY:
*
* $Log: wuart_c.c,v $ * Revision 1.1 2008/01/30 09:52:07 lmitch * Updated to work with new SDK * * Revision 1.1 2006/07/24 14:40:12 rmm * First Release 1v0 (Based on Application Note JN-AN-1005-Wireless-UART Version 1.5). *
*
*
* LAST MODIFIED BY: $Author: lmitch $
* $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 <LcdDriver.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)
{
/* Initialise the LED's and turn them all off */ vLedInitFfd(); vLedControl(0, FALSE); vLedControl(1, FALSE); vLedControl(2, FALSE); vLedControl(3, FALSE);
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();
vAHI_SysCtrlRegisterCallback(vAppQApiPostHwInt);
vAHI_Uart0RegisterCallback(vAppQApiPostHwInt);
vAHI_Timer1RegisterCallback(vAppQApiPostHwInt);
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);
/* 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)
{
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)
{
if (psMlmeInd->uParam.sDcfmScan.u8ScanType == MAC_MLME_SCAN_TYPE_ENERGY_DETECT)
{
if (sCoordData.sSystem.eState == E_STATE_ENERGY_SCANNING)
{
vHandleEnergyScanResponse(psMlmeInd);
sCoordData.sSystem.eState = E_STATE_START_COORDINATOR;
}
}
}
break;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -