⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapp.c

📁 freescale的基于802.15.4的无线通讯例程
💻 C
字号:
/*****************************************************************************
* MyWirelessApp_01 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
*************************************************************************************
************************************************************************************/

static void App_HandleKeys(key_event_t events);
static bool_t App_Idle(void); 

/************************************************************************************
*************************************************************************************
* Private type definitions
*************************************************************************************
************************************************************************************/


/************************************************************************************
*************************************************************************************
* Private memory declarations
*************************************************************************************
************************************************************************************/

/************************************************************************************
*************************************************************************************
* Public memory declarations
*************************************************************************************
************************************************************************************/

/* The current state of the applications state machine */
uint8_t gState;

/************************************************************************************
*************************************************************************************
* Public functions
*************************************************************************************
************************************************************************************/

void DeepSleepWakeupStackProc(void);

/*****************************************************************************
* 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*/
  /* 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)
{
    switch(gState)
    {
    case stateInit:            
      /* Goto idle state and listen for input to the state machine. */
      gState = stateTerminate;
      /* Print to UART */
      UartUtil_Print("\nMyWirelessApp_01 demo application executed successfully.\n");            
      /* 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);       
      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;
    }      
    /* Just to avoid the compiler warning */
    (void)events;
}


/************************************************************************************
*************************************************************************************
* Private functions
*************************************************************************************
************************************************************************************/

/*****************************************************************************
* Handles all key events for this device.
* Interface assumptions: None
* Return value: None
*****************************************************************************/
static void App_HandleKeys
  (
  key_event_t events  /*IN: Events from keyboard module  */
  )
{
  switch ( events ) 
    { 
      case gKBD_EventSW1_c:
      case gKBD_EventSW2_c:
      case gKBD_EventSW3_c:
      case gKBD_EventSW4_c:
      case gKBD_EventLongSW1_c:
      case gKBD_EventLongSW2_c:
      case gKBD_EventLongSW3_c:
      case gKBD_EventLongSW4_c:
        if(gState == stateInit)
          {
          StopLed1Flashing;
          StopLed2Flashing;
          StopLed3Flashing;
          StopLed4Flashing;
          Led1Off;
          Led2Off;
          Led3Off;
          Led4Off;
          LCD_ClearDisplay();
          LCD_WriteString(1,"Application");
          LCD_WriteString(2,"    started");     
          TS_SendEvent(gZappTaskID_c, evtInit);       
          }
    break;
    }    
}         

/******************************************************************************
* The App_Idle(void) function will check for network or UART activity .
* The function may return either of the following values:
*   TRUE     : No activity detected
*   FALSE    : Network or UART activity detected
******************************************************************************/
static bool_t App_Idle(void) 
  {
  if (UartUtil_CheckIdle() == TRUE)
  {
    return TRUE;      
  }   
  else
  {
    return FALSE;  
  }
}

/*****************************************************************************
* The DeepSleepWakeupStackProc(void) function is called each time the 
* application exits the DeepSleep mode .
* 
* Return value:
*     None
*****************************************************************************/
void DeepSleepWakeupStackProc(void){
  return;
}

/******************************************************************************
* The following functions are called by the MAC to put messages into the
* Application's queue. They need to be defined even if they are not used
* in order to avoid linker errors.
******************************************************************************/
   
uint8_t MLME_NWK_SapHandler(nwkMessage_t *pMsg)
{
  /* If the message is not handled anywhere it must be freed. */
  MSG_Free(pMsg);
  return gSuccess_c;
}

uint8_t MCPS_NWK_SapHandler(mcpsToNwkMessage_t *pMsg)
{
  /* If the message is not handled anywhere it must be freed. */
  MSG_Free(pMsg);
  return gSuccess_c;
}

uint8_t ASP_APP_SapHandler(aspToAppMsg_t *pMsg)
{
  /* If the message is not handled anywhere it must be freed. */
  MSG_Free(pMsg);
  return gSuccess_c;
}

/******************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -