diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-10-10 01:13:52 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-10-10 01:13:52 +0200 |
commit | 261e6be038754388212e7a7b69da1318d6a171d2 (patch) | |
tree | 8788bffbb8248aeab9ed07c326445bac491633b7 /gps.h | |
parent | f8e706f8bc5a69f5b8134624516a3597d335685e (diff) |
Add GPS code.
Diffstat (limited to 'gps.h')
-rw-r--r-- | gps.h | 60 |
1 files changed, 60 insertions, 0 deletions
@@ -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<Interrupt::USART3>(); + + private: + static GPS* self; + + void irq(); + + Pool<GPSMsg, 4> msg_pool; + + P<GPSMsg> incomplete_msg; + volatile P<GPSMsg> 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<GPSMsg> read() { + while(!complete) { + Thread::yield(); + } + + complete = false; + + P<GPSMsg> msg = const_cast<P<GPSMsg>&>(complete_msg); + + const_cast<P<GPSMsg>&>(complete_msg).reset(); + + return msg; + } +}; + +#endif |