📄 s3c44b0xsio.c
字号:
/* s3c44b0xSio.c - Samsung s3c44b0x serial driver *//* Copyright 1984-2001 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------2006.07.20 created from s3c44b0x template.*//*DESCRIPTION*/#include "vxWorks.h"#include "sioLib.h"#include "intLib.h"#include "errno.h"#include "s3c44b0xSio.h"#include "ioLib.h"#define S3C44B0X_BAUD_MIN 1200#define S3C44B0X_BAUD_MAX 115200#define S3C44B0X_SIO_DEFAULT_BAUD 38400/* Hardware abstraction macros *//* local defines */#ifndef S3C44B0X_SIO_REG_READ#define S3C44B0X_SIO_REG_READ(pChan, reg, result) \ ((result) = (*(volatile UINT32 *)((UINT32)(pChan)->regs + (reg))))#endif /*S3C44B0X_SIO_REG_READ*/#ifndef S3C44B0X_SIO_REG_WRITE#define S3C44B0X_SIO_REG_WRITE(pChan, reg, data) \ ((*(volatile UINT32 *)((UINT32)(pChan)->regs + (reg))) = (data))#endif /*S3C44B0X_SIO_REG_WRITE*//* for backward compatibility */#ifndef SIO_HUP# define SIO_OPEN 0x100A /* open channel, raise DTR, RTS */# define SIO_HUP 0x100B /* hang-up, lower DTR, RTS */#endif/* forward static declarations */LOCAL int s3c44b0xTxStartup (SIO_CHAN * pSioChan);LOCAL int s3c44b0xCallbackInstall (SIO_CHAN *pSioChan, int callbackType, STATUS (*callback)(), void *callbackArg);LOCAL int s3c44b0xPollOutput (SIO_CHAN *pSioChan, char outChar);LOCAL int s3c44b0xPollInput (SIO_CHAN *pSioChan, char *thisChar);LOCAL int s3c44b0xIoctl (SIO_CHAN *pSioChan, int request, void *arg);LOCAL STATUS dummyCallback (void);/* local variables */LOCAL SIO_DRV_FUNCS s3c44b0xSioDrvFuncs = { s3c44b0xIoctl, s3c44b0xTxStartup, s3c44b0xCallbackInstall, s3c44b0xPollInput, s3c44b0xPollOutput };LOCAL BOOL s3c44b0xIntrMode = FALSE; /* interrupt mode allowed flag *//******************************************************************************** s3c44b0xDevInit - initialize a S3C44B0X_DUSART** This routine initializes the driver* function pointers and then resets the chip in a quiescent state.* The BSP must have already initialized all the device addresses and the* baudFreq fields in the S3C44B0X_DUSART structure before passing it to* this routine.** RETURNS: N/A*/void s3c44b0xDevInit ( S3C44B0X_CHAN * pChan ) { /* initialize each channel's driver function pointers */ pChan->sio.pDrvFuncs = &s3c44b0xSioDrvFuncs; /* install dummy driver callbacks */ pChan->getTxChar = dummyCallback; pChan->putRcvChar = dummyCallback; /* reset the chip */ S3C44B0X_SIO_REG_WRITE(pChan,S3C44B0X_ULCON,(PARITY_NONE | ONE_STOP | WORD_LEN)); S3C44B0X_SIO_REG_WRITE(pChan,S3C44B0X_UFCON, S3C44B0X_UFCON_VAL); S3C44B0X_SIO_REG_WRITE(pChan,S3C44B0X_UCON, S3C44B0X_UCON_VAL); /* setting polled mode is one way to make the device quiet */ s3c44b0xIoctl ((SIO_CHAN *)pChan, SIO_MODE_SET, (void *)SIO_MODE_POLL); s3c44b0xIoctl ((SIO_CHAN *)pChan, SIO_BAUD_SET, (void *)S3C44B0X_SIO_DEFAULT_BAUD); }/******************************************************************************** s3c44b0xDevInit2 - initialize a S3C44B0X_DUSART, part 2** This routine is called by the BSP after interrupts have been connected.* The driver can now operate in interrupt mode. Before this routine is* called only polled mode operations should be allowed.** RETURNS: N/A* ARGSUSED*/void s3c44b0xDevInit2 ( S3C44B0X_CHAN * pChan /* device to initialize */ ) { char outchar = '\0'; UINT32 status; /* * Dummy write to TXBUF to start TX empty interrupt */ S3C44B0X_SIO_REG_WRITE(pChan,S3C44B0X_UTXBUF,outchar); /* Interrupt mode is allowed */ /*SNGKS32C_SIO_REG_WRITE(pChan,SNGKS32C_UCON,UCON_RX|UCON_TX|UCON_BREAK);*/ /* : deleted and added */ S3C44B0X_SIO_REG_WRITE(pChan,S3C44B0X_UCON,UCON_TX_LEVEL|UCON_RX|UCON_TX|0x80); S3C44B0X_SIO_REG_READ(pChan,S3C44B0X_UTRSTAT, status); while ((status & UTRSTAT_TX_READY) != UTRSTAT_TX_READY) S3C44B0X_SIO_REG_READ(pChan,S3C44B0X_UTRSTAT, status); /* : added */ /*SNGKS32C_SIO_REG_WRITE(pChan,SNGKS32C_UCON,UCON_RX|UCON_TX);*/ /* : deleted and added */ S3C44B0X_SIO_REG_WRITE(pChan,S3C44B0X_UCON,UCON_TX_LEVEL|UCON_RX|UCON_TX|0x80); s3c44b0xIntrMode = TRUE; }/******************************************************************************** s3c44b0xIntRcv - handle a channel's receive-character interrupt** RETURNS: N/A*/ void s3c44b0xIntRcv ( S3C44B0X_CHAN * pChan /* channel generating the interrupt */ ) { char inChar; int status; /* * Grab the input character from the chip and hand it off via a * callback. For chips with input FIFO's it is more efficient * to empty the entire FIFO here. */ S3C44B0X_SIO_REG_READ(pChan,S3C44B0X_UTRSTAT, status); if (status & USTAT_RX_READY) { S3C44B0X_SIO_REG_READ(pChan,S3C44B0X_URXBUF, inChar); (*pChan->putRcvChar) (pChan->putRcvArg, inChar); } }/******************************************************************************** s3c44b0xIntTx - handle a channels transmitter-ready interrupt** RETURNS: N/A*/ void s3c44b0xIntTx ( S3C44B0X_CHAN * pChan /* channel generating the interrupt */ ) { char outChar; UINT32 status; /* * If there's a character to transmit then write it out, else reset * the transmitter. For chips with output FIFO's it is more efficient * to fill the entire FIFO here. */ S3C44B0X_SIO_REG_READ(pChan,S3C44B0X_UTRSTAT, status); if((status & USTAT_TX_EMPTY) != USTAT_TX_EMPTY) return; if ((*pChan->getTxChar) (pChan->getTxArg, &outChar) != ERROR) S3C44B0X_SIO_REG_WRITE(pChan, S3C44B0X_UTXBUF, outChar); else { intDisable (pChan->intLevelTx); } }/******************************************************************************** s3c44b0xTxStartup - start the interrupt transmitter** RETURNS: OK on success, ENOSYS if the device is polled-only, or* EIO on hardware error.*/LOCAL int s3c44b0xTxStartup ( SIO_CHAN * pSioChan /* channel to start */ ) { S3C44B0X_CHAN * pChan = (S3C44B0X_CHAN *)pSioChan; S3C44B0X_REG_WRITE32 (S3C44B0X_I_ISPC, (1 << pChan->intLevelTx)); intEnable (pChan->intLevelTx); return (OK); }/******************************************************************************** s3c44b0xCallbackInstall - install ISR callbacks to get/put chars** This driver allows interrupt callbacks for transmitting characters* and receiving characters. In general, drivers may support other* types of callbacks too.** RETURNS: OK on success, or ENOSYS for an unsupported callback type.*/ LOCAL int s3c44b0xCallbackInstall ( SIO_CHAN * pSioChan, /* channel */ int callbackType, /* type of callback */ STATUS (*callback)(), /* callback */ void * callbackArg /* parameter to callback */ ) { S3C44B0X_CHAN * pChan = (S3C44B0X_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); } }/********************************************************************************* s3c44b0xPollOutput - output a character in polled mode** RETURNS: OK if a character arrived, EIO on device error, EAGAIN* if the output buffer if full. ENOSYS if the device is* interrupt-only.*/LOCAL int s3c44b0xPollOutput ( SIO_CHAN *pSioChan, char outChar ) { S3C44B0X_CHAN * pChan = (S3C44B0X_CHAN *)pSioChan; UINT32 status; /* is the transmitter ready to accept a character? */ S3C44B0X_SIO_REG_READ (pChan, S3C44B0X_UTRSTAT, status); if ((status & USTAT_TX_EMPTY) == 0x00) return (EAGAIN); /* write out the character */ S3C44B0X_SIO_REG_WRITE(pChan, S3C44B0X_UTXBUF, outChar); return (OK); }/******************************************************************************** s3c44b0xPollInput - poll the device for input** RETURNS: OK if a character arrived, EIO on device error, EAGAIN* if the input buffer if empty, ENOSYS if the device is* interrupt-only.*/LOCAL int s3c44b0xPollInput ( SIO_CHAN * pSioChan, char * thisChar ) { S3C44B0X_CHAN * pChan = (S3C44B0X_CHAN *)pSioChan; UINT32 status; S3C44B0X_SIO_REG_READ (pChan,S3C44B0X_UTRSTAT, status); if ((status & USTAT_RX_READY) == 0x00) return (EAGAIN); /* no input available at this time */ /* got a character */ S3C44B0X_SIO_REG_READ(pChan, S3C44B0X_URXBUF, *thisChar); return (OK); }/******************************************************************************** s3c44b0xModeSet - toggle between interrupt and polled mode** RETURNS: OK on success, EIO on unsupported mode.*/LOCAL int s3c44b0xModeSet ( S3C44B0X_CHAN * pChan, /* channel */ uint_t newMode /* new mode */ ) { UINT32 temp; if ((newMode != SIO_MODE_POLL) && (newMode != SIO_MODE_INT)) return (EIO); /* Don't enter interrupt mode unless it is allowed. */ if ((newMode == SIO_MODE_INT) && (!s3c44b0xIntrMode)) return (EIO); /* set the new mode */ pChan->mode = newMode; if (pChan->mode == SIO_MODE_INT) { S3C44B0X_SIO_REG_READ(pChan, S3C44B0X_UCON, temp); temp &=UCON_RX_TX_RESET; /**Reset RX and TX mode bits*/ temp |= (UCON_RX|UCON_TX); S3C44B0X_SIO_REG_WRITE(pChan,S3C44B0X_UCON, temp); intEnable(pChan->intLevelRx); } else { S3C44B0X_SIO_REG_READ(pChan, S3C44B0X_UCON, temp); temp &=UCON_RX_TX_RESET; /**Reset RX and TX mode bits*/ temp |= (UCON_RX|UCON_TX); S3C44B0X_SIO_REG_WRITE(pChan,S3C44B0X_UCON, temp); intDisable (pChan->intLevelTx); intDisable (pChan->intLevelRx); } return (OK); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -