-/*
+/*
* Copyright Droids Corporation
* Olivier Matz <zer0@droids-corp.org>
- *
+ *
* 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
#include <pwm_ng.h>
#include <timer.h>
#include <scheduler.h>
-#include <time.h>
+#include <clock_time.h>
#include <adc.h>
#include <pid.h>
#include "../common/i2c_commands.h"
#include "main.h"
+#include "robotsim.h"
#include "ax12_user.h"
#include "strat.h"
#include "cmdline.h"
#include "sensor.h"
#include "actuator.h"
#include "cs.h"
+#include "strat_base.h"
+#include "strat_db.h"
#include "i2c_protocol.h"
-#if __AVR_LIBC_VERSION__ == 10602UL
-#error "won't work with this version"
-#endif
-
/* 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)
struct genboard gen;
struct mainboard mainboard;
-struct mechboard mechboard;
-struct sensorboard sensorboard;
+volatile struct cobboard cobboard;
+volatile struct ballboard ballboard;
+#ifndef HOST_VERSION
/***********************/
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(void *dummy)
{
-#if 1 /* simple blink */
- LED1_TOGGLE();
-#endif
+ static uint8_t a = 0;
+
+ if (mainboard.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)
if ((cpt & 0x3) == 0)
scheduler_interrupt();
}
+#endif
int main(void)
{
- uint16_t seconds;
-
+#ifndef HOST_VERSION
/* brake */
BRAKE_DDR();
BRAKE_OFF();
LED2_OFF();
LED3_OFF();
LED4_OFF();
+#endif
memset(&gen, 0, sizeof(gen));
memset(&mainboard, 0, sizeof(mainboard));
- mainboard.flags = DO_ENCODERS | DO_RS |
- DO_POS | DO_POWER | DO_BD;
- sensorboard.opponent_x = I2C_OPPONENT_NOT_THERE;
+ mainboard.flags = DO_ENCODERS | DO_CS | DO_RS |
+ DO_POS | DO_POWER | DO_BD | DO_ERRBLOCKING;
+ ballboard.lcob = I2C_COB_NONE;
+ ballboard.rcob = I2C_COB_NONE;
/* UART */
uart_init();
+ uart_register_rx_event(CMDLINE_UART, emergency);
+#ifndef HOST_VERSION
#if CMDLINE_UART == 3
fdevopen(uart3_dev_send, uart3_dev_recv);
- uart_register_rx_event(3, emergency);
#elif CMDLINE_UART == 1
fdevopen(uart1_dev_send, uart1_dev_recv);
- uart_register_rx_event(1, emergency);
-#else
-# error not supported
#endif
- //eeprom_write_byte(EEPROM_MAGIC_ADDRESS, EEPROM_MAGIC_MAINBOARD);
/* check eeprom to avoid to run the bad program */
if (eeprom_read_byte(EEPROM_MAGIC_ADDRESS) !=
EEPROM_MAGIC_MAINBOARD) {
+ 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_MAINBOARD);
+ wait_ms(100);
+ bootloader();
}
+#endif /* ! HOST_VERSION */
/* LOGS */
error_register_emerg(mylog);
error_register_notice(mylog);
error_register_debug(mylog);
+#ifndef HOST_VERSION
/* SPI + ENCODERS */
encoders_spi_init(); /* this will also init spi hardware */
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 |
+
+ 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);
/* 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);
NULL, 0);
PWM_NG_INIT16(&gen.servo4, 5, C, 10, PWM_NG_MODE_NORMAL,
NULL, 0);
- pwm_ng_set(&gen.servo2, 290); /* right */
- pwm_ng_set(&gen.servo3, 400); /* left */
- /* 2 lintels 180, 485 */
- /* 1 lintel 155, 520 */
+ support_balls_deploy(); /* init pwm for servos */
+#endif /* !HOST_VERSION */
/* SCHEDULER */
scheduler_init();
+#ifdef HOST_VERSION
+ hostsim_init();
+ robotsim_init();
+#endif
- scheduler_add_periodical_event_priority(do_led_blink, NULL,
- 100000L / SCHEDULER_UNIT,
+#ifndef HOST_VERSION
+ scheduler_add_periodical_event_priority(do_led_blink, NULL,
+ 100000L / SCHEDULER_UNIT,
LED_PRIO);
+#endif /* !HOST_VERSION */
+
/* all cs management */
microb_cs_init();
- /* sensors, will also init hardware adc */
- sensor_init();
-
/* TIME */
time_init(TIME_PRIO);
+#ifndef HOST_VERSION
+ /* sensors, will also init hardware adc */
+ sensor_init();
+
/* start i2c slave polling */
scheduler_add_periodical_event_priority(i2c_poll_slaves, NULL,
8000L / SCHEDULER_UNIT, I2C_POLL_PRIO);
+#endif /* !HOST_VERSION */
/* strat */
gen.logs[0] = E_USER_STRAT;
gen.log_level = 5;
- strat_reset_infos();
+ strat_db_init();
/* strat-related event */
scheduler_add_periodical_event_priority(strat_event, NULL,
25000L / SCHEDULER_UNIT,
STRAT_PRIO);
+#ifndef HOST_VERSION
/* eeprom time monitor */
scheduler_add_periodical_event_priority(do_time_monitor, NULL,
1000000L / SCHEDULER_UNIT,
EEPROM_TIME_PRIO);
+#endif /* !HOST_VERSION */
sei();
printf_P(PSTR("\r\n"));
printf_P(PSTR("Respect et robustesse.\r\n"));
- seconds = eeprom_read_word(EEPROM_TIME_ADDRESS);
- printf_P(PSTR("Running since %d mn %d\r\n"), seconds/60, seconds%60);
+#ifndef HOST_VERSION
+ {
+ uint16_t seconds;
+ seconds = eeprom_read_word(EEPROM_TIME_ADDRESS);
+ printf_P(PSTR("Running since %d mn %d\r\n"), seconds/60, seconds%60);
+ }
+#endif
+
+#ifdef HOST_VERSION
+ strat_reset_pos(400, COLOR_Y(400), COLOR_A(-90));
+#endif
+
cmdline_interact();
return 0;