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

📄 z16f_serial.c

📁 這是一個實時嵌入式作業系統 實作了MCS51 ARM等MCU
💻 C
📖 第 1 页 / 共 2 页
字号:
 *   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 z16f_detach(struct uart_dev_s *dev){  struct z16f_uart_s *priv = (struct z16f_uart_s*)dev->priv;  up_disable_irq(priv->rxirq);  up_disable_irq(priv->txirq);  irq_detach(priv->rxirq);  irq_detach(priv->txirq);}/**************************************************************************** * Name: z16f_rxinterrupt * * Description: *   This is the UART interrupt handler.  It will be invoked when an RX *   event occurs at the Z16F's LIN-UART. * ****************************************************************************/static int z16f_rxinterrupt(int irq, void *context){  struct uart_dev_s  *dev = NULL;  struct z16f_uart_s *priv;  ubyte              status;  if (g_uart1priv.rxirq == irq)    {      dev = &g_uart1port;    }  else if (g_uart0priv.rxirq == irq)    {      dev = &g_uart0port;    }  else    {      PANIC(OSERR_INTERNAL);    }  priv = (struct z16f_uart_s*)dev->priv;  /* Check the LIN-UART status 0 register to determine whether the source of   * the interrupt is error, break, or received data   */  status = getreg8(priv->uartbase + Z16F_UART_STAT0);  /* REVISIT error and break handling */  /* Check if received data is available  */  if (status & Z16F_UARTSTAT0_RDA)    {      /* Handline an incoming, receive byte */      uart_recvchars(dev);    }  return OK;}/**************************************************************************** * Name: z16f_txinterrupt * * Description: *   This is the UART TX interrupt handler.  This interrupt handler will *   be invoked when the X16F LIN UART transmit data register is empty. * ****************************************************************************/static int z16f_txinterrupt(int irq, void *context){  struct uart_dev_s  *dev = NULL;  struct z16f_uart_s *priv;  ubyte              status;  if (g_uart1priv.txirq == irq)    {      dev = &g_uart1port;    }  else if (g_uart0priv.txirq == irq)    {      dev = &g_uart0port;    }  else    {      PANIC(OSERR_INTERNAL);    }  priv = (struct z16f_uart_s*)dev->priv;  /* Verify that the transmit data register is empty */  status = getreg8(priv->uartbase + Z16F_UART_STAT0);  if (status & Z16F_UARTSTAT0_TDRE)    {      /* Handle outgoing, transmit bytes */      uart_xmitchars(dev);    }  return OK;}/**************************************************************************** * Name: z16f_ioctl * * Description: *   All ioctl calls will be routed through this method * ****************************************************************************/static int z16f_ioctl(struct file *filep, int cmd, unsigned long arg){  *get_errno_ptr() = ENOTTY;  return ERROR;}/**************************************************************************** * Name: z16f_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 *   return 'status'. * ****************************************************************************/static int z16f_receive(struct uart_dev_s *dev, uint32 *status){  struct z16f_uart_s *priv = (struct z16f_uart_s*)dev->priv;  ubyte  rxd;  ubyte  stat0;  rxd     = getreg8(priv->uartbase + Z16F_UART_RXD);  stat0   = getreg8(priv->uartbase + Z16F_UART_STAT0);  *status = (uint32)rxd | (((uint32)stat0) << 8);  return rxd;}/**************************************************************************** * Name: z16f_rxint * * Description: *   Call to enable or disable RX interrupts * ****************************************************************************/static void z16f_rxint(struct uart_dev_s *dev, boolean enable){  struct z16f_uart_s *priv  = (struct z16f_uart_s*)dev->priv;  irqstate_t          flags = irqsave();  if (enable)    {#ifndef CONFIG_SUPPRESS_SERIAL_INTS      up_enable_irq(priv->rxirq);#endif    }  else    {      up_disable_irq(priv->rxirq);    }  priv->rxenabled = enable;  irqrestore(flags);}/**************************************************************************** * Name: z16f_rxavailable * * Description: *   Return TRUE if the receive fifo is not empty * ****************************************************************************/static boolean z16f_rxavailable(struct uart_dev_s *dev){  struct z16f_uart_s *priv = (struct z16f_uart_s*)dev->priv;  return ((getreg8(priv->uartbase + Z16F_UART_STAT0) & Z16F_UARTSTAT0_RDA) != 0);}/**************************************************************************** * Name: z16f_send * * Description: *   This method will send one byte on the UART * ****************************************************************************/static void z16f_send(struct uart_dev_s *dev, int ch){  struct z16f_uart_s *priv = (struct z16f_uart_s*)dev->priv;  putreg8(ch, priv->uartbase + Z16F_UART_TXD);}/**************************************************************************** * Name: z16f_txint * * Description: *   Call to enable or disable TX interrupts * ****************************************************************************/static void z16f_txint(struct uart_dev_s *dev, boolean enable){  struct z16f_uart_s *priv  = (struct z16f_uart_s*)dev->priv;  irqstate_t          flags = irqsave();  if (enable)    {#ifndef CONFIG_SUPPRESS_SERIAL_INTS      up_enable_irq(priv->txirq);#endif    }  else    {      up_disable_irq(priv->txirq);    }  priv->txenabled = enable;  irqrestore(flags);}/**************************************************************************** * Name: z16f_txready * * Description: *   Return TRUE if the tranmsit fifo is not full * ****************************************************************************/static boolean z16f_txready(struct uart_dev_s *dev){  struct z16f_uart_s *priv = (struct z16f_uart_s*)dev->priv;  return ((getreg8(priv->uartbase + Z16F_UART_STAT0) & Z16F_UARTSTAT0_TDRE) != 0);}/**************************************************************************** * Name: z16f_txempty * * Description: *   Return TRUE if the transmit fifo is empty * ****************************************************************************/static boolean z16f_txempty(struct uart_dev_s *dev){  struct z16f_uart_s *priv = (struct z16f_uart_s*)dev->priv;  return ((getreg8(priv->uartbase + Z16F_UART_STAT0) & Z16F_UARTSTAT0_TXE) != 0);}/**************************************************************************** * Public Funtions ****************************************************************************//**************************************************************************** * Name: up_earlyserialinit * * 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 z16f_serialinit. * ****************************************************************************/void up_earlyserialinit(void){  (void)z16f_disableuartirq(&TTYS0_DEV);  (void)z16f_disableuartirq(&TTYS1_DEV);  CONSOLE_DEV.isconsole = TRUE;  z16f_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){  ubyte  state;  /* Keep interrupts disabled so that we do not interfere with normal   * driver operation    */  state = z16f_disableuartirq(&CONSOLE_DEV);  /* Check for LF */  if (ch == '\n')    {      /* Add CR before LF */      z16f_consoleput('\r');    }  /* Output the character */  z16f_consoleput((ubyte)ch);  /* It is important to restore the TX interrupt while the send is pending.   * otherwise, TRDE interrupts can be lost since they do not pend after the   * TRDE false->true transition.   */  z16f_restoreuartirq(&CONSOLE_DEV, state);  return ch;}#else /* CONFIG_USE_SERIALDRIVER *//**************************************************************************** * Definitions ****************************************************************************/#ifdef CONFIG_UART1_SERIAL_CONSOLE# define z16f_contrde() \  ((getreg8(Z16F_UART1_STAT0) & Z16F_UARTSTAT0_TDRE) != 0)# define z16f_contxd(ch) \  putreg8((ubyte)(ch), Z16F_UART1_TXD)#else# define z16f_contrde() \  ((getreg8(Z16F_UART0_STAT0) & Z16F_UARTSTAT0_TDRE) != 0)# define z16f_contxd(ch) \  putreg8((ubyte)(ch), Z16F_UART0_TXD)#endif/**************************************************************************** * Private Function Prototypes ****************************************************************************//**************************************************************************** * Private Variables ****************************************************************************//**************************************************************************** * Private Functions ****************************************************************************//**************************************************************************** * Name: z16f_putc ****************************************************************************/static void z16f_putc(int ch){  int tmp;  for (tmp = 1000 ; tmp > 0 && !z16f_contrde(); tmp--);  z16f_contxd(ch);}/**************************************************************************** * Public Functions ****************************************************************************//**************************************************************************** * Name: up_putc ****************************************************************************/int up_putc(int ch){  /* Check for LF */  if (ch == '\n')    {      /* Output CR before LF */      z16f_putc('\r');    }  /* Output character */  z16f_putc(ch);  return ch;}#endif /* CONFIG_USE_SERIALDRIVER */

⌨️ 快捷键说明

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