?? linsci.c
字號:
#define LINSCI_C
/******************************************************************************
*
* Copyright (C) 2005 Freescale Semiconductor, Inc.
* All Rights Reserved
*
* Filename: linsci.c
*
* Revision:
*
* Functions: SCI management module
*
* Description:
*
* Notes:
*
******************************************************************************/
#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_BYTE LIN_TmpSCIStatus; /* byte to clear SCI status, and to receive byte */
#if defined(USEZEROPAGE)
#pragma DATA_SEG DEFAULT
#endif /* defined(USEZEROPAGE) */
/****************************************************************************
* Functions
***************************************************************************/
#pragma CODE_SEG .lintext
#if defined(LINAPI_1_0)
/***************************************************************************
* Function : l_ifc_init_sci0
*
* Description: Initialize SCI to work with LIN bus.
* Set specified baud rate;
* Disable all SCI interrupts;
* Enable Tx and RX pins
*
* Returns: none
*
* Notes: LIN API service
*
**************************************************************************/
void near l_ifc_init_sci0( void )
{
LIN_BYTE intMask;
LIN_DBG_SET_PORT_7;
intMask = LIN_DisableInt(); /* disable interrupts */
/* Disconnect SCI and set initial state -- this is abort any activity */
LIN_StateFlags = LIN_FLAG_IGNORE | LIN_FLAG_DISCONNECT;
/* ??? SCI not disabled while initialization */
LIN_SCISetBaudRate(LIN_CfgConst.LIN_BaudRate); /* set SCI baud rate*/
LIN_SCICR1 = 0; /* one start bit, eight data bits, one stop bit */
LIN_SCICR2 = LIN_SCICR2_TE | LIN_SCICR2_RE; /* enable transmitter & receiver and disable all SCI interrupts */
#if defined(SCI0)
/* Configure interrupt controller to give different priority */
LIN_INT_CFADDR = LIN_INT_CFADDR_IntChan_D; /* Select page containing SCI0 channel vectors */
#if defined(USEXGATE)
LIN_INT_CFDATA3 = (LIN_CfgConst.LIN_SCIIntPriority | LIN_INT_CFADDR_UseXGate); /* Configure SCI priority */
#else
LIN_INT_CFDATA3 = LIN_CfgConst.LIN_SCIIntPriority; /* Configure SCI priority */
#endif /* defined(USEXGATE) */
#elif defined(SCI1)
/* Configure interrupt controller to give different priority */
LIN_INT_CFADDR = LIN_INT_CFADDR_IntChan_D; /* Select page containing SCI1 channel vectors */
#if defined(USEXGATE)
LIN_INT_CFDATA2 = (LIN_CfgConst.LIN_SCIIntPriority | LIN_INT_CFADDR_UseXGate); /* Configure SCI priority */
#else
LIN_INT_CFDATA2 = LIN_CfgConst.LIN_SCIIntPriority; /* Configure SCI priority */
#endif /* defined(USEXGATE) */
#elif defined(SCI2)
/* Configure interrupt controller to give different priority */
LIN_INT_CFADDR = LIN_INT_CFADDR_IntChan_8; /* Select page containing SCI2 channel vectors */
#if defined(USEXGATE)
LIN_INT_CFDATA5 = (LIN_CfgConst.LIN_SCIIntPriority | LIN_INT_CFADDR_UseXGate); /* Configure SCI priority */
#else
LIN_INT_CFDATA5 = LIN_CfgConst.LIN_SCIIntPriority; /* Configure SCI priority */
#endif /* defined(USEXGATE) */
#elif defined(SCI3)
/* Configure interrupt controller to give different priority */
LIN_INT_CFADDR = LIN_INT_CFADDR_IntChan_8; /* Select page containing SCI3 channel vectors */
#if defined(USEXGATE)
LIN_INT_CFDATA4 = (LIN_CfgConst.LIN_SCIIntPriority | LIN_INT_CFADDR_UseXGate); /* Configure SCI priority */
#else
LIN_INT_CFDATA4 = LIN_CfgConst.LIN_SCIIntPriority; /* Configure SCI priority */
#endif /* defined(USEXGATE) */
#elif defined(SCI4)
/* Configure interrupt controller to give different priority */
LIN_INT_CFADDR = LIN_INT_CFADDR_IntChan_8; /* Select page containing SCI4 channel vectors */
#if defined(USEXGATE)
LIN_INT_CFDATA3 = (LIN_CfgConst.LIN_SCIIntPriority | LIN_INT_CFADDR_UseXGate); /* Configure SCI priority */
#else
LIN_INT_CFDATA3 = LIN_CfgConst.LIN_SCIIntPriority; /* Configure SCI priority */
#endif /* defined(USEXGATE) */
#elif defined(SCI5)
/* Configure interrupt controller to give different priority */
LIN_INT_CFADDR = LIN_INT_CFADDR_IntChan_8; /* Select page containing SCI5 channel vectors */
#if defined(USEXGATE)
LIN_INT_CFDATA2 = (LIN_CfgConst.LIN_SCIIntPriority | LIN_INT_CFADDR_UseXGate); /* Configure SCI priority */
#else
LIN_INT_CFDATA2 = LIN_CfgConst.LIN_SCIIntPriority; /* Configure SCI priority */
#endif /* defined(USEXGATE) */
#endif /* defined(SCI0) */
LIN_EnableInt(intMask); /* enable interrupts */
LIN_DBG_CLR_PORT_7;
}
/***************************************************************************
* Function : l_ifc_connect_sci0
*
* Description: Connect SCI -- clear all SCI flags,
* enable SCI interrupts, reset idle timeout.
*
* Returns: 0 -- success
* ~0 -- called before l_ifc_init()
*
* Notes: LIN API.
* If already connected then do nothing.
*
**************************************************************************/
l_bool near l_ifc_connect_sci0( void )
{
l_irqmask intMask;
l_bool ret;
ret = 0; /* suppose that connecting OK */
LIN_DBG_SET_PORT_7;
intMask = LIN_DisableInt(); /* disable interrupts */
/* if l_ifc_connect called before l_ifc_init then return error */
if ( (LIN_StateFlags & LIN_FLAG_NOINIT) != 0 )
{
ret = ~0;
}
/* we are after l_ifc_init */
/* if an interrupt occurs here and call l_sys_init() then we in LIN_FLAG_NOINIT
so we need interrupt disabling -- OPTIM */
/* if interface is already connected then do nothing */
else if ( (LIN_StateFlags & LIN_FLAG_DISCONNECT) != 0 )
{
/* we are in disconnected state -> connect */
/* connect SCI hardware */
LIN_TmpSCIStatus = LIN_SCISR1; /* clear SCI status */
LIN_TmpSCIByte = LIN_SCIDRL;
LIN_SCICR2 |= LIN_SCICR2_RIE; /* enable RX complited interrupt */
/* start to wait break */
LIN_StateFlags = LIN_FLAG_IGNORE;
/* reset idle timeout */
LIN_SetIdleTimeout();
}
LIN_EnableInt(intMask); /* enable interrupts */
LIN_DBG_CLR_PORT_7;
return ret;
}
/***************************************************************************
* Function : l_ifc_disconnect_sci0
*
* Description: Disconnect SCI -- disable SCI interrupts.
*
* Returns: 0 -- success
* ~0 -- called before l_ifc_init()
*
* Notes: LIN API.
* If already disconnected then do nothing.
*
**************************************************************************/
l_bool near l_ifc_disconnect_sci0( void )
{
l_irqmask intMask;
l_bool ret;
ret = 0; /* suppose that disconnecting OK */
LIN_DBG_SET_PORT_7;
intMask = LIN_DisableInt(); /* disable interrupts */
/* if l_ifc_disconnect called before l_ifc_init then return error */
if ( (LIN_StateFlags & LIN_FLAG_NOINIT) != 0 )
{
ret = ~0;
}
/* we are after l_ifc_init */
/* if an interrupt occurs here and call l_sys_init() then we in LIN_FLAG_NOINIT
so we need interrupt disabling -- OPTIM */
/* if interface is already disconnected then do nothing */
else if ( (LIN_StateFlags & LIN_FLAG_DISCONNECT) == 0 )
{
/* we are in connected state -> disconnect */
/* disconnect SCI hardware */
LIN_SCICR2 = LIN_SCICR2_TE | LIN_SCICR2_RE; /* enable transmitter & receiver and disable all SCI interrupts */
/* set disconnected state */
LIN_StateFlags = LIN_FLAG_IGNORE | LIN_FLAG_DISCONNECT;
}
LIN_EnableInt(intMask); /* enable interrupts */
LIN_DBG_CLR_PORT_7;
return ret;
}
#else /* !defined(LINAPI_1_0) */
/***************************************************************************
* Function : LIN_SCIInit
*
* Description: Initialize SCI to work with LIN bus.
* Set specified baud rate;
* Disable all SCI interrupts;
* Enable Tx and RX pins
* Enable Rx interrupt
*
* Returns: none
*
* Notes: 1. SLAVE, MASTER node
* 2. Required for cosmic linker. If no functions are used
* from particular .obj file this file is not linked!
* We can make it as macros ? -- OPTIM
*
**************************************************************************/
void near LIN_SCIInit( void )
{
/* ??? SCI not disabled while initialization */
LIN_SCISetBaudRate(LIN_CfgConst.LIN_BaudRate); /* set SCI baud rate*/
LIN_SCICR1 = 0; /* one start bit, eight data bits, one stop bit */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -