summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNélio Laranjeiro2009-02-02 09:49:05 +0100
committerNélio Laranjeiro2009-02-02 09:49:05 +0100
commit27e1254afc618ef34cf7d49c5158587da465b2be (patch)
treea42908d78a8eeef2f63d93208372214cf7c0664a
parent76e17b119a52c0ec0a4ea36a8276cc552efee2d2 (diff)
digital/avr/modules/trace: Ended the trace module to stop the traces when it
rolls over the flash memory. (Closes #t60).
-rw-r--r--digital/avr/modules/trace/test/test_host/test-trace.c81
-rw-r--r--digital/avr/modules/trace/trace.c10
-rw-r--r--digital/avr/modules/trace/trace.h9
3 files changed, 85 insertions, 15 deletions
diff --git a/digital/avr/modules/trace/test/test_host/test-trace.c b/digital/avr/modules/trace/test/test_host/test-trace.c
index aabd8e16..59a82242 100644
--- a/digital/avr/modules/trace/test/test_host/test-trace.c
+++ b/digital/avr/modules/trace/test/test_host/test-trace.c
@@ -27,13 +27,13 @@
#include "modules/flash/flash.h"
#include <stdio.h>
+#include <string.h>
#include "events.h"
void
flood (void)
{
uint8_t cmd;
- uint32_t addr;
uint32_t count;
uint32_t speed;
@@ -45,9 +45,9 @@ flood (void)
uint32_t arg3;
trace_init ();
+ flash_erase (FLASH_ERASE_FULL, 0);
/* Flood the flash memory with traces. */
- /* A little more than 3 memory sectors, a sector is 4 kbytes. */
for (count = 0; count < 2000; count ++)
{
/* Right motor. */
@@ -64,9 +64,68 @@ flood (void)
TRACE (cmd, speed, position, acc);
cmd = TRACE_IA__IA_CMD;
TRACE (cmd, arg1, arg2, arg3);
+
+ if (trace_status () == TRACE_STATUS_OFF)
+ return;
+ }
+}
+
+uint8_t
+flood_overflow (void)
+{
+ uint8_t cmd;
+ uint32_t count;
+ uint32_t i;
+
+ uint32_t speed;
+ uint32_t position;
+ uint16_t acc;
+
+ uint16_t arg1;
+ uint8_t arg2;
+ uint32_t arg3;
+ uint32_t addr;
+
+ if (trace_init () == TRACE_STATUS_OFF)
+ return TRACE_STATUS_OFF;
+ addr = trace_addr_current ();
+ printf ("Addr begin : %x\n", addr);
+
+ for (i = 0; i < FLASH_ADDRESS_HIGH; i++)
+ {
+ /* Flood the flash memory with traces. */
+ for (count = 0; count < 2000; count ++)
+ {
+ /* Right motor. */
+ speed = 10;
+ position = 11;
+ acc = 12;
+ arg1 = 10;
+ arg2 = 11;
+ arg3 = 12;
+
+ cmd = TRACE_ASSERV__RIGHT_MOTOR;
+ TRACE (cmd, speed, position, acc);
+ cmd = TRACE_ASSERV__LEFT_MOTOR;
+ TRACE (cmd, speed, position, acc);
+ cmd = TRACE_IA__IA_CMD;
+ TRACE (cmd, arg1, arg2, arg3);
+ }
+
+ if (trace_status () == TRACE_STATUS_OFF)
+ {
+ addr = trace_addr_current ();
+ printf ("End address : %x\n", addr);
+ return TRACE_STATUS_OFF;
+ }
}
+
+ addr = trace_addr_current ();
+ printf ("End address : %x\n", addr);
+ return TRACE_STATUS_ON;
}
+
void
dump (void)
{
@@ -74,6 +133,8 @@ dump (void)
uint32_t addr;
status = flash_init ();
+ if (status == TRACE_STATUS_OFF)
+ return;
for (addr = 0; addr < FLASH_ADDRESS_HIGH; addr ++)
{
@@ -82,14 +143,22 @@ dump (void)
}
int
-main (void)
+main (int argc, char **argv)
{
uint8_t i;
- for (i = 0; i < 30; i++)
- flood ();
+ if (strcmp (argv[1], "trace") == 0)
+ {
+ for (i = 0; i < 30; i++)
+ flood ();
+ }
+ else if (strcmp (argv[1], "overflow") == 0)
+ {
+ return flood_overflow ();
+ }
+ else if (strcmp (argv[1], "dump") == 0)
+ dump();
- dump();
return 0;
}
diff --git a/digital/avr/modules/trace/trace.c b/digital/avr/modules/trace/trace.c
index 4fa01af8..c6a78a52 100644
--- a/digital/avr/modules/trace/trace.c
+++ b/digital/avr/modules/trace/trace.c
@@ -32,12 +32,6 @@
#define TRACE_ARGS_MAX 6
#define TRACE_MAX_ARGS (TRACE_ARGS_MAX * TRACE_ARGS_MAX)
-enum trace_status_t
-{
- TRACE_STATUS_OFF,
- TRACE_STATUS_ON
-};
-
struct trace_t
{
/** Flash status. */
@@ -97,7 +91,7 @@ trace_print_arg_4(uint32_t arg)
}
-void
+uint8_t
trace_init (void)
{
int8_t i;
@@ -123,7 +117,9 @@ trace_init (void)
trace_global.addr =
FLASH_ADDRESS_INC(trace_global.addr);
}
+ return TRACE_STATUS_ON;
}
+ return TRACE_STATUS_OFF;
}
void
diff --git a/digital/avr/modules/trace/trace.h b/digital/avr/modules/trace/trace.h
index 937e49a9..72c7c9ef 100644
--- a/digital/avr/modules/trace/trace.h
+++ b/digital/avr/modules/trace/trace.h
@@ -84,7 +84,11 @@
else if (sizeof(arg) == sizeof(uint32_t)) trace_print_arg_4(arg);\
}while (0)
-/* Forward declaration. */
+enum trace_status_t
+{
+ TRACE_STATUS_OFF,
+ TRACE_STATUS_ON
+};
typedef enum trace_status_t trace_status_t;
/** Print an argument of one byte.
@@ -106,10 +110,11 @@ void
trace_print_arg_4(uint32_t arg);
/** Initialise the trace module.
+ * \return the status of the trace module.
* Find the first sector writable and store the following start code
* 0xF33FF22F this indicate the beginning of traces.
*/
-void
+uint8_t
trace_init (void);
/** Print the trace.