diff --git a/sw/airborne/arch/lpc21/mcu_periph/uart_arch.h b/sw/airborne/arch/lpc21/mcu_periph/uart_arch.h index 874449f7b7..eedd044cd6 100644 --- a/sw/airborne/arch/lpc21/mcu_periph/uart_arch.h +++ b/sw/airborne/arch/lpc21/mcu_periph/uart_arch.h @@ -34,6 +34,17 @@ #include "LPC21xx.h" #include BOARD_CONFIG +#define B1200 1200 +#define B2400 2400 +#define B4800 4800 +#define B9600 9600 +#define B19200 19200 +#define B38400 38400 +#define B57600 57600 +#define B100000 100000 +#define B115200 115200 +#define B230400 230400 + #define UART_8N1 (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_NO + ULCR_STOP_1) #define UART_7N1 (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_NO + ULCR_STOP_1) #define UART_8N2 (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_NO + ULCR_STOP_2) diff --git a/sw/airborne/arch/omap/mcu_periph/uart_arch.c b/sw/airborne/arch/omap/mcu_periph/uart_arch.c index 0d4cd02bd1..ad6e85390a 100644 --- a/sw/airborne/arch/omap/mcu_periph/uart_arch.c +++ b/sw/airborne/arch/omap/mcu_periph/uart_arch.c @@ -23,7 +23,6 @@ * omap uart handling */ -// FIXME: uart.h defines B9600 as 9600 #include "mcu_periph/uart.h" #include @@ -32,70 +31,50 @@ #include #include -// FIXME: fms_serial_port includes termios.h that with omap defines B9600 as 12 -// Include termios.h AFTER uart.h. This OVERWRITES (without warning) the paparazzi uart.h B9600 #include "serial_port.h" // #define TRACE(fmt,args...) fprintf(stderr, fmt, args) #define TRACE(fmt,args...) -// Convert the paparazzi B9600 which becomes 9600 to termios B9600 which becomes 12 -// FIXME: not all possible baudrate are available yet. -speed_t baudconvert_drone(uint32_t baud); -speed_t baudconvert_drone(uint32_t baud) -{ - if (baud <= 4800) - return B4800; - else if (baud <= 9600) - return B9600; - else if (baud <= 19200) - return B19200; - else if (baud <= 38400) - return B38400; - else if (baud <= 57600) - return B57600; - return B115200; -} - -void uart_periph_set_baudrate(struct uart_periph* p, uint32_t baud) { - struct SerialPort* fmssp; +void uart_periph_set_baudrate(struct uart_periph* periph, uint32_t baud) { + struct SerialPort* port; // close serial port if already open - if (p->reg_addr != NULL) { - fmssp = (struct SerialPort*)(p->reg_addr); - serial_port_close(fmssp); - serial_port_free(fmssp); + if (periph->reg_addr != NULL) { + port = (struct SerialPort*)(periph->reg_addr); + serial_port_close(port); + serial_port_free(port); } // open serial port - fmssp = serial_port_new(); + port = serial_port_new(); // use register address to store SerialPort structure pointer... - p->reg_addr = (void*)fmssp; + periph->reg_addr = (void*)port; //TODO: set device name in application and pass as argument // FIXME: paparazzi baud is 9600 for B9600 while open_raw needs 12 for B9600 - printf("opening %s on uart0 at %d (termios.h value=%d)\n",p->dev,baud,baudconvert_drone(baud)); - int ret = serial_port_open_raw(fmssp,p->dev,baudconvert_drone(baud)); + printf("opening %s on uart0 at termios.h baud value=%d\n", periph->dev, baud); + int ret = serial_port_open_raw(port,periph->dev, baud); if (ret != 0) { - TRACE("Error opening %s code %d\n",p->dev,ret); + TRACE("Error opening %s code %d\n",periph->dev,ret); } } -void uart_transmit(struct uart_periph* p, uint8_t data ) { - uint16_t temp = (p->tx_insert_idx + 1) % UART_TX_BUFFER_SIZE; +void uart_transmit(struct uart_periph* periph, uint8_t data) { + uint16_t temp = (periph->tx_insert_idx + 1) % UART_TX_BUFFER_SIZE; - if (temp == p->tx_extract_idx) + if (temp == periph->tx_extract_idx) return; // no room // check if in process of sending data - if (p->tx_running) { // yes, add to queue - p->tx_buf[p->tx_insert_idx] = data; - p->tx_insert_idx = temp; + if (periph->tx_running) { // yes, add to queue + periph->tx_buf[periph->tx_insert_idx] = data; + periph->tx_insert_idx = temp; } else { // no, set running flag and write to output register - p->tx_running = TRUE; - struct SerialPort* fmssp = (struct SerialPort*)(p->reg_addr); - int ret = write((int)(fmssp->fd),&data,1); + periph->tx_running = TRUE; + struct SerialPort* port = (struct SerialPort*)(periph->reg_addr); + int ret = write((int)(port->fd), &data, 1); if (ret < 1) { TRACE("w %x [%d]\n",data,ret); @@ -105,35 +84,35 @@ void uart_transmit(struct uart_periph* p, uint8_t data ) { #include -static inline void uart_handler(struct uart_periph* p) { +static inline void uart_handler(struct uart_periph* periph) { unsigned char c='D'; - if (p->reg_addr == NULL) return; // device not initialized ? + if (periph->reg_addr == NULL) return; // device not initialized ? - struct SerialPort* fmssp = (struct SerialPort*)(p->reg_addr); - int fd = fmssp->fd; + struct SerialPort* port = (struct SerialPort*)(periph->reg_addr); + int fd = port->fd; // check if more data to send - if (p->tx_insert_idx != p->tx_extract_idx) { - int ret = write(fd,&(p->tx_buf[p->tx_extract_idx]),1); + if (periph->tx_insert_idx != periph->tx_extract_idx) { + int ret = write(fd, &(periph->tx_buf[periph->tx_extract_idx]), 1); if (ret < 1) { - TRACE("w %x [%d: %s]\n",p->tx_buf[p->tx_extract_idx],ret,strerror(errno)); + TRACE("w %x [%d: %s]\n", periph->tx_buf[periph->tx_extract_idx], ret, strerror(errno)); } - p->tx_extract_idx++; - p->tx_extract_idx %= UART_TX_BUFFER_SIZE; + periph->tx_extract_idx++; + periph->tx_extract_idx %= UART_TX_BUFFER_SIZE; } else { - p->tx_running = FALSE; // clear running flag + periph->tx_running = FALSE; // clear running flag } if(read(fd,&c,1) > 0){ //printf("r %x %c\n",c,c); - uint16_t temp = (p->rx_insert_idx + 1) % UART_RX_BUFFER_SIZE; - p->rx_buf[p->rx_insert_idx] = c; + uint16_t temp = (periph->rx_insert_idx + 1) % UART_RX_BUFFER_SIZE; + periph->rx_buf[periph->rx_insert_idx] = c; // check for more room in queue - if (temp != p->rx_extract_idx) - p->rx_insert_idx = temp; // update insert index + if (temp != periph->rx_extract_idx) + periph->rx_insert_idx = temp; // update insert index } } diff --git a/sw/airborne/arch/omap/mcu_periph/uart_arch.h b/sw/airborne/arch/omap/mcu_periph/uart_arch.h index d5a6fd4301..24c341234f 100644 --- a/sw/airborne/arch/omap/mcu_periph/uart_arch.h +++ b/sw/airborne/arch/omap/mcu_periph/uart_arch.h @@ -27,7 +27,9 @@ #define UART_ARCH_H #include "mcu_periph/uart.h" -#include "std.h" + +// for definition of baud rates +#include #define UART1_irq_handler usart1_irq_handler #define UART2_irq_handler usart2_irq_handler diff --git a/sw/airborne/arch/stm32/mcu_periph/uart_arch.h b/sw/airborne/arch/stm32/mcu_periph/uart_arch.h index a375fb83ee..0b8346ad87 100644 --- a/sw/airborne/arch/stm32/mcu_periph/uart_arch.h +++ b/sw/airborne/arch/stm32/mcu_periph/uart_arch.h @@ -29,6 +29,16 @@ #ifndef STM32_UART_ARCH_H #define STM32_UART_ARCH_H -#include "std.h" +#define B1200 1200 +#define B2400 2400 +#define B4800 4800 +#define B9600 9600 +#define B19200 19200 +#define B38400 38400 +#define B57600 57600 +#define B100000 100000 +#define B115200 115200 +#define B230400 230400 +#define B921600 921600 #endif /* STM32_UART_ARCH_H */ diff --git a/sw/airborne/mcu_periph/uart.h b/sw/airborne/mcu_periph/uart.h index 84fc1626a6..13c1af34a6 100644 --- a/sw/airborne/mcu_periph/uart.h +++ b/sw/airborne/mcu_periph/uart.h @@ -36,20 +36,8 @@ #define UART_DEV_NAME_SIZE 16 /* - * UART Baud rates - * defines because the stupid c preprocessor can't handle enums -*/ -#define B1200 1200 -#define B2400 2400 -#define B4800 4800 -#define B9600 9600 -#define B19200 19200 -#define B38400 38400 -#define B57600 57600 -#define B100000 100000 -#define B115200 115200 -#define B230400 230400 -#define B921600 921600 + * UART Baud rate defines in arch/x/mcu_periph/uart_arch.h + */ #define UBITS_7 7 #define UBITS_8 8