Helper function to allow bitbanging an 8n1 UART. */
| 46 | |
| 47 | /* Helper function to allow bitbanging an 8n1 UART. */ |
| 48 | void uart_bitbang_tx_byte(unsigned char data, void (*set_tx)(int line_state)) |
| 49 | { |
| 50 | const int baud_rate = get_uart_baudrate(); |
| 51 | int i; |
| 52 | struct stopwatch sw; |
| 53 | stopwatch_init(&sw); |
| 54 | |
| 55 | /* Send start bit */ |
| 56 | set_tx(0); |
| 57 | while (stopwatch_duration_usecs(&sw) < MHz / baud_rate) |
| 58 | stopwatch_tick(&sw); |
| 59 | |
| 60 | /* 'i' counts the total bits sent at the end of the loop */ |
| 61 | for (i = 2; i < 10; i++) { |
| 62 | set_tx(data & 1); |
| 63 | data >>= 1; |
| 64 | while (stopwatch_duration_usecs(&sw) < i * MHz / baud_rate) |
| 65 | stopwatch_tick(&sw); |
| 66 | } |
| 67 | |
| 68 | /* Send stop bit */ |
| 69 | set_tx(1); |
| 70 | while (stopwatch_duration_usecs(&sw) < i * MHz / baud_rate) |
| 71 | stopwatch_tick(&sw); |
| 72 | } |
no test coverage detected