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

📄 mac_beacon_handler.c

📁 ucos在NEC平台下的移植
💻 C
📖 第 1 页 / 共 3 页
字号:
/*******************************************************************************************************
 *                                                                                                     *
 *        **********                                                                                   *
 *       ************                                                                                  *
 *      ***        ***                                                                                 *
 *      ***   +++   ***                                                                                *
 *      ***   + +   ***                                                                                *
 *      ***   +                         CHIPCON CC2420 INTEGRATED 802.15.4 MAC AND PHY                 *
 *      ***   + +   ***                        Beacon TX and Tracking + Related                        *
 *      ***   +++   ***                                                                                *
 *      ***        ***                                                                                 *
 *       ************                                                                                  *
 *        **********                                                                                   *
 *                                                                                                     *
 *******************************************************************************************************
 * CONFIDENTIAL                                                                                        *
 * The use of this file is restricted by the signed MAC software license agreement.                    *
 *                                                                                                     *
 * Copyright Chipcon AS, 2004                                                                          *
 *******************************************************************************************************
 * This module contains functions the functions responsible for receiving and transmitting beacons,    *
 * and related functions, such as synchronization and coordinator realignment.                         *
 *******************************************************************************************************
 * Compiler: AVR-GCC                                                                                   *
 * Target platform: CC2420DB, CC2420 + any ATMEGA MCU                                                  *
 *******************************************************************************************************
 * The revision history is located at the bottom of this file                                          *
 *******************************************************************************************************/
#pragma SFR
#pragma NOP
#pragma STOP
#pragma HALT
#pragma DI
#pragma EI
#pragma  section @@DATA beacon at 0xE000///
#include "mac_headers.h"


//-------------------------------------------------------------------------------------------------------
// Beacon-related variables
MAC_BEACON_INFO mbcnInfo;

UINT32 bacupBosCounter;
//-------------------------------------------------------------------------------------------------------




/*******************************************************************************************************
 *******************************************************************************************************
 **************************                 BEACON RECEPTION                  **************************
 *******************************************************************************************************
 *******************************************************************************************************/




//-------------------------------------------------------------------------------------------------------
//  void mbcnRxPeriodicalBeacon(void)
//
//  DESCRIPTION:
//      Creates the task that handles reception of periodical beacons (in a beacon-enabled PAN)
//-------------------------------------------------------------------------------------------------------
void mbcnRxPeriodicalBeacon(void) {
    mschAddTask(mbcnInfo.rxTaskNumber, MAC_TASK_PRI_HIGHEST, mbcnRxPeriodicalBeaconTask, 0);
} // mbcnRxPeriodicalBeacon



/** @fn void mbcnRxPeriodicalBeaconTask(MAC_TASK_INFO *pTask)
*   @param *pTask The pointer to the task innformation for the current task.
*    
*    @brief A Brief description of this function.
*    
*   A mutch longer describtion on line 1 \n
*   And on line 2\n
*    
*    @date 11.11.2004
*    @author THL
*/


//-------------------------------------------------------------------------------------------------------
//  void mbcnRxPeriodicalBeaconTask(MAC_TASK_INFO *pTask)
//
//  DESCRIPTION:
//      Handles configuration of timers related to beacon reception (including starting RX and the
//      timeout to be generated when no beacon is received). It also handles beacon loss.
//
//      Note: When a beacon is received, the current mbcnRxPeriodicalBeacon callback must be cancelled,
//      and a new callback must be set up.
//  
//  
//  TASK DATA:
//      0
//

//-------------------------------------------------------------------------------------------------------
void mbcnRxPeriodicalBeaconTask(MAC_TASK_INFO *pTask) {

    // Beacon loss?
    if (!mbcnInfo.noBcnCountdown) {
        ENABLE_FIFOP_INT();

        // Stop the search/tracking
        if (mbcnInfo.findBeacon) mrxDecrOnCounter();
        mbcnInfo.findBeacon = FALSE;
        mbcnInfo.trackBeacon = FALSE;
            
        // Update buffered PIB attributes
        mbcnUpdateBufferedPibAttributes();

        // Remove and release the task
        mschRemoveTask(pTask->priority, 0);
        mbcnInfo.rxTaskNumber = NO_TASK;
        
        // Make the call to the higher layer
        mlmeSyncLossIndication(BEACON_LOSS);
    
    } else {
        mrxIncrOnCounter();
    
        // Update buffered PIB attributes
        mbcnUpdateBufferedPibAttributes();
               
        // Schedule the next beacon handler, including XTAL error margin (the startup margin is cumulative when missing beacons)
        mtimSetCallback(mbcnRxPeriodicalBeacon, msupCalcBeaconInterval() - mbcnGetBeaconMargin());
        
        // Set the RF channel (but don't mess up scanning)
        if (!(macInfo.state & MAC_STATE_SCAN_BM)) msupSetChannel(ppib.phyCurrentChannel, FALSE);
        
        // Turn on RX and set the off-timer (the off-time is also cumulative)
        mtimSetCallback(mbcnRxBeaconTimeout, (UINT16) 2 * ((UINT16) aMaxLostBeacons - (UINT16) mbcnInfo.noBcnCountdown + (UINT16) 1) * (UINT16) mbcnGetBeaconMargin() + (UINT16) MBCN_RX_STARTUP_OVERHEAD);
        
        // Finish this task, but keep the reservation!
        mschRemoveTask(pTask->priority, MSCH_KEEP_TASK_RESERVED_BM);
    }    

} // mbcnRxPeriodicalBeaconTask




//-------------------------------------------------------------------------------------------------------
//  void mbcnRxBeaconTimeout(void)
//
//  DESCRIPTION:
//      Called when no beacon has been received. Decrements the counter which will give "beacon loss"
//      when it reaches zero. This timeout is set up in mbcnRxPeriodicalBeaconTask().
//-------------------------------------------------------------------------------------------------------
void mbcnRxBeaconTimeout(void) {
    
    // The beacon reception interval is over (mbcnRxBeacon)
    mrxDecrOnCounter();
    
    // Update the tracking counter...
    mbcnInfo.noBcnCountdown--;
    
} // mbcnRxBeaconTimeout




/*******************************************************************************************************
 *******************************************************************************************************
 **************************                BEACON TRANSMISSION                **************************
 *******************************************************************************************************
 *******************************************************************************************************/



#if MAC_OPT_FFD

//-------------------------------------------------------------------------------------------------------
//  void mbcnTxPeriodicalBeacon(void)
//
//  DESCRIPTION:
//      Creates the task that handles transmission of periodical beacons (in a beacon-enabled PAN)
//-------------------------------------------------------------------------------------------------------
void mbcnTxPeriodicalBeacon(void) {
    mschAddTask(mbcnInfo.txTaskNumber, MAC_TASK_PRI_HIGHEST, mbcnTxPeriodicalBeaconTask, 0);
} // mbcnTxPeriodicalBeacon




//-------------------------------------------------------------------------------------------------------
//  void mbcnTxPeriodicalBeaconTask(MAC_TASK_INFO *pTask)
//
//  DESCRIPTION:
//      This task is responsible for beacon transmission, and a few other housekeeping procedures (see
//      the function comments. When finished, this task will continue in the mtxStartTransmission
//      function (the task function pointer and the state is modified.
//
//  TASK DATA:
//      0
//-------------------------------------------------------------------------------------------------------
void mbcnTxPeriodicalBeaconTask(MAC_TASK_INFO *pTask) {
    MAC_TX_PACKET *pPacket = mbcnInfo.pTxPacket;
            
    switch (pTask->state) {
    case MBCN_SET_NEXT_CALLBACK_PREPTX:
        ENABLE_FIFOP_INT();
    
        // Adjust the backoff slot counter
        mtimInfo.bosCounterAdjustTime += (mtimInfo.bosCounter + MBCN_TX_PREPARE_TIME + MBCN_TX_STARTUP_OVERHEAD) * MAC_SYMBOL_DURATION * aUnitBackoffPeriod;
        bacupBosCounter = mtimInfo.bosCounter; //Store for later use.
        
        // Schedule the next beacon handler (if we're still in beaconing mode)
        mtimSetCallback(mbcnTxPeriodicalBeacon, msupCalcBeaconInterval());
        
        // Set the RF channel
        msupSetChannel(ppib.phyCurrentChannel, FALSE);
        
        // Update buffered PIB attributes
        mbcnUpdateBufferedPibAttributes();
        
        // Transmit the beacon, unless we're in scan mode (just increment the sequence number)
        if (macInfo.state & MAC_STATE_SCAN_BM) {
            mpib.macBSN++;
            mschRemoveTask(pTask->priority, MSCH_KEEP_TASK_RESERVED_BM | MSCH_KEEP_TASK_IN_PROGRESS_BM);
        
        } else {
        
            // Update the beacon TX time only when we transmit a beacon...
            DISABLE_GLOBAL_INT();
            mpib.macBeaconTxTime = mtimInfo.bosCounterAdjustTime;
            ENABLE_GLOBAL_INT();
                       
            // Unrequest all indirect packets, and decrement timeToLive
            miqUnrequestAll();
            miqDecrTimeToLive();
            
            // Create the task that later on will remove expired packets
            mschAddTask(mschReserveTask(), MAC_TASK_PRI_MEDIUM, miqExpireIndirectPacketsTask, 0);
            
            // Generate the beacon frame
            mbcnPrepareBeacon(pPacket);
            pPacket->slotted = TRUE;
            pTask->state = MBCN_START_TRANSMISSION;
        }
        break;
        
    case MBCN_START_TRANSMISSION:
   

⌨️ 快捷键说明

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