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

📄 mac_timer.c

📁 ucos在NEC平台下的移植
💻 C
📖 第 1 页 / 共 2 页
字号:
            // Update the link on the callback before this entry
            if (prevIndex != NO_CALLBACK) {
                pMtimCallbacks[prevIndex].nextCallback = nextIndex;
            }
            
            // Update the link on the next callback entry
            if (nextIndex != NO_CALLBACK) {
                pMtimCallbacks[nextIndex].prevCallback = prevIndex;
                pMtimCallbacks[nextIndex].timeout += pMtimCallbacks[n].timeout;
            }
            
            // Update nextCallback if the removed callback was the first entry
            if (n == mtimInfo.nextCallback) mtimInfo.nextCallback = pMtimCallbacks[n].nextCallback;
            ENABLE_GLOBAL_INT();
            return TRUE;
        }
    }
    ENABLE_GLOBAL_INT();
    return FALSE;
} // mtimeCancelCallback




//-------------------------------------------------------------------------------------------------------
//  void mtimAlignWithBeacon(void)
//
//  DESCRIPTION:
//      Adjusts the timer to the last received packet (which should be a beacon!)
//-------------------------------------------------------------------------------------------------------
void mtimAlignWithBeacon(void) {
    
    DISABLE_GLOBAL_INT();
	
///UART_StartTx("\r\nT1\r\n>");   ///
UART_StartTx("1");   ///

    // Delay the next timer tick
    ///OCR1A = MAC_TIMER_OVERFLOW_VALUE + mtimInfo.captureTcnt - (MAC_TIMER_BACKOFF_SLOT_OFFSET + 322 - 1);
///OCR3A = MAC_TIMER_OVERFLOW_VALUE + mtimInfo.captureTcnt - (MAC_TIMER_BACKOFF_SLOT_OFFSET + 322 - 1);///
CR000 = MAC_TIMER_OVERFLOW_VALUE + mtimInfo.captureTcnt - (MAC_TIMER_BACKOFF_SLOT_OFFSET + 322 - 1);///
	mtimInfo.bosCounter -= mtimInfo.captureBosCounter;
    
    // Clear the compare(A) interrupt flag
    ///TIFR = BM(OCF1A);
///ETIFR = BM(OCF3A);///
TMIF000= 0;///
    
    // Set the beacon "time stamp"
    mtimInfo.bosCounterAdjustTime += (mtimInfo.captureBosCounter * (UINT32) MAC_SYMBOL_DURATION * (UINT32) aUnitBackoffPeriod) + (UINT32) mtimInfo.captureTcnt / CLOCK_SPEED_MHZ;
    
    ENABLE_GLOBAL_INT();
    
} // mtimAlignWithBeacon




//-------------------------------------------------------------------------------------------------------
//  SIGNAL(SIG_INPUT_CAPTURE1)
//
//  DESCRIPTION:
//      This interrupt is trigged when the CC2420 SFD pin goes high at the start of a transmitted/
//      received frame. The ISR generates a time stamp to be used with beacons.
//-------------------------------------------------------------------------------------------------------
///SIGNAL(SIG_INPUT_CAPTURE1) {
///ISR(TIMER3_CAPT_vect){///
__interrupt void MD_INTTM001() {///

///__interrupt void INTTM001() {///

///DISABLE_GLOBAL_INT();///

///UART_StartTx("\r\nT2\r\n>");   ///
UART_StartTx("2");   ///


    ///mtimInfo.captureTcnt = ICR1;
    /// mtimInfo.captureTcnt = ICR3;///
        mtimInfo.captureTcnt = CR001;///
    mtimInfo.captureBosCounter = mtimInfo.bosCounter;
    
   /// if ((TCNT1 > ICR1) && BM(OCF1A)){
  /// if ((TCNT3 > ICR3) && BM(OCF3A)){///
 ///if ((TM00> CR001) && (TMIF000)){///???
        if (TM00> CR001){///???
       
        mtimInfo.captureBosCounter++;
    }
    mtimInfo.captureTime = mtimInfo.bosCounterAdjustTime + (mtimInfo.captureBosCounter * MAC_SYMBOL_DURATION * aUnitBackoffPeriod) + (UINT32) mtimInfo.captureTcnt / CLOCK_SPEED_MHZ;

///ENABLE_GLOBAL_INT();///
} // SIGNAL(SIG_INPUT_CAPTURE1)




//-------------------------------------------------------------------------------------------------------
//  SIGNAL(SIG_OUTPUT_COMPARE1A)
//
//  DESCRIPTION:
//      Timer tick interrupt at an interval of 320 us.
//      Handles callback timers, and initiates task execution at every backoff slot boundary.
//      The FIFOP interrupt is turned off initially, and can (optionally) be turned back on by running
//      tasks.
//-------------------------------------------------------------------------------------------------------
///SIGNAL(SIG_OUTPUT_COMPARE1A) {
///ISR(TIMER3_COMPA_vect){
__interrupt void MD_INTTM000(){///
///__interrupt void INTTM000(){///

    MAC_CALLBACK_INFO *pMCI;
	
	///DISABLE_GLOBAL_INT();///
///UART_StartTx("3");   ///
    
    // Clear the flag which is used to trigger WAIT_FOR_BOUNDARY()
    ///TIFR = BM(OCF1B);
    ///ETIFR = BM(OCF3B);///
    TMIF010=0; ///

	
    // Reset the overflow flag (could be modified to skew the timing)
    ///OCR1A = MAC_TIMER_OVERFLOW_VALUE;
    ///OCR3A = MAC_TIMER_OVERFLOW_VALUE;
   /// CR000 = MAC_TIMER_OVERFLOW_VALUE;///
    
    // Disable the FIFOP interrupt to make sure that it won't interrupt the callbacks 
    DISABLE_FIFOP_INT();

	    ////DISABLE_T3_COMPC_INT();///
	    ///DISABLE_T1_COMPC_INT();////
	    DISABLE_TIMER51_INT();///!!!


    
    // Handle callbacks    
    if (mtimInfo.nextCallback != NO_CALLBACK) {
        pMCI = &pMtimCallbacks[mtimInfo.nextCallback];
        if (!--pMCI->timeout) {
callback:   mtimInfo.nextCallback = pMCI->nextCallback;
            pMCI->occupied = FALSE;
            pMCI->pFunc();
            DISABLE_GLOBAL_INT();
            if (mtimInfo.nextCallback != NO_CALLBACK) {
                pMCI = &pMtimCallbacks[mtimInfo.nextCallback];
                pMCI->prevCallback = NO_CALLBACK;
                if (!pMCI->timeout) goto callback;
            }
        }
    }
    mtimInfo.bosCounter++;    
	



///if(test>100){test=3;};///
///test++;///

array1[COMA]=INTP;
COMA++;

    // Handle tasks
    ENABLE_GLOBAL_INT();
    mschDoTask();
    
    // Some tasks will enable the FIFOP interrupt, and others will not.
    // Anyway, make sure that we leave from this interrupt in the correct state
    DISABLE_GLOBAL_INT();

    ////DISABLE_T3_COMPC_INT();///
    ///DISABLE_T1_COMPC_INT();////
DISABLE_TIMER51_INT();///!!!

	
    if (mrxInfo.keepFifopIntOff) {
        DISABLE_FIFOP_INT();
    } else {
        ENABLE_FIFOP_INT();
    }
	
    ///ENABLE_GLOBAL_INT();///
} // SIGNAL(SIG_OUTPUT_COMPARE1A)




//-------------------------------------------------------------------------------------------------------
//  SIGNAL(SIG_OUTPUT_COMPARE1C)
//
//  DESCRIPTION:
//      Used by the FIFOP interrupt to make sure that is enabled a short while after it has returned. 
//      This allows for timer ticks in between, which has a lower priority than the FIFOP interrupt.
//-------------------------------------------------------------------------------------------------------
///SIGNAL(SIG_OUTPUT_COMPARE1C) {
///ISR(TIMER1_COMPC_vect){////
/*
__interrupt void MD_INTTM011(){///

DISABLE_GLOBAL_INT();///

UART_StartTx("4");   ///


    ENABLE_FIFOP_INT();
 
	    ////DISABLE_T3_COMPC_INT();///
DISABLE_T1_COMPC_INT();////

	ENABLE_GLOBAL_INT();///
} // SIGNAL(SIG_OUTPUT_COMPARE1C)
*/
__interrupt void MD_INTTM51(){///
///__interrupt void MD_INTTM50(){///

///DISABLE_GLOBAL_INT();///

///UART_StartTx("51");   ///

///test++;///

    ENABLE_FIFOP_INT();
 
	    ////DISABLE_T3_COMPC_INT();///
///DISABLE_T1_COMPC_INT();////
///TIMER51_STOP();///
		DISABLE_TIMER51_INT();///

///TIMER50_STOP();///
		///DISABLE_TM50_INT();///

	///ENABLE_GLOBAL_INT();///
} // SIGNAL(SIG_OUTPUT_COMPARE1C)


/*******************************************************************************************************
 * Revision history:
 *
 * $Log: mac_timer.c,v $
 * Revision 1.10  2004/11/11 09:39:23  thl
 * Fixed SIGNAL(SIG_INPUT_CAPTURE1) function
 *
 * Revision 1.9  2004/11/10 09:33:15  thl
 * Fixed a number of bugs according to: MAC software check lists.xls
 *
 * Revision 1.8  2004/08/13 13:04:48  jol
 * CC2420 MAC Release v0.7
 *
 *
 *******************************************************************************************************/

⌨️ 快捷键说明

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