High Altitude Recovery Payload

HARP: High Altitude Recovery Payload

Version 0.1: RC design

/media/uploads/tylerjw/_scaled_2012-07-23_mbed_xbee_breadboard.jpg

By connecting the second xbee to a computer using a terminal command and supplying the characters L, R, C, F the light patterns change on the mbed.

Files at this revision

API Documentation at this revision

Comitter:
tylerjw
Date:
Mon Jul 23 19:20:55 2012 +0000
Child:
1:21a6da67311c
Commit message:
0.1 LED change with serial xbee connection

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
rtos.lib Show annotated file Show diff for this revision Revisions of this file
watchdog.cpp Show annotated file Show diff for this revision Revisions of this file
watchdog.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jul 23 19:20:55 2012 +0000
@@ -0,0 +1,68 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "watchdog.h"
+
+// Setup the watchdog timer
+Watchdog wdt;
+
+// xbee serial connection
+Serial xbee(p13,p14);
+
+// status leds
+BusOut status_led(LED4, LED3, LED2, LED1);
+
+typedef struct {
+    char msg;   // the direction to turn in
+} message_p;
+
+MemoryPool<message_p, 16> mpool_p;
+Queue<message_p, 16> queue_p;
+
+void xbee_thread(void const *argument) {
+    while (true) {
+        if (xbee.readable()) {
+            message_p *message = mpool_p.alloc();
+            message->msg = xbee.getc();
+
+            queue_p.put(message);
+        }
+        Thread::wait(100);
+    }
+}
+
+int main (void) {
+    status_led = 0x9;
+    // setup watchdog
+    wdt.kick(2.0); // 2 second watchdog
+    // setup xbee serial
+    xbee.baud(9600);
+
+    Thread thread1(xbee_thread);
+
+    while (true) {
+
+        osEvent evt_p = queue_p.get(1000); // wait for 1 second
+
+        if (evt_p.status == osEventMessage) {
+            message_p *message = (message_p*)evt_p.value.p;
+            printf("\nMessage from xbee: %c\n\r", message->msg);
+            switch (message->msg) {
+                case 'L': // turn left
+                    status_led = 0x3;
+                    break;
+                case 'C': // center
+                    status_led = 0x6;
+                    break;
+                case 'R': // turn right
+                    status_led = 0xC;
+                    break;
+                case 'F': // flare
+                    status_led = 0xF;
+                    break;
+            }
+
+            mpool_p.free(message);
+        }
+        wdt.kick();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Jul 23 19:20:55 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rtos.lib	Mon Jul 23 19:20:55 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/rtos/#68e146c0e76b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/watchdog.cpp	Mon Jul 23 19:20:55 2012 +0000
@@ -0,0 +1,20 @@
+#include "mbed.h"
+#include "watchdog.h"
+
+// Simon's Watchdog code from
+// http://mbed.org/forum/mbed/topic/508/
+
+// Load timeout value in watchdog timer and enable
+void Watchdog::kick(float s) {
+    LPC_WDT->WDCLKSEL = 0x1;                // Set CLK src to PCLK
+    uint32_t clk = SystemCoreClock / 16;    // WD has a fixed /4 prescaler, PCLK default is /4
+    LPC_WDT->WDTC = s * (float)clk;
+    LPC_WDT->WDMOD = 0x3;                   // Enabled and Reset
+    kick();
+}
+// "kick" or "feed" the dog - reset the watchdog timer
+// by writing this required bit pattern
+void Watchdog::kick() {
+    LPC_WDT->WDFEED = 0xAA;
+    LPC_WDT->WDFEED = 0x55;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/watchdog.h	Mon Jul 23 19:20:55 2012 +0000
@@ -0,0 +1,7 @@
+#include "mbed.h"
+
+class Watchdog {
+public:
+    void kick(float); // init watchdog to number of seconds
+    void kick(); // kick the dog
+};
\ No newline at end of file