aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--system-clock/include/spin.h17
-rw-r--r--system-clock/src/spin.c50
2 files changed, 67 insertions, 0 deletions
diff --git a/system-clock/include/spin.h b/system-clock/include/spin.h
new file mode 100644
index 0000000..a920847
--- /dev/null
+++ b/system-clock/include/spin.h
@@ -0,0 +1,17 @@
+#ifndef H__SPIN_
+#define H__SPIN_
+
+#include <stdint.h>
+
+/*
+ * Flash a code on the status LED.
+ *
+ * The flash codes a binary from MSB to LSB. A long flash is a 1, a short flash
+ * is a 0. Each independent flashing is succeced by a break of 4 times that
+ * of a long flash.
+ */
+void spin(uint8_t code);
+
+
+
+#endif /* H__SPIN_ */
diff --git a/system-clock/src/spin.c b/system-clock/src/spin.c
new file mode 100644
index 0000000..f233054
--- /dev/null
+++ b/system-clock/src/spin.c
@@ -0,0 +1,50 @@
+#include "spin.h"
+#include "gpio.h"
+#include "delay.h"
+
+#define SHORT_DELAY 200000
+#define LONG_DELAY (SHORT_DELAY * 2)
+
+static void flash_bit(
+ gpio_output_pin_t out_pin,
+ uint8_t bit /* 0 => 0, non-zero => 1 */)
+{
+ pin_on(out_pin);
+ if (bit) {
+ delay(LONG_DELAY);
+ } else {
+ delay(SHORT_DELAY);
+ }
+ pin_off(out_pin);
+ delay(SHORT_DELAY);
+}
+
+void spin(uint8_t c)
+{
+ uint8_t code;
+ __IO gpio_port_t* port_b = enable_gpio(GPIO_PORT_B);
+ gpio_output_pin_t pin3 = set_gpio_pin_output(port_b, PIN_3);
+
+ for(;;) {
+ code = c;
+ flash_bit(pin3, code & 0x80);
+ code <<= 1;
+ flash_bit(pin3, code & 0x80);
+ code <<= 1;
+ flash_bit(pin3, code & 0x80);
+ code <<= 1;
+ flash_bit(pin3, code & 0x80);
+
+
+ code <<= 1;
+ flash_bit(pin3, code & 0x80);
+ code <<= 1;
+ flash_bit(pin3, code & 0x80);
+ code <<= 1;
+ flash_bit(pin3, code & 0x80);
+ code <<= 1;
+ flash_bit(pin3, code & 0x80);
+
+ delay(LONG_DELAY * 4);
+ }
+}