aboutsummaryrefslogtreecommitdiff
path: root/system-clock/src
diff options
context:
space:
mode:
Diffstat (limited to 'system-clock/src')
-rw-r--r--system-clock/src/spin.c50
1 files changed, 50 insertions, 0 deletions
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);
+ }
+}