Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-rabault committed Aug 29, 2023
1 parent 01031a5 commit f76ce13
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions network/serial_network/HAL/NATIVE/serial_network_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <termios.h>
#include <errno.h>
#include <sys/ioctl.h>
#ifdef __linux__
#include <linux/serial.h>
#endif
#endif

/*******************************************************************************
Expand Down Expand Up @@ -278,23 +281,26 @@ void SerialHAL_Init(uint8_t *rx_buffer, uint32_t buffer_size)
}
#else
// Set the baudrate
struct serial_struct ser_info;
if (ioctl(serial_port, TIOCGSERIAL, &ser_info) < 0)
// Get current serial port settings
struct termios2 serial_settings;
if (ioctl(serial_port, TCGETS2, &serial_settings) != 0)
{
perror("Error getting serial info");
perror("Error getting current settings");
close(serial_port);
return 1;
}

ser_info.flags &= ~ASYNC_SPD_MASK; // Clear current baud rate
ser_info.flags |= ASYNC_SPD_CUST; // Set custom baud rate
ser_info.custom_divisor = ser_info.baud_base / SERIAL_NETWORK_BAUDRATE; // Set desired baud rate
if (ioctl(serial_port, TIOCSSERIAL, &ser_info) < 0)
// Set new baud rate
serial_settings.c_cflag &= ~CBAUD; // Clear existing baud rate settings
serial_settings.c_cflag |= BOTHER; // Set custom baud rate
serial_settings.c_ispeed = 1000000; // Input baud rate
serial_settings.c_ospeed = 1000000; // Output baud rate

if (ioctl(serial_port, TCSETS2, &serial_settings) != 0)
{
printf("Error setting baudrate attributes\n");
printf("Error code: %d\n", errno);
perror("Error setting baud rate");
close(serial_port);
LUOS_ASSERT(0);
return 1;
}
#endif
#endif
Expand Down

0 comments on commit f76ce13

Please sign in to comment.