summaryrefslogtreecommitdiff
path: root/digital
diff options
context:
space:
mode:
authorNicolas Schodet2011-05-02 23:28:00 +0200
committerNicolas Schodet2011-05-03 01:36:05 +0200
commitc34c7f4b78ddf31d422454cb440ed31647d9b964 (patch)
tree1a80e4384226fc4e07a16a1ad21cb3c5c88a9b95 /digital
parent092057218111adb25119f0099c5ad951a5b10d69 (diff)
digital/{ai,io}: move timer and chrono to ai
Diffstat (limited to 'digital')
-rw-r--r--digital/ai/src/utils/chrono.c (renamed from digital/io/src/chrono.c)18
-rw-r--r--digital/ai/src/utils/chrono.h (renamed from digital/io/src/chrono.h)10
-rw-r--r--digital/ai/src/utils/timer.avr.c (renamed from digital/io/src/main_timer.avr.c)17
-rw-r--r--digital/ai/src/utils/timer.h (renamed from digital/io/src/main_timer.h)44
-rw-r--r--digital/io/src/Makefile4
-rw-r--r--digital/io/src/bot.h5
-rw-r--r--digital/io/src/main.c8
-rw-r--r--digital/io/src/simu.host.c4
-rw-r--r--digital/io/src/trace.trc2
-rw-r--r--digital/io/src/usdist.c2
-rw-r--r--digital/io/src/usdist.h2
11 files changed, 48 insertions, 68 deletions
diff --git a/digital/io/src/chrono.c b/digital/ai/src/utils/chrono.c
index b73b627c..a1212e19 100644
--- a/digital/io/src/chrono.c
+++ b/digital/ai/src/utils/chrono.c
@@ -1,5 +1,5 @@
/* chrono.c */
-/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
+/* ai - Robot Artificial Intelligence. {{{
*
* Copyright (C) 2008 Dufour Jérémy
*
@@ -22,11 +22,9 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* }}} */
-
#include "common.h"
-#include "bot.h"
-#include "main_timer.h"
+#include "timer.h"
#include "asserv.h"
#include "twi_master.h"
@@ -43,13 +41,9 @@
* match is over (chrono_is_match_over, chrono_end_match).
*/
-/**
- * Number of overflows of the timer/counter 0 to wait before the match is
- * over.
- * Basically, it is match_duration / timer_counter_0_overflow_duration.
- * Minus one is here for safety reason (because rounding is done at plus one).
- */
-#define CHRONO_MATCH_OVERFLOW_COUNT (MATCH_DURATION_MS / MT_TC0_PERIOD - 1)
+/** Number of overflows of the timer to wait before the match is over. */
+#define CHRONO_MATCH_OVERFLOW_COUNT \
+ (CHRONO_MATCH_DURATION_MS / TIMER_PERIOD_MS)
/**
* Duration of a loop to emulate from the original behaviour, in ms.
@@ -121,7 +115,7 @@ chrono_enabled (void)
uint32_t
chrono_remaining_time (void)
{
- return chrono_ov_count_ * MT_TC0_PERIOD;
+ return chrono_ov_count_ * TIMER_PERIOD_MS;
}
void
diff --git a/digital/io/src/chrono.h b/digital/ai/src/utils/chrono.h
index e2b09ac8..38bf3d61 100644
--- a/digital/io/src/chrono.h
+++ b/digital/ai/src/utils/chrono.h
@@ -1,7 +1,7 @@
#ifndef chrono_h
#define chrono_h
/* chrono.h */
-/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
+/* ai - Robot Artificial Intelligence. {{{
*
* Copyright (C) 2008 Dufour Jérémy
*
@@ -28,16 +28,18 @@
/**
* @file Module to manage the chrono responsible to stop the bot after 90s.
*
- * It is based on the main timer (time/counter 0) to know when to stop the
- * bot.
+ * It is based on the main timer to know when to stop the bot.
*
* The main loop should never last more than the 4.44ms defined, otherwise,
* this module will not be precise at all!
*/
+/** Duration of a match in milliseconds, with margin. */
+#define CHRONO_MATCH_DURATION_MS (90000 - 2500)
+
/**
* Initialize the chrono module.
- * It setups it for a duration of MATCH_DURATION_MS.
+ * It setups it for a duration of CHRONO_MATCH_DURATION_MS.
*/
void
chrono_init (void);
diff --git a/digital/io/src/main_timer.avr.c b/digital/ai/src/utils/timer.avr.c
index bcb185b6..b8756d88 100644
--- a/digital/io/src/main_timer.avr.c
+++ b/digital/ai/src/utils/timer.avr.c
@@ -1,5 +1,5 @@
-/* main_timer.avr.c */
-/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
+/* timer.avr.c */
+/* ai - Robot Artificial Intelligence. {{{
*
* Copyright (C) 2009 Dufour Jérémy
*
@@ -22,30 +22,29 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* }}} */
-
#include "common.h"
-#include "main_timer.h"
+#include "timer.h"
#include "modules/utils/utils.h"
#include "io.h"
void
-main_timer_init (void)
+timer_init (void)
{
/* Configuration of the timer/counter 0:
* - top = 0xff,
* - prescaler = 256,
* -> Fov = F_io / (prescaler * (TOP + 1))
- * -> Tov = 1 / Fov = 4.444 ms.
+ * -> Tov = 1 / Fov
* Note: if you change the TCCR0 register value, please also update
- * MT_TC0_PRESCALER and MT_TC0_TOP. */
+ * TIMER_TC0_PRESCALER and TIMER_TC0_TOP. */
TCCR0 = regv (FOC0, WGM00, COM01, COM0, WGM01, CS02, CS01, CS00,
0, 0, 0, 0, 0, 1, 1, 0);
}
uint8_t
-main_timer_wait (void)
+timer_wait (void)
{
/* Let's pretend we have reached overflow before calling this function. */
uint8_t count_before_ov = 1;
@@ -55,6 +54,6 @@ main_timer_wait (void)
count_before_ov = 0;
/* Write 1 to clear overflow. */
TIFR = _BV (TOV0);
-
return count_before_ov;
}
+
diff --git a/digital/io/src/main_timer.h b/digital/ai/src/utils/timer.h
index b04c1775..e085b86e 100644
--- a/digital/io/src/main_timer.h
+++ b/digital/ai/src/utils/timer.h
@@ -1,7 +1,7 @@
-#ifndef main_timer_h
-#define main_timer_h
-/* main_timer.h */
-/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
+#ifndef timer_h
+#define timer_h
+/* timer.h */
+/* ai - Robot Artificial Intelligence. {{{
*
* Copyright (C) 2009 Dufour Jérémy
*
@@ -26,14 +26,7 @@
* }}} */
/**
- * @file Main timer.
- * The main timer is responsible for making the main loop executed regularly
- * to a specific time (at least).
- *
- * Sometimes, the main loop can be executed less frequently that we want
- * because it takes too much time! This is bad and should be avoided.
- *
- * The main timer used the timer/counter 0 of the AVR.
+ * Tick timer, used to slow down the main loop to a given rate.
*/
/**
@@ -41,28 +34,25 @@
* If you want to change this value, you also need to change the TCCR0
* register.
*/
-#define MT_TC0_PRESCALER 256L
+#define TIMER_TC0_PRESCALER 256L
+
/**
* Top configured for timer/counter 0.
* If you want to change this value, you also need to change the TCCR0
* register.
*/
-#define MT_TC0_TOP 255
-/**
- * Period of timer/counter 0 (in millisecond).
- */
-#define MT_TC0_PERIOD \
- (1000.0 / (AC_FREQ / (MT_TC0_PRESCALER * (MT_TC0_TOP + 1))))
+#define TIMER_TC0_TOP 255
-/**
- * Initialize the main timer to 4.444 ms.
- * This function setup the timer/counter 0 configuration register.
- */
+/** Period of timer, ms. */
+#define TIMER_PERIOD_MS \
+ (1000.0 / (AC_FREQ / (TIMER_TC0_PRESCALER * (TIMER_TC0_TOP + 1))))
+
+/** Initialise timer. */
void
-main_timer_init (void);
+timer_init (void);
/**
- * Wait until the main timer overflows.
+ * Wait until the timer overflows.
* @return
* - 0 if we are on time (we have not reached overflow before calling this
* function).
@@ -73,6 +63,6 @@ main_timer_init (void);
* correctly!
*/
uint8_t
-main_timer_wait (void);
+timer_wait (void);
-#endif /* main_timer_h */
+#endif /* timer_h */
diff --git a/digital/io/src/Makefile b/digital/io/src/Makefile
index 7ac4eefe..a21b0c1b 100644
--- a/digital/io/src/Makefile
+++ b/digital/io/src/Makefile
@@ -4,7 +4,7 @@ BASE = ../../avr
PROGS = io
# Sources to compile.
io_SOURCES = main.c servo.avr.c eeprom.avr.c pwm.c \
- switch.avr.c chrono.c main_timer.avr.c servo_pos.c \
+ switch.avr.c chrono.c timer.avr.c servo_pos.c \
twi_master.c asserv.c mimot.c \
simu.host.c contact.c usdist.c radar.c \
path.c food.c events.host.c \
@@ -12,7 +12,7 @@ io_SOURCES = main.c servo.avr.c eeprom.avr.c pwm.c \
# Modules needed for IO.
MODULES = proto uart twi utils adc math/fixed math/geometry path/astar \
trace flash spi
-AI_MODULES = twi_master common
+AI_MODULES = twi_master common utils
# Configuration file.
CONFIGFILE = avrconfig.h
# IO board use an ATMega128.
diff --git a/digital/io/src/bot.h b/digital/io/src/bot.h
index 01515574..b4112e92 100644
--- a/digital/io/src/bot.h
+++ b/digital/io/src/bot.h
@@ -30,11 +30,6 @@
*/
/**
- * Duration of a match in milliseconds, with margin.
- */
-#define MATCH_DURATION_MS (90000 - 2500)
-
-/**
* The scaling factor, millimeter per step.
*/
#ifdef HOST
diff --git a/digital/io/src/main.c b/digital/io/src/main.c
index b29d1fea..be04366f 100644
--- a/digital/io/src/main.c
+++ b/digital/io/src/main.c
@@ -39,7 +39,7 @@
#include <string.h>
#endif /* HOST */
-#include "main_timer.h"
+#include "timer.h"
#include "simu.host.h"
#include "asserv.h"
@@ -261,7 +261,7 @@ main_init (void)
/* Enable interrupts */
sei ();
/* Main timer */
- main_timer_init ();
+ timer_init ();
/* Load parameters */
eeprom_load_param ();
/* Dirty fix */
@@ -305,14 +305,14 @@ main_loop (void)
{
/* Wait for an overflow of the main timer (4.444ms) */
{
- uint8_t timer_count = main_timer_wait ();
+ uint8_t timer_count = timer_wait ();
if (main_stats_timer_)
proto_send1b('M', timer_count);
if (timer_count == 1)
{
/* Main timer has reached overflow earlier!
We are late and this is really bad. */
- TRACE (TRACE_MAIN_TIMER__LATE);
+ TRACE (TRACE_TIMER__LATE);
}
}
diff --git a/digital/io/src/simu.host.c b/digital/io/src/simu.host.c
index 276c3b14..f1b7e0d2 100644
--- a/digital/io/src/simu.host.c
+++ b/digital/io/src/simu.host.c
@@ -214,13 +214,13 @@ switch_update (void)
}
void
-main_timer_init (void)
+timer_init (void)
{
simu_init ();
}
uint8_t
-main_timer_wait (void)
+timer_wait (void)
{
mex_node_wait_date (mex_node_date () + 4);
simu_step ();
diff --git a/digital/io/src/trace.trc b/digital/io/src/trace.trc
index 4cdcf8e0..1da5012b 100644
--- a/digital/io/src/trace.trc
+++ b/digital/io/src/trace.trc
@@ -1,4 +1,4 @@
-EVENT main_timer__late "MainTimer: we are late."
+EVENT timer__late "Timer: we are late."
EVENT fsm__handle_event from 1 event 1 to 1 "FSM: %i =%i=> %i."
EVENT move__go_to xd 2 yd 2 "Move: (%d, %d)."
EVENT food__best food 1 "Food best: %d."
diff --git a/digital/io/src/usdist.c b/digital/io/src/usdist.c
index df26ea79..d6fd9730 100644
--- a/digital/io/src/usdist.c
+++ b/digital/io/src/usdist.c
@@ -24,7 +24,7 @@
* }}} */
#include "common.h"
#include "usdist.h"
-#include "main_timer.h"
+#include "timer.h"
#include "modules/adc/adc.h"
#include "modules/utils/utils.h"
diff --git a/digital/io/src/usdist.h b/digital/io/src/usdist.h
index 541d1c93..9a4a6646 100644
--- a/digital/io/src/usdist.h
+++ b/digital/io/src/usdist.h
@@ -42,7 +42,7 @@
#define USDIST_MM_TOO_FAR 650
/** Measuring period in cycles. */
-#define USDIST_PERIOD_CYCLE (uint8_t) (8.0 / MT_TC0_PERIOD)
+#define USDIST_PERIOD_CYCLE (uint8_t) (8.0 / TIMER_PERIOD_MS)
/** Array containing the last measures in millimeters. */
extern uint16_t usdist_mm[USDIST_NB];