From 6642b9d795d9a8bcb0a8bdc5dee4b030a19008d4 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 7 Mar 2008 10:54:15 +0100 Subject: * digital/avr/modules/twi/test: - added commands to send and receive a variable number of bytes. --- digital/avr/modules/twi/test/avrconfig_master.h | 2 +- digital/avr/modules/twi/test/avrconfig_slave.h | 4 +-- digital/avr/modules/twi/test/test_twi_master.c | 36 +++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/digital/avr/modules/twi/test/avrconfig_master.h b/digital/avr/modules/twi/test/avrconfig_master.h index 16becdcf..21bc4888 100644 --- a/digital/avr/modules/twi/test/avrconfig_master.h +++ b/digital/avr/modules/twi/test/avrconfig_master.h @@ -42,7 +42,7 @@ /* proto - Protocol module. */ /** Maximum argument size. */ -#define AC_PROTO_ARGS_MAX_SIZE 8 +#define AC_PROTO_ARGS_MAX_SIZE 16 /** Callback function name. */ #define AC_PROTO_CALLBACK proto_callback /** Putchar function name. */ diff --git a/digital/avr/modules/twi/test/avrconfig_slave.h b/digital/avr/modules/twi/test/avrconfig_slave.h index 394c5937..2635810d 100644 --- a/digital/avr/modules/twi/test/avrconfig_slave.h +++ b/digital/avr/modules/twi/test/avrconfig_slave.h @@ -36,9 +36,9 @@ /** Activate slave part. */ #define AC_TWI_SLAVE_ENABLE 1 /** Slave recv buffer size. */ -#define AC_TWI_SL_RECV_BUFFER_SIZE 1 +#define AC_TWI_SL_RECV_BUFFER_SIZE 16 /** Slave send buffer size. */ -#define AC_TWI_SL_SEND_BUFFER_SIZE 1 +#define AC_TWI_SL_SEND_BUFFER_SIZE 16 /* proto - Protocol module. */ /** Maximum argument size. */ diff --git a/digital/avr/modules/twi/test/test_twi_master.c b/digital/avr/modules/twi/test/test_twi_master.c index 85b48686..d65d185d 100644 --- a/digital/avr/modules/twi/test/test_twi_master.c +++ b/digital/avr/modules/twi/test/test_twi_master.c @@ -65,6 +65,25 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) } } break; + case c ('r', 2): + /* Read n bytes from an address slave + * 2 parameter: + * - slave address. + * - nb of bytes. + */ + { + uint8_t data[16]; + int8_t d = twi_ms_read (args[0], data, args[1]); + if (d != 0) + proto_send0 ('e'); + else + { + while (!twi_ms_is_finished ()) + ; + proto_send ('R', args[1], data); + } + } + break; case c ('t', 2): /* Test for sending and receiving multiple data. * It sends a random number of bytes to the slave and then read back @@ -141,8 +160,21 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) utils_reset (); break; default: - /* Error */ - proto_send0 ('?'); + /* Variable number of arguments. */ + if (cmd == 's') + { + /* Send n bytes to a slave address. + * 1+n parameters: + * - slave address; + * - n x data. + */ + twi_ms_send (args[0], &args[1], size - 1); + while (!twi_ms_is_finished ()) + ; + } + else + /* Error */ + proto_send0 ('?'); return; } /* Acknowledge what has been done */ -- cgit v1.2.3