diff --git a/conf/firmwares/rotorcraft.makefile b/conf/firmwares/rotorcraft.makefile index 34b481573d..bba591c1c7 100644 --- a/conf/firmwares/rotorcraft.makefile +++ b/conf/firmwares/rotorcraft.makefile @@ -117,6 +117,8 @@ $(TARGET).srcs += $(SRC_FIRMWARE)/autopilot.c $(TARGET).srcs += mcu_periph/i2c.c $(TARGET).srcs += $(SRC_ARCH)/mcu_periph/i2c_arch.c +include $(CFG_SHARED)/uart.makefile + # # Electrical subsystem / Analog Backend @@ -165,14 +167,6 @@ ifeq ($(BOARD), ardrone) ns_srcs += $(SRC_BOARD)/gpio_ardrone.c endif - -ns_srcs += mcu_periph/uart.c -ns_srcs += $(SRC_ARCH)/mcu_periph/uart_arch.c -ifeq ($(ARCH), linux) -ns_srcs += $(SRC_ARCH)/serial_port.c -endif - - # # add other subsystems to rotorcraft firmware in airframe file: # diff --git a/conf/firmwares/subsystems/shared/uart.makefile b/conf/firmwares/subsystems/shared/uart.makefile new file mode 100644 index 0000000000..842c69cc41 --- /dev/null +++ b/conf/firmwares/subsystems/shared/uart.makefile @@ -0,0 +1,19 @@ +# Hey Emacs, this is a -*- makefile -*- + +ifndef UART_INCLUDED + +UART_INCLUDED = 1 + +UART_SRCS = mcu_periph/uart.c $(SRC_ARCH)/mcu_periph/uart_arch.c +ifeq ($(ARCH), linux) +UART_SRCS += $(SRC_ARCH)/serial_port.c +endif +ifeq ($(TARGET), nps) +UART_CFLAGS += -Iarch/linux +UART_SRCS += arch/linux/serial_port.c +endif + +$(TARGET).CFLAGS += $(UART_CFLAGS) +$(TARGET).srcs += $(UART_SRCS) + +endif diff --git a/sw/airborne/arch/sim/mcu_periph/uart_arch.c b/sw/airborne/arch/sim/mcu_periph/uart_arch.c new file mode 120000 index 0000000000..c0b0c8d0e9 --- /dev/null +++ b/sw/airborne/arch/sim/mcu_periph/uart_arch.c @@ -0,0 +1 @@ +../../linux/mcu_periph/uart_arch.c \ No newline at end of file diff --git a/sw/airborne/arch/sim/mcu_periph/uart_arch.h b/sw/airborne/arch/sim/mcu_periph/uart_arch.h deleted file mode 100644 index 6ed4ac0180..0000000000 --- a/sw/airborne/arch/sim/mcu_periph/uart_arch.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2012 The Paparazzi Team - * - * This file is part of paparazzi. - * - * paparazzi is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * paparazzi is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with paparazzi; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/** - * @file arch/sim/mcu_periph/uart_arch.h - * Dummy header for handling of UART hardware in sim. - */ - -#include -#include -#include -#include -#include -#include - -#define STDINOUT_BUFFER_SIZE 256 -#define FD_STDIN 0 - -extern char stdinout_buffer[STDINOUT_BUFFER_SIZE]; -extern uint8_t stdinout_rx_insert_idx; -extern uint8_t stdinout_rx_extract_idx; - -#define UART_SPEED(_def) {} - -static inline bool StdInOutChAvailable(void) -{ - struct timeval tv; - fd_set fds; - tv.tv_sec = 0; - tv.tv_usec = 0; - FD_ZERO(&fds); - FD_SET(FD_STDIN, &fds); - select(1, &fds, NULL, NULL, &tv); - if (FD_ISSET(FD_STDIN, &fds)) { - char tmp_buf[STDINOUT_BUFFER_SIZE]; - uint8_t n = read(FD_STDIN, tmp_buf, STDINOUT_BUFFER_SIZE); - unsigned int i; - for (i = 0; i < n; i++) { - stdinout_buffer[stdinout_rx_insert_idx] = tmp_buf[i]; - stdinout_rx_insert_idx++; /* Auto overflow */ - } - } - return (stdinout_rx_insert_idx != stdinout_rx_extract_idx); -} - -#define StdInOutTransmit(_char) putchar(_char) -#define StdInOutGetch() ({ \ - assert(stdinout_rx_insert_idx != stdinout_rx_extract_idx); \ - stdinout_buffer[stdinout_rx_extract_idx++]; \ - }) diff --git a/sw/airborne/arch/sim/mcu_periph/uart_arch.h b/sw/airborne/arch/sim/mcu_periph/uart_arch.h new file mode 120000 index 0000000000..a9c1ee3ba6 --- /dev/null +++ b/sw/airborne/arch/sim/mcu_periph/uart_arch.h @@ -0,0 +1 @@ +../../linux/mcu_periph/uart_arch.h \ No newline at end of file