uart.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef __SW_FIFO__
  2. #define __SW_FIFO__
  3. #include <stdint.h>
  4. #define FIFO_BUFFER_SIZE 128 // software buffer size (in bytes)
  5. //typedef uint8_t unsigned char
  6. // UART data transmit function
  7. // - checks if there's room in the transmit sw buffer
  8. // - if there's room, it transfers data byte to sw buffer
  9. // - automatically handles "uart_tx_buffer_full_flag"
  10. // - sets the overflow flag upon software buffer overflow (doesn't overwrite existing data)
  11. // - if this is the first data byte in the buffer, it enables the "hw buffer empty" interrupt
  12. void uart_send_byte(uint8_t byte);
  13. // UART data receive function
  14. // - checks if data exists in the receive sw buffer
  15. // - if data exists, it returns the oldest element contained in the buffer
  16. // - automatically handles "uart_rx_buffer_full_flag"
  17. // - if no data exists, it clears the uart_rx_flag
  18. uint8_t uart_get_byte(void);
  19. volatile extern uint8_t uart_rx_fifo_not_empty_flag; // this flag is automatically set and cleared by the software buffer
  20. volatile extern uint8_t uart_rx_fifo_full_flag; // this flag is automatically set and cleared by the software buffer
  21. volatile extern uint8_t uart_rx_fifo_ovf_flag; // this flag is not automatically cleared by the software buffer
  22. volatile extern uint8_t uart_tx_fifo_full_flag; // this flag is automatically set and cleared by the software buffer
  23. volatile extern uint8_t uart_tx_fifo_ovf_flag; // this flag is not automatically cleared by the software buffer
  24. volatile extern uint8_t uart_tx_fifo_not_empty_flag; // this flag is automatically set and cleared by the software buffer
  25. void usartInterrupt(void);
  26. int serialAvailable();
  27. unsigned char serialRead(void);
  28. #endif