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

📄 coldfiresio.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* coldfireSio.c - coldfire Serial Communications driver *//* Copyright 1984-1998 Wind River Systems, Inc. *//*modification history--------------------01c,31aug98,gls  Fixed incorrect usage of CLOCAL01b,09jul98,gls  Adapted to WRS coding conventions01a,01may98,mem  written, based on m5204Sio.c.*//*DESCRIPTIONThis is the driver for the UART contained in the ColdFire Microcontroller.Only asynchronous serial operation is supported by this driver.  Thedefault serial settings are 8 data bits, 1 stop bit, no parity, 9600buad, and software flow control.  These default settings can beoverridden by setting the COLDFIRE_CHAN options and baudRate fields tothe desired values before calling coldfireDevInit.  See sioLib.h foroptions values.  The defaults for the module can be changed byredefining the macros COLDFIRE_DEFAULT_OPTIONS and COLDFIRE_DEFAULT_BAUD andrecompiling this driver.This driver uses the system clock as the input to the baud rategenerator.  The clkRate field must be set to the system clock rate inHZ for the baud rate calculations to work correctly.  The actual rangeof supported baud rates depends on the system clock speed.  For example,with a 25MHz system clock, the lowest baud rate is 24, and the highestis over 38400.  Because the baud rate values are calculated on request,there is no checking that the requested baud rate is standard, you canset the UART to operate at 4357 baud if you wish.USAGEA COLDFIRE_CHAN structure is used to describe the chip.The BSP's sysHwInit() routine typically calls sysSerialHwInit()which initializes all the H/W addresses in the COLDFIRE_CHAN structurebefore calling coldfireDevInit().  This enables the chip to operate inpolled mode, but not interrupt mode.  Calling coldfireDevInit2() fromthe sysSerialHwInit2() routine allows interrupts to be enabled andinterrupt mode operation to be used..CSi.e.#include "drv/multi/coldfireSio.h"COLDFIRE_CHAN coldfireUart;			/@ my device structure @/#define INT_VEC_UART	(24+3)		/@ use single vector, #27 @/sysSerialHwInit()    {    /@ initialize the register pointers/data for uart @/    coldfireUart.clkRate	= MASTER_CLOCK;    coldfireUart.intVec	= INT_VEC_UART;    coldfireUart.mr	= COLDFIRE_UART_MR(SIM_BASE);    coldfireUart.sr	= COLDFIRE_UART_SR(SIM_BASE);    coldfireUart.csr	= COLDFIRE_UART_CSR(SIM_BASE);    coldfireUart.cr	= COLDFIRE_UART_CR(SIM_BASE);    coldfireUart.rb	= COLDFIRE_UART_RB(SIM_BASE);    coldfireUart.tb	= COLDFIRE_UART_TB(SIM_BASE);    coldfireUart.ipcr	= COLDFIRE_UART_IPCR(SIM_BASE);    coldfireUart.acr	= COLDFIRE_UART_ACR(SIM_BASE);    coldfireUart.isr	= COLDFIRE_UART_ISR(SIM_BASE);    coldfireUart.imr	= COLDFIRE_UART_IMR(SIM_BASE);    coldfireUart.bg1	= COLDFIRE_UART_BG1(SIM_BASE);    coldfireUart.bg2	= COLDFIRE_UART_BG2(SIM_BASE);    coldfireUart.ivr	= COLDFIRE_UART_IVR(SIM_BASE);    coldfireUart.ip	= COLDFIRE_UART_IP(SIM_BASE);    coldfireUart.op1	= COLDFIRE_UART_OP1(SIM_BASE);    coldfireUart.op2	= COLDFIRE_UART_OP2(SIM_BASE);    coldfireDevInit (&coldfireUart);    }.CEThe BSP's sysHwInit2() routine typically calls sysSerialHwInit2() whichconnects the chips interrupts via intConnect() to the singleinterrupt handler coldfireInt.  After the interrupt service routines are connected, the user then calls coldfireDevInit2() to allow the driver to turn on interrupt enable bits..CSi.e.sysSerialHwInit2 ()    {    /@ connect single vector for 5204 @/    intConnect (INUM_TO_IVEC(MY_VEC), coldfireInt, (int)&coldfireUart);    ...    /@ allow interrupts to be enabled @/    coldfireDevInit2 (&coldfireUart);    }.CESPECIAL CONSIDERATIONS:The CLOCAL hardware option presumes that CTS outputs are not wired asnecessary.  CLOCAL is one of the default options for thisreason.As to the output port, this driver does not manipulate the output port,or it's configuration register in any way.  As stated above, if the userdoes not select the CLOCAL option then the output port bit must be wiredcorrectly or the hardware flow control will not function as desired.INCLUDE FILES: drv/sio/coldfireSio.h*/#include "vxWorks.h"#include "sioLib.h"#include "intLib.h"#include "errno.h"#include "drv/sio/coldfireSio.h"/* forward static declarations */LOCAL STATUS coldfireModeSet (COLDFIRE_CHAN *, UINT);LOCAL STATUS coldfireBaudSet (COLDFIRE_CHAN *, UINT);LOCAL STATUS coldfireOptsSet (COLDFIRE_CHAN *, UINT);LOCAL int    coldfireIoctl (COLDFIRE_CHAN *, int, void *);LOCAL int    coldfireTxStartup (COLDFIRE_CHAN *);LOCAL int    coldfireCallbackInstall (COLDFIRE_CHAN *, int, STATUS (*)(), void *);LOCAL int    coldfirePollInput (COLDFIRE_CHAN *, char *);LOCAL int    coldfirePollOutput (COLDFIRE_CHAN*, char);LOCAL STATUS coldfireDummyCallback (void);      void coldfireAcrSetClr (COLDFIRE_CHAN * pChan,			      UCHAR setBits, UCHAR clearBits);      void coldfireImrSetClr (COLDFIRE_CHAN * pChan,			      UCHAR setBits, UCHAR clearBits);      void coldfireOprSetClr (COLDFIRE_CHAN * pChan,			      UCHAR setBits, UCHAR clearBits);/* driver functions */LOCAL SIO_DRV_FUNCS coldfireSioDrvFuncs =    {    (int (*)(SIO_CHAN *, int, void *))coldfireIoctl,    (int (*)(SIO_CHAN *))coldfireTxStartup,    (int (*)())coldfireCallbackInstall,    (int (*)(SIO_CHAN *, char*))coldfirePollInput,    (int (*)(SIO_CHAN *, char))coldfirePollOutput    };/* typedefs *//* defines */#ifndef COLDFIRE_DEFAULT_BAUD#   define COLDFIRE_DEFAULT_BAUD  9600#endif#ifndef COLDFIRE_DEFAULT_OPTIONS    /* no handshake, rcvr enabled, 8 data bits, 1 stop bit, no parity */#   define COLDFIRE_DEFAULT_OPTIONS (CREAD | CS8 | CLOCAL)#endif/* Hardware read/write routines.  Can be redefined to create drivers * for boards with special i/o access procedures. The reg pointer * arguments are the register pointers from the COLDFIRE_CHAN structure. */#ifndef COLDFIRE_READ#   define COLDFIRE_READ(x)	(*x)	/* argument is register pointer */#endif#ifndef COLDFIRE_WRITE#   define COLDFIRE_WRITE(x,y)	(*x = y) /* args are reg ptr and data */#endif#define MAX_OPTIONS	(0xff)/******************************************************************************** coldfireDevInit - intialize a COLDFIRE_CHAN** The BSP must have already initialized all the device addresses, etc in* coldfire_CHAN structure. This routine initializes some transmitter &* receiver status values to be used in the interrupt mask register and then* resets the chip to a quiescent state.** RETURNS: N/A*/void coldfireDevInit    (    COLDFIRE_CHAN * pChan    )    {    int baudRate;    int oldlevel;        /* save away requested baud rate */    baudRate = pChan->baudRate;    pChan->baudRate = 0;    pChan->pDrvFuncs	= &coldfireSioDrvFuncs;    pChan->getTxChar	= coldfireDummyCallback;    pChan->putRcvChar	= coldfireDummyCallback;    coldfireImrSetClr (pChan, 0, ~0);    coldfireAcrSetClr (pChan, 0, ~0);    coldfireOprSetClr (pChan, 0, ~0);    pChan->mode		= 0; /* undefined */    pChan->intEnable	= FALSE;    pChan->acrCopy	= 0;    pChan->imrCopy	= 0;    pChan->oprCopy	= 0;    if ((pChan->options == 0) || (pChan->options > MAX_OPTIONS))	pChan->options = COLDFIRE_DEFAULT_OPTIONS;    oldlevel = intLock ();    /* Clear the interrupt mask register */    coldfireImrSetClr (pChan, 0, ~0);    /* Reset the transmitters & receivers  */    COLDFIRE_WRITE (pChan->cr, COLDFIRE_UART_CR_RESET_RX);    COLDFIRE_WRITE (pChan->cr, COLDFIRE_UART_CR_RESET_TX);    COLDFIRE_WRITE (pChan->cr, COLDFIRE_UART_CR_RESET_ERR);    COLDFIRE_WRITE (pChan->cr, COLDFIRE_UART_CR_RESET_BRK);    COLDFIRE_WRITE (pChan->cr, COLDFIRE_UART_CR_RESET_ERR);    /* Use internal timer */    COLDFIRE_WRITE (pChan->csr,		    COLDFIRE_UART_CSR_TIMER_RX | COLDFIRE_UART_CSR_TIMER_TX);    /* TX is disabled */    coldfireOptsSet (pChan, pChan->options);    if (coldfireBaudSet(pChan, baudRate) == ERROR)	coldfireBaudSet (pChan, COLDFIRE_DEFAULT_BAUD);    intUnlock (oldlevel);    }/******************************************************************************** coldfireDevInit2 - intialize a COLDFIRE_CHAN, part 2** This routine is called as part of sysSerialHwInit2() and tells* the driver that interrupt vectors are connected and that it is* safe to allow interrupts to be enabled.** RETURNS: N/A*/void coldfireDevInit2    (    COLDFIRE_CHAN * pChan    )    {    /* Allow interrupt mode */    pChan->intEnable = TRUE;    COLDFIRE_WRITE (pChan->ivr, pChan->intVec);    coldfireModeSet (pChan, pChan->mode);    }/******************************************************************************** coldfireImrSetClr - set and clear bits in the UART's interrupt mask register** This routine sets and clears bits in the UART's IMR.** This routine sets and clears bits in a local copy of the IMR, then* writes that local copy to the UART.  This means that all changes to* the IMR must go through this routine.  Otherwise, any direct changes* to the IMR would be lost the next time this routine is called.** Set has priority over clear.  Thus you can use this routine to update* multiple bit fields by specifying the field mask as the clear bits.** RETURNS: N/A*/void coldfireImrSetClr    (    COLDFIRE_CHAN * pChan,    UCHAR setBits,       /* which bits to set in the IMR   */    UCHAR clearBits      /* which bits to clear in the IMR */    )    {    pChan->imrCopy = ((pChan->imrCopy & ~clearBits) | setBits);    COLDFIRE_WRITE (pChan->imr, pChan->imrCopy);    }/******************************************************************************** coldfireImr - return current interrupt mask register contents** This routine returns the interrupt mask register contents.  The imr* is not directly readable, a copy of the last value written is kept* in the UART data structure.** RETURNS: Returns interrupt mask register contents.*/UCHAR coldfireImr    (    COLDFIRE_CHAN * pChan    )    {    return (pChan->imrCopy);    }/******************************************************************************** coldfireAcrSetClr - set and clear bits in the UART's aux control register** This routine sets and clears bits in the UART's ACR.** This routine sets and clears bits in a local copy of the ACR, then* writes that local copy to the UART.  This means that all changes to* the ACR must go through this routine.  Otherwise, any direct changes* to the ACR would be lost the next time this routine is called.** Set has priority over clear.  Thus you can use this routine to update* multiple bit fields by specifying the field mask as the clear bits.** RETURNS: N/A*/void coldfireAcrSetClr    (    COLDFIRE_CHAN * pChan,    UCHAR setBits,       /* which bits to set in the ACR   */    UCHAR clearBits      /* which bits to clear in the ACR */    )    {    pChan->acrCopy = ((pChan->acrCopy & ~clearBits) | setBits);    COLDFIRE_WRITE (pChan->acr, pChan->acrCopy);    }/******************************************************************************** coldfireAcr - return aux control register contents** This routine returns the auxilliary control register contents.  The acr* is not directly readable, a copy of the last value written is kept* in the UART data structure.** RETURNS: Returns auxilliary control register (acr) contents.*/UCHAR coldfireAcr    (    COLDFIRE_CHAN * pChan    )    {    return (pChan->acrCopy);    }/******************************************************************************** coldfireOprSetClr - set and clear bits in the output port register** This routine sets and clears bits in the UART's OPR.** A copy of the current opr contents is kept in the UART data structure.** RETURNS: N/A*/void coldfireOprSetClr    (    COLDFIRE_CHAN * pChan,    UCHAR setBits,       /* which bits to set in the OPR   */    UCHAR clearBits      /* which bits to clear in the OPR */    )    {    pChan->oprCopy = ((pChan->oprCopy & ~clearBits) | setBits);    COLDFIRE_WRITE (pChan->op2, clearBits);    COLDFIRE_WRITE (pChan->op1, setBits);    }/******************************************************************************** coldfireOpr - return the current state of the output register** This routine returns the current state of the output register from* the saved copy in the UART data structure.  The actual opr contents* are not directly readable.** RETURNS: Returns the current output register state.*/UCHAR coldfireOpr    (    COLDFIRE_CHAN * pChan    )    {    return (pChan->oprCopy);    }/******************************************************************************** coldfireDummyCallback - dummy callback routine.** RETURNS:* Always returns ERROR*/LOCAL STATUS coldfireDummyCallback (void)    {    return (ERROR);    }/******************************************************************************** coldfireTxStartup - start the interrupt transmitter.** This routine enables the transmitters for the specified UART channel so that* the UART channel will interrupt the CPU when TxRDY bit in the status* register is set.** Just enable the transmitter, don't output.  The driver may have just* switched from POLL mode and may still be outputting a character.** RETURNS:* Returns OK on success, or EIO on hardware error.*/LOCAL int coldfireTxStartup    (    COLDFIRE_CHAN * pChan    )    {    COLDFIRE_WRITE (pChan->cr, COLDFIRE_UART_CR_TX_ENABLE);

⌨️ 快捷键说明

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