serial.h 782 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef __SERIAL_H__
  2. #define __SERIAL_H__
  3. #include <stdio.h>
  4. #define SERIAL_DTR 0
  5. #define SERIAL_RTS 1
  6. struct baud_code {
  7. int baud;
  8. int code;
  9. };
  10. struct ring_buf {
  11. char data[4096];
  12. unsigned int start;
  13. unsigned int size;
  14. };
  15. struct serial_device {
  16. int fd;
  17. FILE *f;
  18. struct ring_buf in_buf;
  19. struct ring_buf out_buf;
  20. };
  21. extern const struct baud_code baud_codes[];
  22. int serial_open(struct serial_device *port, const char *path, int baud);
  23. void serial_close(struct serial_device *port);
  24. int serial_setbaud(struct serial_device *port, int baud);
  25. void serial_setline(struct serial_device *port, int line, int state);
  26. int serial_read(struct serial_device *port, char *buf, int len, int timeout);
  27. void serial_write(struct serial_device *port, const char *text);
  28. #endif