X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=projects%2Fmicrob2010%2Fcobboard%2Fmain.c;h=215fb5c0ee895d393d35a4ea9c800029992417e7;hp=d0526a5161a8b917c2d1349dc42a74e7cd9c0dc9;hb=4f7bc6a1332aa9cd2ac3cf8f34bf990203cb03e7;hpb=1714f4ee916fca95ce24120ea6e698237913f947 diff --git a/projects/microb2010/cobboard/main.c b/projects/microb2010/cobboard/main.c index d0526a5..215fb5c 100755 --- a/projects/microb2010/cobboard/main.c +++ b/projects/microb2010/cobboard/main.c @@ -1,7 +1,7 @@ -/* +/* * Copyright Droids Corporation * Olivier Matz - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -58,13 +58,14 @@ #include "state.h" #include "actuator.h" #include "spickle.h" +#include "shovel.h" #include "cs.h" #include "i2c_protocol.h" /* 0 means "programmed" * ---- with 16 Mhz quartz * CKSEL 3-0 : 0111 - * SUT 1-0 : 10 + * SUT 1-0 : 10 * CKDIV8 : 1 * ---- bootloader * BOOTZ 1-0 : 01 (4K bootloader) @@ -108,22 +109,27 @@ void bootloader(void) __asm__ __volatile__ ("ldi r31,0xf8\n"); __asm__ __volatile__ ("ldi r30,0x00\n"); __asm__ __volatile__ ("eijmp\n"); - + /* never returns */ } void do_led_blink(__attribute__((unused)) void *dummy) { -#if 1 /* simple blink */ - static uint8_t a=0; - - if(a) - LED1_ON(); - else - LED1_OFF(); - - a = !a; -#endif + static uint8_t a = 0; + + if (cobboard.flags & DO_ERRBLOCKING) { + if (a & 1) + LED1_ON(); + else + LED1_OFF(); + } + else { + if (a & 4) + LED1_ON(); + else + LED1_OFF(); + } + a++; } static void main_timer_interrupt(void) @@ -152,7 +158,8 @@ int main(void) memset(&gen, 0, sizeof(gen)); memset(&cobboard, 0, sizeof(cobboard)); /* cs is enabled after arm_calibrate() */ - cobboard.flags = DO_ENCODERS | DO_POWER; // DO_BD + cobboard.flags = DO_ENCODERS | DO_POWER | DO_BD | + DO_ERRBLOCKING; /* UART */ uart_init(); @@ -166,13 +173,17 @@ int main(void) # error not supported #endif - eeprom_write_byte(EEPROM_MAGIC_ADDRESS, EEPROM_MAGIC_COBBOARD); /* check eeprom to avoid to run the bad program */ if (eeprom_read_byte(EEPROM_MAGIC_ADDRESS) != EEPROM_MAGIC_COBBOARD) { + int c; sei(); - printf_P(PSTR("Bad eeprom value\r\n")); - while(1); + printf_P(PSTR("Bad eeprom value ('f' to force)\r\n")); + c = uart_recv(CMDLINE_UART); + if (c == 'f') + eeprom_write_byte(EEPROM_MAGIC_ADDRESS, EEPROM_MAGIC_COBBOARD); + wait_ms(100); + bootloader(); } /* LOGS */ @@ -195,15 +206,15 @@ int main(void) timer0_register_OV_intr(main_timer_interrupt); /* PWM */ - PWM_NG_TIMER_16BITS_INIT(1, TIMER_16_MODE_PWM_10, + PWM_NG_TIMER_16BITS_INIT(1, TIMER_16_MODE_PWM_10, TIMER1_PRESCALER_DIV_1); - PWM_NG_TIMER_16BITS_INIT(4, TIMER_16_MODE_PWM_10, + PWM_NG_TIMER_16BITS_INIT(4, TIMER_16_MODE_PWM_10, TIMER4_PRESCALER_DIV_1); - - PWM_NG_INIT16(&gen.pwm1_4A, 4, A, 10, PWM_NG_MODE_SIGNED | - PWM_NG_MODE_SIGN_INVERTED, &PORTD, 4); - PWM_NG_INIT16(&gen.pwm2_4B, 4, B, 10, PWM_NG_MODE_SIGNED, - &PORTD, 5); + + PWM_NG_INIT16(&gen.pwm1_4A, 4, A, 10, PWM_NG_MODE_SIGNED, + &PORTD, 4); + PWM_NG_INIT16(&gen.pwm2_4B, 4, B, 10, PWM_NG_MODE_SIGNED | + PWM_NG_MODE_SIGN_INVERTED, &PORTD, 5); PWM_NG_INIT16(&gen.pwm3_1A, 1, A, 10, PWM_NG_MODE_SIGNED, &PORTD, 6); PWM_NG_INIT16(&gen.pwm4_1B, 1, B, 10, PWM_NG_MODE_SIGNED | @@ -212,11 +223,11 @@ int main(void) /* servos */ - PWM_NG_TIMER_16BITS_INIT(3, TIMER_16_MODE_PWM_10, + PWM_NG_TIMER_16BITS_INIT(3, TIMER_16_MODE_PWM_10, TIMER1_PRESCALER_DIV_256); PWM_NG_INIT16(&gen.servo1, 3, C, 10, PWM_NG_MODE_NORMAL, NULL, 0); - PWM_NG_TIMER_16BITS_INIT(5, TIMER_16_MODE_PWM_10, + PWM_NG_TIMER_16BITS_INIT(5, TIMER_16_MODE_PWM_10, TIMER1_PRESCALER_DIV_256); PWM_NG_INIT16(&gen.servo2, 5, A, 10, PWM_NG_MODE_NORMAL, NULL, 0); @@ -224,12 +235,12 @@ int main(void) NULL, 0); PWM_NG_INIT16(&gen.servo4, 5, C, 10, PWM_NG_MODE_NORMAL, NULL, 0); - + /* SCHEDULER */ scheduler_init(); - scheduler_add_periodical_event_priority(do_led_blink, NULL, - 100000L / SCHEDULER_UNIT, + scheduler_add_periodical_event_priority(do_led_blink, NULL, + 100000L / SCHEDULER_UNIT, LED_PRIO); /* all cs management */ microb_cs_init(); @@ -245,13 +256,16 @@ int main(void) sei(); - /* actuators */ - actuator_init(); + printf_P(PSTR("cobboard start\r\n")); - /* spickle */ + /* spickle, shovel */ spickle_init(); + shovel_init(); -/* state_init(); */ + /* actuators */ + actuator_init(); + + state_init(); printf_P(PSTR("\r\n")); printf_P(PSTR("Dass das Gluck deinen Haus setzt.\r\n")); @@ -261,7 +275,10 @@ int main(void) gen.log_level = 5; cobboard.flags |= DO_CS; -/* state_machine(); */ + spickle_pack(I2C_LEFT_SIDE); + spickle_pack(I2C_RIGHT_SIDE); + + state_machine(); cmdline_interact(); return 0;