mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-06 07:53:43 +08:00
Adding stub include files and uart functions to permit uart coms on overo.
This commit is contained in:
@@ -251,7 +251,7 @@ TARGET_DIR = ~
|
||||
SRC_FMS=fms
|
||||
|
||||
overo_test_uart.ARCHDIR = omap
|
||||
overo_test_uart.CFLAGS = -I. -I$(SRC_FMS)
|
||||
overo_test_uart.CFLAGS = -I. -I$(SRC_FMS) -I$(SRC_BETH)
|
||||
overo_test_uart.srcs = $(SRC_BETH)/overo_test_uart.c
|
||||
|
||||
overo_test_uart.CFLAGS += -DFMS_PERIODIC_FREQ=500
|
||||
@@ -265,7 +265,7 @@ overo_test_uart.LDFLAGS += -levent -lm
|
||||
overo_test_uart.srcs += $(SRC_BETH)/overo_gcs_com.c
|
||||
overo_test_uart.CFLAGS += -DUBX -DGPS -DUSE_UART0 -DUART0_BAUD=B38400 -DGPS_LINK=Uart0 -DGPS_USE_LATLONG
|
||||
#overo_test_uart.CFLAGS += -DUBX -DGPS -DUSE_UART1 -DUART1_BAUD=B9600 -DGPS_LINK=Uart1 -DGPS_USE_LATLONG
|
||||
overo_test_uart.srcs += gps_ubx.c gps.c latlong.c $(SRC_FMS)/uart_hw.c
|
||||
overo_test_uart.srcs += gps_ubx.c gps.c latlong.c $(SRC_BETH)/uart_hw.c
|
||||
|
||||
#
|
||||
# Overo twisting
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef GPS_HW_H
|
||||
#define GPS_HW_H
|
||||
|
||||
#endif /* GPS_HW_H */
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef SYS_TIME_HW_H
|
||||
#define SYS_TIME_HW_H
|
||||
|
||||
#endif /* SYS_TIME_HW_H */
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* Paparazzi $Id$
|
||||
*
|
||||
* Copyright (C) 2009 Antoine Drouin <poinix@gmail.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "uart.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "fms_serial_port.h"
|
||||
|
||||
#ifdef USE_UART0
|
||||
|
||||
volatile uint16_t uart0_rx_insert_idx, uart0_rx_extract_idx;
|
||||
uint8_t uart0_rx_buffer[UART0_RX_BUFFER_SIZE];
|
||||
|
||||
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;
|
||||
int uart0_fd;
|
||||
extern uint8_t portnum;
|
||||
|
||||
void uart0_init( void ) {
|
||||
|
||||
fmssp0 = serial_port_new();
|
||||
//TODO: set device name in application and pass as argument
|
||||
if (portnum == 0) {
|
||||
serial_port_open_raw(fmssp0,"/dev/ttyUSB0",UART0_BAUD);
|
||||
}
|
||||
if (portnum == 1) {
|
||||
serial_port_open_raw(fmssp0,"/dev/ttyUSB1",UART0_BAUD);
|
||||
}
|
||||
uart0_fd = (int)fmssp0->fd;
|
||||
|
||||
// initialize the transmit data queue
|
||||
uart0_tx_extract_idx = 0;
|
||||
uart0_tx_insert_idx = 0;
|
||||
uart0_tx_running = FALSE;
|
||||
|
||||
// initialize the receive data queue
|
||||
uart0_rx_extract_idx = 0;
|
||||
uart0_rx_insert_idx = 0;
|
||||
|
||||
}
|
||||
|
||||
void uart0_transmit( uint8_t data ) {
|
||||
|
||||
uint16_t temp = (uart0_tx_insert_idx + 1) % UART0_TX_BUFFER_SIZE;
|
||||
|
||||
if (temp == uart0_tx_extract_idx)
|
||||
return; // no room
|
||||
|
||||
// check if in process of sending data
|
||||
if (uart0_tx_running) { // yes, add to queue
|
||||
uart0_tx_buffer[uart0_tx_insert_idx] = data;
|
||||
uart0_tx_insert_idx = temp;
|
||||
}
|
||||
else { // no, set running flag and write to output register
|
||||
uart0_tx_running = TRUE;
|
||||
write(uart0_fd,&data,1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool_t uart0_check_free_space( uint8_t len) {
|
||||
int16_t space = uart0_tx_extract_idx - uart0_tx_insert_idx;
|
||||
if (space <= 0)
|
||||
space += UART0_TX_BUFFER_SIZE;
|
||||
return (uint16_t)(space - 1) >= len;
|
||||
}
|
||||
|
||||
void uart0_handler(void) {
|
||||
unsigned char c='D';
|
||||
|
||||
// check if more data to send
|
||||
if (uart0_tx_insert_idx != uart0_tx_extract_idx) {
|
||||
write(uart0_fd,&uart0_tx_buffer[uart0_tx_extract_idx],1);
|
||||
uart0_tx_extract_idx++;
|
||||
uart0_tx_extract_idx %= UART0_TX_BUFFER_SIZE;
|
||||
}
|
||||
else {
|
||||
uart0_tx_running = FALSE; // clear running flag
|
||||
// USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
|
||||
}
|
||||
|
||||
if(read(uart0_fd,&c,1) > 0){
|
||||
uint16_t temp = (uart0_rx_insert_idx + 1) % UART0_RX_BUFFER_SIZE;
|
||||
uart0_rx_buffer[uart0_rx_insert_idx] = c;
|
||||
// check for more room in queue
|
||||
if (temp != uart0_rx_extract_idx)
|
||||
uart0_rx_insert_idx = temp; // update insert index
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif /* USE_UART0 */
|
||||
|
||||
#ifdef USE_UART1
|
||||
|
||||
volatile uint16_t uart1_rx_insert_idx, uart1_rx_extract_idx;
|
||||
uint8_t uart1_rx_buffer[UART1_RX_BUFFER_SIZE];
|
||||
|
||||
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;
|
||||
int uart1_fd;
|
||||
|
||||
void uart1_init( void ) {
|
||||
|
||||
fmssp1 = serial_port_new();
|
||||
|
||||
serial_port_open_raw(fmssp1,"/dev/ttyUSB1",UART1_BAUD);
|
||||
|
||||
uart1_fd = (int)fmssp1->fd;
|
||||
|
||||
// initialize the transmit data queue
|
||||
uart1_tx_extract_idx = 0;
|
||||
uart1_tx_insert_idx = 0;
|
||||
uart1_tx_running = FALSE;
|
||||
|
||||
// initialize the receive data queue
|
||||
uart1_rx_extract_idx = 0;
|
||||
uart1_rx_insert_idx = 0;
|
||||
|
||||
}
|
||||
|
||||
void uart1_transmit( uint8_t data ) {
|
||||
|
||||
uint16_t temp = (uart1_tx_insert_idx + 1) % UART1_TX_BUFFER_SIZE;
|
||||
|
||||
if (temp == uart1_tx_extract_idx)
|
||||
return; // no room
|
||||
|
||||
// check if in process of sending data
|
||||
if (uart1_tx_running) { // yes, add to queue
|
||||
uart1_tx_buffer[uart1_tx_insert_idx] = data;
|
||||
uart1_tx_insert_idx = temp;
|
||||
}
|
||||
else { // no, set running flag and write to output register
|
||||
uart1_tx_running = TRUE;
|
||||
write(uart1_fd,&data,1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool_t uart1_check_free_space( uint8_t len) {
|
||||
int16_t space = uart1_tx_extract_idx - uart1_tx_insert_idx;
|
||||
if (space <= 0)
|
||||
space += UART1_TX_BUFFER_SIZE;
|
||||
return (uint16_t)(space - 1) >= len;
|
||||
}
|
||||
|
||||
void uart1_handler(void) {
|
||||
unsigned char c='D';
|
||||
|
||||
// check if more data to send
|
||||
if (uart1_tx_insert_idx != uart1_tx_extract_idx) {
|
||||
write(uart1_fd,&uart1_tx_buffer[uart1_tx_extract_idx],1);
|
||||
uart1_tx_extract_idx++;
|
||||
uart1_tx_extract_idx %= UART1_TX_BUFFER_SIZE;
|
||||
}
|
||||
else {
|
||||
uart1_tx_running = FALSE; // clear running flag
|
||||
// USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
|
||||
}
|
||||
|
||||
if(read(uart1_fd,&c,1) > 0){
|
||||
uint16_t temp = (uart1_rx_insert_idx + 1) % UART1_RX_BUFFER_SIZE;;
|
||||
uart1_rx_buffer[uart1_rx_insert_idx] = c;
|
||||
// check for more room in queue
|
||||
if (temp != uart1_rx_extract_idx)
|
||||
uart1_rx_insert_idx = temp; // update insert index
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif /* USE_UART1 */
|
||||
|
||||
void uart_init( void )
|
||||
{
|
||||
#ifdef USE_UART0
|
||||
uart0_init();
|
||||
#endif
|
||||
#ifdef USE_UART1
|
||||
uart1_init();
|
||||
#endif
|
||||
#ifdef USE_UART2
|
||||
uart2_init();
|
||||
#endif
|
||||
#ifdef USE_UART3
|
||||
uart3_init();
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2009 Antoine Drouin <poinix@gmail.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
*\brief STM32 usart functions
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef UART_HW_H
|
||||
#define UART_HW_H
|
||||
|
||||
#include "std.h"
|
||||
/*
|
||||
#define B9600 9600
|
||||
#define B38400 38400
|
||||
#define B57600 57600
|
||||
#define B115200 115200
|
||||
*/
|
||||
|
||||
#define Uart1_init uart1_init()
|
||||
#define Uart2_init uart2_init()
|
||||
#define Uart3_init uart3_init()
|
||||
#define Uart5_init uart5_init()
|
||||
|
||||
#define UART1_irq_handler usart1_irq_handler
|
||||
#define UART2_irq_handler usart2_irq_handler
|
||||
#define UART3_irq_handler usart3_irq_handler
|
||||
#define UART5_irq_handler usart5_irq_handler
|
||||
|
||||
#if defined USE_UART0 || OVERRIDE_UART0_IRQ_HANDLER
|
||||
extern void uart0_handler(void);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef USE_UART0
|
||||
#define UART0_RX_BUFFER_SIZE 128
|
||||
#define UART0_TX_BUFFER_SIZE 128
|
||||
|
||||
extern volatile uint16_t uart0_rx_insert_idx, uart0_rx_extract_idx;
|
||||
extern uint8_t uart0_rx_buffer[UART0_RX_BUFFER_SIZE];
|
||||
|
||||
extern volatile uint16_t uart0_tx_insert_idx, uart0_tx_extract_idx;
|
||||
extern volatile bool_t uart0_tx_running;
|
||||
extern uint8_t uart0_tx_buffer[UART0_TX_BUFFER_SIZE];
|
||||
|
||||
#define Uart0ChAvailable() (uart0_rx_insert_idx != uart0_rx_extract_idx)
|
||||
#define Uart0Getch() ({ \
|
||||
uint8_t ret = uart0_rx_buffer[uart0_rx_extract_idx]; \
|
||||
uart0_rx_extract_idx = (uart0_rx_extract_idx + 1)%UART0_RX_BUFFER_SIZE; \
|
||||
ret; \
|
||||
})
|
||||
|
||||
#endif /* USE_UART0 */
|
||||
|
||||
#if defined USE_UART1 || OVERRIDE_UART1_IRQ_HANDLER
|
||||
extern void uart1_handler(void);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef USE_UART1
|
||||
#define UART1_RX_BUFFER_SIZE 128
|
||||
#define UART1_TX_BUFFER_SIZE 128
|
||||
|
||||
extern volatile uint16_t uart1_rx_insert_idx, uart1_rx_extract_idx;
|
||||
extern uint8_t uart1_rx_buffer[UART1_RX_BUFFER_SIZE];
|
||||
|
||||
extern volatile uint16_t uart1_tx_insert_idx, uart1_tx_extract_idx;
|
||||
extern volatile bool_t uart1_tx_running;
|
||||
extern uint8_t uart1_tx_buffer[UART1_TX_BUFFER_SIZE];
|
||||
|
||||
#define Uart1ChAvailable() (uart1_rx_insert_idx != uart1_rx_extract_idx)
|
||||
#define Uart1Getch() ({ \
|
||||
uint8_t ret = uart1_rx_buffer[uart1_rx_extract_idx]; \
|
||||
uart1_rx_extract_idx = (uart1_rx_extract_idx + 1)%UART1_RX_BUFFER_SIZE; \
|
||||
ret; \
|
||||
})
|
||||
|
||||
#endif /* USE_UART1 */
|
||||
|
||||
|
||||
void uart_init( void );
|
||||
|
||||
#endif /* UART_HW_H */
|
||||
Reference in New Issue
Block a user