📄 hpcserial.c
字号:
/* hpcSerial.c - Intel HPC Serial Port tty driver *//* Copyright 2000 Intel Corp. *//*modification history--------------------01a,27Jun00,jdg created*//*DESCRIPTIONThis is the device driver for the Intel HPC serial portThis driver uses the HPC (Host Pci Communications) driver to emulate a normal serial port (with the exception that baud rate and other parameters are undefined..SH DATA STRUCTURESAn HPC_SERIAL_CHAN data structure is used to describe each channel, thisstructure is described in HPCSerial.h..SH CALLBACKSServicing a "space available" 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 hpcsDevInit().The BSP's sysHwInit() routine typically calls sysSerialHwInit(), whichinitialises the hardware-specific fields in the HPC_SERIAL_CHAN structurebefore calling hpcsDevInit() whichresets the device and installs the driver function pointers.*//* includes */#include "vxWorks.h"#include "sioLib.h"#include "hpcSerial.h"#include "config.h"/* local defines *//* locals *//* function prototypes */LOCAL STATUS hpcsDummyCallback (void);LOCAL STATUS hpcsIoctl (SIO_CHAN * pSioChan, int request, int arg);LOCAL int hpcsTxStartup (SIO_CHAN * pSioChan);LOCAL int hpcsCallbackInstall (SIO_CHAN * pSioChan, int callbackType, STATUS (*callback)(), void * callbackArg);LOCAL int hpcsPollInput (SIO_CHAN * pSioChan, char *);LOCAL int hpcsPollOutput (SIO_CHAN * pSioChan, char);LOCAL void hpcsPutRcvChars(unsigned char *buff, unsigned int len, void *pChan);LOCAL unsigned int hpcsGetTxChars(unsigned char **buf, void *pChan);/* driver functions */LOCAL SIO_DRV_FUNCS hpcsDrvFuncs = { (int (*)())hpcsIoctl, hpcsTxStartup, hpcsCallbackInstall, hpcsPollInput, hpcsPollOutput };/********************************************************************************* hpcsDummyCallback - dummy callback routine.** RETURNS: ERROR, always.*/LOCAL STATUS hpcsDummyCallback (void) { return ERROR; }/********************************************************************************* hpcsDevInit - initialise an HPC 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* HPC_SERIAL_CHAN structure.** RETURNS: N/A*/void hpcsDevInit ( HPC_SERIAL_CHAN * pChan /* ptr to HPC_SERIAL_CHAN describing this channel */ ) { int oldlevel = intLock(); /* initialise the driver function pointers in the SIO_CHAN */ pChan->sio.pDrvFuncs = &hpcsDrvFuncs; /* set the non BSP-specific constants */ pChan->getTxChar = hpcsDummyCallback; pChan->putRcvChar = hpcsDummyCallback; pChan->channelMode = 0; /* am undefined mode */ intUnlock (oldlevel); return; }/********************************************************************************* hpcsDevInit2 - Open HPC channel** RETURNS: N/A*/void hpcsDevInit2 ( HPC_SERIAL_CHAN * pChan /* ptr to HPC_SERIAL_CHAN describing this channel */ ) { int oldlevel = intLock(); /* initialise the channel */ hpcOpenSio(pChan->channelNum, hpcsPutRcvChars, pChan, hpcsGetTxChars, pChan); intUnlock (oldlevel); return; }LOCAL void hpcsPutRcvChars ( unsigned char *buff, unsigned int len, void *pChan1 ) { unsigned int i; HPC_SERIAL_CHAN *pChan = (HPC_SERIAL_CHAN*) pChan1; for (i=0; i<len; i++) { (*pChan->putRcvChar)(pChan->putRcvArg, (char) buff[i]); } }LOCAL unsigned int hpcsGetTxChars ( unsigned char **buf, void *pChan1 ) { HPC_SERIAL_CHAN *pChan = (HPC_SERIAL_CHAN*) pChan1; int i; int gotOne; UINT32 ch; for (i=0; i<HPC_TX_BUFF_SIZE; i++) { gotOne = ((*pChan->getTxChar)(pChan->getTxArg, &ch) != ERROR); if (gotOne) { pChan->txBuf[i] = (char)ch; } else { break; } } *buf = &pChan->txBuf[0]; return i;}/******************************************************************************** hpcsCallbackInstall - install ISR callbacks to get/put chars.** This routine installs interrupt callbacks for transmitting characters* and receiving characters.** RETURNS: OK on success, or ENOSYS for an unsupported callback type.**/LOCAL int hpcsCallbackInstall ( SIO_CHAN * pSioChan, /* ptr to SIO_CHAN describing this channel */ int callbackType, /* type of callback */ STATUS (*callback)(), /* callback */ void * callbackArg /* parameter to callback */ ) { HPC_SERIAL_CHAN * pChan = (HPC_SERIAL_CHAN *)pSioChan; switch (callbackType) { case SIO_CALLBACK_GET_TX_CHAR: pChan->getTxChar = callback; pChan->getTxArg = callbackArg; return OK; case SIO_CALLBACK_PUT_RCV_CHAR: pChan->putRcvChar = callback; pChan->putRcvArg = callbackArg; return OK; default: return ENOSYS; } }/********************************************************************************* hpcsTxStartup - transmitter startup routine** Call interrupt level char output routine and enable interrupt** RETURNS: OK on success, ENOSYS if the device is polled-only, or* EIO on hardware error.*/LOCAL int hpcsTxStartup ( SIO_CHAN * pSioChan /* ptr to SIO_CHAN describing this channel */ ) { HPC_SERIAL_CHAN * pChan = (HPC_SERIAL_CHAN *)pSioChan; if (pChan->channelMode == SIO_MODE_INT) { hpcStartio(pChan->channelNum); return OK; } else { return ENOSYS; } }/******************************************************************************** hpcsPollOutput - output a character in polled mode.** RETURNS: OK if a character arrived, EIO on device error, EAGAIN* if the output buffer is full, ENOSYS if the device is interrupt-only.*/LOCAL int hpcsPollOutput ( SIO_CHAN * pSioChan, /* ptr to SIO_CHAN describing this channel */ char outChar /* char to output */ ) { HPC_SERIAL_CHAN * pChan = (HPC_SERIAL_CHAN *)pSioChan; if (0 == hpcPolledSend(pChan->channelNum, (unsigned char*)&outChar, 1)) return EAGAIN; else return OK; }/******************************************************************************** hpcsPollInput - poll the device for input.** RETURNS: OK if a character arrived, EIO on device error, EAGAIN* if the input buffer is empty, ENOSYS if the device is interrupt-only.*/LOCAL int hpcsPollInput ( SIO_CHAN * pSioChan, /* ptr to SIO_CHAN describing this channel */ char * thisChar /* pointer to where to return character */ ) { HPC_SERIAL_CHAN * pChan = (HPC_SERIAL_CHAN *)pSioChan; int n; unsigned char buf; n = hpcPolledRcv(pChan->channelNum, &buf, 1, NULL); if (n == 0) return EAGAIN; *thisChar = (char)buf; return OK; }/********************************************************************************* hpcsIoctl - 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 hpcsIoctl ( SIO_CHAN * pSioChan, /* ptr to SIO_CHAN describing this channel */ int request, /* request code */ int arg /* some argument */ ) { STATUS status; /* status to return */ HPC_SERIAL_CHAN * pChan = (HPC_SERIAL_CHAN *)pSioChan; status = OK; /* preset to return OK */ switch (request) { case SIO_BAUD_SET: status = ENOSYS; break; case SIO_BAUD_GET: status = ENOSYS; break; case SIO_MODE_SET: /* * Set the mode (e.g., to interrupt or polled). Return OK * or EIO for an unknown or unsupported mode. */ if ((arg != SIO_MODE_POLL) && (arg != SIO_MODE_INT)) { status = EIO; break; } pChan->channelMode = arg; break; case SIO_MODE_GET: /* Get the current mode and return OK */ *(int *)arg = pChan->channelMode; break; case SIO_AVAIL_MODES_GET: /* Get the available modes and return OK */ *(int *)arg = SIO_MODE_INT | SIO_MODE_POLL; break; case SIO_HW_OPTS_SET: /* * Optional command to set the hardware options (as defined * in sioLib.h). * Return OK, or ENOSYS if this command is not implemented. * Note: several hardware options are specified at once. * This routine should set as many as it can and then return * OK. The SIO_HW_OPTS_GET is used to find out which options * were actually set. */ case SIO_HW_OPTS_GET: /* * Optional command to get the hardware options (as defined * in sioLib.h). Return OK or ENOSYS if this command is not * implemented. Note: if this command is unimplemented, it * will be assumed that the driver options are CREAD | CS8 * (e.g., eight data bits, one stop bit, no parity, ints enabled). */ default: status = ENOSYS; } return status; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -