📄 s3c2410xsio.c
字号:
*/LOCAL int s3c2410xPollInput ( SIO_CHAN * pSioChan, char * thisChar ) { S3C2410X_CHAN * pChan = (S3C2410X_CHAN *)pSioChan; UINT32 status; S3C2410X_SIO_REG_READ (pChan,S3C2410X_USTAT, status); if ((status & USTAT_RX_AVAIL) == 0x00) return (EAGAIN); S3C2410X_SIO_REG_READ(pChan, S3C2410X_URXBUF, *thisChar); return (OK); }/******************************************************************************** s3c2410xModeSet - toggle between interrupt and polled mode** RETURNS: OK on success, EIO on unsupported mode.*/LOCAL int s3c2410xModeSet ( S3C2410X_CHAN * pChan, /* channel */ uint_t newMode /* new mode */ ) { UINT32 temp; UINT32 tempUINT32; if ((newMode != SIO_MODE_POLL) && (newMode != SIO_MODE_INT)) return (EIO); if ((newMode == SIO_MODE_INT) && (!s3c2410xIntrMode)) return (EIO); pChan->mode = newMode; if (pChan->mode == SIO_MODE_INT) { switch((int)(pChan->regs)) { case SERIAL_B_BASE_ADR: s3c2410x_INT_REG_WRITE(S3C2410X_SUBSRCPND, ((1<<SUBINT_LVL_TXD1)|(1<<SUBINT_LVL_RXD1))); break; case SERIAL_A_BASE_ADR: default: s3c2410x_INT_REG_WRITE(S3C2410X_SUBSRCPND, ((1<<SUBINT_LVL_TXD0)|(1<<SUBINT_LVL_RXD0))); } intEnable(pChan->intLevelRx); S3C2410X_SIO_REG_READ(pChan, S3C2410X_UCON, temp); temp &=UCON_RX_TX_RESET; temp |= (UCON_RX|UCON_TX); S3C2410X_SIO_REG_WRITE(pChan,S3C2410X_UCON, temp); s3c2410x_INT_REG_READ(S3C2410X_INTSUBMSK,tempUINT32); switch((int)(pChan->regs)) { case SERIAL_B_BASE_ADR: tempUINT32 &= ~((1<<SUBINT_LVL_RXD1)|(1<<SUBINT_LVL_TXD1)); break; case SERIAL_A_BASE_ADR: default: tempUINT32 &= ~((1<<SUBINT_LVL_RXD0)|(1<<SUBINT_LVL_TXD0)); } s3c2410x_INT_REG_WRITE(S3C2410X_INTSUBMSK,tempUINT32); } else { S3C2410X_SIO_REG_READ(pChan, S3C2410X_UCON, temp); temp &=UCON_RX_TX_RESET; temp |= (UCON_RX|UCON_TX); S3C2410X_SIO_REG_WRITE(pChan,S3C2410X_UCON, temp); intDisable (pChan->intLevelRx); s3c2410x_INT_REG_READ(S3C2410X_INTSUBMSK,tempUINT32); switch((int)(pChan->regs)) { case SERIAL_B_BASE_ADR: tempUINT32 |= ((1<<SUBINT_LVL_RXD1)|(1<<SUBINT_LVL_TXD1)); break; case SERIAL_A_BASE_ADR: default: tempUINT32 |= ((1<<SUBINT_LVL_RXD0)|(1<<SUBINT_LVL_TXD0)); } s3c2410x_INT_REG_WRITE(S3C2410X_INTSUBMSK,tempUINT32); } return (OK);}/********************************************************************************* s3c2410xHup - hang up the modem control lines ** Resets the RTS and DTR signals.** RETURNS: OK*/LOCAL STATUS s3c2410xHup ( S3C2410X_CHAN * pChan /* pointer to channel */ ) { FAST int oldlevel; /* current interrupt level mask */ oldlevel = intLock (); intUnlock (oldlevel); return (OK); } /********************************************************************************* s3c2410xOpen - Set the modem control lines ** Set the modem control lines(RTS, DTR) TRUE if not already set. ** RETURNS: OK*/LOCAL STATUS s3c2410xOpen ( S3C2410X_CHAN * pChan /* pointer to channel */ ) { FAST int oldlevel; /* current interrupt level mask */ oldlevel = intLock (); intUnlock (oldlevel); return (OK); }/******************************************************************************** s3c2410xOptSet - set hardware options** This routine sets up the hardware according to the specified option* argument. If the hardware cannot support a particular option value, then* it should ignore that portion of the request.** RETURNS: OK upon success, or EIO for invalid arguments.*/LOCAL int s3c2410xOptSet ( S3C2410X_CHAN * pChan, /* channel */ uint_t newOpts /* new options */ ) { UINT8 dataBits = 0x03; UINT8 stopBits = 0x00; BOOL hdweFlowCtrl=TRUE; BOOL rcvrEnable = TRUE; int lvl; UINT8 temp=PARITY_NONE; UINT32 result; if (pChan == NULL || newOpts & 0xffffff00) return EIO; /* do nothing if options already set */ if (pChan->options == newOpts) return OK; switch (newOpts & CSIZE) { case CS5: dataBits = 0x00; break; case CS6: dataBits = 0x01; break; case CS7: dataBits = 0x02; break; case CS8: default: dataBits = 0x03; break; } if (newOpts & STOPB) stopBits = 0x04; else stopBits = 0x00; switch (newOpts & (PARENB|PARODD)) { case PARENB|PARODD: temp=PARITY_ODD; break; case PARENB: temp=PARITY_EVEN; break; case PARODD: break; default: case 0: temp=PARITY_NONE ;/* no parity */ break; } if (newOpts & CLOCAL) { hdweFlowCtrl = FALSE; } if ((newOpts & CREAD) == 0) rcvrEnable = FALSE; lvl = intLock (); S3C2410X_SIO_REG_READ(pChan, S3C2410X_ULCON, result); S3C2410X_SIO_REG_WRITE(pChan,S3C2410X_ULCON,(result|dataBits|temp|stopBits)); intUnlock (lvl); pChan->options = newOpts; return (OK); }/********************************************************************************* s3c2410xIoctl - special device control*** RETURNS: OK on success, ENOSYS on unsupported request, EIO on failed* request.*/LOCAL int s3c2410xIoctl ( SIO_CHAN * pSioChan, /* device to control */ int request, /* request code */ void * someArg /* some argument */ ) { S3C2410X_CHAN *pChan = (S3C2410X_CHAN *) pSioChan; int oldlevel; /* current interrupt level mask */ int arg = (int)someArg; switch (request) { case SIO_BAUD_SET: if (arg == 0) return s3c2410xHup (pChan); if (arg < S3C2410X_BAUD_MIN || arg > S3C2410X_BAUD_MAX) { return (EIO); } switch(arg) { case 1200: oldlevel = intLock (); S3C2410X_SIO_REG_WRITE(pChan,S3C2410X_UBRDIV,S3C2410X_CNT0_1200|S3C2410X_CNT1_VAL); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 2400: oldlevel = intLock (); S3C2410X_SIO_REG_WRITE(pChan,S3C2410X_UBRDIV,S3C2410X_CNT0_2400|S3C2410X_CNT1_VAL); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 4800: oldlevel = intLock (); S3C2410X_SIO_REG_WRITE(pChan,S3C2410X_UBRDIV,S3C2410X_CNT0_4800|S3C2410X_CNT1_VAL); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 9600: oldlevel = intLock (); S3C2410X_SIO_REG_WRITE(pChan,S3C2410X_UBRDIV,S3C2410X_CNT0_9600|S3C2410X_CNT1_VAL); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 19200: oldlevel = intLock (); S3C2410X_SIO_REG_WRITE(pChan,S3C2410X_UBRDIV,S3C2410X_CNT0_19200|S3C2410X_CNT1_VAL); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 38400: oldlevel = intLock (); S3C2410X_SIO_REG_WRITE(pChan,S3C2410X_UBRDIV,S3C2410X_CNT0_38400|S3C2410X_CNT1_VAL); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 57600: oldlevel = intLock (); S3C2410X_SIO_REG_WRITE(pChan,S3C2410X_UBRDIV,S3C2410X_CNT0_57600|S3C2410X_CNT1_VAL); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 115200: oldlevel = intLock (); S3C2410X_SIO_REG_WRITE(pChan,S3C2410X_UBRDIV,S3C2410X_CNT0_115200|S3C2410X_CNT1_VAL); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 230400: oldlevel = intLock (); S3C2410X_SIO_REG_WRITE(pChan,S3C2410X_UBRDIV,S3C2410X_CNT0_230400|S3C2410X_CNT1_VAL); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 460800: oldlevel = intLock (); S3C2410X_SIO_REG_WRITE(pChan,S3C2410X_UBRDIV,S3C2410X_CNT0_460800|S3C2410X_CNT1_VAL); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); default: return(EIO); } break; case SIO_BAUD_GET: *(int *)arg = pChan->baudRate; break; case SIO_MODE_SET: return (s3c2410xModeSet (pChan, arg)); case SIO_MODE_GET: *(int *)arg = pChan->mode; return (OK); case SIO_AVAIL_MODES_GET: *(int *)arg = SIO_MODE_INT | SIO_MODE_POLL; return (OK); case SIO_HW_OPTS_SET: return (s3c2410xOptSet (pChan, arg)); case SIO_HW_OPTS_GET: *(int *)arg = pChan->options; return (OK); case SIO_HUP: if (pChan->options & HUPCL) return (s3c2410xHup (pChan)); return (OK); case SIO_OPEN: return (s3c2410xOpen (pChan)); default: return (ENOSYS); } return (ENOSYS); }/********************************************************************************* dummyCallback - dummy callback routine** RETURNS: ERROR.*/LOCAL STATUS dummyCallback (void) { return (ERROR); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -