diff --git a/sw/airborne/avr/uart_ap.c b/sw/airborne/avr/uart_ap.c index 64af86204a..ced7d45d82 100644 --- a/sw/airborne/avr/uart_ap.c +++ b/sw/airborne/avr/uart_ap.c @@ -163,3 +163,13 @@ void uart1_init( void ) { sbi(UCSR1B, RXCIE ); } + +bool_t uart1_buffer_size; +uint8_t uart1_buffer[UART_BUFFER_LEN]; + +SIGNAL( SIG_UART1_RECV ) { + if (uart1_buffer_size < UART_BUFFER_LEN) { + uart1_buffer[uart1_buffer_size] = UDR1; + uart1_buffer_size++; + } /** else overrun */ +} diff --git a/sw/airborne/avr/uart_ap_hw.h b/sw/airborne/avr/uart_ap_hw.h index 2b24f753e1..cfb1814b41 100644 --- a/sw/airborne/avr/uart_ap_hw.h +++ b/sw/airborne/avr/uart_ap_hw.h @@ -39,3 +39,5 @@ uint8_t c = UDR1; \ cb(c); \ } + +#define UART_BUFFER_LEN 16 diff --git a/sw/airborne/gps.h b/sw/airborne/gps.h index 9aaaaa6cd0..e45419ac02 100644 --- a/sw/airborne/gps.h +++ b/sw/airborne/gps.h @@ -74,5 +74,14 @@ extern struct svinfo gps_svinfos[GPS_NB_CHANNELS]; #include "ubx.h" #endif +#define GPS_BUFFER uart1_buffer +#define GPS_BUFFER_SIZE uart1_buffer_size + + +#define GpsBuffer() (GPS_BUFFER_SIZE > 0) +#define ReadGpsBuffer() { \ + GpsParse(GPS_BUFFER, GPS_BUFFER_SIZE); \ + GPS_BUFFER_SIZE = 0; \ +} #endif /* GPS_H */ diff --git a/sw/airborne/gps_ubx.c b/sw/airborne/gps_ubx.c index a1a389cb0a..98de95b640 100644 --- a/sw/airborne/gps_ubx.c +++ b/sw/airborne/gps_ubx.c @@ -141,7 +141,7 @@ void parse_gps_msg( void ) { uint8_t gps_nb_ovrn; -static inline void parse_ubx( uint8_t c ) { +void parse_ubx( uint8_t c ) { if (ubx_status < GOT_PAYLOAD) { ck_a += c; ck_b += ck_a; @@ -207,17 +207,3 @@ static inline void parse_ubx( uint8_t c ) { ubx_status = UNINIT; return; } - -#ifdef AVR_ARCH - -#ifdef SIMUL -ReceiveUart0(parse_ubx); -#endif - -#ifndef WAVECARD_ON_GPS -ReceiveUart1(parse_ubx); -#endif - - -#endif /* AVR_ARCH */ - diff --git a/sw/airborne/mainloop.c b/sw/airborne/mainloop.c index 37ebb9602e..cd4d624e06 100644 --- a/sw/airborne/mainloop.c +++ b/sw/airborne/mainloop.c @@ -130,6 +130,9 @@ void periodic_task_ap( void) { void event_task_ap( void ) { #ifdef GPS + if (GpsBuffer()) { + ReadGpsBuffer(); + } if (gps_msg_received) { /* parse and use GPS messages */ parse_gps_msg(); diff --git a/sw/airborne/uart_ap.h b/sw/airborne/uart_ap.h index 0bc0b8ebe6..4ad75a7969 100644 --- a/sw/airborne/uart_ap.h +++ b/sw/airborne/uart_ap.h @@ -25,6 +25,7 @@ #define _UART_H_ #include +#include "std.h" #include "uart_ap_hw.h" extern void uart0_init_tx(void); @@ -37,5 +38,7 @@ extern void uart0_print_hex16(const uint16_t); extern void uart0_transmit(const uint8_t); extern void uart1_transmit(const uint8_t); +extern bool_t uart1_buffer_size; +extern uint8_t uart1_buffer[UART_BUFFER_LEN]; #endif diff --git a/sw/airborne/ubx.h b/sw/airborne/ubx.h index fd460774ac..925486f5b2 100644 --- a/sw/airborne/ubx.h +++ b/sw/airborne/ubx.h @@ -57,5 +57,13 @@ extern uint8_t send_ck_a, send_ck_b; #define GPS_FIX_VALID(gps_mode) (gps_mode == 3) +extern void parse_ubx( uint8_t c ); + +#define GpsParse(_gps_buffer, _gps_buffer_size) { \ + uint8_t i; \ + for(i = 0; i < _gps_buffer_size; i++) { \ + parse_ubx(_gps_buffer[i]); \ + } \ +} #endif /* UBX_H */ diff --git a/sw/tools/gen_ubx.ml b/sw/tools/gen_ubx.ml index 6a51484347..3956f0620a 100644 --- a/sw/tools/gen_ubx.ml +++ b/sw/tools/gen_ubx.ml @@ -115,7 +115,7 @@ let parse_message = fun class_name m -> let s = sizeof (format f) in let p = param_name f in let t = param_type f in - fprintf out " %s _%s = %s; UbxSend%dByAddr((uint8_t*)_%s);\\\n" t p p s p + fprintf out " %s _%s = %s; UbxSend%dByAddr((uint8_t*)&_%s);\\\n" t p p s p | "block" -> List.iter send_one_field (Xml.children f) | _ -> assert (false) in