serial_loop.c 542 B

123456789101112131415161718192021222324252627282930313233
  1. #include "io.h"
  2. #include "serial.h"
  3. #include "timer.h"
  4. #include "idle.h"
  5. void program_serial_loop_main(const char *arg)
  6. {
  7. unsigned int port = SERIAL_COM1;
  8. unsigned int last_send;
  9. const char msg[] = "hello serial\r\n";
  10. (void)arg;
  11. serial_init(port);
  12. last_send = get_ticks_ms();
  13. for (;;) {
  14. unsigned int now = get_ticks_ms();
  15. if (now - last_send >= 1000) {
  16. last_send = now;
  17. serial_puts(port, msg);
  18. }
  19. while (serial_has_data(port)) {
  20. char c = serial_getc_nb(port);
  21. if (c)
  22. io_putchar(c);
  23. }
  24. cpu_idle();
  25. }
  26. }