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

📄 lininit.c

📁 飞思卡尔车身控制技术研讨会资料 里面有LIN的主从节点源程序
💻 C
字号:
#define LININIT_C

/******************************************************************************
*                                                       
*       Copyright (C) 2005 Freescale Semiconductor, Inc.
*       All Rights Reserved								              
*														                            
* Filename:     lininit.c                
*														                            
* Revision:      										                    
*														                            
* Functions:    LIN Driver initialization 
*												                            
* Description:  
*
* Notes:        
*
******************************************************************************/

#include <linbase.h>


#if defined(LIN_DBG_CHECK_INTERNAL_ERROR)

LIN_BYTE    LIN_InternalError;           /* Internal error code */

#endif /* defined(LIN_DBG_CHECK_INTERNAL_ERROR) */


#if defined(LINAPI_1_0)

/***************************************************************************
 * Function :   l_sys_init
 *
 * Description: Initialise driver 
 * 
 * Returns:     Always returns 0
 *
 * Notes:       LIN API service call
 *
 **************************************************************************/
l_bool l_sys_init ( void )
{    
    LIN_BYTE    i;
    LIN_BYTE    intMask;

    LIN_DBG_SET_PORT_7;

    intMask = LIN_DisableInt();     /* disable interrupts */

    /* Set initial state -- this is abort any activity, interface is disconnected */
    LIN_StateFlags  = LIN_FLAG_NOINIT | LIN_FLAG_DISCONNECT | LIN_FLAG_IGNORE;

    /* Initialize Error Counters */
    LIN_ErrTxCounter = 0;
    LIN_ErrRxCounter = 0;

    /* Initialize all signal flags with 0 */
    for( i = 0; i <= LinSigMaxIdx; i++ )
    {
        LinSigFlags[i] = 0;
    }

    /* Initialize transmitted messages with NO_DATA */
    /* NB: now -- for all transmitted and received messages -- OPTIM */
    for( i = 0; i < LinListSize; i++ )
    {
        LinMsgStatus[i] = LIN_MSG_NODATA;   /* Set NODATA */
    }

    /* Set idle timeout if it has not set yet */
    LIN_SetIdleTimeout();               

    /* Debug initializing */
#if defined(LIN_DBG_CHECK_INTERNAL_ERROR)
    LIN_InternalError = LIN_ERROR_0;
#endif /* defined(LIN_DBG_CHECK_INTERNAL_ERROR) */
    LIN_DBG_INIT_PORT(0x00);

    LIN_EnableInt(intMask);     /* enable interrupts */

    LIN_DBG_CLR_PORT_7;

    return 0;
} 


#else /* !defined(LINAPI_1_0) */

/***************************************************************************
 * Function :   LIN_Init
 *
 * Description: Initialise driver - software & hardware
 * 
 * Returns:     none
 *
 * Notes:       Freescale API service call
 *
 **************************************************************************/
void  LIN_Init ( void )
{    
    LIN_BYTE    i;
    LIN_BYTE    intMask;

    LIN_DBG_SET_PORT_7;

    intMask = LIN_DisableInt();     /* disable interrupts */

    /* Set initial state -- this is abort any activity */
    LIN_StateFlags  = LIN_FLAG_IGNORE;

    /* Initialize Error Counters */
    LIN_ErrTxCounter = 0;
    LIN_ErrRxCounter = 0;

    /* Initialize messages with NO_DATA */
    for( i = 0; i < LinListSize; i++ )
    {
        LinMsgStatus[i] = LIN_MSG_NODATA;   /* Set NO_DATA */
    }

#if defined(MASTER)
    /* Initialize Timer for LIN (Slave don't use any timers) */
    LIN_TimerInit();
#endif /* defined(MASTER) */

    /* Initialize SCI for LIN */
    LIN_SCIInit();

    /* Set idle timeout if it has not set yet */
    LIN_SetIdleTimeout();               

    /* Debug initializing */
#if defined(LIN_DBG_CHECK_INTERNAL_ERROR)
    LIN_InternalError = LIN_ERROR_0;
#endif /* defined(LIN_DBG_CHECK_INTERNAL_ERROR) */
    LIN_DBG_INIT_PORT(0x00);

    LIN_EnableInt(intMask);     /* enable interrupts */

    LIN_DBG_CLR_PORT_7;
    
    //LIN_SetTimeout(2u);   
} 


/***************************************************************************
 * Function :   LIN_DisableInt
 *
 * Description: disable interrupts 
 * 
 * Returns:     Interrupt state 
 *
 * Notes:       only for Freescale API
 *              
 **************************************************************************/
#if defined(S08) && defined(CW08)
#pragma OPTION ADD handle_register "-Or"
#endif /* defined(S08) && defined(CW08) */

LIN_BYTE LIN_DisableInt( void )
{
#if defined(S08) && defined(CW08)
    { 
        asm tpa; 
        asm sei; 
    }    
#endif /* defined(S08) && defined(CW08) */
}

#if defined(S08) && defined(CW08)
#pragma OPTION DEL handle_register 
#endif /* defined(S08) && defined(CW08) */

/***************************************************************************
 * Function :   LIN_EnableInt
 *
 * Description: enable interrupts
 * 
 * Returns:     
 *
 * Notes:       only for Freescale API
 *              
 **************************************************************************/
#if defined(S08) && defined(CW08)
#pragma OPTION ADD handle_register "-Or"
#endif /* defined(S08) && defined(CW08) */

void LIN_EnableInt( LIN_BYTE mask)
{    
#if defined(S08) && defined(CW08)
    { 
        asm tap;
    }
#endif /* defined(S08) && defined(CW08) */
}

#if defined(S08) && defined(CW08)
#pragma OPTION DEL handle_register
#endif /* defined(S08) && defined(CW08) */


#endif /* !defined(LINAPI_1_0) */

⌨️ 快捷键说明

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