summaryrefslogtreecommitdiff
path: root/n/es-2006/src
diff options
context:
space:
mode:
authordufourj2006-05-11 21:39:02 +0000
committerdufourj2006-05-11 21:39:02 +0000
commite9e974cb64950afe3bf54c82d5a047a18655b831 (patch)
tree262f27a7aa25b73b4fc7f32655e03aa3cc330a12 /n/es-2006/src
parent4d3ee19aec9942f5ef1ddcc2b0dd843cd50bf49a (diff)
ES :
RVB : - renomage de es_config en timer_1 ; - possibilité de configurer des paramètres du module RVB de façon dynamique. Autre : - ajout de la gestion du bouton de sélection de couleurs, jack et contact frontal (Patrick).
Diffstat (limited to 'n/es-2006/src')
-rw-r--r--n/es-2006/src/Makefile2
-rw-r--r--n/es-2006/src/main.c29
-rw-r--r--n/es-2006/src/others.h82
-rw-r--r--n/es-2006/src/sensor_rvb.c87
-rw-r--r--n/es-2006/src/sensor_rvb.h16
-rw-r--r--n/es-2006/src/timer_1.c (renamed from n/es-2006/src/es_config.c)4
-rw-r--r--n/es-2006/src/timer_1.h (renamed from n/es-2006/src/es_config.h)8
-rw-r--r--n/es-2006/src/timer_main.h1
8 files changed, 164 insertions, 65 deletions
diff --git a/n/es-2006/src/Makefile b/n/es-2006/src/Makefile
index 0c109f3..460d20d 100644
--- a/n/es-2006/src/Makefile
+++ b/n/es-2006/src/Makefile
@@ -1,6 +1,6 @@
BASE = ../../avr
PROGS = es
-es_SOURCES = main.c sensor_rvb.c es_config.c barillet.c
+es_SOURCES = main.c sensor_rvb.c timer_1.c barillet.c
MODULES = proto uart utils
CONFIGFILE = avrconfig.h
# atmega8, atmega8535, atmega128...
diff --git a/n/es-2006/src/main.c b/n/es-2006/src/main.c
index e95db14..b69c861 100644
--- a/n/es-2006/src/main.c
+++ b/n/es-2006/src/main.c
@@ -32,8 +32,9 @@
#include "timer_main.h" /* main timer */
#include "sensor_rvb.h" /* RVB sensors management */
-#include "es_config.h" /* timer/counter 1 */
+#include "timer_1.h" /* timer/counter 1 */
+#include "others.h" /* define game color mode + jack + frontal sensor */
/* Statistics for RVB sensors */
uint8_t sensor_rvb_stat_enable[RVB_MAX_SENSOR] = { 0 };
@@ -61,9 +62,25 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
sensor_rvb_stat_enable[compt] = sensor_rvb_stats[compt] =
args[2];
break;
-// case c ('s', 2):
-// sensor_rvb_watch (args[0], args[1]);
+ /* RVB sensors configuration */
+ case c ('R', 3):
+ sensor_rvb_config (args[0], args[1], args[2]);
+ break;
+ /* color mode game */
+ case c ('c', 0 ):
+ proto_send1b('c', others_selectcoul());
+ break;
+
+// /* contact */
+// case c ('t', 0 ):
+// proto_send1b('t', others_contact());
// break;
+//
+// /* jack */
+// case c ('j', 0 ):
+// proto_send1b('j', others_jack());
+// break;
+
/* Unknown commands */
default:
proto_send0 ('?');
@@ -88,7 +105,8 @@ main (void)
timer1_init ();
/* Init RVB sensors system */
sensor_rvb_init ();
-
+ /* Init Color button init */
+ others_init();
/* Enable interrupts */
sei ();
@@ -106,7 +124,8 @@ main (void)
{
/* Re init stats system for this sensor */
sensor_rvb_stats[compt] = sensor_rvb_stat_enable[compt];
- proto_send4w ('S', sensor_rvb_values[compt][0],
+ // FIXME useless 16 bit value.
+ proto_send5w ('S', compt, sensor_rvb_values[compt][0],
sensor_rvb_values[compt][1], sensor_rvb_values[compt][2],
sensor_rvb_values[compt][3]);
}
diff --git a/n/es-2006/src/others.h b/n/es-2006/src/others.h
new file mode 100644
index 0000000..dd88722
--- /dev/null
+++ b/n/es-2006/src/others.h
@@ -0,0 +1,82 @@
+#ifndef others_h
+#define others_h
+// others.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/io.h"
+
+/* pin responsible for the color mode */
+#define JACK_PIN 0
+#define SELECT_COLOR_PIN 1
+#define CONTACT_PIN 2
+
+/* (to be set 1 <-> 0) */
+#define BLUE_COLOR_GAME_MODE _BV(0) /* 0000 0000 = 0 */
+#define RED_COLOR_GAME_MODE _BV(SELECT_COLOR_PIN) /* 0000 0010 = 2 */
+
+/* READ PINA */
+/* access to value of pins of PORTA */
+#define GET_PIN_OF_PORTA(n) ( PINA & _BV(n) )
+
+// /* SET DDRA */
+// /* set bit of DDR to 0 in order to set the pin n of PORTA in mode in */
+// #define SET_PIN_IN_MODE_IN_OF_PORTA(n) ( DDRA &= ~_BV(n) )
+// /* set bit of DDR to 1 in order to set the pin n of PORTA in mode out */
+// #define SET_PIN_IN_MODE_OUT_OF_PORTA(n) ( DDRA |= ~_BV(n) )
+
+/** return the value of pin select color */
+inline uint8_t others_selectcoul(void)
+{
+ return GET_PIN_OF_PORTA(SELECT_COLOR_PIN);
+};
+
+/** return the value of pin jack */
+inline uint8_t others_jack(void)
+{
+ return GET_PIN_OF_PORTA(JACK_PIN);
+};
+
+/** return the value of pin contact */
+inline uint8_t others_contact(void)
+{
+ return GET_PIN_OF_PORTA(CONTACT_PIN);
+};
+
+/** initialisation of color button (put select color pin in mode 'IN') */
+inline void others_init(void)
+{
+ /* init DDRA (0 default) */
+
+ /* DDR = 0 pin in mode IN */
+ /* XXXX XXXX & 1111 1101 = XXXX XX0X */
+ /* DDRA &= ~_BV(SELECT_COLOR_PIN); */
+
+ /* pull up in mode in */
+ PORTA = PORTA | _BV(SELECT_COLOR_PIN) | _BV(JACK_PIN) | _BV(CONTACT_PIN);
+};
+
+
+
+#endif // others_h
diff --git a/n/es-2006/src/sensor_rvb.c b/n/es-2006/src/sensor_rvb.c
index b6576e1..e98d62f 100644
--- a/n/es-2006/src/sensor_rvb.c
+++ b/n/es-2006/src/sensor_rvb.c
@@ -23,7 +23,7 @@
*
* }}} */
#include "sensor_rvb.h"
-#include "es_config.h"
+#include "timer_1.h"
#include "io.h"
#include "modules/utils/utils.h" /* regv */
@@ -34,11 +34,12 @@
/** Colors selection pins. */
#define S1RVB 7
#define S0RVB 6
-/** Max input capture before considering we can start the real capture. */
-#define RVB_MAX_FALSE_IC 8
+/** Max input capture before considering we can start the real capture.
+ * (default value) */
+#define RVB_MAX_FALSE_IC 9
/** Max overflow of the timer 1 before thinking the sensor is HS. */
/* TODO Find a way to compute this value */
-#define RVB_MAX_OVERFLOW 250
+#define RVB_MAX_OVERFLOW 253
/** Wait time between IO change in ns. */
#define RVB_SENSOR_DELAY_IO 125
/** All the possible states. */
@@ -52,6 +53,13 @@
#define RVB_STATE_NEXT_COLOR 4 /* Selecting another color */
#define RVB_STATE_WATCH 5 /* For debuging */
+/*** Config ***/
+/** Max input capture before considering we can start the real capture. */
+uint8_t sensor_rvb_conf_max_false_ic_;
+/** Max overflow of the timer 1 before thinking the sensor is HS. */
+uint8_t sensor_rvb_conf_max_ov_;
+/** Wait time between IO change in ns. */
+uint8_t sensor_rvb_conf_delay_;
/** RVB sensor state flag. */
volatile uint8_t sensor_rvb_state_;
/** Internal computed result for one color. */
@@ -64,8 +72,6 @@ volatile uint8_t sensor_rvb_color_;
volatile uint8_t sensor_rvb_overflow_count_;
/** Results table for 9 RVB sensors (RVCB) */
volatile uint16_t sensor_rvb_values[RVB_MAX_SENSOR][4];
-/** Geting stats only for one sensors and disabling computing the others. */
-uint8_t sensor_rvb_enable;
/** Count the number of IC before starting a good capture. */
uint8_t sensor_rvb_ic_count_;
@@ -89,7 +95,7 @@ sensor_rvb_color_select (uint8_t sensor_rvb_color)
/* Select the color */
PORTF = (PORTF & ~0xC0) | (sensor_rvb_color << 6);
/* Wait a little */
- utils_delay_ns (RVB_SENSOR_DELAY_IO);
+ utils_delay_ns (sensor_rvb_conf_delay_);
/* Color exists */
return 1;
default:
@@ -124,11 +130,11 @@ sensor_rvb_sensor_select (uint8_t sensor_rvb_num)
PORTC = 0xff;
PORTD |= _BV(6);
/* Wait a little */
- utils_delay_ns (RVB_SENSOR_DELAY_IO);
+ utils_delay_ns (sensor_rvb_conf_delay_);
return 0;
}
/* Wait a little */
- utils_delay_ns (RVB_SENSOR_DELAY_IO);
+ utils_delay_ns (sensor_rvb_conf_delay_);
return 1;
}
@@ -136,8 +142,10 @@ sensor_rvb_sensor_select (uint8_t sensor_rvb_num)
void
sensor_rvb_init (void)
{
- /* We enable the system */
- sensor_rvb_enable = 1;
+ /* Init config */
+ sensor_rvb_conf_max_false_ic_ = RVB_MAX_FALSE_IC;
+ sensor_rvb_conf_max_ov_ = RVB_MAX_OVERFLOW;
+ sensor_rvb_conf_delay_ = RVB_SENSOR_DELAY_IO;
/* No sensor selected */
sensor_rvb_sensor_select (0);
/* Put ENA* pins in output */
@@ -149,46 +157,33 @@ sensor_rvb_init (void)
sensor_rvb_state_ = RVB_STATE_SLEEP;
}
+/** Configure some internal variables. */
+void
+sensor_rvb_config (uint8_t false_ic, uint8_t max_ov, uint8_t latency)
+{
+ sensor_rvb_conf_max_false_ic_ = false_ic;
+ sensor_rvb_conf_max_ov_ = max_ov;
+ sensor_rvb_conf_delay_ = latency;
+}
+
/** Start updating RVBC values for sensors. */
void
sensor_rvb_start_capture (void)
{
/* Are we already getting a sensor ? */
- if ((sensor_rvb_state_ == RVB_STATE_SLEEP) && sensor_rvb_enable)
+ if (sensor_rvb_state_ == RVB_STATE_SLEEP)
{
sensor_rvb_state_ = RVB_STATE_NEXT_SENSOR;
/* Start with sensor one */
sensor_rvb_number_ = 0;
/* Select it and launch capture */
sensor_rvb_update ();
+ /* Enable interrupt for IC1 and counter overflow */
+ TIMSK |= _BV (TICIE1);
+ TIMSK |= _BV (TOIE1);
}
}
-/** Watch only one sensor. Usefull for debugging. *//*{{{*/
-void
-sensor_rvb_watch (uint8_t sensor_num, uint8_t sensor_col)
-{
- // XXX Better approach.
- return;
- /* Disable all interrupt that could be enabled */
- TIMSK &= ~_BV (TICIE1);
- TIMSK &= ~_BV (TOIE1);
- /* Put ourself in off mode */
- sensor_rvb_enable = 0;
- sensor_rvb_state_ = RVB_STATE_WATCH;
- /* Select the color */
- sensor_rvb_color_select (sensor_rvb_color_ = sensor_col);
- /* Disable sensors */
- sensor_rvb_sensor_select (0);
- /* Wait a little */
- utils_delay_ns (RVB_SENSOR_DELAY_IO);
- /* Select sensor here */
- sensor_rvb_sensor_select (sensor_num + 1);
- /* Wait for output of sensor to be ready */
- utils_delay_ns (RVB_SENSOR_DELAY_IO);
-}
-/*}}}*/
-
/** Update everything for you. */
void
sensor_rvb_update (void)
@@ -205,8 +200,7 @@ sensor_rvb_update (void)
{
sensor_rvb_state_ = RVB_STATE_WAIT_IC;
/* Ensure we have no pending interrupt for IC1. */
- // XXX | ?
- TIFR |= _BV (ICF1);
+ TIFR = _BV (ICF1);
/* Enable interrupt for IC1 */
TIMSK |= _BV (TICIE1);
}
@@ -221,6 +215,9 @@ sensor_rvb_update (void)
/* Disable IC1 and TC1 overflow interrupts */
TIMSK &= ~_BV (TICIE1);
TIMSK &= ~_BV (TOIE1);
+ /* Ensure we have no pending interrupt for IC1. */
+ TIFR = _BV (ICF1);
+ /* Finish ! Go to sleep */
sensor_rvb_state_ = RVB_STATE_SLEEP;
return;
}
@@ -228,12 +225,10 @@ sensor_rvb_update (void)
sensor_rvb_color_select (sensor_rvb_color_ = 0);
sensor_rvb_state_ = RVB_STATE_WAIT_IC;
sensor_rvb_overflow_count_ = 0;
- /* Ensure we have no pending interrupt for IC1. */
- // XXX | ?
- TIFR |= _BV (ICF1);
- /* Enable interrupt for IC1 and counter overflow */
+// /* Ensure we have no pending interrupt for IC1. */
+// TIFR = _BV (ICF1);
+ /* Enable interrupt for IC1 */
TIMSK |= _BV (TICIE1);
- TIMSK |= _BV (TOIE1);
}
}
@@ -249,7 +244,7 @@ SIGNAL (SIG_OVERFLOW1)
case RVB_STATE_WAIT_IC2:
// XXX >= Sucks !
// TODO : check this >= and the IC2 used
- if (++sensor_rvb_overflow_count_ >= RVB_MAX_OVERFLOW)
+ if (++sensor_rvb_overflow_count_ >= sensor_rvb_conf_max_ov_)
{
/* Disable IC interrupt */
TIMSK &= ~_BV (TICIE1);
@@ -267,7 +262,7 @@ SIGNAL (SIG_INPUT_CAPTURE1)
switch (sensor_rvb_state_)
{
case RVB_STATE_WAIT_IC:
- sensor_rvb_ic_count_ = RVB_MAX_FALSE_IC;
+ sensor_rvb_ic_count_ = sensor_rvb_conf_max_false_ic_;
sensor_rvb_state_ = RVB_STATE_WAIT_IC2;
/* nobreak */
case RVB_STATE_WAIT_IC2:
diff --git a/n/es-2006/src/sensor_rvb.h b/n/es-2006/src/sensor_rvb.h
index d138311..de9a498 100644
--- a/n/es-2006/src/sensor_rvb.h
+++ b/n/es-2006/src/sensor_rvb.h
@@ -59,9 +59,7 @@
/** Results table for 9 RVB sensors (RVCB) :
* Values are in the folowing order : Red, Blue, Clear, Green. */
-extern volatile uint16_t sensor_rvb_values [RVB_MAX_SENSOR][4];
-/** Geting stats only for one sensors and disabling computing the others. */
-extern uint8_t sensor_rvb_enable;
+extern volatile uint16_t sensor_rvb_values[RVB_MAX_SENSOR][4];
/** Initialisation of the RVB sensors module. */
void sensor_rvb_init (void);
@@ -69,8 +67,14 @@ void sensor_rvb_init (void);
/** Start a capture RVBC values for sensors if we are not already doing one. */
void sensor_rvb_start_capture (void);
-/** Watch only one sensor. Usefull for debugging.
- * Does not work ! XXX */
-void sensor_rvb_watch (uint8_t sensor_num, uint8_t color_num);
+/** Configure some internal variables.
+ * - false_ic = maximum input capture to ignore before begining the real
+ * capture.
+ * - max_ov = maximum overflow of the timer/counter 1 before setting the
+ * sensor dead. uint8_t !
+ * - latency = delay between change for sensor. Must be more than 100ns. This
+ * setting is in ns.
+ */
+void sensor_rvb_config (uint8_t false_ic, uint8_t max_ov, uint8_t latency);
#endif // sensor_rvb_h
diff --git a/n/es-2006/src/es_config.c b/n/es-2006/src/timer_1.c
index 1342bea..cbbe1e7 100644
--- a/n/es-2006/src/es_config.c
+++ b/n/es-2006/src/timer_1.c
@@ -1,4 +1,4 @@
-/* es_config.c */
+/* timer_1.c */
/* es - Input/Output general purpose board. {{{
*
* Copyright (C) 2006 Dufour Jérémy
@@ -22,7 +22,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* }}} */
-#include "es_config.h"
+#include "timer_1.h"
/** Initialisation of the shared register for the timer/counter 1. */
inline void
diff --git a/n/es-2006/src/es_config.h b/n/es-2006/src/timer_1.h
index 5a94c84..3981c3c 100644
--- a/n/es-2006/src/es_config.h
+++ b/n/es-2006/src/timer_1.h
@@ -1,6 +1,6 @@
-#ifndef es_config_h
-#define es_config_h
-// es_config.h
+#ifndef timer_1_h
+#define timer_1_h
+// timer_1.h
// es - Input/Output general purpose board. {{{
//
// Copyright (C) 2006 Dufour Jérémy
@@ -38,4 +38,4 @@
/** Initialisation of the shared register for the timer/counter 1. */
extern void timer1_init (void);
-#endif // es_config_h
+#endif // timer_1_h
diff --git a/n/es-2006/src/timer_main.h b/n/es-2006/src/timer_main.h
index 6a932b7..458db2e 100644
--- a/n/es-2006/src/timer_main.h
+++ b/n/es-2006/src/timer_main.h
@@ -45,7 +45,6 @@ timer_main_wait (void)
while (!(TIFR & _BV (TOV0)))
;
/* Write 1 to clear. */
- // XXX Check why there is no |
TIFR = _BV (TOV0);
}