From 8e6335ad1ff9df290693d5f4bbf919c205d846cc Mon Sep 17 00:00:00 2001 From: Jérémy Dufour Date: Mon, 18 May 2009 13:03:56 +0200 Subject: * digital/io/src: - integrate trace usage into flash. --- digital/io/src/Makefile | 7 ++++++- digital/io/src/asserv.c | 15 +++++++++++++++ digital/io/src/avrconfig.h | 16 +++++++++++++++- digital/io/src/init.fsm | 4 +++- digital/io/src/init_cb.c | 4 ++++ digital/io/src/main.c | 15 ++++++++++++--- digital/io/src/trace.trc | 3 +++ 7 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 digital/io/src/trace.trc diff --git a/digital/io/src/Makefile b/digital/io/src/Makefile index 947b03c0..0f4a18ef 100644 --- a/digital/io/src/Makefile +++ b/digital/io/src/Makefile @@ -7,7 +7,7 @@ io_SOURCES = main.c asserv.c servo.avr.c eeprom.avr.c sharp.c pwm.c \ switch.avr.c chrono.c main_timer.avr.c servo_pos.c \ simu.host.c contact.c # Modules needed for IO. -MODULES = proto uart twi utils adc math/fixed path +MODULES = proto uart twi utils adc math/fixed path trace flash spi # Configuration file. CONFIGFILE = avrconfig.h # IO board use an ATMega128. @@ -19,3 +19,8 @@ OPTIMIZE = -O2 FSM_SOURCES := top move filterbridge elevator cylinder init # Include FSM makefile. include $(BASE)/make/Makefile.fsm + +trace_event.h: trace.trc + PYTHONPATH=$(BASE)/../../host python $(BASE)/../../tools/trace/trace.py -t create -e $(@:%.h=%_t) -i $< -o $@ + +main.c: trace_event.h diff --git a/digital/io/src/asserv.c b/digital/io/src/asserv.c index cea5fc8a..1c86664f 100644 --- a/digital/io/src/asserv.c +++ b/digital/io/src/asserv.c @@ -30,8 +30,10 @@ #include "modules/utils/byte.h" /* v*_to_v* */ #include "modules/math/fixed/fixed.h" #include "modules/utils/crc.h" +#include "modules/trace/trace.h" #include "giboulee.h" /* BOT_* */ #include "io.h" +#include "trace_event.h" /** Scaling factor. */ uint32_t asserv_scale; @@ -74,6 +76,7 @@ static uint32_t asserv_scale_inv; * It is used for the acknowledge of the command sent to the asserv. */ static uint8_t asserv_twi_seq; +static uint8_t trace_asserv_twi_seq; /** * Shared buffer used to send commands to the asserv. @@ -215,6 +218,9 @@ asserv_twi_send (uint8_t length) if (twi_ms_send (AC_ASSERV_TWI_ADDRESS, asserv_twi_buffer, length) != 0) return 1; + /* Sending a command. */ + TRACE (TRACE_ASSERV__SEND, asserv_twi_buffer[1], asserv_twi_buffer[2]); + /* Update until the command is sent */ asserv_twi_update (); @@ -237,6 +243,7 @@ asserv_init (void) asserv_update_status (); /* Reset sequence number */ asserv_twi_seq = asserv_status.seq; + trace_asserv_twi_seq = asserv_twi_seq + 1; /* Scaling factor. */ asserv_set_scale (BOT_SCALE * (1L << 24)); } @@ -269,6 +276,13 @@ asserv_update_status (void) asserv_status.position.a = v8_to_v16 (status_buffer[9], status_buffer[10]); asserv_status.arm_position = v8_to_v16 (status_buffer[11], status_buffer[12]); asserv_status.elevator_position = v8_to_v16 (status_buffer[13], status_buffer[14]); + if (trace_asserv_twi_seq == asserv_status.seq) + { + /* Next ack. */ + trace_asserv_twi_seq++; + TRACE (TRACE_ASSERV__LAST_STATUS_ACK, asserv_status.seq, + asserv_status.status); + } } /* Is last command sent to the asserv board is being executed? */ @@ -290,6 +304,7 @@ asserv_retransmit (void) * retransmission */ if (--asserv_retransmit_counter == 0) { + TRACE (TRACE_ASSERV__RETRANSMIT, asserv_twi_buffer[1]); /* Retransmit! */ asserv_twi_send (asserv_retransmit_length); return 1; diff --git a/digital/io/src/avrconfig.h b/digital/io/src/avrconfig.h index 74ceb238..b0afb529 100644 --- a/digital/io/src/avrconfig.h +++ b/digital/io/src/avrconfig.h @@ -55,7 +55,7 @@ /** 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 DROP +#define AC_UART0_SEND_BUFFER_FULL WAIT /** In HOST compilation: * - STDIO: use stdin/out. * - PTS: use pseudo terminal. */ @@ -110,4 +110,18 @@ */ #define AC_ASSERV_STATUS_LENGTH 15 +/* spi - SPI module. */ +/** Select driver: HARD, SOFT, or NONE. */ +#define AC_SPI0_DRIVER HARD +/** Same thing for an optionnal second SPI driver. */ +#define AC_SPI1_DRIVER NONE + +/* flash - Flash SPI AVR module. */ +/** Flash PORT used. */ +#define AC_FLASH_PORT PORTD +/** Flash DDR used. */ +#define AC_FLASH_DDR DDRD +/** Flash SS pin. */ +#define AC_FLASH_BIT_SS 5 + #endif /* avrconfig_h */ diff --git a/digital/io/src/init.fsm b/digital/io/src/init.fsm index faf41e2b..cbd2233d 100644 --- a/digital/io/src/init.fsm +++ b/digital/io/src/init.fsm @@ -8,7 +8,9 @@ States: IDLE waiting for the beginning of the top FSM WAIT_JACK_IN - waiting for the jack to be inserted into the bot + waiting for the jack to be inserted into the bot. + get color for the rest of the FSM. + erase flash. WAIT_2_SEC [timeout=450] waiting for operator's hand not on jack anymore GOTO_THE_WALL diff --git a/digital/io/src/init_cb.c b/digital/io/src/init_cb.c index 1f681d47..4efdff82 100644 --- a/digital/io/src/init_cb.c +++ b/digital/io/src/init_cb.c @@ -31,6 +31,7 @@ #include "main.h" #include "aquajim.h" #include "switch.h" +#include "modules/trace/trace.h" /* * IDLE =start=> @@ -51,7 +52,10 @@ init__IDLE__start (void) fsm_branch_t init__WAIT_JACK_IN__jack_inserted_into_bot (void) { + /* Get the color. */ bot_color = switch_get_color (); + /* Initialize trace module (erase the flash). */ + trace_init (); return init_next (WAIT_JACK_IN, jack_inserted_into_bot); } diff --git a/digital/io/src/main.c b/digital/io/src/main.c index cabe9734..6bd2d14b 100644 --- a/digital/io/src/main.c +++ b/digital/io/src/main.c @@ -28,6 +28,7 @@ #include "modules/proto/proto.h" #include "modules/utils/utils.h" #include "modules/path/path.h" +#include "modules/flash/flash.h" /* AVR include, non HOST */ #ifndef HOST @@ -717,9 +718,17 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) } break; default: - /* Unknown commands */ - proto_send0 ('?'); - return; + { + uint8_t error = 1; + if (cmd == 'l') + error = flash_log (size, args); + if (error) + { + /* Unknown commands */ + proto_send0 ('?'); + return; + } + } } /* When no error, acknowledge commands */ proto_send (cmd, size, args); diff --git a/digital/io/src/trace.trc b/digital/io/src/trace.trc new file mode 100644 index 00000000..7f3e68c1 --- /dev/null +++ b/digital/io/src/trace.trc @@ -0,0 +1,3 @@ +EVENT asserv__retransmit seq 1 "Asserv[0x%02x]: retransmiting" +EVENT asserv__send seq 1 cmd 1 "Asserv[0x%02x]: sending: !%c" +EVENT asserv__last_status_ack seq 1 status 1 "Asserv[0x%02x]: status: %x" -- cgit v1.2.3