⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ez80_serial.c

📁 這是一個實時嵌入式作業系統 實作了MCS51 ARM等MCU
💻 C
📖 第 1 页 / 共 2 页
字号:
 *   Disable the UART.  This method is called when the serial port is closed * ****************************************************************************/static void ez80_shutdown(struct uart_dev_s *dev){  struct ez80_dev_s *priv = (struct ez80_dev_s*)CONSOLE_DEV.priv;  ez80_disableuartint(priv);}/**************************************************************************** * Name: ez80_attach * * Description: *   Configure the UART to operation in interrupt driven mode.  This method is *   called when the serial port is opened.  Normally, this is just after the *   the setup() method is called, however, the serial console may operate in *   a non-interrupt driven mode during the boot phase. * *   RX and TX interrupts are not enabled when by the attach method (unless the *   hardware supports multiple levels of interrupt enabling).  The RX and TX *   interrupts are not enabled until the txint() and rxint() methods are called. * ****************************************************************************/static int ez80_attach(struct uart_dev_s *dev){  struct ez80_dev_s *priv = (struct ez80_dev_s*)dev->priv;  /* Attach the IRQ */  return irq_attach(priv->irq, ez80_interrrupt);}/**************************************************************************** * Name: ez80_detach * * Description: *   Detach UART interrupts.  This method is called when the serial port is *   closed normally just before the shutdown method is called.  The exception is *   the serial console which is never shutdown. * ****************************************************************************/static void ez80_detach(struct uart_dev_s *dev){  struct ez80_dev_s *priv = (struct ez80_dev_s*)dev->priv;  ez80_disableuartint(priv);  irq_detach(priv->irq);}/**************************************************************************** * Name: ez80_interrrupt * * Description: *   This is the UART interrupt handler.  It will be invoked *   when an interrupt received on the 'irq'  It should call *   uart_transmitchars or uart_receivechar to perform the *   appropriate data transfers.  The interrupt handling logic\ *   must be able to map the 'irq' number into the approprite *   uart_dev_s structure in order to call these functions. * ****************************************************************************/static int ez80_interrrupt(int irq, void *context){  struct uart_dev_s *dev = NULL;  struct ez80_dev_s   *priv;  volatile uint32    cause;  if (g_uart0priv.irq == irq)    {      dev = &g_uart0port;    }  else if (g_uart1priv.irq == irq)    {      dev = &g_uart1port;    }  else    {      PANIC(OSERR_INTERNAL);    }  priv = (struct ez80_dev_s*)dev->priv;  cause = ez80_serialin(priv, EZ80_UART_IIR) & EZ80_UARTIIR_CAUSEMASK;  if (cause == (EZ80_UARTINSTS_CTO|EZ80_UARTIIR_INTBIT) ||      cause == (EZ80_UARTINSTS_RDR|EZ80_UARTIIR_INTBIT))    {      /* Receive characters from the RX fifo */      uart_recvchars(dev);    }  else if (cause == (EZ80_UARTINSTS_TC|EZ80_UARTIIR_INTBIT))    {      uart_xmitchars(dev);    }  return OK;}/**************************************************************************** * Name: ez80_ioctl * * Description: *   All ioctl calls will be routed through this method * ****************************************************************************/static int ez80_ioctl(struct file *filep, int cmd, unsigned long arg){  *get_errno_ptr() = ENOTTY;  return ERROR;}/**************************************************************************** * Name: ez80_receive * * Description: * Called (usually) from the interrupt level to receive one character from * the UART.  Error bits associated with the receipt are provided in the * the return 'status'. * ****************************************************************************/static int ez80_receive(struct uart_dev_s *dev, unsigned int *status){  struct ez80_dev_s *priv = (struct ez80_dev_s*)dev->priv;  ubyte rbr = ez80_serialin(priv, EZ80_UART_RBR);  ubyte lsr = ez80_serialin(priv, EZ80_UART_LSR);  *status = (unsigned int)lsr;  return rbr;}/**************************************************************************** * Name: ez80_rxint * * Description: *   Call to enable or disable RX interrupts * ****************************************************************************/static void ez80_rxint(struct uart_dev_s *dev, boolean enable){  struct ez80_dev_s *priv = (struct ez80_dev_s*)dev->priv;  ubyte ier = ez80_serialin(priv, EZ80_UART_IER);    if (enable)    {#ifndef CONFIG_SUPPRESS_SERIAL_INTS      ier |= EZ80_UARTEIR_RIE;      ez80_serialout(priv, EZ80_UART_IER, ier);#endif    }  else    {      ier &= ~EZ80_UARTEIR_RIE;      ez80_serialout(priv, EZ80_UART_IER, ier);    }}/**************************************************************************** * Name: ez80_rxavailable * * Description: *   Return TRUE if the receive fifo is not empty * ****************************************************************************/static boolean ez80_rxavailable(struct uart_dev_s *dev){  struct ez80_dev_s *priv = (struct ez80_dev_s*)dev->priv;  return (ez80_serialin(priv, EZ80_UART_LSR) & EZ80_UARTLSR_DR) != 0;}/**************************************************************************** * Name: ez80_send * * Description: *   This method will send one byte on the UART * ****************************************************************************/static void ez80_send(struct uart_dev_s *dev, int ch){  struct ez80_dev_s *priv = (struct ez80_dev_s*)dev->priv;  ez80_serialout(priv, EZ80_UART_THR, (ubyte)ch);}/**************************************************************************** * Name: ez80_txint * * Description: *   Call to enable or disable TX interrupts * ****************************************************************************/static void ez80_txint(struct uart_dev_s *dev, boolean enable){  struct ez80_dev_s *priv = (struct ez80_dev_s*)dev->priv;  ubyte ier = ez80_serialin(priv, EZ80_UART_IER);  if (enable)    {#ifndef CONFIG_SUPPRESS_SERIAL_INTS      ier |= EZ80_UARTEIR_TIE;      ez80_serialout(priv, EZ80_UART_IER, ier);#endif    }  else    {      ier &= ~EZ80_UARTEIR_TIE;      ez80_serialout(priv, EZ80_UART_IER, ier);    }}/**************************************************************************** * Name: ez80_txready * * Description: *   Return TRUE if the tranmsit fifo is not full * ****************************************************************************/static boolean ez80_txready(struct uart_dev_s *dev){  struct ez80_dev_s *priv = (struct ez80_dev_s*)dev->priv;  return (ez80_serialin(priv, EZ80_UART_LSR) & EZ80_UARTLSR_THRE) != 0;}/**************************************************************************** * Name: ez80_txempty * * Description: *   Return TRUE if the transmit fifo is empty * ****************************************************************************/static boolean ez80_txempty(struct uart_dev_s *dev){  struct ez80_dev_s *priv = (struct ez80_dev_s*)dev->priv;  return (ez80_serialin(priv, EZ80_UART_LSR) & EZ80_UARTLSR_TEMT) != 0;}/**************************************************************************** * Public Functions ****************************************************************************//**************************************************************************** * Name: up_serialinit * * Description: *   Performs the low level UART initialization early in  *   debug so that the serial console will be available *   during bootup.  This must be called before up_serialinit. * ****************************************************************************/void up_earlyserialinit(void){  ez80_disableuartint(TTYS0_DEV.priv);  ez80_disableuartint(TTYS1_DEV.priv);  CONSOLE_DEV.isconsole = TRUE;  ez80_setup(&CONSOLE_DEV);}/**************************************************************************** * Name: up_serialinit * * Description: *   Register serial console and serial ports.  This assumes *   that up_earlyserialinit was called previously. * ****************************************************************************/void up_serialinit(void){  (void)uart_register("/dev/console", &CONSOLE_DEV);  (void)uart_register("/dev/ttyS0", &TTYS0_DEV);  (void)uart_register("/dev/ttyS1", &TTYS1_DEV);}/**************************************************************************** * Name: up_putc * * Description: *   Provide priority, low-level access to support OS debug *   writes * ****************************************************************************/int up_putc(int ch){  struct ez80_dev_s *priv = (struct ez80_dev_s*)CONSOLE_DEV.priv;  ubyte ier = ez80_serialin(priv, EZ80_UART_IER);  ez80_disableuartint(priv);  /* Check for LF */  if (ch == '\n')    {      /* Output CR before LF*/      ez80_waittxready(priv);      ez80_serialout(priv, EZ80_UART_THR, '\r');    }  /* Output the character */  ez80_waittxready(priv);  ez80_serialout(priv, EZ80_UART_THR, (ubyte)ch);  /* Wait for the character to be sent before re-enabling interrupts */   ez80_waittxready(priv);  ez80_restoreuartint(priv, ier);  return ch;}#else /* CONFIG_USE_SERIALDRIVER *//**************************************************************************** * Definitions ****************************************************************************/#ifdef CONFIG_UART1_SERIAL_CONSOLE# define ez80_inp(offs)      inp((EZ80_UART1_BASE+(offs)))# define ez80_outp(offs,val) outp((EZ80_UART1_BASE+(offs)), (val))#else# define ez80_inp(offs)      inp((EZ80_UART0_BASE+(offs)))# define ez80_outp(offs,val) outp((EZ80_UART0_BASE+(offs)), (val))#endif#define ez80_txready() ((ez80_inp(EZ80_UART_LSR) & EZ80_UARTLSR_THRE) != 0)#define ez80_send(ch)  ez80_outp(EZ80_UART_THR, ch)/**************************************************************************** * Private Function Prototypes ****************************************************************************//**************************************************************************** * Private Variables ****************************************************************************//**************************************************************************** * Private Functions ****************************************************************************//**************************************************************************** * Name: ez80_putc ****************************************************************************/static void ez80_putc(int ch){  int tmp;  for (tmp = 1000 ; tmp > 0 && !ez80_txready(); tmp--);  ez80_send(ch);}/**************************************************************************** * Public Functions ****************************************************************************//**************************************************************************** * Name: up_putc ****************************************************************************/int up_putc(int ch){  /* Check for LF */  if (ch == '\n')    {      /* Output CR before LF */      ez80_putc('\r');    }  /* Output character */  ez80_putc(ch);  return ch;}#endif /* CONFIG_USE_SERIALDRIVER */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -