?? wuart_e.c
字號(hào):
/****************************************************************************
*
* MODULE: wuart_e.c
*
* COMPONENT: $RCSfile: wuart_e.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_e.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 ***/
/****************************************************************************/
/* 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)
{
/* Debug hooks: include these regardless of whether debugging or not */ HAL_GDB_INIT(); HAL_BREAKPOINT(); 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)
{
/* Initialise the LED's and turn them all off */ vLedInitRfd(); vLedControl(0, FALSE); vLedControl(1, FALSE); 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();
{
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
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)
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -