mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-09 21:45:54 +00:00
btstack_uart_block_posix: drain output before changing baud rate
This commit is contained in:
parent
0168d82ebc
commit
9233108786
@ -176,29 +176,15 @@ static int btstack_uart_posix_set_baudrate(uint32_t baudrate){
|
|||||||
|
|
||||||
log_info("h4_set_baudrate %u", baudrate);
|
log_info("h4_set_baudrate %u", baudrate);
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
|
|
||||||
// From https://developer.apple.com/library/content/samplecode/SerialPortSample/Listings/SerialPortSample_SerialPortSample_c.html
|
|
||||||
|
|
||||||
// The IOSSIOSPEED ioctl can be used to set arbitrary baud rates
|
|
||||||
// other than those specified by POSIX. The driver for the underlying serial hardware
|
|
||||||
// ultimately determines which baud rates can be used. This ioctl sets both the input
|
|
||||||
// and output speed.
|
|
||||||
|
|
||||||
speed_t speed = baudrate;
|
|
||||||
if (ioctl(fd, IOSSIOSPEED, &speed) == -1) {
|
|
||||||
log_error("btstack_uart_posix_set_baudrate: error calling ioctl(..., IOSSIOSPEED, %u) - %s(%d).\n", baudrate, strerror(errno), errno);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
struct termios toptions;
|
struct termios toptions;
|
||||||
|
|
||||||
if (tcgetattr(fd, &toptions) < 0) {
|
if (tcgetattr(fd, &toptions) < 0) {
|
||||||
log_error("btstack_uart_posix_set_baudrate: Couldn't get term attributes");
|
log_error("btstack_uart_posix_set_baudrate: Couldn't get term attributes");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __APPLE__
|
||||||
|
|
||||||
speed_t brate = baudrate; // let you override switch below if needed
|
speed_t brate = baudrate; // let you override switch below if needed
|
||||||
switch(baudrate) {
|
switch(baudrate) {
|
||||||
case 9600: brate=B9600; break;
|
case 9600: brate=B9600; break;
|
||||||
@ -251,11 +237,29 @@ static int btstack_uart_posix_set_baudrate(uint32_t baudrate){
|
|||||||
}
|
}
|
||||||
cfsetospeed(&toptions, brate);
|
cfsetospeed(&toptions, brate);
|
||||||
cfsetispeed(&toptions, brate);
|
cfsetispeed(&toptions, brate);
|
||||||
|
#endif
|
||||||
|
|
||||||
if( tcsetattr(fd, TCSANOW, &toptions) < 0) {
|
// also set options for __APPLE__ to enforce write drain
|
||||||
|
// Mac OS Mojave: tcsdrain did not work as expected
|
||||||
|
|
||||||
|
if( tcsetattr(fd, TCSADRAIN, &toptions) < 0) {
|
||||||
log_error("Couldn't set term attributes");
|
log_error("Couldn't set term attributes");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// From https://developer.apple.com/library/content/samplecode/SerialPortSample/Listings/SerialPortSample_SerialPortSample_c.html
|
||||||
|
|
||||||
|
// The IOSSIOSPEED ioctl can be used to set arbitrary baud rates
|
||||||
|
// other than those specified by POSIX. The driver for the underlying serial hardware
|
||||||
|
// ultimately determines which baud rates can be used. This ioctl sets both the input
|
||||||
|
// and output speed.
|
||||||
|
|
||||||
|
speed_t speed = baudrate;
|
||||||
|
if (ioctl(fd, IOSSIOSPEED, &speed) == -1) {
|
||||||
|
log_error("btstack_uart_posix_set_baudrate: error calling ioctl(..., IOSSIOSPEED, %u) - %s(%d).\n", baudrate, strerror(errno), errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user