📄 wuart_e.c
字号:
/****************************************************************************
*
* MODULE: Wireless UART
*
* COMPONENT: wuart_e.c,v
*
* VERSION:
*
* REVISION: 1.3
*
* DATED: 2006/11/09 12:57:10
*
* STATUS: Exp
*
* AUTHOR: Ian Morris
*
* DESCRIPTION
*
* CHANGE HISTORY:
*
* wuart_e.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:28 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 ***/
/****************************************************************************/
/* 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)
{
vLedInitRfd();
vLedControl(0,0);
vLedControl(1,0);
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);
/* 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;
}
}
/****************************************************************************
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -