2 * Copyright (c) 2011, Olivier MATZ <zer0@droids-corp.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the University of California, Berkeley nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * avrdude -p atmega1284p -P usb -c avrispmkii -U lfuse:w:0xff:m -U hfuse:w:0x91:m -U efuse:w:0xff:m
30 * -> it failed but I answered y, then make reset and it was ok
34 #include <aversive/queue.h>
35 #include <aversive/endian.h>
36 #include <aversive/wait.h>
37 #include <aversive/error.h>
56 #include "eeprom_config.h"
57 #include "gps_venus.h"
59 #include "../fpv-common/i2c_commands.h"
60 #include "i2c_protocol.h"
64 struct imuboard imuboard;
65 volatile uint32_t global_ms;
67 /* global xbee device */
68 struct xbee_dev *xbee_dev;
72 #define BOOTLOADER_ADDR 0x3f000
73 if (pgm_read_byte_far(BOOTLOADER_ADDR) == 0xff) {
74 printf_P(PSTR("Bootloader is not present\r\n"));
78 /* ... very specific :( */
92 /* __asm__ __volatile__ ("ldi r31,0xf8\n"); */
93 /* __asm__ __volatile__ ("ldi r30,0x00\n"); */
94 /* __asm__ __volatile__ ("eijmp\n"); */
97 /* return time in milliseconds on unsigned 16 bits */
98 uint16_t get_time_ms(void)
108 static void main_timer_interrupt(void)
110 static uint16_t cycles;
111 static uint8_t stack = 0;
112 static uint8_t cpt = 0;
116 if (global_ms & 0x80)
121 if ((cpt & 0x03) != 0)
124 /* the following code is only called one interrupt among 4: every 682us
125 * (at 12 Mhz) = 8192 cycles */
127 if (cycles >= 12000) {
136 if ((cpt & 0x3) == 0)
137 callout_manage(&imuboard.intr_cm);
148 DDRB = 0x18 /* LEDs */;
151 uart_register_rx_event(CMDLINE_UART, emergency);
153 fdevopen(cmdline_dev_send, cmdline_dev_recv);
155 timer0_register_OV_intr(main_timer_interrupt);
157 callout_mgr_init(&imuboard.intr_cm, get_time_ms);
161 error_register_emerg(mylog);
162 error_register_error(mylog);
163 error_register_warning(mylog);
164 error_register_notice(mylog);
165 error_register_debug(mylog);
167 /* communication with mpu6050 */
170 /* i2c hw to communicate with mainboard */
171 i2c_init(I2C_MODE_SLAVE, I2C_IMUBOARD_ADDR);
173 i2c_register_recv_event(i2c_recvevent);
174 i2c_register_send_event(i2c_sendevent);
176 eeprom_load_config();
182 printf_P(PSTR("\r\n"));
183 rdline_newline(&imuboard.rdl, imuboard.prompt);