imuboard: fix call to bootloader
[fpv.git] / imuboard / main.c
index 386528b..7de8acb 100644 (file)
@@ -28,6 +28,9 @@
 /* fuses:
  * avrdude -p atmega1284p -P usb -c avrispmkii -U lfuse:w:0xff:m -U hfuse:w:0x91:m -U efuse:w:0xff:m
  * -> it failed but I answered y, then make reset and it was ok
+ *
+ * with bootloader:
+ * avrdude -p atmega1284p -P usb -c avrispmkii -U lfuse:w:0xff:m -U hfuse:w:0x90:m -U efuse:w:0xff:m
  */
 
 #include <aversive.h>
 #include <i2c.h>
 
 #include "eeprom_config.h"
+#include "gps.h"
+#ifdef GPS_VENUS
 #include "gps_venus.h"
+#endif
+#ifdef GPS_UBX
+#include "gps_ubx.h"
+#endif
 #include "sd_log.h"
 #include "../common/i2c_commands.h"
 #include "i2c_protocol.h"
 struct imuboard imuboard;
 volatile uint32_t global_ms;
 
-/* global xbee device */
-struct xbee_dev *xbee_dev;
-
 void bootloader(void)
 {
-#define BOOTLOADER_ADDR 0x3f000
+#define BOOTLOADER_ADDR 0x1e000
        if (pgm_read_byte_far(BOOTLOADER_ADDR) == 0xff) {
                printf_P(PSTR("Bootloader is not present\r\n"));
                return;
@@ -88,10 +94,10 @@ void bootloader(void)
        ACSR = 0;
        ADCSRA = 0;
 
-       /* XXX */
-       /* __asm__ __volatile__ ("ldi r31,0xf8\n"); */
-       /* __asm__ __volatile__ ("ldi r30,0x00\n"); */
-       /* __asm__ __volatile__ ("eijmp\n"); */
+       __asm__ __volatile__ ("ldi r30,0x00\n");
+       __asm__ __volatile__ ("ldi r31,0xf0\n");
+       //__asm__ __volatile__ ("eijmp\n");
+       __asm__ __volatile__ ("ijmp\n");
 }
 
 /* return time in milliseconds on unsigned 16 bits */
@@ -140,9 +146,6 @@ static void main_timer_interrupt(void)
                LED2_OFF();
 }
 
-/* XXX */
-int sd_main(void);
-
 int main(void)
 {
        DDRB = 0x18 /* LEDs */;
@@ -156,6 +159,17 @@ int main(void)
 
        callout_mgr_init(&imuboard.intr_cm, get_time_ms);
 
+#if 0
+       sei(); //XXX
+       printf_P(PSTR("starting...\r\n"));
+       while (1) {
+               int16_t c;
+               c = uart_recv_nowait(0);
+               if (c >= 0)
+                       printf("%x\n", (uint8_t)c);
+       }
+#endif
+
        cmdline_init();
        /* LOGS */
        error_register_emerg(mylog);
@@ -173,22 +187,28 @@ int main(void)
        i2c_register_recv_event(i2c_recvevent);
        i2c_register_send_event(i2c_sendevent);
 
+       sei();
+       printf_P(PSTR("starting...\r\n"));
        eeprom_load_config();
 
        sd_log_open();
 
-       sei();
-
        printf_P(PSTR("\r\n"));
        rdline_newline(&imuboard.rdl, imuboard.prompt);
 
-       //sd_main();
        imu_init();
-       //imu_loop();
+#ifdef GPS_VENUS
        gps_venus_init();
-       gps_loop();
+#endif
+#ifdef GPS_UBX
+       gps_ubx_init();
+#endif
+
+       imuboard.flags |= IMUBOARD_F_BOOT_OK;
 
        while (1) {
+               imu_log(0);
+               gps_log(0);
                cmdline_poll();
        }