From 261e6be038754388212e7a7b69da1318d6a171d2 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Mon, 10 Oct 2011 01:13:52 +0200 Subject: Add GPS code. --- gps.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 gps.h (limited to 'gps.h') diff --git a/gps.h b/gps.h new file mode 100644 index 0000000..c37fc8a --- /dev/null +++ b/gps.h @@ -0,0 +1,60 @@ +#ifndef GPS_H +#define GPS_H + +#include "stm32.h" +#include "interrupt.h" +#include "thread.h" + +#include "pool.h" + +struct GPSMsg { + unsigned int n; + uint8_t buf[128]; + + GPSMsg() : n(0) {} +}; + +class GPS { + friend void interrupt(); + + private: + static GPS* self; + + void irq(); + + Pool msg_pool; + + P incomplete_msg; + volatile P complete_msg; + + volatile bool complete; + + public: + GPS() { + self = this; + } + + void enable() { + RCC.enable(RCC.USART3); + USART3.BRR = 7500; // 4800 baud + USART3.CR1 = 0x202c; + + Interrupt::enable(Interrupt::USART3); + } + + P read() { + while(!complete) { + Thread::yield(); + } + + complete = false; + + P msg = const_cast&>(complete_msg); + + const_cast&>(complete_msg).reset(); + + return msg; + } +}; + +#endif -- cgit v1.2.3