From 307cfe164910eccc70c086c083595d637c7fb987 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 19 Nov 2011 20:02:14 +0100 Subject: Moved driver related files to a subdirectory. --- drivers/gps.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 drivers/gps.h (limited to 'drivers/gps.h') diff --git a/drivers/gps.h b/drivers/gps.h new file mode 100644 index 0000000..c37fc8a --- /dev/null +++ b/drivers/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