📄 sngks32csio-old.c
字号:
) {/* 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) && (!at91cIntrMode)) return (EIO); /* set the new mode */ pChan->mode = newMode;#if 0 if (pChan->mode == SIO_MODE_INT) { AT91C_SIO_REG_READ(pChan, SNGKS32C_UCON, temp); temp &=UCON_RX_TX_RESET; /**Reset RX and TX mode bits*/ temp |= (UCON_RX|UCON_TX); AT91C_SIO_REG_WRITE(pChan,SNGKS32C_UCON, temp); intEnable(pChan->intLevelRx); } else { AT91C_SIO_REG_READ(pChan, SNGKS32C_UCON, temp); temp &=UCON_RX_TX_RESET; /**Reset RX and TX mode bits*/ temp |= (UCON_RX|UCON_TX); AT91C_SIO_REG_WRITE(pChan,SNGKS32C_UCON, temp); intDisable (pChan->intLevelTx); intDisable (pChan->intLevelRx); } #endif if (pChan->mode == SIO_MODE_INT) { AT91C_SIO_REG_WRITE(pChan, AT91C_US_CR,AT91C_US_RSTRX | AT91C_US_RSTTX); /*Reset RX & TX*/ AT91C_SIO_REG_WRITE(pChan, AT91C_US_CR, AT91C_US_RXEN |AT91C_US_TXEN); /*Enable Rx & Tx*/ AT91C_SIO_REG_WRITE(pChan, AT91C_US_IER, AT91C_US_RXRDY |AT91C_US_TXRDY); /*Enable Rx & Tx interrupt*/ intEnable(pChan->intLevel); } else { AT91C_SIO_REG_WRITE(pChan, AT91C_US_CR,AT91C_US_RSTRX | AT91C_US_RSTTX); /*Reset RX & TX*/ AT91C_SIO_REG_WRITE(pChan, AT91C_US_CR, AT91C_US_RXEN |AT91C_US_TXEN); /*Enable Rx & Tx*/ intDisable (pChan->intLevel); } return (OK); }/********************************************************************************* at91cHup - hang up the modem control lines ** Resets the RTS and DTR signals.** RETURNS: OK*/LOCAL STATUS at91cHup ( AT91C_CHAN * pChan /* pointer to channel */ ) { FAST int oldlevel; /* current interrupt level mask */ oldlevel = intLock (); /* set RTS and DTR low */ /*AT91C_SIO_REG_WRITE(pChan, AT91C_US_CR, AT91C_US_RTSDIS | AT91C_US_DTRDIS); */ intUnlock (oldlevel); return (OK); } /********************************************************************************* at91cOpen - Set the modem control lines ** Set the modem control lines(RTS, DTR) TRUE if not already set. ** RETURNS: OK*/LOCAL STATUS at91cOpen ( AT91C_CHAN * pChan /* pointer to channel */ ) { FAST int oldlevel; /* current interrupt level mask */ oldlevel = intLock (); /* set RTS and DTR active *//* AT91C_SIO_REG_WRITE(pChan, AT91C_US_CR, AT91C_US_RTSEN | AT91C_US_DTREN); */ intUnlock (oldlevel); return (OK); }/******************************************************************************** at91cOptSet - 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 at91cOptSet ( AT91C_CHAN * pChan, /* channel */ uint_t newOpts /* new options */ ) { UINT32 dataBits = AT91C_US_CHRL_8_BITS; UINT32 stopBits = AT91C_US_NBSTOP_1_BIT; BOOL hdweFlowCtrl=TRUE; BOOL rcvrEnable = TRUE; int lvl; UINT32 temp=AT91C_US_PAR_NONE; UINT32 result; if (pChan == NULL || newOpts & 0xffffff00) return EIO; /* do nothing if options already set */ if (pChan->options == newOpts) return OK; /* ignore requests for unsupported options */ /* decode individual request elements */ switch (newOpts & CSIZE) { case CS5: dataBits = AT91C_US_CHRL_5_BITS; break; case CS6: dataBits = AT91C_US_CHRL_6_BITS; break; case CS7: dataBits = AT91C_US_CHRL_7_BITS; break; default: case CS8: dataBits = AT91C_US_CHRL_8_BITS; break; } if (newOpts & STOPB) stopBits = AT91C_US_NBSTOP_2_BIT; else stopBits = AT91C_US_NBSTOP_1_BIT; switch (newOpts & (PARENB|PARODD)) { case PARENB|PARODD: /* enable odd parity */ temp=AT91C_US_PAR_ODD; break; case PARENB: /* enable even parity */ temp=AT91C_US_PAR_EVEN; break; case PARODD: /* invalid mode, not normally used. */ break; default: case 0: temp=AT91C_US_PAR_NONE ;/* no parity */ break; } if (newOpts & CLOCAL) { /* clocal disables hardware flow control */ hdweFlowCtrl = FALSE; } if ((newOpts & CREAD) == 0) rcvrEnable = FALSE; lvl = intLock (); /* * Reset the device according to dataBits, stopBits, hdweFlowCtrl, * rcvrEnable, and parity selections. */ /* AT91C_SIO_REG_READ(pChan, AT91C_US_MR, result); AT91C_SIO_REG_WRITE(pChan,AT91C_US_MR,(result|dataBits|temp|stopBits));*/ AT91C_SIO_REG_WRITE(pChan,AT91C_US_CR,AT91C_US_RSTRX | AT91C_US_RSTTX);/*RESET*/ AT91C_SIO_REG_WRITE(pChan,AT91C_US_CR,AT91C_US_RXEN | AT91C_US_TXEN); /*TX&RX ENABLE*/ AT91C_SIO_REG_WRITE(pChan,AT91C_US_MR,(dataBits|temp|stopBits)); intUnlock (lvl); pChan->options = newOpts; return (OK); }/********************************************************************************* at91cIoctl - special device control** This routine handles the IOCTL messages from the user. It supports commands * to get/set baud rate, mode(INT,POLL), hardware options(parity, number of * data bits) and modem control(RTS/CTS and DTR/DSR handshakes).* The ioctl commands SIO_HUP and SIO_OPEN are used to implement the HUPCL(hang* up on last close) function.** As on a UNIX system, requesting a baud rate of zero is translated into* a hangup request. The DTR and RTS lines are dropped. This should cause* a connected modem to drop the connection. The SIO_HUP command will only* hangup if the HUPCL option is active. The SIO_OPEN function will raise* DTR and RTS lines whenever it is called. Use the BAUD_RATE=0 function* to hangup when HUPCL is not active.** The CLOCAL option will disable hardware flow control. When selected,* hardware flow control is not used. When not selected hardware flow control* is based on the RTS/CTS signals. CTS is the clear to send input* from the other end. It must be true for this end to begin sending new* characters. In most drivers, the RTS signal will be assumed to be connected* to the opposite end's CTS signal and can be used to control output from* the other end. Raising RTS asserts CTS at the other end and the other end* can send data. Lowering RTS de-asserts CTS and the other end will stop* sending data. (This is non-EIA defined use of RTS).** RETURNS: OK on success, ENOSYS on unsupported request, EIO on failed* request.*/LOCAL int at91cIoctl ( SIO_CHAN * pSioChan, /* device to control */ int request, /* request code */ void * someArg /* some argument */ ) { AT91C_CHAN *pChan = (AT91C_CHAN *) pSioChan; int oldlevel; /* current interrupt level mask */ int arg = (int)someArg; switch (request) { case SIO_BAUD_SET: /* * like unix, a baud request for 0 is really a request to * hangup. */ if (arg == 0) return at91cHup (pChan); /* * Set the baud rate. Return EIO for an invalid baud rate, or * OK on success. */ if (arg < AT91C_BAUD_MIN || arg > AT91C_BAUD_MAX) { return (EIO); } /* Calculate the baud rate constant for the new baud rate */ switch(arg) { case 1200: /* disable interrupts during chip access */ oldlevel = intLock (); AT91C_SIO_REG_WRITE(pChan,AT91C_US_BRGR, AT91C_CD_1200); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 2400: /* disable interrupts during chip access */ oldlevel = intLock (); AT91C_SIO_REG_WRITE(pChan,AT91C_US_BRGR, AT91C_CD_2400); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 4800: /* disable interrupts during chip access */ oldlevel = intLock (); AT91C_SIO_REG_WRITE(pChan,AT91C_US_BRGR, AT91C_CD_4800); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 9600: /* disable interrupts during chip access */ oldlevel = intLock (); AT91C_SIO_REG_WRITE(pChan,AT91C_US_BRGR,AT91C_CD_9600); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 19200: /* disable interrupts during chip access */ oldlevel = intLock (); AT91C_SIO_REG_WRITE(pChan,AT91C_US_BRGR,AT91C_CD_19200); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 38400: /* disable interrupts during chip access */ oldlevel = intLock (); AT91C_SIO_REG_WRITE(pChan,AT91C_US_BRGR,AT91C_CD_38400); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 57600: /* disable interrupts during chip access */ oldlevel = intLock (); AT91C_SIO_REG_WRITE(pChan,AT91C_US_BRGR,AT91C_CD_57600); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 115200: /* disable interrupts during chip access */ oldlevel = intLock (); AT91C_SIO_REG_WRITE(pChan,AT91C_US_BRGR,AT91C_CD_115200); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); case 230400: /* disable interrupts during chip access */ oldlevel = intLock (); AT91C_SIO_REG_WRITE(pChan,AT91C_US_BRGR,AT91C_CD_230400); intUnlock (oldlevel); pChan->baudRate=arg; return (OK);#if 0 case 460800: /* disable interrupts during chip access */ oldlevel = intLock (); AT91C_SIO_REG_WRITE(pChan,AT91C_US_BRGR, ); intUnlock (oldlevel); pChan->baudRate=arg; return (OK); #endif default: return(EIO); } break; case SIO_BAUD_GET: /* Get the baud rate and return OK */ *(int *)arg = pChan->baudRate; break; case SIO_MODE_SET: /* * Set the mode (e.g., to interrupt or polled). Return OK * or EIO for an unknown or unsupported mode. */ return (at91cModeSet (pChan, arg)); case SIO_MODE_GET: /* Get the current mode and return OK. */ *(int *)arg = pChan->mode; return (OK); case SIO_AVAIL_MODES_GET: /* Get the available modes and return OK. */ *(int *)arg = SIO_MODE_INT | SIO_MODE_POLL; return (OK); 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. */ return (at91cOptSet (pChan, arg)); 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). */ *(int *)arg = pChan->options; return (OK); case SIO_HUP: /* check if hupcl option is enabled */ if (pChan->options & HUPCL) return (at91cHup (pChan)); return (OK); case SIO_OPEN: return (at91cOpen (pChan)); /* always open */ default: return (ENOSYS); } return (ENOSYS); }/********************************************************************************* dummyCallback - dummy callback routine** RETURNS: ERROR.*/LOCAL STATUS dummyCallback (void) { return (ERROR); }#if 0void myDelay(){ int i; *(volatile UINT32 *)0xfffff800 = 0x35; *(volatile UINT32 *)0xfffff810 = 0x35; while(1) { *(volatile UINT32 *)0xfffff834 = 0x35;/*lit*/ for(i=0;i<1000000;i++); *(volatile UINT32 *)0xfffff830 = 0x35; for(i=0;i<1000000;i++); }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -