uartsup.h
上传用户:poi891205
上传日期:2013-07-15
资源大小:9745k
文件大小:5k
源码类别:

DVD

开发平台:

C/C++

  1. /*
  2. ** FILE
  3. ** uartsup.h
  4. **
  5. ** DESCRIPTION
  6. ** UART debugging support function
  7. **
  8. ** NOTE
  9. ** These inline functions are standalone and use only register file access.
  10. ** Important for debugging.
  11. */
  12. #ifndef __UARTSUP_H
  13. #define __UARTSUP_H
  14. // LSR 0: tx-rdy 1: tx-fifo not-full
  15. // 1: rx-rdy 1: rx-fifo not-empty
  16. #define UART_LSR_TX_RDY     (1<<0)
  17. #define UART_LSR_RX_RDY     (1<<1)
  18. #define UART_TX_EMPTY       (1<<6)
  19. #define UART_RX_EMPTY       (1<<7)
  20. #define UART0_tx_rdy() (regs0->uart0_lsr & UART_LSR_TX_RDY)
  21. #define UART0_rx_rdy() (regs0->uart0_lsr & UART_LSR_RX_RDY)
  22. #define UART0_tx_empty() (regs0->uart0_lsr & UART_TX_EMPTY)
  23. #define UART0_putc_nw(c)        (regs0->uart0_data = (c))
  24. #define UART1_tx_rdy() (regs0->uart1_lsr & UART_LSR_TX_RDY)
  25. #define UART1_rx_rdy() (regs0->uart1_lsr & UART_LSR_RX_RDY)
  26. #define UART1_tx_empty() (regs0->uart1_lsr & UART_TX_EMPTY)
  27. #define UART1_putc_nw(c)        (regs0->uart1_data = (c))
  28. // UART0
  29. #define UART0_wait()            do { while (!UART0_tx_rdy()) ; } while (0)
  30. #define UART0_flush()           do { while (!UART0_tx_empty()) ; } while (0)
  31. #define UART0_putc(c)           do { UART0_wait(); UART0_putc_nw(c); } while (0)
  32. #define UART0_putc_nl(c)        do { UART0_putc(c); if (c==0x0a) UART0_putc(0x0d); } while (0)
  33. #define UART0_puthex(c) do {                            
  34.                                     int __i;
  35.                                     unsigned __v = (c);
  36.                                     for (__i=0;__i<8;__i++)
  37.                                     {                           
  38.                                         UART0_putc(radix_table[(__v>>28)&0x0f]); 
  39.                                         __v <<= 4;              
  40.                                     }                           
  41. } while (0)
  42. #define UART0_puthex4(c) do {                            
  43.                                     int __i;                    
  44.                                     unsigned __v = (unsigned)(c); 
  45.                                     for (__i=0;__i<4;__i++)     
  46.                                     {
  47.                                         UART0_putc(radix_table[(__v>>12)&0x0f]); 
  48.                                         __v <<= 4;              
  49.                                     }                           
  50.                                 } while (0)
  51. #define UART0_puthex2(c) do {                            
  52.                                     unsigned __v = (unsigned)(c); 
  53.                                     UART0_putc(radix_table[(__v>>4)&0x0f]); 
  54.                                     UART0_putc(radix_table[(__v>>0)&0x0f]); 
  55.                                 } while (0)
  56. #define UART0_puts(s) do {
  57.                                     int __c;
  58.                                     const char *__s = (const char *)(s); 
  59.                                     while ((__c=*__s++))
  60.                                     {
  61.                                         UART0_putc_nl(__c);     
  62.                                     }
  63.                                 } while (0)
  64. // UART1
  65. #define UART1_wait()            do { while (!UART1_tx_rdy()) ; } while (0)
  66. #define UART1_flush()           do { while (!UART1_tx_empty()) ; } while (0)
  67. #define UART1_putc(c)           do { UART1_wait(); UART1_putc_nw(c); } while (0)
  68. #define UART1_puthex(c) do {                            
  69.                                     int __i;
  70.                                     unsigned __v = (c);
  71.                                     for (__i=0;__i<8;__i++)
  72.                                     {                           
  73.                                         UART1_putc(radix_table[(__v>>28)&0x0f]); 
  74.                                         __v <<= 4;              
  75.                                     }                           
  76. } while (0)
  77. #define UART1_puthex4(c) do {                            
  78.                                     int __i;                    
  79.                                     unsigned __v = (c);         
  80.                                     for (__i=0;__i<4;__i++)     
  81.                                     {
  82.                                         UART1_putc(radix_table[(__v>>12)&0x0f]); 
  83.                                         __v <<= 4;              
  84.                                     }                           
  85.                                 } while (0)
  86. #define UART1_puthex2(c) do {                            
  87.                                     unsigned __v = (unsigned)(c); 
  88.                                     UART1_putc(radix_table[(__v>>4)&0x0f]); 
  89.                                     UART1_putc(radix_table[(__v>>0)&0x0f]); 
  90.                                 } while (0)
  91. #define UART1_puts(s) do {
  92.                                     int __c;
  93.                                     const char *__s = (const char *)(s); 
  94.                                     while ((__c=*__s++))
  95.                                     {
  96.                                         UART1_putc(__c);        
  97.                                         if (__c==0x0a) UART1_putc(0x0d); 
  98.                                     }
  99.                                 } while (0)
  100. #endif /*__UARTSUP_H*/