2 * Copyright Droids Corporation
3 * Olivier Matz <zer0@droids-corp.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * Revision : $Id: main.c,v 1.8 2009-05-02 10:08:09 zer0 Exp $
27 #include <aversive/pgmspace.h>
28 #include <aversive/wait.h>
29 #include <aversive/error.h>
30 #include <avr/eeprom.h>
35 #include <scheduler.h>
36 #include <clock_time.h>
41 #include <control_system_manager.h>
42 #include <trajectory_manager.h>
43 #include <blocking_detection_manager.h>
44 #include <robot_system.h>
45 #include <position_manager.h>
46 #include <encoders_microb.h>
57 #if __AVR_LIBC_VERSION__ == 10602UL
58 //#error "won't work with this version"
61 /* 0 means "programmed"
62 * ---- with 16 Mhz quartz
67 * BOOTZ 1-0 : 01 (4K bootloader)
68 * BOOTRST : 0 (reset on bootloader)
74 struct mainboard mainboard;
76 void do_led_blink(void *dummy)
78 #if 1 /* simple blink */
83 static void main_timer_interrupt(void)
85 static uint8_t cpt = 0;
86 static uint8_t encoder_running = 0;
97 encoders_microb_manage(NULL);
100 if ((cpt & 0x3) == 0)
101 scheduler_interrupt();
118 memset(&gen, 0, sizeof(gen));
119 memset(&mainboard, 0, sizeof(mainboard));
120 mainboard.flags = DO_ENCODERS | DO_RS |
121 DO_POS | DO_POWER | DO_BD;
125 #if CMDLINE_UART == 0
126 fdevopen(uart0_dev_send, uart0_dev_recv);
127 uart_register_rx_event(0, emergency);
128 #elif CMDLINE_UART == 1
129 fdevopen(uart1_dev_send, uart1_dev_recv);
130 uart_register_rx_event(1, emergency);
132 # error not supported
136 error_register_emerg(mylog);
137 error_register_error(mylog);
138 error_register_warning(mylog);
139 error_register_notice(mylog);
140 error_register_debug(mylog);
142 encoders_microb_init();
146 timer0_register_OV_intr(main_timer_interrupt);
149 PWM_NG_TIMER_16BITS_INIT(1, TIMER_16_MODE_PWM_10,
150 TIMER1_PRESCALER_DIV_1);
151 PWM_NG_INIT16(&gen.pwm1_1A, 1, A, 10, PWM_NG_MODE_SIGNED,
153 PWM_NG_INIT16(&gen.pwm2_1B, 1, B, 10, PWM_NG_MODE_SIGNED,
158 PWM_NG_TIMER_16BITS_INIT(3, TIMER_16_MODE_PWM_10,
159 TIMER1_PRESCALER_DIV_1);
160 PWM_NG_INIT16(&gen.pwm3_3A, 3, A, 10, PWM_NG_MODE_SIGNED,
162 PWM_NG_INIT16(&gen.pwm4_3B, 3, B, 10, PWM_NG_MODE_SIGNED | PWM_NG_MODE_SIGN_INVERTED,
168 scheduler_add_periodical_event_priority(do_led_blink, NULL,
169 100000L / SCHEDULER_UNIT,
171 /* all cs management */
174 /* sensors, will also init hardware adc */
180 time_init(TIME_PRIO);
183 gen.logs[0] = E_USER_STRAT;
188 printf_P(PSTR("\r\n"));
189 printf_P(PSTR("Respekt Robustheit!\r\n"));