📄 at91uart.c
字号:
/* return (at91Hup (pChan)); */ /* * Set the baud rate. Return EIO for an invalid baud rate, or * OK on success. */ if (arg < AT91_BAUD_MIN || arg > AT91_BAUD_MAX) { return (EIO); } /* Calculate the baud rate constant for the new baud rate */ baudConstant = AT91_MASTER_CLOCK / arg / 16; /* disable interrupts during chip access */ oldLevel = intLock (); pUsart->US_BRGR = baudConstant; intUnlock (oldLevel); pParas->baudRate = arg; return (OK); case SIO_BAUD_GET: *(int *)someArg = pParas->baudRate; return (OK); case SIO_MODE_SET: /* * Set the mode (e.g., to interrupt or polled). Return OK * or EIO for an unknown or unsupported mode. */ return (at91ModeSet (pChan, arg)); case SIO_MODE_GET: /* Get the current mode and return OK. */ *(int *)someArg = pChan->mode; return (OK); case SIO_AVAIL_MODES_GET: /* TODO - set the available modes and return OK. */ *(int *)someArg = 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 (at91OptSet (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 *)someArg = pChan->options; return (OK); #if 0 case SIO_HUP: /* check if hupcl option is enabled */ if (pChan->options & HUPCL) return (at91Hup (pChan)); return (OK); case SIO_OPEN: return (at91Open (pChan)); /* always open */#endif#if 0 /* TODO - optional modem control line support */ /* * These new ioctl commands are for monitoring and setting the * state of the modem control lines under user control. The * return values from these calls inform the user about which * control lines are inputs and which are outputs. Basically * this lets the user know if the device is wired for DTE or * DCE configuration. It also informs the user if any signals * are missing altogether. */ case SIO_MSTAT_GET: return templateMstatGet(pChan); case SIO_MCTRL_BITS_SET: return templateMstatSetClr (pChan, arg, TRUE); case SIO_MCTRL_BITS_CLR: return templateMstatSetClr (pChan, arg, FALSE); /* * The ISIG and OSIG masks tell the user which signals are actually * outputs and which aren't. In our case here, we assume the device * is DTE mapped with DTR and RTS as outputs. DSR and CTS as inputs. * This template driver doesn't support RI. */ case SIO_MCTRL_OSIG_MASK: *(int *)someArg = TEMPLATE_OSIG_MASK; break; case SIO_MCTRL_ISIG_MASK: *(int *)someArg = TEMPLATE_ISIG_MASK; break;#endif /* optional Modem control line support */#if 0 /* TODO - optional keyboard scan code support */ /* * The following new ioctl commands are meant only for keyboard * input devices to use. These allow the user to specify and * examine the type of keyboard character mapping to use. The * possible types are NONE (raw scan codes), ASCII (default ascii * mappings, and UNICODE for standard 16 bit unicode mappings. * * Our template driver supports only raw and ascii modes. */ case SIO_KYBD_MODE_SET: switch (arg) { case SIO_KYBD_MODE_RAW: case SIO_KYBD_MODE_ASCII: break; case SIO_KYBD_MODE_UNICODE: return ENOSYS; /* template doesn't support unicode */ } pChan->scanMode = arg; return OK; case SIO_KYBD_MODE_GET: *(int *)someArg = pChan->scanMode; return OK;#endif /* optional keyboard scan code support */ default: return ENOSYS; } return OK; }/********************************************************************************* dummyTxCallback - dummy Tx callback routine** RETURNS: ERROR.*/LOCAL STATUS at91DummyTxCallback ( void * callbackArg, /* argument registered with callback */ char * pChara /* ptr to data location */ ) { static BOOL doit = TRUE; /* * TODO - Until an upstream module connects to this device, there * is no data available to send. We should only be concerned * if this callback is being called repeatedly and often. That * could indicate an interrupt servicing problem of some kind. */ if (doit) { printf ("Dummy txCallback: 0x%x 0x%x\n", (int)callbackArg, (int)pChara); doit = FALSE; } return (ERROR); }/********************************************************************************* dummyRxCallback - dummy Rx callback routine** RETURNS: N/A.* ARGSUSED*/LOCAL void at91DummyRxCallback ( void * callbackArg, /* argument registered with callback */ char data /* receive data */ ) { static BOOL doit = TRUE; /* * TODO - Device is transferring data, but there is no * upstream module connected to receive it. Lets log * a message about incoming data being lost. Buts lets * do this only once we don't want a 'flood' of logged * messages. */ if (doit) { printf ("Dummy rxCallback: 0x%x 0x%x\n", (int)callbackArg, (int)data); doit = FALSE; } return; }/********************************************************************************* dummyErrCallback - dummy Error callback routine** There should be an sioLib module to provide dummyCallbacks for all SIO* drivers to use.** RETURNS: N/A.* ARGSUSED*/LOCAL void at91DummyErrCallback ( void * callbackArg, /* argument registered with callback */ int errorCode, /* error code */ void * pData, /* ptr to device specific data */ int size /* size of device specific data */ ) { static BOOL doit = TRUE; /* TODO - We could log the reported error (once). */ if (doit) { printf ("Dummy errorCallback: 0x%x 0x%x 0x%x %d\n", (int)callbackArg, errorCode, (int)pData, size); doit = FALSE; } return; }/********************************************************************************* at91Probe - probe for device ** Try to determine if device is present. Do not reconfigure device if it* is there. This should be a passive probe that does not interfere with* the device.** RETURNS:* Returns OK if device adaptor is there, ERROR if not there.*/LOCAL STATUS at91Probe ( AT91_UART_CHAN * pChan /* channel to probe */ ) { /* * the UART and DBGU is internal controller of AT91RM9200 CPU, * so we needn't to probe it */ return OK; }#if 0/********************************************************************************* at91Verify - verify at91_uart chan structure** Given a pointer to what should be a AT91_UART_CHAN, verify that it really* is a AT91_UART_CHAN structure.** This routine should not be called at every level with every routine. It is* primarily provided for use with the xxxDestroy routine. Performance will be* a problem if every pointer is checked for validity with every use.** RETURNS:* Returns OK if pointer is valid, ERROR if not.*/LOCAL STATUS at91Verify ( AT91_UART_CHAN * pChan /* pointer to be verified */ ) { /* * Examine the structure. Look for magic cookies or flag bits. * Anything that would confirm this pointer as being a valid * AT91_UART_CHAN pointer. */ if (pChan == NULL) return ERROR; return OK; }#endif#if 0 /* Optional modem control line support *//********************************************************************************* at91MstatGet - read device modem control line status** Read the device modem control lines and map them to the standard* modem signal bits.** RETURNS:* Returns the modem control line status bits.*/LOCAL int at91MstatGet ( AT91_UART_CHAN *pChan ) { AT91_UART_CHAN * pChan = (AT91_UART_CHAN *)pSioChan; UINT32 status; int result = 0; AT91PS_USART pUsart; /* point to UART register index by ioBase of pChan */ pUsart = (AT91PS_USART)(pChan->ioBase); /* Read RX device status */ status = pUsart->US_CSR; /* Now map device status bits, to standard status bits */ if (rawStatus & TEMPLATE_MSR_CD) result |= SIO_MODEM_CD; if (rawStatus & TEMPLATE_MSR_DTR) result |= SIO_MODEM_DTR; if (rawStatus & TEMPLATE_MSR_DSR) result |= SIO_MODEM_DSR; if (rawStatus & TEMPLATE_MSR_RTS) result |= SIO_MODEM_RTS; if (rawStatus & TEMPLATE_MSR_CTS) result |= SIO_MODEM_CTS; return result; }/********************************************************************************* templateMstatSetClear - set/clear modem control lines** This routine allows the user to set or clear individual modem control* lines. Of course, only the output lines can actually be changed.** RETURNS:* OK, or EIO upon detecting a hardware fault.*/LOCAL int templateMstatSetClr ( TEMPLATE_CHAN *pChan, UINT bits, /* bits to change */ BOOL setFlag /* TRUE = set, FALSE = clear */ ) { UINT8 rawStatus; UINT8 rawMask = 0; /* Read current modem status */ TEMPLATE_SIO_READ8 (pChan, TEMPLATE_MSR_ID, &rawStatus); /* ignore input only bits */ bits &= TEMPLATE_OSIG_MASK; /* Now map standard bits to device specific bits */ if (bits & SIO_MODEM_DTR) rawMask |= TEMPLATE_MSR_DTR; if (bits & SIO_MODEM_RTS) rawMask |= TEMPLATE_MSR_RTS; /* Update device with new output signals */ if (setFlag) rawStatus |= rawMask; /* set new bits */ else rawStatus &= ~rawMask; /* clear bits */ TEMPLATE_SIO_WRITE8 (pChan, TEMPLATE_MSR_ID, rawStatus); return OK; }#endif /* optional modem control line support */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -