MCPcopy Create free account
hub / github.com/coreboot/coreboot / uart_bitbang_tx_byte

Function uart_bitbang_tx_byte

src/drivers/uart/util.c:48–72  ·  view source on GitHub ↗

Helper function to allow bitbanging an 8n1 UART. */

Source from the content-addressed store, hash-verified

46
47/* Helper function to allow bitbanging an 8n1 UART. */
48void 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}

Callers 1

uart_tx_byteFunction · 0.85

Calls 5

stopwatch_initFunction · 0.85
set_txFunction · 0.85
stopwatch_duration_usecsFunction · 0.85
stopwatch_tickFunction · 0.85
get_uart_baudrateFunction · 0.50

Tested by

no test coverage detected