mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-05 06:54:49 +08:00
@@ -108,6 +108,9 @@ ap.srcs += $(SRC_ARCH)/subsystems/settings_arch.c
|
||||
|
||||
ap.srcs += mcu_periph/uart.c
|
||||
ap.srcs += $(SRC_ARCH)/mcu_periph/uart_arch.c
|
||||
ifeq ($(ARCH), omap)
|
||||
ap.srcs += $(SRC_ARCH)/serial_port.c
|
||||
endif
|
||||
|
||||
# I2C is needed for speed controllers and barometers on lisa
|
||||
ifeq ($(TARGET), ap)
|
||||
@@ -291,17 +294,3 @@ ap.srcs += $(SRC_FIRMWARE)/guidance/guidance_v_adapt.c
|
||||
ap.srcs += $(SRC_FIRMWARE)/navigation.c
|
||||
ap.srcs += subsystems/navigation/common_flight_plan.c
|
||||
|
||||
#
|
||||
# FMS choice
|
||||
#
|
||||
# include booz2_fms_test_signal.makefile
|
||||
# or
|
||||
# include booz2_fms_datalink.makefile
|
||||
# or
|
||||
# nothing
|
||||
#
|
||||
ifeq ($(ARCH), omap)
|
||||
SRC_FMS=fms
|
||||
ap.CFLAGS += -I. -I$(SRC_FMS)
|
||||
ap.srcs += $(SRC_FMS)/fms_serial_port.c
|
||||
endif
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
* omap uart handling
|
||||
*/
|
||||
|
||||
// FIXME: uart.h defines B9600 as 9600
|
||||
#include "mcu_periph/uart.h"
|
||||
|
||||
#include <stdint.h>
|
||||
@@ -32,70 +31,50 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// 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 "fms/fms_serial_port.h"
|
||||
#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 FmsSerialPort* 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 FmsSerialPort*)(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 FmsSerialPort* fmssp = (struct FmsSerialPort*)(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 <errno.h>
|
||||
|
||||
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 FmsSerialPort* fmssp = (struct FmsSerialPort*)(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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,9 @@
|
||||
#define UART_ARCH_H
|
||||
|
||||
#include "mcu_periph/uart.h"
|
||||
#include "std.h"
|
||||
|
||||
// for definition of baud rates
|
||||
#include <termios.h>
|
||||
|
||||
#define UART1_irq_handler usart1_irq_handler
|
||||
#define UART2_irq_handler usart2_irq_handler
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "fms_serial_port.h"
|
||||
#include "serial_port.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -13,17 +13,17 @@
|
||||
#define TRACE(type,fmt,args...)
|
||||
#define TRACE_ERROR 1
|
||||
|
||||
struct FmsSerialPort* serial_port_new(void) {
|
||||
struct FmsSerialPort* me = malloc(sizeof(struct FmsSerialPort));
|
||||
struct SerialPort* serial_port_new(void) {
|
||||
struct SerialPort* me = malloc(sizeof(struct SerialPort));
|
||||
return me;
|
||||
}
|
||||
|
||||
void serial_port_free(struct FmsSerialPort* me) {
|
||||
void serial_port_free(struct SerialPort* me) {
|
||||
free(me);
|
||||
}
|
||||
|
||||
|
||||
void serial_port_flush(struct FmsSerialPort* me) {
|
||||
void serial_port_flush(struct SerialPort* me) {
|
||||
/*
|
||||
* flush any input that might be on the port so we start fresh.
|
||||
*/
|
||||
@@ -33,7 +33,7 @@ void serial_port_flush(struct FmsSerialPort* me) {
|
||||
}
|
||||
}
|
||||
|
||||
void serial_port_flush_output(struct FmsSerialPort* me) {
|
||||
void serial_port_flush_output(struct SerialPort* me) {
|
||||
/*
|
||||
* flush any input that might be on the port so we start fresh.
|
||||
*/
|
||||
@@ -43,7 +43,7 @@ void serial_port_flush_output(struct FmsSerialPort* me) {
|
||||
}
|
||||
}
|
||||
|
||||
int serial_port_open_raw(struct FmsSerialPort* me, const char* device, speed_t speed) {
|
||||
int serial_port_open_raw(struct SerialPort* me, const char* device, speed_t speed) {
|
||||
if ((me->fd = open(device, O_RDWR | O_NONBLOCK | O_NOCTTY)) < 0) {
|
||||
TRACE(TRACE_ERROR,"%s, open failed: %s (%d)\n", device, strerror(errno), errno);
|
||||
return -1;
|
||||
@@ -78,7 +78,7 @@ int serial_port_open_raw(struct FmsSerialPort* me, const char* device, speed_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
int serial_port_open(struct FmsSerialPort* me, const char* device,
|
||||
int serial_port_open(struct SerialPort* me, const char* device,
|
||||
void(*term_conf_callback)(struct termios*, speed_t*)) {
|
||||
|
||||
speed_t speed;
|
||||
@@ -108,7 +108,7 @@ int serial_port_open(struct FmsSerialPort* me, const char* device,
|
||||
|
||||
}
|
||||
|
||||
void serial_port_close(struct FmsSerialPort* me) {
|
||||
void serial_port_close(struct SerialPort* me) {
|
||||
|
||||
/* if null pointer or file descriptor indicates error just bail */
|
||||
if (!me || me->fd < 0)
|
||||
@@ -20,24 +20,24 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FMS_SERIAL_PORT_H
|
||||
#define FMS_SERIAL_PORT_H
|
||||
#ifndef SERIAL_PORT_H
|
||||
#define SERIAL_PORT_H
|
||||
|
||||
#include <termios.h>
|
||||
|
||||
struct FmsSerialPort {
|
||||
struct SerialPort {
|
||||
int fd; /* serial device fd */
|
||||
struct termios orig_termios; /* saved tty state structure */
|
||||
struct termios cur_termios; /* tty state structure */
|
||||
};
|
||||
|
||||
extern struct FmsSerialPort* serial_port_new(void);
|
||||
extern void serial_port_free(struct FmsSerialPort* me);
|
||||
extern void serial_port_flush(struct FmsSerialPort* me);
|
||||
extern void serial_port_flush_output(struct FmsSerialPort* me);
|
||||
extern int serial_port_open_raw(struct FmsSerialPort* me, const char* device, speed_t speed);
|
||||
extern int serial_port_open(struct FmsSerialPort* me, const char* device,
|
||||
extern struct SerialPort* serial_port_new(void);
|
||||
extern void serial_port_free(struct SerialPort* me);
|
||||
extern void serial_port_flush(struct SerialPort* me);
|
||||
extern void serial_port_flush_output(struct SerialPort* me);
|
||||
extern int serial_port_open_raw(struct SerialPort* me, const char* device, speed_t speed);
|
||||
extern int serial_port_open(struct SerialPort* me, const char* device,
|
||||
void(*term_conf_callback)(struct termios*, speed_t*));
|
||||
extern void serial_port_close(struct FmsSerialPort* me);
|
||||
extern void serial_port_close(struct SerialPort* me);
|
||||
|
||||
#endif /* FMS_SERIAL_PORT_H */
|
||||
#endif /* SERIAL_PORT_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 */
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
#include "fms_periodic.h"
|
||||
#include "fms_debug.h"
|
||||
#include "fms_serial_port.h"
|
||||
#include "serial_port.h"
|
||||
|
||||
#include "overo_gcs_com.h"
|
||||
#include "uart_hw.h"
|
||||
@@ -57,7 +57,7 @@ void check_gps(void);
|
||||
uint8_t nav_utm_zone0 = 31;
|
||||
|
||||
static uint16_t foo = 0;
|
||||
//struct FmsSerialPort* fmssp;
|
||||
//struct SerialPort* fmssp;
|
||||
//int spfd;
|
||||
uint8_t portnum;
|
||||
#ifdef GPS_CONFIGURE
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "fms_serial_port.h"
|
||||
#include "serial_port.h"
|
||||
|
||||
|
||||
#ifdef USE_UART0
|
||||
@@ -39,7 +39,7 @@ volatile uint16_t uart0_tx_insert_idx, uart0_tx_extract_idx;
|
||||
volatile bool_t uart0_tx_running;
|
||||
uint8_t uart0_tx_buffer[UART0_TX_BUFFER_SIZE];
|
||||
|
||||
struct FmsSerialPort* fmssp0;
|
||||
struct SerialPort* fmssp0;
|
||||
int uart0_fd;
|
||||
extern uint8_t portnum;
|
||||
|
||||
@@ -165,7 +165,7 @@ volatile uint16_t uart1_tx_insert_idx, uart1_tx_extract_idx;
|
||||
volatile bool_t uart1_tx_running;
|
||||
uint8_t uart1_tx_buffer[UART1_TX_BUFFER_SIZE];
|
||||
|
||||
struct FmsSerialPort* fmssp1;
|
||||
struct SerialPort* fmssp1;
|
||||
int uart1_fd;
|
||||
|
||||
void uart1_init( void ) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user