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

📄 lininit.c

📁 BCM 控制demo源代码
💻 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(USEXGATE)
#include <string.h>
#include <linxgate.h>
#endif /* defined(USEXGATE) */


#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(LIN_DBG_CHECK_INTERNAL_ERROR)

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

LIN_ZPAGE LIN_BYTE    LIN_InternalError;           /* Internal error code */

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

#endif /* defined(LIN_DBG_CHECK_INTERNAL_ERROR) */

/****************************************************************************
 * Function prototypes 
 ***************************************************************************/
#if defined(CW12)
extern void near _Startup( void );      /* HiCross compiler startup routine declaration */
#endif  /* defined(CW12)   */

#if defined (USEXGATE)
extern __near void _FAR_COPY_LOGICAL_GLOBAL_RC(void);
#endif

/****************************************************************************
 * Functions 
 ***************************************************************************/
/* Cosmic compiler startup routine is declared via _asm xref,
   because C symbols are undefined in Cosmic inline assembler expressions */
#pragma CODE_SEG .lintext

/***************************************************************************
 * Function :   LIN_Startup( )
 *
 * Description: Initialize mode registers and
 *              call compiler startup function
 *
 * Returns:     no returns value
 *
 * Notes:
 *
 **************************************************************************/
#if defined(CW12)

#pragma NO_FRAME
#pragma NO_ENTRY
#pragma NO_EXIT 
#pragma NO_RETURN
void near LIN_Startup( void ) 
{
                                
#if defined(USEZEROPAGE)	
	LIN_DIRECT = LIN_CfgConst.LIN_ZeroPage;	/* Map the Zero page*/ 
#endif /* defined(USEZEROPAGE) */	
	
    asm                         /* Jump to normal startup */ 
    {    
        jmp _Startup 
    }                   
}

#endif  /* defined(CW12)   */



#if defined(LINAPI_1_0)

/***************************************************************************
 * Function :   l_sys_init
 *
 * Description: Initialise driver 
 * 
 * Returns:     Always returns 0
 *
 * Notes:       LIN API service call
 *
 **************************************************************************/
l_bool near 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_StateFlagsInit
 *
 * Description: Set initial state -- this is abort any activity  
 * 
 * Returns:     none
 *
 * Notes:       RC574C add this function on the 19-jan-2006.
 *
 **************************************************************************/
void near LIN_StateFlagsInit ( void )
{
	LIN_StateFlags  = LIN_FLAG_IGNORE;
}

/***************************************************************************
 * Function :   LIN_Init
 *
 * Description: Initialise driver - software & hardware
 * 
 * Returns:     none
 *
 * Notes:       Freescale API service call
 *
 **************************************************************************/
void near 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(USEXGATE)
  /* init XGATE */

  /* initialize the XGATE vector block and set the XGVBR register to its start address */
  // XGVBR = (unsigned int)(void*__far)(XGATE_VectorTable - XGATE_VECTOR_OFFSET);

  /* enable XGATE mode and interrupts */
    XGMCTL =  (LIN_XGMCTL_XGEM | LIN_XGMCTL_XGFRZM | LIN_XGMCTL_XGIEM |LIN_XGMCTL_XGE | LIN_XGMCTL_XGFRZ | LIN_XGMCTL_XGIE );

#endif /* defined(USEXGATE) */

#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;
} 

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

LIN_BYTE near LIN_DisableInt( void )
{

#if defined(CW12)
    { 
        asm tfr ccr, b; 
        asm sei;
    }    
#endif /* defined(CW12)*/
}


#if defined(CW12)
#pragma OPTION DEL handle_register 
#endif /* defined(CW12) */

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

void near LIN_EnableInt( LIN_BYTE mask)
{

#if defined(CW12)
    { 
        asm tfr b, ccr;     /* ldaa mask; asm tap; */
    } 
#endif /* defined(CW12)*/
}


#if defined(CW12)
#pragma OPTION DEL handle_register
#endif /* defined(CW12) */


#endif /* !defined(LINAPI_1_0) */
#pragma CODE_SEG DEFAUL

⌨️ 快捷键说明

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