Merge branch 'master' into patch-2 · espressif/arduino-esp32@bfae8d5 (original) (raw)

`@@ -757,7 +757,11 @@ bool uartSetRxTimeout(uart_t *uart, uint8_t numSymbTimeout) {

`

757

757

`if (uart == NULL) {

`

758

758

`return false;

`

759

759

` }

`

760

``

-

``

760

`+

uint16_t maxRXTimeout = uart_get_max_rx_timeout(uart->num);

`

``

761

`+

if (numSymbTimeout > maxRXTimeout) {

`

``

762

`+

log_e("Invalid RX Timeout value, its limit is %d", maxRXTimeout);

`

``

763

`+

return false;

`

``

764

`+

}

`

761

765

`UART_MUTEX_LOCK();

`

762

766

`bool retCode = (ESP_OK == uart_set_rx_timeout(uart->num, numSymbTimeout));

`

763

767

`UART_MUTEX_UNLOCK();

`

`@@ -1382,4 +1386,24 @@ int uart_send_msg_with_break(uint8_t uartNum, uint8_t *msg, size_t msgSize) {

`

1382

1386

`return uart_write_bytes_with_break(uartNum, (const void *)msg, msgSize, 12);

`

1383

1387

`}

`

1384

1388

``

``

1389

`+

// returns the maximum valid uart RX Timeout based on the UART Source Clock and Baudrate

`

``

1390

`+

uint16_t uart_get_max_rx_timeout(uint8_t uartNum) {

`

``

1391

`+

if (uartNum >= SOC_UART_NUM) {

`

``

1392

`+

log_e("UART%d is invalid. This device has %d UARTs, from 0 to %d.", uartNum, SOC_UART_NUM, SOC_UART_NUM - 1);

`

``

1393

`+

return (uint16_t)-1;

`

``

1394

`+

}

`

``

1395

`+

uint16_t tout_max_thresh = uart_ll_max_tout_thrd(UART_LL_GET_HW(uartNum));

`

``

1396

`+

uint8_t symbol_len = 1; // number of bits per symbol including start

`

``

1397

`+

uart_parity_t parity_mode;

`

``

1398

`+

uart_stop_bits_t stop_bit;

`

``

1399

`+

uart_word_length_t data_bit;

`

``

1400

`+

uart_ll_get_data_bit_num(UART_LL_GET_HW(uartNum), &data_bit);

`

``

1401

`+

uart_ll_get_stop_bits(UART_LL_GET_HW(uartNum), &stop_bit);

`

``

1402

`+

uart_ll_get_parity(UART_LL_GET_HW(uartNum), &parity_mode);

`

``

1403

`+

symbol_len += (data_bit < UART_DATA_BITS_MAX) ? (uint8_t)data_bit + 5 : 8;

`

``

1404

`+

symbol_len += (stop_bit > UART_STOP_BITS_1) ? 2 : 1;

`

``

1405

`+

symbol_len += (parity_mode > UART_PARITY_DISABLE) ? 1 : 0;

`

``

1406

`+

return (uint16_t)(tout_max_thresh / symbol_len);

`

``

1407

`+

}

`

``

1408

+

1385

1409

`#endif /* SOC_UART_SUPPORTED */

`