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

📄 lintmr.c

📁 BCM 控制demo源代码
💻 C
字号:
#define LINTMR_C
/******************************************************************************
*                                                       
*       Copyright (C) 2005 Freescale Semiconductor, Inc.
*       All Rights Reserved								              
*														                            
* Filename:     lintmr.c                
*														                            
* Revision:      										                    
*														                            
* Functions:    LIN Timeout management module 
*												                            
* Description:  
*												                            
* Notes:        Protocol timeouts -- only for Master node
*												                            
******************************************************************************/

#include <linbase.h>

#pragma MESSAGE DISABLE C4200 /* WARNING C4200: other segment than in previous declaration */

/****************************************************************************
 * All common-purpose RAM variables shall be declared here.
 * Some of the variables (more often used) can be located in the DIRECT page
 ***************************************************************************/
#if defined(USEZEROPAGE)
#pragma DATA_SEG __SHORT_SEG ZeroSeg
#endif /* defined(USEZEROPAGE) */

LIN_ZPAGE LIN_WORD LIN_IdleTimeout;          /* counter for idle timeout */

#if defined(USEZEROPAGE)
#pragma DATA_SEG DEFAULT
#endif /* defined(USEZEROPAGE) */

#if !defined(LINAPI_1_0)

#if defined(MASTER)


#if defined(USEZEROPAGE)
#pragma DATA_SEG __SHORT_SEG ZeroSeg
#endif /* defined(USEZEROPAGE) */

LIN_ZPAGE LIN_BYTE LIN_ProtocolTimeout;      /* counter for protocol timeout */
LIN_ZPAGE LIN_WORD LIN_LengthCh0Tick;        /* length of one timer Channel 1 overflow tick;
                                                the LIN_LengthCh0Tick is not declared as static due to 
                                                it used as symbol in assembler macro, but Cosmic compiler
                                                eliminate symbol references to static variables */
LIN_ZPAGE LIN_BYTE  LIN_TmpTPMStatus;        /* byte to clear TPM status  */

#if defined(USEZEROPAGE)
#pragma DATA_SEG DEFAULT
#endif /* defined(USEZEROPAGE) */


/****************************************************************************
 * Functions 
 ***************************************************************************/
#pragma CODE_SEG .lintext


#if !defined(USEXGATE)
/***************************************************************************
 * Function :   LIN_SetTimeout
 *
 * Description: Set protocol timeout.
 *                  - disable channel 0 interrupt
 *                  - set timeout
 *                  - enable channel 0 interrupt
 *                  - set LIN_ProtocolTimeout value
 *
 * Returns:     none
 *
 * Notes:       none
 *
 **************************************************************************/
void near LIN_SetTimeout(LIN_BYTE timeoutIndex)
{
	LIN_PITINTE        &= ~LIN_PITINTE_PINTE;	                    /* at first, disable PIT channel interrupt */
	
    LIN_LengthCh0Tick   = LIN_MTO_Ticks[timeoutIndex];	            /* at second, set timeout */
	LIN_PITMTLD0        = LIN_CfgConst.LIN_PIT_MicroCounterValue;	/* Load the micro counter 0 value into the load register */

	LIN_PITLD           = LIN_LengthCh0Tick;	                    /* Load the timeout value into channel load register */

	LIN_PITCFLMT       |= LIN_PITCFLMT_PFLMT0;	                    /* load the micro counter 0 */
	LIN_PITFLT         |= LIN_PITFLT_PFLT;	                        /* load the channel counter */
	
	LIN_PITTF           = LIN_PITTF_PTF;	                        /* clear channel interrupt flag */
	LIN_PITINTE        |= LIN_PITINTE_PINTE;	                    /* enable channel Interrupt*/
    
    LIN_ProtocolTimeout = LIN_MTO_Counter[timeoutIndex];            /* set LIN_ProtocolTimeout value for this timeout */
}
#endif /* !defined(USEXGATE) */

/***************************************************************************
 * Function :   LIN_CancelTimeout
 *
 * Description: Cancel protocol timeout
 *
 * Returns:     none
 *
 * Notes:       none
 *
 **************************************************************************/
void near LIN_CancelTimeout( void )
{
    /* disable channel interrupt */
	LIN_PITINTE &= ~LIN_PITINTE_PINTE;	/* disable PIT Channel Interrupt*/
}

#if !defined(USEXGATE)
/***************************************************************************
 * Function :   LIN_ISR_Timer
 *
 * Description: Timer interrupt routine. 
 *              Used for:   LIN_MaxFrameTime, 
 *                          LIN_WakeupDelimiterTime
 *                          timeouts maintenance.
 *              Also used for:  break generation.
 *                 
 * Returns:     none
 *
 * Notes:       
 *
 **************************************************************************/
LIN_INTERRUPT LIN_ISR_Timer( void ) 
{
    LIN_DBG_SET_PORT_0;
    LIN_DBG_SET_PORT_4;

    --LIN_ProtocolTimeout;

    if ( LIN_ProtocolTimeout == 0)
    {   
        /* timeout expired */

        /* clear interrupt flag and disable channel interrupt */
		LIN_PITINTE &= ~LIN_PITINTE_PINTE;	/* disable PIT channel interrupt */
		LIN_PITTF    = LIN_PITTF_PTF;	/* clear channel interrupt flag */
        
        LIN_Timeout();
    }
    else
    {
        /* timeout continued */

        /* arm timer Channel for next compare */
		LIN_PITTF    = LIN_PITTF_PTF;	/* clear channel interrupt flag */
		LIN_PITINTE |= LIN_PITINTE_PINTE;	/* enable channel Interrupt*/
    
    }

    LIN_DBG_CLR_PORT_4;
    LIN_DBG_CLR_PORT_0;
}
#endif /* ifndef USEXGATE */

#define LIN_MAXMODULO   0xFFFFu
/**************************************************************************
 * Function :   LIN_TimerInit
 *
 * Description: Timer Module Initialization
 *
 * Returns:     none
 *
 * Notes:       none
 *
 **************************************************************************/
void near LIN_TimerInit( void ) 
{
	LIN_PITCFLMT &= ~LIN_PITCFLMT_PITE;	/* disable PIT */
	
	LIN_INT_CFADDR = LIN_INT_CFADDR_IntChan_7;	/* Select page containing PIT channel vectors */

#if defined (CHANNEL_0)	
#if defined (USEXGATE)	
	LIN_INT_CFDATA5 = (LIN_CfgConst.LIN_PITIntPriority | LIN_INT_CFADDR_UseXGate);	/* Configure PIT priority */
#else	
	LIN_INT_CFDATA5 = LIN_CfgConst.LIN_PITIntPriority;	/* Configure PIT priority */
#endif /* defined (USEXGATE) */	
	
#elif defined (CHANNEL_1)	
#if defined (USEXGATE)	
	LIN_INT_CFDATA4 = (LIN_CfgConst.LIN_PITIntPriority | LIN_INT_CFADDR_UseXGate);	
#else	
	LIN_INT_CFDATA4 = LIN_CfgConst.LIN_PITIntPriority;	
#endif /* defined (USEXGATE) */	
	
#elif defined (CHANNEL_2)	
#if defined (USEXGATE)	
	LIN_INT_CFDATA3 = (LIN_CfgConst.LIN_PITIntPriority | LIN_INT_CFADDR_UseXGate);	
#else	
	LIN_INT_CFDATA3 = LIN_CfgConst.LIN_PITIntPriority;	
#endif /* defined (USEXGATE) */	
	
	
#elif defined (CHANNEL_3)	
#if defined (USEXGATE)	
	LIN_INT_CFDATA2 = (LIN_CfgConst.LIN_PITIntPriority | LIN_INT_CFADDR_UseXGate);	
#else	
	LIN_INT_CFDATA2 = LIN_CfgConst.LIN_PITIntPriority;	
#endif /* defined (USEXGATE) */	



#endif /* defined (CHANNEL_0) */	

	
	LIN_PITMTLD0 = LIN_CfgConst.LIN_PIT_MicroCounterValue;	/* Load the micro counter 0 value into the load register */
	
	LIN_PITINTE &= ~ LIN_PITINTE_PINTE;	/* disable PIT channel interrupt */
	LIN_PITTF = LIN_PITTF_PTF;	/* clear channel interrupt flag */
	
	LIN_PITCE = (PITCE | LIN_PITCE_PCE);  /* enable PIT channel */
	
	LIN_PITCFLMT |= LIN_PITCFLMT_PITE;	/* enable PIT */
}

#endif /* defined(MASTER) */

/***************************************************************************
 * Function :   LIN_IdleClock
 *
 * Description: User time clock for Idle timeout.
 *              Update "no-bus-activity" condition counter
 *              and check, if the condition meets.
 *                 
 * Returns:     none
 *
 * Notes:       1. API Service call       
 *
 **************************************************************************/
void near LIN_IdleClock( void ) 
{
    LIN_BYTE        intMask;

    LIN_DBG_SET_PORT_7;

    intMask = LIN_DisableInt();         /* Disable interrupts -- do we really need it? */

    if ( LIN_IdleTimeout != 0  )
        {
            --LIN_IdleTimeout;
        }

    LIN_EnableInt(intMask);             /* enable interrupts */    

    LIN_DBG_CLR_PORT_7;
}

#endif /* !defined(LINAPI_1_0) */

/***************************************************************************
 * Function :   LIN_SetIdleTimeout
 *
 * Description: Set/reset LIN_IdleTimeout variable from constant
 *                 
 * Returns:     none
 *
 * Notes:       
 *
 **************************************************************************/
void near LIN_SetIdleTimeout( void )
{
    LIN_IdleTimeout = LIN_CfgConst.LIN_IdleTimeoutClocks;    
}

#pragma CODE_SEG DEFAULT

⌨️ 快捷键说明

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