usart working... when debugged...

This commit is contained in:
Philippe Teuwen
2019-04-20 19:17:32 +02:00
parent 7ca1e98776
commit 6e744043f5
9 changed files with 162 additions and 118 deletions

View File

@@ -103,6 +103,7 @@ bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed);
/* Gets the current speed of the serial port, in baud.
*/
uint32_t uart_get_speed(const serial_port sp);
extern uint32_t uart_speed;
#endif // _UART_H_

View File

@@ -60,6 +60,9 @@
# define SOL_TCP IPPROTO_TCP
#endif
// To memorise baudrate, we don't want to call get_speed systematically
uint32_t uart_speed;
typedef struct termios term_info;
typedef struct {
int fd; // Serial port file descriptor
@@ -206,7 +209,8 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
}
}
}
printf("[=] UART Setting serial baudrate %u\n", speed);
uart_speed = uart_get_speed(sp);
printf("[=] UART Setting serial baudrate %u\n", uart_speed);
return sp;
}
@@ -408,7 +412,10 @@ bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) {
// Set port speed (Input and Output)
cfsetispeed(&ti, stPortSpeed);
cfsetospeed(&ti, stPortSpeed);
return (tcsetattr(spu->fd, TCSANOW, &ti) != -1);
bool result = tcsetattr(spu->fd, TCSANOW, &ti) != -1;
if (result)
uart_speed = uiPortSpeed;
return result;
}
uint32_t uart_get_speed(const serial_port sp) {

View File

@@ -42,6 +42,9 @@
#ifdef _WIN32
#include <windows.h>
// To memorise baudrate, we don't want to call get_speed systematically
uint32_t uart_speed;
typedef struct {
HANDLE hPort; // Serial port handle
DCB dcb; // Device control settings
@@ -121,7 +124,8 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
}
}
}
printf("[=] UART Setting serial baudrate %i\n", speed);
uart_speed = uart_get_speed(sp);
printf("[=] UART Setting serial baudrate %u\n", uart_speed);
return sp;
}
@@ -152,6 +156,8 @@ bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) {
spw->dcb.BaudRate = uiPortSpeed;
bool result = SetCommState(spw->hPort, &spw->dcb);
PurgeComm(spw->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
if (result)
uart_speed = uiPortSpeed;
return result;
}