summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--n/es-2006/src/Makefile13
-rw-r--r--n/es-2006/src/avrconfig.h86
-rw-r--r--n/es-2006/src/main.c91
-rw-r--r--n/es-2006/src/rvb_sensor.c218
-rw-r--r--n/es-2006/src/rvb_sensor.h70
-rw-r--r--n/es-2006/src/timer.h51
6 files changed, 529 insertions, 0 deletions
diff --git a/n/es-2006/src/Makefile b/n/es-2006/src/Makefile
new file mode 100644
index 0000000..6bbb85a
--- /dev/null
+++ b/n/es-2006/src/Makefile
@@ -0,0 +1,13 @@
+BASE = ../../avr
+PROGS = es
+es_SOURCES = main.c rvb_sensor.c
+MODULES = proto uart utils
+CONFIGFILE = avrconfig.h
+# atmega8, atmega8535, atmega128...
+AVR_MCU = atmega64
+# -O2 : speed
+# -Os : size
+OPTIMIZE = -O2
+HOST_LIBS = -lm
+
+include $(BASE)/make/Makefile.gen
diff --git a/n/es-2006/src/avrconfig.h b/n/es-2006/src/avrconfig.h
new file mode 100644
index 0000000..2c2c103
--- /dev/null
+++ b/n/es-2006/src/avrconfig.h
@@ -0,0 +1,86 @@
+#ifndef avrconfig_h
+#define avrconfig_h
+/* avrconfig.h */
+/* asserv - Position & speed motor control on AVR. {{{
+ *
+ * Copyright (C) 2005 Nicolas Schodet
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * 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
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+/* global */
+/** AVR Frequency : 1000000, 1843200, 2000000, 3686400, 4000000, 7372800,
+ * 8000000, 11059200, 14745600, 16000000, 18432000, 20000000. */
+#define AC_FREQ 14745600
+
+/* uart - UART module. */
+/** Select hardware uart for primary uart: 0, 1 or -1 to disable. */
+#define AC_UART0_PORT 1
+/** Baudrate: 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 76800,
+ * 115200, 230400, 250000, 500000, 1000000. */
+#define AC_UART0_BAUDRATE 115200
+/** Send mode:
+ * - POLLING: no interrupts.
+ * - RING: interrupts, ring buffer. */
+#define AC_UART0_SEND_MODE RING
+/** Recv mode, same as send mode. */
+#define AC_UART0_RECV_MODE RING
+/** Character size: 5, 6, 7, 8, 9 (only 8 implemented). */
+#define AC_UART0_CHAR_SIZE 8
+/** Parity : ODD, EVEN, NONE. */
+#define AC_UART0_PARITY EVEN
+/** Stop bits : 1, 2. */
+#define AC_UART0_STOP_BITS 1
+/** Send buffer size, should be power of 2 for RING mode. */
+#define AC_UART0_SEND_BUFFER_SIZE 32
+/** Recv buffer size, should be power of 2 for RING mode. */
+#define AC_UART0_RECV_BUFFER_SIZE 32
+/** If the send buffer is full when putc:
+ * - DROP: drop the new byte.
+ * - WAIT: wait until there is room in the send buffer. */
+#define AC_UART0_SEND_BUFFER_FULL WAIT
+/** In HOST compilation:
+ * - STDIO: use stdin/out.
+ * - PTS: use pseudo terminal. */
+#define AC_UART0_HOST_DRIVER PTS
+/** Same thing for secondary port. */
+#define AC_UART1_PORT -1
+#define AC_UART1_BAUDRATE 115200
+#define AC_UART1_SEND_MODE RING
+#define AC_UART1_RECV_MODE RING
+#define AC_UART1_CHAR_SIZE 8
+#define AC_UART1_PARITY EVEN
+#define AC_UART1_STOP_BITS 1
+#define AC_UART1_SEND_BUFFER_SIZE 32
+#define AC_UART1_RECV_BUFFER_SIZE 32
+#define AC_UART1_SEND_BUFFER_FULL WAIT
+#define AC_UART1_HOST_DRIVER PTS
+
+/* proto - Protocol module. */
+/** Maximum argument size. */
+#define AC_PROTO_ARGS_MAX_SIZE 8
+/** Callback function name. */
+#define AC_PROTO_CALLBACK proto_callback
+/** Putchar function name. */
+#define AC_PROTO_PUTC uart0_putc
+/** Support for quote parameter. */
+#define AC_PROTO_QUOTE 1
+
+#endif /* avrconfig_h */
diff --git a/n/es-2006/src/main.c b/n/es-2006/src/main.c
new file mode 100644
index 0000000..dc4f14f
--- /dev/null
+++ b/n/es-2006/src/main.c
@@ -0,0 +1,91 @@
+/* main.c */
+/* es - Input/Output general purpose board. {{{
+ *
+ * Copyright (C) 2006 Dufour Jérémy
+ *
+ * Robot APB Team/Efrei 2004.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * 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
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+#include "common.h"
+#include "io.h"
+#include "modules/uart/uart.h"
+#include "modules/proto/proto.h"
+#include "modules/utils/utils.h"
+
+#include "timer.h"
+#include "rvb_sensor.h"
+
+
+/* Statistics for sensors */
+uint8_t rvb_sensors_stats = 0;
+uint8_t rvb_sensors_stats_enable = 0;
+
+/** Call when we receive some data from proto (uart) */
+void
+proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
+{
+ /* This macro combine command and size in one integer. */
+#define c(cmd, size) (cmd << 8 | size)
+ switch (c (cmd, size))
+ {
+ /* Reset */
+ case c ('z', 0):
+ utils_reset ();
+ break;
+ case c ('S', 1):
+ rvb_sensors_stats = rvb_sensors_stats_enable = args[0];
+ break;
+ case c ('s', 2):
+ rvb_sensor_watch (args[0], args[1]);
+ break;
+ /* Unknown command */
+ default:
+ proto_send0 ('?');
+ return;
+ }
+ /* When no error acknoledge. */
+ proto_send (cmd, size, args);
+#undef c
+}
+
+int
+main (void)
+{
+ uart0_init ();
+ timer_init ();
+ rvb_sensors_init ();
+ sei ();
+ proto_send0 ('z');
+
+ while (1)
+ {
+ timer_wait ();
+ if (rvb_sensors_stats_enable && !--rvb_sensors_stats)
+ {
+ rvb_sensors_stats = rvb_sensors_stats_enable;
+ proto_send4w ('S', rvb_sensors_values[7][0],
+ rvb_sensors_values[7][1], rvb_sensors_values[7][2],
+ rvb_sensors_values[7][3]);
+ }
+ rvb_sensors_start_update ();
+ while (uart0_poll ())
+ proto_accept (uart0_getc ());
+ }
+}
diff --git a/n/es-2006/src/rvb_sensor.c b/n/es-2006/src/rvb_sensor.c
new file mode 100644
index 0000000..0315e1c
--- /dev/null
+++ b/n/es-2006/src/rvb_sensor.c
@@ -0,0 +1,218 @@
+/* rvb_sensor.c */
+/* es - Input/Output general purpose board. {{{
+ *
+ * Copyright (C) 2006 Dufour Jérémy
+ *
+ * Robot APB Team/Efrei 2004.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * 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
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+#include "rvb_sensor.h"
+
+#include "io.h"
+#include "modules/utils/utils.h" /* regv */
+#include "modules/uart/uart.h" /* */
+
+#define S1RVB 7
+#define S0RVB 6
+/* Wait time between IO change in ns */
+#define RVB_SENSOR_DELAY_IO 125
+
+/** Internal counter */
+static volatile uint16_t sensor_value_;
+/** Sensor state flag */
+static volatile uint8_t sensor_state_;
+/** Sensor used actually */
+volatile uint8_t sensor_number_;
+/** Color of the actual sensor */
+volatile uint8_t sensor_color_;
+/** Number of overflow interruption since last edge change */
+uint8_t sensor_overflow_count_;
+
+volatile uint16_t rvb_sensors_values [9][5];
+
+uint8_t sensor_disable = 0;
+
+/** Update everything for you. */
+static void
+rvb_sensors_update_state (void)
+{
+// uart0_putc ('u');
+ if (sensor_state_ == 1)
+ {
+ /* Disable sensors */
+ rvb_sensors_disable ();
+ /* Wait a little */
+ utils_delay_ns (RVB_SENSOR_DELAY_IO);
+ switch (++sensor_number_)
+ {
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+// PORTC = ~_BV(sensor_number_);
+// break;
+ case 8:
+// PORTD &= ~_BV(6);
+// break;
+ case 9:
+// PORTC = ~_BV(0);
+// break;
+ PORTD &= ~_BV(6);
+ break;
+ default:
+ /* We are at the end */
+ sensor_state_ = 0;
+ return;
+ }
+ /* Wait for output of sensor to be ready */
+ utils_delay_ns (RVB_SENSOR_DELAY_IO);
+ /* Start with first color */
+ sensor_color_ = 0;
+ }
+ /* Select the color */
+ PORTF = (PORTF & ~0xC0) | (sensor_color_ << 6);
+ /* Enable interrupt for IC1 */
+ TIMSK |= _BV (TICIE1);
+// uart0_putc ('e');
+ // XXX
+// TIMSK |= _BV (TOIE1);
+}
+
+/** Counter 1 overflow. */
+SIGNAL (SIG_OVERFLOW1)
+{
+ // XXX For the moment.
+ if (++sensor_overflow_count_ == 2)
+ {
+ sensor_state_ = 1;
+ rvb_sensors_update_state ();
+ }
+}
+
+/** Interrupt on falling edge for Input Capture 1. */
+SIGNAL (SIG_INPUT_CAPTURE1)
+{
+ switch (sensor_state_)
+ {
+ case 1:
+ /* Ignore this capture */
+ sensor_state_++;
+ break;
+ case 2:
+ /* Save capture start */
+ sensor_value_ = ICR1;
+ /* New capture */
+ sensor_overflow_count_ = 0;
+ /* Enable interruption for overflow */
+ sensor_state_++;
+// TIMSK |= _BV (TOIE1);
+ break;
+ case 3:
+ /* Disable this interruption */
+ TIMSK &= ~_BV (TICIE1);
+ /* Disable interruption for overflow */
+ TIMSK &= ~_BV (TOIE1);
+ /* Compute value */
+ //TODO
+ sensor_value_ = ICR1 - sensor_value_;
+ /* Save */
+ rvb_sensors_values[sensor_number_ - 1][sensor_color_] = sensor_value_;
+ /* Next color */
+ sensor_color_++;
+ /* If no more colour, next sensor */
+ if (sensor_color_ == 4)
+ sensor_state_ = 1;
+ rvb_sensors_update_state ();
+ break;
+ }
+}
+
+/** Start updating RVBC values for sensors. */
+void
+rvb_sensors_start_update (void)
+{
+// uart0_putc ('i');
+ /* Are we already getting a sensor ? */
+ if (!sensor_state_ && !sensor_disable)
+ {
+ sensor_state_ = 1;
+ /* Start with sensor one */
+ sensor_number_ = 0;
+ /* Select it and launch capture */
+ rvb_sensors_update_state ();
+ }
+}
+
+/** Initialisation. */
+void
+rvb_sensors_init (void)
+{
+ /* Disable sensors */
+ rvb_sensors_disable ();
+ /* Put enable ports in output mode */
+ DDRC = 0xff;
+ DDRD |= _BV(6);
+ /* Put color selector mode in output mode */
+ DDRF |= _BV(S0RVB) | _BV(S1RVB);
+ /* Initialisation of counter :
+ * Noise canceler, 1 for prescaling and that's all */
+ TCCR1B |= _BV(ICNC1) | _BV(CS10);
+ /* Nothing to do for the moment */
+ sensor_state_ = 0;
+}
+
+void
+rvb_sensor_watch (uint8_t sensor_num, uint8_t sensor_col)
+{
+ /* Disable this interruption */
+ TIMSK &= ~_BV (TICIE1);
+ /* Disable interruption for overflow */
+ TIMSK &= ~_BV (TOIE1);
+ sensor_disable = 1;
+ /* Disable sensors */
+ rvb_sensors_disable ();
+ /* Wait a little */
+ utils_delay_ns (RVB_SENSOR_DELAY_IO);
+ switch (++sensor_num)
+ {
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ PORTC = ~_BV(sensor_num);
+ break;
+ case 8:
+ PORTD &= ~_BV(6);
+ break;
+ case 9:
+ PORTC = ~_BV(0);
+ break;
+ }
+ /* Wait for output of sensor to be ready */
+ utils_delay_ns (RVB_SENSOR_DELAY_IO);
+ /* Select the color */
+ PORTF = (PORTF & ~0xC0) | (sensor_col << 6);
+}
+
diff --git a/n/es-2006/src/rvb_sensor.h b/n/es-2006/src/rvb_sensor.h
new file mode 100644
index 0000000..cddf20d
--- /dev/null
+++ b/n/es-2006/src/rvb_sensor.h
@@ -0,0 +1,70 @@
+#ifndef rvb_sensor_h
+#define rvb_sensor_h
+// rvb_sensor.h
+// es - Input/Output general purpose board. {{{
+//
+// Copyright (C) 2006 Dufour Jérémy
+//
+// Robot APB Team/Efrei 2004.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// 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
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+
+#include "common.h"
+#include "io.h"
+
+/** Manage all the RVB sensors.
+Connectors :
+ ENARVB7 PORTC7
+ ENARVB6 PORTC6
+ ENARVB5 PORTC5
+ ENARVB4 PORTC4
+ ENARVB3 PORTC3
+ ENARVB2 PORTC2
+ ENARVB1 PORTC1
+ ENANB1 PORTD6
+ ENANB2 PORTC0
+ OUTRVB PORTD7/PORTD4(IC1)
+ S0RVB PORTF6
+ S1RVB PORTF7
+*/
+
+/* Wonderful table of data */
+// XXX
+extern volatile uint16_t rvb_sensors_values [9][5];
+
+/** Disable all sensors. */
+extern inline void rvb_sensors_disable (void)
+{
+ /* High for disable */
+ PORTC = 0xff;
+ PORTD |= _BV(6);
+}
+
+/** Initialisation. */
+void rvb_sensors_init (void);
+
+/** Start updating RVBC values for sensors. */
+void rvb_sensors_start_update (void);
+
+// XXX
+extern uint8_t sensor_disable;
+void
+rvb_sensor_watch (uint8_t sensor_num, uint8_t color_num);
+
+#endif // rvb_sensor_h
diff --git a/n/es-2006/src/timer.h b/n/es-2006/src/timer.h
new file mode 100644
index 0000000..70f2de6
--- /dev/null
+++ b/n/es-2006/src/timer.h
@@ -0,0 +1,51 @@
+#ifndef timer_h
+#define timer_h
+// timer.h
+// es - Input/Output general purpose board. {{{
+//
+// Copyright (C) 2006 Dufour Jérémy
+// From Ni.
+//
+// Robot APB Team/Efrei 2004.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// 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
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+
+/** Initialise the timer. */
+inline void
+timer_init (void)
+{
+ TCCR0 = regv (FOC0, WGM00, COM01, COM0, WGM01, CS02, CS01, CS00,
+ 0, 0, 0, 0, 0, 1, 1, 0);
+ /* Fov = F_io / (prescaler * (TOP + 1))
+ * TOP = 0xff
+ * prescaler = 256
+ * Tov = 1 / Fov = 4.444 ms */
+}
+
+/** Wait for timer overflow. */
+inline void
+timer_wait (void)
+{
+ while (!(TIFR & _BV (TOV0)))
+ ;
+ /* Write 1 to clear. */
+ TIFR = _BV (TOV0);
+}
+
+#endif // timer_h