mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-15 23:42:52 +00:00
h5: enable even parity on posix if incorrect frame received
This commit is contained in:
parent
c7525ffc25
commit
a6da1bb0db
@ -58,13 +58,13 @@ int btstack_uart_posix_open(const char * device_name, int flowcontrol, uint32_t
|
||||
int flags = O_RDWR | O_NOCTTY | O_NONBLOCK;
|
||||
int fd = open(device_name, flags);
|
||||
if (fd == -1) {
|
||||
perror("init_serialport: Unable to open port ");
|
||||
perror("posix_open: Unable to open port ");
|
||||
perror(device_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tcgetattr(fd, &toptions) < 0) {
|
||||
perror("init_serialport: Couldn't get term attributes");
|
||||
perror("posix_open: Couldn't get term attributes");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -74,6 +74,10 @@ int btstack_uart_posix_open(const char * device_name, int flowcontrol, uint32_t
|
||||
toptions.c_cflag &= ~CSTOPB;
|
||||
toptions.c_cflag |= CS8;
|
||||
|
||||
// 8E1
|
||||
// toptions.c_cflag |= PARENB; // enable even parity
|
||||
//
|
||||
|
||||
if (flowcontrol) {
|
||||
// with flow control
|
||||
toptions.c_cflag |= CRTSCTS;
|
||||
@ -90,7 +94,7 @@ int btstack_uart_posix_open(const char * device_name, int flowcontrol, uint32_t
|
||||
toptions.c_cc[VTIME] = 0;
|
||||
|
||||
if(tcsetattr(fd, TCSANOW, &toptions) < 0) {
|
||||
perror("init_serialport: Couldn't set term attributes");
|
||||
perror("posix_open: Couldn't set term attributes");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -108,7 +112,7 @@ int btstack_uart_posix_set_baudrate(int fd, uint32_t baudrate){
|
||||
struct termios toptions;
|
||||
|
||||
if (tcgetattr(fd, &toptions) < 0) {
|
||||
perror("init_serialport: Couldn't get term attributes");
|
||||
perror("posix_open: Couldn't get term attributes");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -153,9 +157,27 @@ int btstack_uart_posix_set_baudrate(int fd, uint32_t baudrate){
|
||||
cfsetispeed(&toptions, brate);
|
||||
|
||||
if( tcsetattr(fd, TCSANOW, &toptions) < 0) {
|
||||
perror("init_serialport: Couldn't set term attributes");
|
||||
perror("posix_set_baudrate: Couldn't set term attributes");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int btstack_uart_posix_set_parity(int fd, int parity){
|
||||
struct termios toptions;
|
||||
if (tcgetattr(fd, &toptions) < 0) {
|
||||
perror("posix_set_parity: Couldn't get term attributes");
|
||||
return -1;
|
||||
}
|
||||
if (parity){
|
||||
toptions.c_cflag |= PARENB; // enable even parity
|
||||
} else {
|
||||
toptions.c_cflag &= ~PARENB; // enable even parity
|
||||
}
|
||||
if(tcsetattr(fd, TCSANOW, &toptions) < 0) {
|
||||
perror("posix_set_parity: Couldn't set term attributes");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -58,11 +58,19 @@
|
||||
int btstack_uart_posix_open(const char * device_name, int flowcontrol, uint32_t baudrate);
|
||||
|
||||
/**
|
||||
* @brief Set baudrate
|
||||
* @brief Set Baudrate
|
||||
* @param fd
|
||||
* @param baudrate
|
||||
* @returns 0 if successful
|
||||
*/
|
||||
int btstack_uart_posix_set_baudrate(int fd, uint32_t baudrate);
|
||||
|
||||
/**
|
||||
* @brief Set Parity
|
||||
* @param fd
|
||||
* @param parity
|
||||
* @returns 0 if successful
|
||||
*/
|
||||
int btstack_uart_posix_set_parity(int fd, int parity);
|
||||
|
||||
#endif
|
||||
|
@ -344,6 +344,15 @@ static void hci_transport_h5_process_frame(uint16_t frame_size){
|
||||
log_info_hexdump(slip_header, 4);
|
||||
log_info_hexdump(slip_payload, frame_size_without_header);
|
||||
|
||||
// CSR 8811 does not seem to auto-detect H5 mode and sends data with even parity.
|
||||
// if this byte sequence is detected, just enable even parity
|
||||
const uint8_t sync_response_bcsp[] = {0x01, 0x7a, 0x06, 0x10};
|
||||
if (memcmp(sync_response_bcsp, slip_header, 4) == 0){
|
||||
log_info("h5: detected BSCP SYNC sent with Even Parity -> discard frame and enable Even Parity");
|
||||
btstack_uart_posix_set_parity(hci_transport_h5_data_source.fd, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// validate header checksum
|
||||
uint8_t header_checksum = slip_header[0] + slip_header[1] + slip_header[2] + slip_header[3];
|
||||
if (header_checksum != 0xff){
|
||||
|
Loading…
x
Reference in New Issue
Block a user