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

📄 mac_timer.h

📁 ucos在NEC平台下的移植
💻 H
字号:
/*******************************************************************************************************
 *                                                                                                     *
 *        **********                                                                                   *
 *       ************                                                                                  *
 *      ***        ***                                                                                 *
 *      ***   +++   ***                                                                                *
 *      ***   + +   ***                                                                                *
 *      ***   +                         CHIPCON CC2420 INTEGRATED 802.15.4 MAC AND PHY                 *
 *      ***   + +   ***                           Low-Level Timing Functions                           *
 *      ***   +++   ***                                                                                *
 *      ***        ***                                                                                 *
 *       ************                                                                                  *
 *        **********                                                                                   *
 *                                                                                                     *
 *******************************************************************************************************
 * CONFIDENTIAL                                                                                        *
 * The use of this file is restricted by the signed MAC software license agreement.                    *
 *                                                                                                     *
 * Copyright Chipcon AS, 2004                                                                          *
 *******************************************************************************************************
 * This module contains the MAC callback timer, which is used to handle timer events, and start the    *
 * execution of tasks. handles. The timer generates a T1.COMPA interrupt at every                      *
 * 320 usecs = 20 symbols = 1 backoff slot.                                                            *
 *                                                                                                     *
 * Command strobes that need to be aligned with backoff slot boundary must use the WAIT_FOR_BOUNADRY() *
 * macro.                                                                                              *
 *                                                                                                     *
 * NOTE: These functions are meant to be used with an 8 MHz crystal oscillator!                        *
 *******************************************************************************************************
 * Compiler: AVR-GCC                                                                                   *
 * Target platform: CC2420DB, CC2420 + any ATMEGA MCU                                                  *
 *******************************************************************************************************
 * The revision history is located at the bottom of this file                                          *
 *******************************************************************************************************/
#ifndef MAC_TIMER_H
#define MAC_TIMER_H




/*******************************************************************************************************
 *******************************************************************************************************
 **************************               CONSTANTS AND MACROS                **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------
// The timer overflow value
#define CLOCK_SPEED_MHZ                 8 //@@@ 8  // MHz 
#define MAC_SYMBOL_DURATION             16 // us
#define MAC_TIMER_OVERFLOW_VALUE        (CLOCK_SPEED_MHZ * MAC_SYMBOL_DURATION * aUnitBackoffPeriod - 1)

// Backoff slot boundary offset (1/4 into the timer tick interval)
#define MAC_TIMER_BACKOFF_SLOT_OFFSET   ((MAC_TIMER_OVERFLOW_VALUE + 1) / 4)

// Waits for the next backoff slot boandary (global interrupts should be turned off!)
#define WAIT_FOR_BOUNDARY()             while (!(TIFR & BM(OCF1B)))

// The number of callbacks available in the pool
#define MAC_CALLBACK_COUNT 12

// Callback queue terminator
#define NO_CALLBACK 0xFF
//-------------------------------------------------------------------------------------------------------




/*******************************************************************************************************
 *******************************************************************************************************
 **************************                   MODULE DATA                     **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------
// Internal module data

// Callback table
typedef struct {
    VFPTR pFunc;
    INT32 timeout;
    UINT8 nextCallback;
    UINT8 prevCallback;
    ZBOOL  occupied;
} MAC_CALLBACK_INFO;

// Backoff slot counter
typedef struct {
    INT32 volatile bosCounter;
    UINT32 captureTime;
    UINT32 captureBosCounter;
    UINT16 captureTcnt;
    UINT32 bosCounterAdjustTime;
    UINT8 beaconDuration;
    UINT8 volatile nextCallback;
} MAC_TIMER_INFO;
extern MAC_TIMER_INFO mtimInfo;
//-------------------------------------------------------------------------------------------------------




/*******************************************************************************************************
 *******************************************************************************************************
 **************************               FUNCTION PROTOTYPES                 **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------
// Callback timer setup (timeout in backoff slots (rounded downwards)
void mtimInit(void);
ZBOOL mtimSetCallback(VFPTR pFunc, INT32 timeout);
ZBOOL mtimCancelCallback(void *pFunc);

// Callback timer adjustments (align this node's timer with the last received beacon)
void mtimAlignWithBeacon(void);
//-------------------------------------------------------------------------------------------------------


#endif




/*******************************************************************************************************
 * Revision history:
 *
 * $Log: mac_timer.h,v $
 * Revision 1.6  2004/12/10 12:41:56  thl
 * On a sync request the MAC now check if we have a none beacon network,
 * if this is the case a the sync request is canceld.
 *
 * Revision 1.5  2004/08/13 13:04:44  jol
 * CC2420 MAC Release v0.7
 *
 *
 *******************************************************************************************************/

⌨️ 快捷键说明

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