X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=projects%2Fmicrob2010%2Fcobboard%2Fmain.c;h=d01a92e83e42cc35a64e5c7f0b14c5896cb1c5af;hp=62103c813fa2faefaff7534219b5883a411f07db;hb=aa68be2d5d596693bda1109e4ccd6489f613b4f7;hpb=0c4732c1e255ea56aa766b772dfdb6be49620830 diff --git a/projects/microb2010/cobboard/main.c b/projects/microb2010/cobboard/main.c index 62103c8..d01a92e 100755 --- a/projects/microb2010/cobboard/main.c +++ b/projects/microb2010/cobboard/main.c @@ -115,16 +115,21 @@ void bootloader(void) void do_led_blink(__attribute__((unused)) void *dummy) { -#if 1 /* simple blink */ - static uint8_t a=0; + static uint8_t a = 0; - if(a) - LED1_ON(); - else - LED1_OFF(); - - a = !a; -#endif + 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) @@ -153,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(); @@ -167,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 */ @@ -183,8 +193,6 @@ int main(void) error_register_notice(mylog); error_register_debug(mylog); - wait_ms(3000); - /* SPI + ENCODERS */ encoders_spi_init(); /* this will also init spi hardware */ @@ -203,10 +211,10 @@ int main(void) 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 | @@ -248,6 +256,8 @@ int main(void) sei(); + printf_P(PSTR("cobboard start\r\n")); + /* actuators */ actuator_init(); @@ -265,6 +275,9 @@ int main(void) gen.log_level = 5; cobboard.flags |= DO_CS; + spickle_pack(I2C_LEFT_SIDE); + spickle_pack(I2C_RIGHT_SIDE); + state_machine(); cmdline_interact();