summaryrefslogtreecommitdiff
path: root/src/micropeak/ao_async.c
diff options
context:
space:
mode:
authorBdale Garbee <bdale@gag.com>2013-01-12 10:57:22 -0700
committerBdale Garbee <bdale@gag.com>2013-01-12 10:57:22 -0700
commit670034eef48d63cdaec8d271fa93da984ffe2ea9 (patch)
tree422713fba95404876049f785255942ce6d9c4afd /src/micropeak/ao_async.c
parent8c5ebaf88b459b09924753a8077393a7b0639133 (diff)
parentd374d6be7eb040457f4df6c38b5d057f26ee741c (diff)
Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
Diffstat (limited to 'src/micropeak/ao_async.c')
-rw-r--r--src/micropeak/ao_async.c43
1 files changed, 37 insertions, 6 deletions
diff --git a/src/micropeak/ao_async.c b/src/micropeak/ao_async.c
index 04bba9e8..3556f54c 100644
--- a/src/micropeak/ao_async.c
+++ b/src/micropeak/ao_async.c
@@ -21,20 +21,51 @@
#define AO_ASYNC_BAUD 38400l
#define AO_ASYNC_DELAY (uint8_t) (1000000l / AO_ASYNC_BAUD)
+#define LED_PORT PORTB
+
+void
+ao_async_start(void)
+{
+ LED_PORT |= (1 << AO_LED_SERIAL);
+}
+
+void
+ao_async_stop(void)
+{
+ LED_PORT &= ~(1 << AO_LED_SERIAL);
+}
+
void
ao_async_byte(uint8_t byte)
{
uint8_t b;
uint16_t w;
- /* start bit */
-
- /* start data stop */
- w = 0x001 | (byte << 1) | 0x000;
+ /* start data stop */
+ w = (0x000 << 0) | (byte << 1) | (0x001 << 9);
+ ao_arch_block_interrupts();
for (b = 0; b < 10; b++) {
- ao_led_set((w & 1) << AO_LED_SERIAL);
+ uint8_t v = LED_PORT & ~(1 << AO_LED_SERIAL);
+ v |= (w & 1) << AO_LED_SERIAL;
+ LED_PORT = v;
w >>= 1;
- ao_delay_us(26);
+
+ /* Carefully timed to hit around 9600 baud */
+ asm volatile ("nop");
+ asm volatile ("nop");
+
+ asm volatile ("nop");
+ asm volatile ("nop");
+ asm volatile ("nop");
+ asm volatile ("nop");
+ asm volatile ("nop");
+
+ asm volatile ("nop");
+ asm volatile ("nop");
+ asm volatile ("nop");
+ asm volatile ("nop");
+ asm volatile ("nop");
}
+ ao_arch_release_interrupts();
}