uart.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. uart.h: Definitions for the UART access routines
  3. */
  4. #ifndef UART_H
  5. #define UART_H
  6. #include <stdint.h>
  7. #include <stdio.h>
  8. #include "config.h"
  9. //#ifdef CONFIG_UART_DEBUG
  10. #if 1
  11. #ifdef __AVR__
  12. # include <avr/pgmspace.h>
  13. void uart_puts_P( prog_char *text );
  14. #else
  15. # define uart_puts_P(str) uart_puts(str)
  16. #endif
  17. void uart_init( void );
  18. unsigned char uart_getc( void );
  19. unsigned char uart_gotc( void );
  20. void uart_putc( char c );
  21. void uart_puts( const char *str );
  22. void uart_puthex( uint8_t num );
  23. void uart_trace( void *ptr, uint16_t start, uint16_t len );
  24. void uart_flush( void );
  25. int printf( const char *fmt, ... );
  26. int snprintf( char *str, size_t size, const char *format, ... );
  27. #define uart_putcrlf() uart_putc('\n')
  28. /* A few symbols to make this code work for all four UARTs */
  29. #if defined(CONFIG_UART_NUM) && CONFIG_UART_NUM == 0
  30. # define UART_PCONBIT 3
  31. # define UART_PCLKREG PCLKSEL0
  32. # define UART_PCLKBIT 6
  33. # define UART_REGS LPC_UART0
  34. # define UART_HANDLER UART0_IRQHandler
  35. # define UART_IRQ UART0_IRQn
  36. #elif CONFIG_UART_NUM == 1
  37. # define UART_PCONBIT 4
  38. # define UART_PCLKREG PCLKSEL0
  39. # define UART_PCLKBIT 8
  40. # define UART_REGS LPC_UART1
  41. # define UART_HANDLER UART1_IRQHandler
  42. # define UART_IRQ UART1_IRQn
  43. #elif CONFIG_UART_NUM == 2
  44. # define UART_PCONBIT 24
  45. # define UART_PCLKREG PCLKSEL1
  46. # define UART_PCLKBIT 16
  47. # define UART_REGS LPC_UART2
  48. # define UART_HANDLER UART2_IRQHandler
  49. # define UART_IRQ UART2_IRQn
  50. #elif CONFIG_UART_NUM == 3
  51. # define UART_PCONBIT 25
  52. # define UART_PCLKREG PCLKSEL1
  53. # define UART_PCLKBIT 18
  54. # define UART_REGS LPC_UART3
  55. # define UART_HANDLER UART3_IRQHandler
  56. # define UART_IRQ UART3_IRQn
  57. #else
  58. # error CONFIG_UART_NUM is not set or has an invalid value!
  59. #endif
  60. #else
  61. #define uart_init() do {} while(0)
  62. #define uart_getc() 0
  63. #define uart_putc(x) do {} while(0)
  64. #define uart_puthex(x) do {} while(0)
  65. #define uart_flush() do {} while(0)
  66. #define uart_puts_P(x) do {} while(0)
  67. #define uart_puts(x) do {} while(0)
  68. #define uart_putcrlf() do {} while(0)
  69. #define uart_trace(a,b,c) do {} while(0)
  70. #endif
  71. #endif