📄 sa1100sio.c
字号:
/* sa1100Sio.c - Digital Semiconductor SA-1100 UART tty driver *//* Copyright 1998 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01a,22jan98,jpd created from ambaSio.c version 01d.*//*DESCRIPTIONThis is the device driver for the Digital Semiconductor SA-1100 UARTs.This chip contains 5 serial ports, but only ports 1 and 3 are usable asUARTs, the others support Universal Serial Bus (USB), SDLC, IrDAInfrared Communications Port (ICP) and Multimedia Communications Port(MCP)/Synchronous Serial Port (SSP).The UARTs are identical in design. They contain a universalasynchronous receiver/transmitter, and a baud-rate generator, The UARTscontain an 8-entry, 8-bit FIFO to buffer outgoing data and a 12-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 a framing, parity or receiver overrunerror is present within the bottom four entries of the receive FIFO,when the transmit FIFO is half-empty or receive FIFO is one- totwo-thirds full, when a begin and end of break is detected on thereceiver, and when the receive FIFO is partially full and the receiveris idle for three or more frame periods.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 SA1100_CHAN structure before callingsa1100DevInit().The UART supports baud rates from 56.24 to 230.4 kbps..SH DATA STRUCTURESAn SA1100_CHAN data structure is used to describe each channel, thisstructure is described in h/drv/sio/sa1100Sio.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 sa1100DevInit(), and sa1100Int().The BSP's sysHwInit() routine typically calls sysSerialHwInit(), whichinitialises the hardware-specific fields in the SA1100_CHAN structure(e.g. register I/O addresses etc) before calling sa1100DevInit() whichresets the device and installs the driver function pointers. Afterthis the UART will be enabled and ready to generate interrupts, butthose interrupts will be disabled in the interrupt controller.The following example shows the first parts of the initialisation:.CS#include "drv/sio/sa1100Sio.h"LOCAL SA1100_CHAN sa1100Chan[N_SA1100_UART_CHANS];void sysSerialHwInit (void) { int i; for (i = 0; i < N_SA1100_UART_CHANNELS; i++) { sa1100Chan[i].regs = devParas[i].baseAdrs; sa1100Chan[i].baudRate = CONSOLE_BAUD_RATE; sa1100Chan[i].xtal = UART_XTAL_FREQ; sa1100Chan[i].level = devParas[i].intLevel; /@ set up GPIO pins and UART pin reassignment @/ ... /@ * Initialise driver functions, getTxChar, putRcvChar * and channelMode and initialise UART @/ sa1100DevInit(&sa1100Chan[i]); } }.CEThe BSP's sysHwInit2() routine typically calls sysSerialHwInit2(),which connects the chips interrupts via intConnect() and enables thoseinterrupts, as shown in the following example:.CSvoid sysSerialHwInit2 (void) { int i; for (i = 0; i < N_SA1100_UART_CHANNELS; i++) { /@ connect and enable interrupts @/ (void)intConnect (INUM_TO_IVEC(devParas[i].vector), sa1100Int, (int) &sa1100Chan[i]); intEnable (devParas[i].intLevel); } }.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 SA1100_CHAN structure. sysSerialReset is called from sysToMonitor() and should reset theserial devices to an inactive state (prevent them from generating anyinterrupts)..SH INCLUDE FILES:drv/sio/sa1100Sio.h sioLib.h.SH SEE ALSO:.I Digital StrongARM SA-1100 Portable Communications Microcontroller, DataSheet,.I Digital Semiconductor StrongARM SA-1100 Microprocessor Evaluation Platform,User's Guide*/#include "vxWorks.h"#include "intLib.h"#include "errnoLib.h"#include "errno.h"#include "sioLib.h"#include "drv/sio/sa1100Sio.h"/* local defines */#ifndef SA1100_UART_REG_READ#define SA1100_UART_REG_READ(pChan, reg, result) \ ((result) = (*(volatile UINT32 *)((UINT32)(pChan)->regs + (reg))))#endif#ifndef SA1100_UART_REG_WRITE#define SA1100_UART_REG_WRITE(pChan, reg, data) \ ((*(volatile UINT32 *)((UINT32)(pChan)->regs + (reg))) = (data))#endif/* locals *//* function prototypes */LOCAL STATUS sa1100DummyCallback (void);LOCAL void sa1100InitChannel (SA1100_CHAN * pChan);LOCAL STATUS sa1100Ioctl (SIO_CHAN * pSioChan, int request, int arg);LOCAL int sa1100TxStartup (SIO_CHAN * pSioChan);LOCAL int sa1100CallbackInstall (SIO_CHAN * pSioChan, int callbackType, STATUS (*callback)(), void * callbackArg);LOCAL int sa1100PollInput (SIO_CHAN * pSioChan, char *);LOCAL int sa1100PollOutput (SIO_CHAN * pSioChan, char);/* driver functions */LOCAL SIO_DRV_FUNCS sa1100SioDrvFuncs = { (int (*)())sa1100Ioctl, sa1100TxStartup, sa1100CallbackInstall, sa1100PollInput, sa1100PollOutput };/********************************************************************************* sa1100DummyCallback - dummy callback routine.** RETURNS: ERROR, always.*/LOCAL STATUS sa1100DummyCallback (void) { return ERROR; }/********************************************************************************* sa1100DevInit - initialise an SA1100 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* SA1100_CHAN structure.** RETURNS: N/A*/void sa1100DevInit ( SA1100_CHAN * pChan /* ptr to SA1100_CHAN describing this channel */ ) { int oldlevel = intLock(); /* initialise the driver function pointers in the SIO_CHAN */ pChan->sio.pDrvFuncs = &sa1100SioDrvFuncs; /* set the non BSP-specific constants */ pChan->getTxChar = sa1100DummyCallback; pChan->putRcvChar = sa1100DummyCallback; pChan->channelMode = 0; /* am undefined mode */ /* initialise the chip */ sa1100InitChannel (pChan); intUnlock (oldlevel); return; }/********************************************************************************* sa1100InitChannel - initialise UART** This routine performs hardware initialisation of the UART channel.** RETURNS: N/A*/LOCAL void sa1100InitChannel ( SA1100_CHAN * pChan /* ptr to SA1100_CHAN describing this channel */ ) { UINT32 brd; /* Disable UART so can set line speed */ SA1100_UART_REG_WRITE (pChan, UTCR3, 0); /* Clear Status Register sticky bits */ SA1100_UART_REG_WRITE (pChan, UTSR0, 0xFF); /* Set word format: set 8 bits, 1 stop bit, no parity. */ SA1100_UART_REG_WRITE (pChan, UTCR0, (WORD_LEN_8 | ONE_STOP | PARITY_NONE)); /* Set baud rate divisor */ brd = (pChan->xtal / (16 * pChan->baudRate)) - 1; SA1100_UART_REG_WRITE (pChan, UTCR1, (brd >> 8) & 0xF); SA1100_UART_REG_WRITE (pChan, UTCR2, brd & 0xFF); /* Enable UART and rx and tx interrupts */ SA1100_UART_REG_WRITE (pChan, UTCR3, UTCR3_RXE | UTCR3_TXE | UTCR3_RIM | UTCR3_TIM); }/********************************************************************************* sa1100Ioctl - 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 sa1100Ioctl ( 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 */ UINT32 cr3; SA1100_CHAN * pChan = (SA1100_CHAN *)pSioChan; status = OK; /* preset to return OK */ switch (request) { case SIO_BAUD_SET: /*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -