From 99e387e488e94ab78f50529fdc58b3fad7ec9cae Mon Sep 17 00:00:00 2001 From: Jérémy Dufour Date: Sat, 1 Mar 2008 18:13:13 +0100 Subject: * TWI: modify to have a working test on cards: - work with one byte of data exchanged (master send a byte to slave then read it back); - does not manage when slave is not here (no timeout); - use more proto_ functions rather than uart_ ones; - support reset and unknown functions on both test programs; - update configurations to be compatible with the cards used for the test; - add comments. --- digital/avr/modules/twi/test/test_twi_sl.c | 39 ++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'digital/avr/modules/twi/test/test_twi_sl.c') diff --git a/digital/avr/modules/twi/test/test_twi_sl.c b/digital/avr/modules/twi/test/test_twi_sl.c index 8672a6f7..b6cbc050 100644 --- a/digital/avr/modules/twi/test/test_twi_sl.c +++ b/digital/avr/modules/twi/test/test_twi_sl.c @@ -26,26 +26,55 @@ #include "common.h" #include "modules/twi/twi.h" +#include "modules/proto/proto.h" #include "modules/uart/uart.h" +#include "modules/utils/utils.h" #include "io.h" +void +proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) +{ +#define c(cmd, size) (cmd << 8 | size) + switch (c (cmd, size)) + { + /* Reset */ + case 'z': + utils_reset (); + break; + /* Error */ + default: + proto_send0 ('?'); + return; + } + /* Acknowledge what has been done */ + proto_send (cmd, size, args); +} + int main (void) { - uint8_t data[TWI_SL_RCPT_SIZE]; + /* Enable interruptions */ sei (); + /* Initialize serial port */ uart0_init (); - uart0_putc ('s'); - uart0_putc ('s'); - uart0_putc ('s'); + /* We have successfully boot */ + proto_send0 ('z'); + /* Initialize TWI */ twi_init (0x02); - data[0] = 0; + /* I am a slave */ + proto_send0 ('S'); while (42) { + uint8_t data[TWI_SL_RCPT_SIZE]; + data[0] = 0; + /* Check for data */ if (twi_sl_poll (data, TWI_SL_RCPT_SIZE)) { + /* Receive and store them */ twi_sl_update (data, TWI_SL_RCPT_SIZE); } + if (uart0_poll ()) + proto_accept (uart0_getc ()); } return 0; } -- cgit v1.2.3