40 #include <px4_platform_common/px4_config.h> 41 #include <px4_platform_common/defines.h> 43 #include <sys/types.h> 44 #include <sys/ioctl.h> 54 #include <arch/board/board.h> 63 int uart2_nwrite0 = 0;
64 int uart2_nwrite1 = 0;
65 int uart2_buffer_size = 0;
68 int uart2 = open(
"/dev/ttyS1", O_RDWR | O_NONBLOCK | O_NOCTTY);
71 printf(
"ERROR opening UART2, aborting..\n");
75 struct termios uart2_config;
77 struct termios uart2_config_original;
79 int termios_state = 0;
89 ioctl(uart2, FIONSPACE, (
unsigned long)&uart2_buffer_size);
92 #define UART_BREAK_RUNTIME_CONF 93 #ifdef UART_BREAK_RUNTIME_CONF 95 if ((termios_state = tcgetattr(uart2, &uart2_config)) < 0) {
96 printf(
"ERROR getting termios config for UART2: %d\n", termios_state);
101 memcpy(&uart2_config_original, &uart2_config,
sizeof(
struct termios));
104 if (cfsetispeed(&uart2_config, B9600) < 0 || cfsetospeed(&uart2_config, B9600) < 0) {
105 printf(
"ERROR setting termios config for UART2: %d\n", termios_state);
110 if ((termios_state = tcsetattr(uart2, TCSANOW, &uart2_config)) < 0) {
111 printf(
"ERROR setting termios config for UART2\n");
127 ioctl(uart2, TIOCSBRK, 0);
132 ioctl(uart2, TIOCCBRK, 0);
146 uint8_t sample_uart2[] = {
'U',
'A',
'R',
'T',
'2',
' ',
'#', 0xff};
148 int messages = uart2_buffer_size /
sizeof(sample_uart2);
149 messages = messages / 2;
152 for (i = 0; i < messages; i++) {
154 r =
write(uart2, sample_uart2,
sizeof(sample_uart2));
172 ioctl(uart2, TIOCSBRK, 0);
177 ioctl(uart2, TIOCCBRK, 0);
186 for (i = 0; i < messages; i++) {
188 r =
write(uart2, sample_uart2,
sizeof(sample_uart2));
198 for (wait = 0; wait < 1000 && left != uart2_buffer_size; wait++) {
199 ioctl(uart2, FIONSPACE, (
unsigned long)&left);
203 #define UART_BREAK_RUNTIME_CONF 204 #ifdef UART_BREAK_RUNTIME_CONF 207 if ((termios_state = tcsetattr(uart2, TCSANOW, &uart2_config_original)) < 0) {
208 printf(
"ERROR setting termios config for UART2\n");
216 printf(
"uart2_buffer_size %d wait %d uart2_nwrite0 %d uart2_nwrite1 %d\n", uart2_buffer_size, wait, uart2_nwrite0,
static void write(bootloader_app_shared_t *pshared)
int test_uart_break(int argc, char *argv[])