microb 2010
[aversive.git] / projects / microb2010 / tests / static_beacon / coin.c
diff --git a/projects/microb2010/tests/static_beacon/coin.c b/projects/microb2010/tests/static_beacon/coin.c
new file mode 100644 (file)
index 0000000..88a80a3
--- /dev/null
@@ -0,0 +1,472 @@
+# 1 "/home/zer0/zavr/projects/microb2010/tests/static_beacon/static_beacon.c"
+# 1 "/home/zer0/zavr/projects/microb2010/tests/static_beacon//"
+# 1 "<built-in>"
+# 1 "<command-line>"
+# 1 "/home/zer0/zavr/projects/microb2010/tests/static_beacon/static_beacon.c"
+# 23 "/home/zer0/zavr/projects/microb2010/tests/static_beacon/static_beacon.c"
+# 1 "/home/zer0/zavr/include/aversive.h" 1
+# 31 "/home/zer0/zavr/include/aversive.h"
+# 1 "./autoconf.h" 1
+# 32 "/home/zer0/zavr/include/aversive.h" 2
+
+
+# 1 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/interrupt.h" 1 3
+# 38 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/interrupt.h" 3
+# 1 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/io.h" 1 3
+# 94 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/io.h" 3
+# 1 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/sfr_defs.h" 1 3
+# 126 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/sfr_defs.h" 3
+# 1 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/inttypes.h" 1 3
+# 37 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/inttypes.h" 3
+# 1 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdint.h" 1 3
+# 121 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdint.h" 3
+typedef int int8_t __attribute__((__mode__(__QI__)));
+typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
+typedef int int16_t __attribute__ ((__mode__ (__HI__)));
+typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
+typedef int int32_t __attribute__ ((__mode__ (__SI__)));
+typedef unsigned int uint32_t __attribute__ ((__mode__ (__SI__)));
+
+typedef int int64_t __attribute__((__mode__(__DI__)));
+typedef unsigned int uint64_t __attribute__((__mode__(__DI__)));
+# 142 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdint.h" 3
+typedef int16_t intptr_t;
+
+
+
+
+typedef uint16_t uintptr_t;
+# 159 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdint.h" 3
+typedef int8_t int_least8_t;
+
+
+
+
+typedef uint8_t uint_least8_t;
+
+
+
+
+typedef int16_t int_least16_t;
+
+
+
+
+typedef uint16_t uint_least16_t;
+
+
+
+
+typedef int32_t int_least32_t;
+
+
+
+
+typedef uint32_t uint_least32_t;
+
+
+
+
+
+
+
+typedef int64_t int_least64_t;
+
+
+
+
+
+
+typedef uint64_t uint_least64_t;
+# 213 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdint.h" 3
+typedef int8_t int_fast8_t;
+
+
+
+
+typedef uint8_t uint_fast8_t;
+
+
+
+
+typedef int16_t int_fast16_t;
+
+
+
+
+typedef uint16_t uint_fast16_t;
+
+
+
+
+typedef int32_t int_fast32_t;
+
+
+
+
+typedef uint32_t uint_fast32_t;
+
+
+
+
+
+
+
+typedef int64_t int_fast64_t;
+
+
+
+
+
+
+typedef uint64_t uint_fast64_t;
+# 273 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdint.h" 3
+typedef int64_t intmax_t;
+
+
+
+
+typedef uint64_t uintmax_t;
+# 38 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/inttypes.h" 2 3
+# 77 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/inttypes.h" 3
+typedef int32_t int_farptr_t;
+
+
+
+typedef uint32_t uint_farptr_t;
+# 127 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/sfr_defs.h" 2 3
+# 95 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/io.h" 2 3
+# 229 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/io.h" 3
+# 1 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/iom8.h" 1 3
+# 230 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/io.h" 2 3
+# 317 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/io.h" 3
+# 1 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/portpins.h" 1 3
+# 318 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/io.h" 2 3
+
+# 1 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/common.h" 1 3
+# 320 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/io.h" 2 3
+
+# 1 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/version.h" 1 3
+# 322 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/io.h" 2 3
+
+
+# 1 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/fuse.h" 1 3
+# 223 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/fuse.h" 3
+typedef struct
+{
+    unsigned char low;
+    unsigned char high;
+} __fuse_t;
+# 325 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/io.h" 2 3
+
+
+# 1 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/lock.h" 1 3
+# 328 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/io.h" 2 3
+# 39 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/avr/interrupt.h" 2 3
+# 35 "/home/zer0/zavr/include/aversive.h" 2
+
+
+
+# 1 "/home/zer0/zavr/include/aversive/types.h" 1
+# 47 "/home/zer0/zavr/include/aversive/types.h"
+typedef uint8_t u08;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef uint64_t u64;
+typedef int8_t s08;
+typedef int16_t s16;
+typedef int32_t s32;
+typedef int64_t s64;
+# 39 "/home/zer0/zavr/include/aversive.h" 2
+# 1 "/home/zer0/zavr/include/aversive/errno.h" 1
+# 33 "/home/zer0/zavr/include/aversive/errno.h"
+# 1 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/errno.h" 1 3
+# 55 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/errno.h" 3
+extern int errno;
+# 34 "/home/zer0/zavr/include/aversive/errno.h" 2
+# 40 "/home/zer0/zavr/include/aversive.h" 2
+# 1 "/home/zer0/zavr/include/aversive/irq_lock.h" 1
+# 41 "/home/zer0/zavr/include/aversive.h" 2
+# 125 "/home/zer0/zavr/include/aversive.h"
+struct extract32 {
+ union {
+  struct {
+
+   uint8_t u8_0;
+   uint8_t u8_1;
+   uint8_t u8_2;
+   uint8_t u8_3;
+
+
+
+
+
+
+  } __attribute__ ((packed)) u8;
+  struct {
+
+   uint16_t u16_0;
+   uint16_t u16_1;
+
+
+
+
+  } __attribute__ ((packed)) u16;
+  struct {
+
+   uint8_t u8_0;
+   uint16_t u16_mid;
+   uint8_t u8_3;
+
+
+
+
+
+  } __attribute__ ((packed)) u16_b;
+  uint32_t u32;
+ } __attribute__ ((packed)) u;
+} __attribute__ ((packed));
+# 174 "/home/zer0/zavr/include/aversive.h"
+struct extract16 {
+ union {
+  struct {
+
+   uint8_t u8_0;
+   uint8_t u8_1;
+
+
+
+
+  } __attribute__ ((packed)) u8;
+  uint16_t u16;
+ } __attribute__ ((packed)) u;
+} __attribute__ ((packed));
+# 24 "/home/zer0/zavr/projects/microb2010/tests/static_beacon/static_beacon.c" 2
+# 1 "/home/zer0/zavr/include/aversive/wait.h" 1
+# 45 "/home/zer0/zavr/include/aversive/wait.h"
+# 1 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/util/delay.h" 1 3
+# 39 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/util/delay.h" 3
+# 1 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/util/delay_basic.h" 1 3
+# 65 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/util/delay_basic.h" 3
+static inline void _delay_loop_1(uint8_t __count) __attribute__((always_inline));
+static inline void _delay_loop_2(uint16_t __count) __attribute__((always_inline));
+# 80 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/util/delay_basic.h" 3
+void
+_delay_loop_1(uint8_t __count)
+{
+ __asm__ volatile (
+  "1: dec %0" "\n\t"
+  "brne 1b"
+  : "=r" (__count)
+  : "0" (__count)
+ );
+}
+# 102 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/util/delay_basic.h" 3
+void
+_delay_loop_2(uint16_t __count)
+{
+ __asm__ volatile (
+  "1: sbiw %0,1" "\n\t"
+  "brne 1b"
+  : "=w" (__count)
+  : "0" (__count)
+ );
+}
+# 40 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/util/delay.h" 2 3
+# 79 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/util/delay.h" 3
+static inline void _delay_us(double __us) __attribute__((always_inline));
+static inline void _delay_ms(double __ms) __attribute__((always_inline));
+# 107 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/util/delay.h" 3
+void
+_delay_us(double __us)
+{
+ uint8_t __ticks;
+ double __tmp = ((((unsigned long)(16000000))) / 3e6) * __us;
+ if (__tmp < 1.0)
+  __ticks = 1;
+ else if (__tmp > 255)
+ {
+  _delay_ms(__us / 1000.0);
+  return;
+ }
+ else
+  __ticks = (uint8_t)__tmp;
+ _delay_loop_1(__ticks);
+}
+# 141 "/usr/lib/gcc/avr/4.3.2/../../../avr/include/util/delay.h" 3
+void
+_delay_ms(double __ms)
+{
+ uint16_t __ticks;
+ double __tmp = ((((unsigned long)(16000000))) / 4e3) * __ms;
+ if (__tmp < 1.0)
+  __ticks = 1;
+ else if (__tmp > 65535)
+ {
+
+  __ticks = (uint16_t) (__ms * 10.0);
+  while(__ticks)
+  {
+
+   _delay_loop_2(((((unsigned long)(16000000))) / 4e3) / 10);
+   __ticks --;
+  }
+  return;
+ }
+ else
+  __ticks = (uint16_t)__tmp;
+ _delay_loop_2(__ticks);
+}
+# 46 "/home/zer0/zavr/include/aversive/wait.h" 2
+# 59 "/home/zer0/zavr/include/aversive/wait.h"
+static inline void wait_ms(uint16_t n)
+{
+  while ( n -- )
+    _delay_loop_2(((unsigned long)(16000000))/4000);
+}
+# 25 "/home/zer0/zavr/projects/microb2010/tests/static_beacon/static_beacon.c" 2
+# 100 "/home/zer0/zavr/projects/microb2010/tests/static_beacon/static_beacon.c"
+static inline void xmit_0(void)
+{
+ uint8_t t = (((17 + 17) * 10) / 3);
+ (*(volatile uint8_t *)((0x2E) + 0x20)) = 0;
+ (*(volatile uint8_t *)((0x2F) + 0x20)) = 0;
+ _delay_loop_1(t);
+}
+
+static inline void xmit_1(void)
+{
+ uint8_t t = (((17 + 17) * 10) / 3);
+ (*(volatile uint8_t *)((0x2E) + 0x20)) = (1 << (4)) | (1 << (3));
+ (*(volatile uint16_t *)((0x2C) + 0x20)) = (17 + 17)-1;
+ (*(volatile uint8_t *)((0x2F) + 0x20)) = (1 << (7)) | (1 << (1));
+ (*(volatile uint8_t *)((0x2E) + 0x20)) = (1 << (4)) | (1 << (3)) | (1 << (0));
+ _delay_loop_1(t);
+}
+
+
+
+static inline void xmit_manchester_0(void)
+{
+ xmit_0();
+ xmit_1();
+}
+
+static inline void xmit_manchester_1(void)
+{
+ xmit_1();
+ xmit_0();
+}
+
+
+
+static void xmit_bits(uint8_t *buf, uint8_t nbit)
+{
+ uint8_t i;
+ uint8_t byte = *buf;
+
+ for (i=0; i<nbit; i++) {
+  if (byte & 1)
+   xmit_manchester_1();
+  else
+   xmit_manchester_0();
+
+
+  byte >>= 1;
+
+
+  if (((i & 0x07) == 0) && (i != 0))
+   byte = *(++buf);
+ }
+ xmit_0();
+}
+
+
+static inline int8_t wait_laser(void)
+{
+ uint8_t photos;
+ uint8_t time;
+
+
+
+ while (((*(volatile uint8_t *)((0x13) + 0x20)) & ((1 << (0)) | (1 << (1)))) != ((1 << (0)) | (1 << (1))));
+
+
+ while ((photos = ((*(volatile uint8_t *)((0x13) + 0x20)) & ((1 << (0)) | (1 << (1))))) == ((1 << (0)) | (1 << (1))));
+
+ if (photos != ((1 << (1))))
+  return -1;
+ time = (*(volatile uint8_t *)((0x32) + 0x20));
+ ( (*(volatile uint8_t *)((0x12) + 0x20)) |= (1 << (5)));
+
+
+ while ((photos = ((*(volatile uint8_t *)((0x13) + 0x20)) & ((1 << (0)) | (1 << (1))))) == ((1 << (1)))) {
+  if ((*(volatile uint8_t *)((0x32) + 0x20)) - time > ((uint8_t)25))
+   return -1;
+ }
+ if (photos != ((1 << (0)) | (1 << (1))))
+  return -1;
+
+
+
+ while ((photos = ((*(volatile uint8_t *)((0x13) + 0x20)) & ((1 << (0)) | (1 << (1))))) == ((1 << (0)) | (1 << (1)))) {
+  if ((*(volatile uint8_t *)((0x32) + 0x20)) - time > ((uint8_t)250))
+   return -1;
+ }
+ ( (*(volatile uint8_t *)((0x12) + 0x20)) |= (1 << (6)));
+ if ((*(volatile uint8_t *)((0x32) + 0x20)) - time < ((uint8_t)0))
+  return -1;
+ if (photos != ((1 << (0))))
+  return -1;
+# 206 "/home/zer0/zavr/projects/microb2010/tests/static_beacon/static_beacon.c"
+ return 0;
+}
+
+
+
+int main(void)
+{
+
+ uint8_t frame = 0x0B;
+ int8_t ret;
+
+
+ (*(volatile uint8_t *)((0x11) + 0x20)) = (1 << (5)) | (1 << (6)) | (1 << (7));
+ (*(volatile uint8_t *)((0x17) + 0x20)) |= (1 << (1));
+# 240 "/home/zer0/zavr/projects/microb2010/tests/static_beacon/static_beacon.c"
+ (*(volatile uint16_t *)((0x26) + 0x20)) = (17 + 17);
+ (*(volatile uint16_t *)((0x2A) + 0x20)) = 17;
+ (*(volatile uint8_t *)((0x2F) + 0x20)) = (1 << (7)) | (1 << (1));
+ (*(volatile uint8_t *)((0x2E) + 0x20)) = (1 << (4)) | (1 << (3));
+
+
+ (*(volatile uint8_t *)((0x33) + 0x20)) = (1 << (1)) | (1 << (0));
+
+ while (1) {
+
+
+  ret = wait_laser();
+
+  ( (*(volatile uint8_t *)((0x12) + 0x20)) &= ~ (1 << (5)));
+  ( (*(volatile uint8_t *)((0x12) + 0x20)) &= ~ (1 << (6)));
+
+  if (ret)
+   continue;
+
+
+
+  ( (*(volatile uint8_t *)((0x12) + 0x20)) |= (1 << (7)));
+
+  xmit_bits(&frame, 4);
+
+
+  wait_ms(10);
+  ( (*(volatile uint8_t *)((0x12) + 0x20)) &= ~ (1 << (7)));
+
+
+
+
+
+ }
+ return 0;
+}