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

📄 ixm1200sio.c

📁 vxworks的BSP开发配置文件
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ixm1200Sio.c - Intel IXM1200 UART tty driver *//* Copyright 1998 Wind River Systems, Inc.; Copyright 1999 Intel Corp. */#include "copyright_wrs.h"/*modification history--------------------01e,30aug01,scm  adjust to reflect ixm1200...01d,06Oct00,jdg  Added Big-Endian support01c,07Mar00,jdg  Added support for B0 revision ixp120001b,13aug99,jdg  changed name from vbsa1200 to ixp1200eb01a,07may99,jdg  created from sa1100Sio.c version 01a.*//*DESCRIPTIONThis is the device driver for the Intel IXM1200 UART.The UART contains a universalasynchronous receiver/transmitter, and a baud-rate generator, The UARTcontains an 8-entry, 8-bit FIFO to buffer outgoing data and an 8-entry11-bit FIFO to buffer incoming data.  If a framing, overrun or parityerror occurs during reception, the appropriate error bits are stored inthe receive FIFO along with the received data.  The only mode ofoperation supported is with the FIFOs enabled.The UART design does not support modem control input or output signalse.g. DTR, RI, RTS, DCD, CTS and DSR.An interrupt is generated when the receive FIFO is non-empty and when the transmit FIFO is empty.Only asynchronous serial operation is supported by the UARTs whichsupports 7 or 8 bit word lengths with or without parity and with one ortwo stop bits. The only serial word format supported by the driver is 8data bits, 1 stop bit, no parity,  The default baud rate is determinedby the BSP by filling in the IXM1200_CHAN structure before callingixm1200UartDevInit().The UART supports baud rates from 56.24 to 230.4 kbps..SH DATA STRUCTURESAn IXM1200_CHAN data structure is used to describe each channel, thisstructure is described in ixm1200Sio.h..SH CALLBACKSServicing a "transmitter ready" interrupt involves making a callback toa higher level library in order to get a character to transmit.  Bydefault, this driver installs dummy callback routines which do nothing.A higher layer library that wants to use this driver (e.g. ttyDrv)will install its own callback routine using the SIO_INSTALL_CALLBACKioctl command.  Likewise, a receiver interrupt handler makes a callbackto pass the character to the higher layer library. .SH MODESThis driver supports both polled and interrupt modes..SH USAGEThe driver is typically only called by the BSP. The directly callableroutines in this modules are ixm1200UartDevInit(), and ixm1200UartInt().The BSP's sysHwInit() routine typically calls sysSerialHwInit(), whichinitialises the hardware-specific fields in the IXM1200_CHAN structurebefore calling ixm1200UartDevInit() whichresets the device and installs the driver function pointers.  Afterthis the UART will be enabled but it will not have interrupts enabled.The BSP's sysHwInit2() routine typically calls ixm1200UartDevInit2(),which enables the interrupts. This is done because the IXM1200 does nothave a true interrupt controller and hence the only way to enable/disablethe UART interrupts is by modifying the UART control registers directly.Likewise, there is a ixm1200UartDevReset() routine which disablesthe UART interrupts. This is typically used in sysSerialReset to quietthe UART interrupts within sysToMonitor.The following example shows the first parts of the initialisation:.CS#include "ixm1200Sio.h"LOCAL IXM1200_CHAN ixm1200Chan[N_IXM1200_UART_CHANS];void sysSerialHwInit (void)    {    int i;    for (i = 0; i < N_IXM1200_UART_CHANNELS; i++)        {        ixm1200Chan[i].baudRate = CONSOLE_BAUD_RATE;        ixm1200Chan[i].xtal = UART_XTAL_FREQ;         ...        /@         * Initialise driver functions, getTxChar, putRcvChar         * and channelMode and initialise UART         @/        ixm1200UartDevInit(&ixm1200Chan[i]);        }    }.CEThe BSP's sysHwInit2() routine typically calls sysSerialHwInit2(),which connects the chips interrupts via intConnect() and enables thoseinterrupts by calling ixm1200UartDevInit2(), as shown in the following example:.CSvoid sysSerialHwInit2 (void)    {    int i;    for (i = 0; i < N_IXM1200_UART_CHANNELS; i++)        {        /@ connect and enable interrupts @/        (void) intConnect (INUM_TO_IVEC(INT_VEC_UART),                           ixm1200UartInt, (int) &ixm1200Chan[i]);        ixm1200UartDevInit2(&ixm1200Chan[i]);        }    }.CE.SH BSPBy convention all the BSP-specific serial initialisation is performedin a file called sysSerial.c, which is #include'ed by sysLib.c.sysSerial.c implements at least four functions, sysSerialHwInit()sysSerialHwInit2(), sysSerialChanGet(), and sysSerialReset(). The firsttwo have been described above, the others work as follows:sysSerialChanGet is called by usrRoot to get the serial channeldescriptor associated with a serial channel number. The routine takes asingle parameter which is a channel number ranging between zero andNUM_TTY. It returns a pointer to the corresponding channel descriptor,SIO_CHAN *, which is just the address of the IXM1200_CHAN structure. sysSerialReset is called from sysToMonitor() and should reset theserial devices to an inactive state (prevent them from generating anyinterrupts)..SH INCLUDE FILES:ixm1200Sio.h sioLib.h.SH SEE ALSO:*//* includes */#include "vxWorks.h"#include "intLib.h"#include "errnoLib.h"#include "errno.h"#include "sioLib.h"#include "ixm1200Sio.h"/* local defines  *//* locals *//* function prototypes */LOCAL STATUS ixm1200UartDummyCallback (void);LOCAL void ixm1200UartInitChannel (IXM1200_CHAN * pChan);LOCAL STATUS ixm1200UartIoctl (SIO_CHAN * pSioChan, int request, int arg);LOCAL int ixm1200UartTxStartup (SIO_CHAN * pSioChan);LOCAL int ixm1200UartCallbackInstall (SIO_CHAN * pSioChan, int callbackType,                                      STATUS (*callback)(), void * callbackArg);LOCAL int ixm1200UartPollInput (SIO_CHAN * pSioChan, char *);LOCAL int ixm1200UartPollOutput (SIO_CHAN * pSioChan, char);/* driver functions */LOCAL SIO_DRV_FUNCS ixm1200SioDrvFuncs =    {    (int (*)())ixm1200UartIoctl,    ixm1200UartTxStartup,    ixm1200UartCallbackInstall,    ixm1200UartPollInput,    ixm1200UartPollOutput    };/********************************************************************************* ixm1200UartDummyCallback - dummy callback routine.** RETURNS: ERROR, always.*/LOCAL STATUS ixm1200UartDummyCallback (void)    {    return ERROR;    }/********************************************************************************* ixm1200UartDevInit - initialise an IXM1200 channel** This routine initialises some SIO_CHAN function pointers and then resets* the chip to a quiescent state.  Before this routine is called, the BSP* must already have initialised all the device addresses, etc. in the* IXM1200_CHAN structure.** RETURNS: N/A*/void ixm1200UartDevInit    (    IXM1200_CHAN *       pChan   /* ptr to IXM1200_CHAN describing this channel */    )    {    int oldlevel = intLock();    /* initialise the driver function pointers in the SIO_CHAN */    pChan->sio.pDrvFuncs = &ixm1200SioDrvFuncs;    /* set the non BSP-specific constants */    pChan->getTxChar = ixm1200UartDummyCallback;    pChan->putRcvChar = ixm1200UartDummyCallback;    pChan->channelMode = 0;    /* am undefined mode */    /* initialise the chip */    ixm1200UartInitChannel (pChan);    intUnlock (oldlevel);    return;    }/********************************************************************************* ixm1200UartDevInit2 - initialise UART interupts** This routine performs hardware initialisation of the UART channel.* It will enable receive interrupts. * Transmit interrupts are enabled, but the ISR will probably find that* there is nothing to do and disable them.** RETURNS: N/A*/void ixm1200UartDevInit2    (    IXM1200_CHAN *       pChan   /* ptr to IXM1200_CHAN describing this channel */    )    {    int oldlevel = intLock();    pChan->uartCR |= UART_RX_INT_EN | UART_TX_INT_EN;    IXM1200_REG_WRITE( UART_CR, pChan->uartCR );    intUnlock (oldlevel);    }/********************************************************************************* ixm1200UartInitChannel - initialise UART** This routine performs hardware initialisation of the UART channel.** This does not enable the interrupts because we cannot mask them out* due to lack of interrupt controller.** RETURNS: N/A*/LOCAL void ixm1200UartInitChannel    (    IXM1200_CHAN *       pChan   /* ptr to IXM1200_CHAN describing this channel */    )    {    UINT32      cr;    if (sysCpuRev < 1) {        /* Clear any outstanding interrupts and disable the uart */        IXM1200_REG_WRITE( UART_CR, UART_INT_CLR);    } else {        /* Disable uart */        IXM1200_REG_WRITE( UART_CR, 0);    }    /* Compute baud rate divisor */    cr = (((pChan->xtal / (16 * pChan->baudRate)) - 1) & 0x3FF) << 16;    /* Set word format: 8 bits, 1 stop bit, no parity */    /* Leave interrupts disabled */    cr |=         UART_DSS_8BIT |         UART_SBS_1BIT |         UART_EN;    pChan->uartCR = cr;    IXM1200_REG_WRITE( UART_CR, 0);    IXM1200_REG_WRITE( UART_CR, cr );    }/********************************************************************************* ixm1200UartIoctl - special device control** This routine handles the IOCTL messages from the user.** RETURNS: OK on success, ENOSYS on unsupported request, EIO on failed* request.*/LOCAL STATUS ixm1200UartIoctl    (    SIO_CHAN *  pSioChan,       /* ptr to SIO_CHAN describing this channel */    int         request,        /* request code */    int         arg             /* some argument */    )    {    int         oldlevel;       /* current interrupt level mask */    STATUS      status;         /* status to return */    UINT32      brd;            /* baud rate divisor */    IXM1200_CHAN * pChan = (IXM1200_CHAN *)pSioChan;    status = OK;        /* preset to return OK */    switch (request)        {        case SIO_BAUD_SET:            /*             * Set the baud rate. Return EIO for an invalid baud rate, or             * OK on success.             *             * Calculate the baud rate divisor: it must be non-zero and must             * fit in a 10-bit register.             */            brd = (pChan->xtal / (16 * arg)) - 1;            if (brd & ~0x3FF)                {

⌨️ 快捷键说明

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