📄 mapp.c
字号:
/*****************************************************************************
* MyWirelessApp_02 demo application
*
* (c) Copyright 2006, Freescale, Inc. All rights reserved.
*
*
* No part of this document must be reproduced in any form - including copied,
* transcribed, printed or by any electronic means - without specific written
* permission from Freescale Semiconductor Danmark A/S.
*****************************************************************************/
#include "MApp.h"
/************************************************************************************
*************************************************************************************
* Private macros
*************************************************************************************
************************************************************************************/
/************************************************************************************
*************************************************************************************
* Private prototypes
*************************************************************************************
************************************************************************************/
/* Forward declarations of helper functions */
static uint8_t App_StartScan(uint8_t scanType);
static uint8_t App_WaitMsg(nwkMessage_t *pMsg, uint8_t msgType);
static void App_HandleScanEdConfirm(nwkMessage_t *pMsg);
static void App_HandleKeys(key_event_t events) ;
static bool_t App_Idle(void);
/************************************************************************************
*************************************************************************************
* Private type definitions
*************************************************************************************
************************************************************************************/
void DeepSleepWakeupStackProc(void);
/************************************************************************************
*************************************************************************************
* Private memory declarations
*************************************************************************************
************************************************************************************/
/* Application input queues */
static anchor_t mMlmeNwkInputQueue;
/************************************************************************************
*************************************************************************************
* Public memory declarations
*************************************************************************************
************************************************************************************/
/* The current state of the applications state machine */
uint8_t gState;
/************************************************************************************
*************************************************************************************
* Public functions
*************************************************************************************
************************************************************************************/
/*****************************************************************************
* Initialization function for the App Task. This is called during
* initialization and should contain any application specific initialization
* (ie. hardware initialization/setup, table initialization, power up
* notificaiton.
*
* Interface assumptions: None
*
* Return value: None
*
*****************************************************************************/
void MApp_init(void)
{
/* The initial application state */
gState = stateInit;
/* Initialize the 802.15.4 stack */
Init_802_15_4();
/* Initialize the MAC 802.15.4 extended address */
Init_MacExtendedAddress();
/* Initialize the timer module.
This is done because the UART module uses the TMR module and this must be initialized
If you use TMR module functionality for your own, you must not recall this function */
TMR_Init();
/* register keyboard callback function */
KBD_Init(App_HandleKeys);
/* initialize LCD Module */
LCD_Init();
/* Initialize the UART so that we can print out status messages */
UartUtil_Init(gDefaultUartUtilBaudRate_c);
/* Initialize LowPowerModule if included*/
#if (gLpmIncluded_d==1)
PWR_CheckForAndEnterNewPowerState_Init();
#endif /*gLpmIncluded_d*/
/* Prepare input queues.*/
MSG_InitQueue(&mMlmeNwkInputQueue);
/* Enable MCU interrupts */
IrqControlLib_EnableAllIrqs();
/*signal app ready*/
Led1Flashing;
Led2Flashing;
Led3Flashing;
Led4Flashing;
UartUtil_Print("\nPress any switch on board to start running the application.\n");
LCD_ClearDisplay();
LCD_WriteString(1,"Press any key");
LCD_WriteString(2,"to start.");
}
/*****************************************************************************
*Mac Application Task event processor. This function is called to
* process all events for the task. Events include timers, messages and any
* other user defined events
*
* Interface assumptions: None
*
* Return value: None
*****************************************************************************/
void AppTask(event_t events)
{
/* Pointer for storing the messages from MLME */
void *pMsgIn;
/* Stores the error/success code returned by some functions. */
uint8_t ret;
/* The application state machine */
switch(gState)
{
case stateInit:
/* Print a welcome message to the UART */
UartUtil_Print("MyWirelessApp_02 demo application is initialized and ready.\n\n");
/* Go to the next state and signal the application task */
gState = stateScanEdStart;
TS_SendEvent(gZappTaskID_c, evtStartScan);
break;
case stateScanEdStart:
/* Start the Energy Detection scan, and goto wait for confirm state. */
UartUtil_Print("Initiating the Energy Detection Scan\n");
/*print a message on the LCD also*/
LCD_ClearDisplay();
LCD_WriteString(1,"Starting Energy");
LCD_WriteString(2,"Detection Scan");
ret = App_StartScan(gScanModeED_c);
if(ret == errorNoError)
{
gState = stateScanEdWaitConfirm;
}
break;
case stateScanEdWaitConfirm:
/* Stay in this state until the MLME Scan confirm message
arrives, and has been processed. Then goto listen state. */
if (events & evtMessageFromMLME)
{
pMsgIn = MSG_DeQueue(&mMlmeNwkInputQueue);
if (pMsgIn)
{
ret = App_WaitMsg(pMsgIn, gNwkScanCnf_c);
if(ret == errorNoError)
{
/* Process the ED scan confirm. The logical
channel is selected by this function. */
App_HandleScanEdConfirm(pMsgIn);
gState = stateTerminate;
/* Print out that app will enter sleep mode, if LPM module included*/
#if (gLpmIncluded_d==1)
UartUtil_Print("Application enters now sleep mode.\n");
#endif /*gLpmIncluded_d*/
/* Send evtTerminate to TS */
TS_SendEvent(gZappTaskID_c, evtTerminate);
}
MSG_Free(pMsgIn);
}
}
break;
case stateTerminate:
/*Allow the device to enter to sleep if no activity on UART */
if (App_Idle() == TRUE)
{
#if (gLpmIncluded_d==1)
UartUtil_ConfigureStopMode(TRUE);
PWR_AllowDeviceToSleep();
#endif /*gLpmIncluded_d */
}
else
{
/*stay in this state until no activity on UART*/
TS_SendEvent(gZappTaskID_c, evtTerminate);
}
break;
}
}
/************************************************************************************
*************************************************************************************
* Private functions
*************************************************************************************
************************************************************************************/
/******************************************************************************
* The App_StartScan(scanType) function will start the scan process of the
* specified type in the MAC. This is accomplished by allocating a MAC message,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -