esp32/machine_uart: Implement the functionality of timeout_char arg.
Using it for the rx-timeout. The value is given as ms, which is then converted to character times. A value of less than a character time will cause the rx call to return immediately after 1 character, which may be inefficient at high transmission rates. Addresses #8778.
This commit is contained in:
parent
425d8fc0d6
commit
5f4539b0ca
|
@ -267,12 +267,18 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
|
|||
}
|
||||
|
||||
// set timeout_char
|
||||
// make sure it is at least as long as a whole character (13 bits to be safe)
|
||||
// make sure it is at least as long as a whole character (12 bits here)
|
||||
if (args[ARG_timeout_char].u_int != -1) {
|
||||
self->timeout_char = args[ARG_timeout_char].u_int;
|
||||
uint32_t min_timeout_char = 13000 / baudrate + 1;
|
||||
if (self->timeout_char < min_timeout_char) {
|
||||
self->timeout_char = min_timeout_char;
|
||||
uint32_t char_time_ms = 12000 / baudrate + 1;
|
||||
uint32_t rx_timeout = self->timeout_char / char_time_ms;
|
||||
if (rx_timeout < 1) {
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0)
|
||||
uart_set_rx_full_threshold(self->uart_num, 1);
|
||||
#endif
|
||||
uart_set_rx_timeout(self->uart_num, 1);
|
||||
} else {
|
||||
uart_set_rx_timeout(self->uart_num, rx_timeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue