summaryrefslogtreecommitdiff
path: root/digital/avr/modules/twi/test
diff options
context:
space:
mode:
Diffstat (limited to 'digital/avr/modules/twi/test')
-rw-r--r--digital/avr/modules/twi/test/Makefile21
-rw-r--r--digital/avr/modules/twi/test/Makefile.master25
-rw-r--r--digital/avr/modules/twi/test/Makefile.slave24
-rw-r--r--digital/avr/modules/twi/test/master/Makefile14
-rw-r--r--digital/avr/modules/twi/test/master/avrconfig.h (renamed from digital/avr/modules/twi/test/avrconfig_master.h)64
-rw-r--r--digital/avr/modules/twi/test/slave/Makefile14
-rw-r--r--digital/avr/modules/twi/test/slave/avrconfig.h (renamed from digital/avr/modules/twi/test/avrconfig_slave.h)71
-rw-r--r--digital/avr/modules/twi/test/test_twi.c (renamed from digital/avr/modules/twi/test/test_twi_master.c)173
-rw-r--r--digital/avr/modules/twi/test/test_twi.py (renamed from digital/avr/modules/twi/test/test_twi_host.py)11
-rw-r--r--digital/avr/modules/twi/test/test_twi_sl.c90
10 files changed, 185 insertions, 322 deletions
diff --git a/digital/avr/modules/twi/test/Makefile b/digital/avr/modules/twi/test/Makefile
deleted file mode 100644
index 1af68de3..00000000
--- a/digital/avr/modules/twi/test/Makefile
+++ /dev/null
@@ -1,21 +0,0 @@
-# Quick dirty makefile to help you build the test program for twi.
-# It is required to clean before building each program because they share the
-# same object with different defines.
-# Files are copied in *.keep.hex.
-all: subclean
- # Slave
- $(MAKE) -f Makefile.slave
- cp test_twi_sl.hex test_twi_sl.keep.hex
- $(MAKE) -f Makefile.slave clean
- # Master
- $(MAKE) -f Makefile.master
- cp test_twi_master.hex test_twi_master.keep.hex
- $(MAKE) -f Makefile.master clean
-
-subclean:
- # General cleaning
- $(MAKE) -f Makefile.slave clean
- $(MAKE) -f Makefile.master clean
-
-clean: subclean
- rm -f test_twi_master.keep.hex test_twi_sl.keep.hex
diff --git a/digital/avr/modules/twi/test/Makefile.master b/digital/avr/modules/twi/test/Makefile.master
deleted file mode 100644
index 55a762c0..00000000
--- a/digital/avr/modules/twi/test/Makefile.master
+++ /dev/null
@@ -1,25 +0,0 @@
-BASE = ../../..
-PROGS = test_twi_master
-test_twi_master_SOURCES = test_twi_master.c
-DOC =
-EXTRACTDOC =
-MODULES = twi uart proto math/random utils
-
-
-CONFIGFILE = avrconfig_master.h
-TEST_CONFIGFILES = avrconfig_master.h
-
-
-# atmega8, atmega8535, atmega128...
-AVR_MCU = atmega128
-# -O2 : speed
-# -Os : size
-OPTIMIZE = -O2
-
-DEFS =
-LIBS =
-
-# Test compilations.
-TEST_MCU = atmega8535 atmega128
-
-include $(BASE)/make/Makefile.gen
diff --git a/digital/avr/modules/twi/test/Makefile.slave b/digital/avr/modules/twi/test/Makefile.slave
deleted file mode 100644
index 35f84bcd..00000000
--- a/digital/avr/modules/twi/test/Makefile.slave
+++ /dev/null
@@ -1,24 +0,0 @@
-BASE = ../../..
-PROGS = test_twi_sl
-test_twi_sl_SOURCES = test_twi_sl.c
-DOC =
-EXTRACTDOC =
-MODULES = twi uart proto utils
-
-
-CONFIGFILE = avrconfig_slave.h
-TEST_CONFIGFILES = avrconfig_slave.h
-
-# atmega8, atmega8535, atmega128...
-AVR_MCU = atmega128
-# -O2 : speed
-# -Os : size
-OPTIMIZE = -O2
-
-DEFS =
-LIBS =
-
-# Test compilations.
-TEST_MCU = atmega8535 atmega128
-
-include $(BASE)/make/Makefile.gen
diff --git a/digital/avr/modules/twi/test/master/Makefile b/digital/avr/modules/twi/test/master/Makefile
new file mode 100644
index 00000000..59e36f55
--- /dev/null
+++ b/digital/avr/modules/twi/test/master/Makefile
@@ -0,0 +1,14 @@
+BASE = ../../../..
+PROGS = test_twi_master
+test_twi_master_SOURCES = test_twi.c
+MODULES = twi uart proto math/random utils
+CONFIGFILE = avrconfig.h
+# atmega8, atmega8535, atmega128...
+AVR_MCU = atmega128
+# -O2 : speed
+# -Os : size
+OPTIMIZE = -Os
+
+vpath %.c ..
+
+include $(BASE)/make/Makefile.gen
diff --git a/digital/avr/modules/twi/test/avrconfig_master.h b/digital/avr/modules/twi/test/master/avrconfig.h
index a65f872f..c3b572a3 100644
--- a/digital/avr/modules/twi/test/avrconfig_master.h
+++ b/digital/avr/modules/twi/test/master/avrconfig.h
@@ -3,17 +3,17 @@
/* avrconfig.h */
/* avr.twi - TWI AVR module. {{{
*
- * Copyright (C) 2005 Demonchy Clément
+ * Copyright (C) 2010 Nicolas Schodet
*
- * Robot APB Team/Efrei 2006.
- * Web: http://assos.efrei.fr/robot/
- * Email: robot AT efrei DOT fr
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -25,31 +25,11 @@
*
* }}} */
-/* global */
+/* utils */
/** AVR Frequency : 1000000, 1843200, 2000000, 3686400, 4000000, 7372800,
* 8000000, 11059200, 14745600, 16000000, 18432000, 20000000. */
#define AC_FREQ 14745600
-/* twi - TWI module. */
-/** Activate master part. */
-#define AC_TWI_MASTER_ENABLE 1
-/** Activate slave part. */
-#define AC_TWI_SLAVE_ENABLE 0
-/** Slave recv buffer size. */
-#define AC_TWI_SL_RECV_BUFFER_SIZE 16
-/** Slave send buffer size. */
-#define AC_TWI_SL_SEND_BUFFER_SIZE 16
-
-/* proto - Protocol module. */
-/** Maximum argument size. */
-#define AC_PROTO_ARGS_MAX_SIZE 16
-/** Callback function name. */
-#define AC_PROTO_CALLBACK proto_callback
-/** Putchar function name. */
-#define AC_PROTO_PUTC uart0_putc
-/** Support for quote parameter. */
-#define AC_PROTO_QUOTE 1
-
/* uart - UART module. */
/** Select hardware uart for primary uart: 0, 1 or -1 to disable. */
#define AC_UART0_PORT 1
@@ -59,9 +39,9 @@
/** Send mode:
* - POLLING: no interrupts.
* - RING: interrupts, ring buffer. */
-#define AC_UART0_SEND_MODE POLLING
+#define AC_UART0_SEND_MODE RING
/** Recv mode, same as send mode. */
-#define AC_UART0_RECV_MODE POLLING
+#define AC_UART0_RECV_MODE RING
/** Character size: 5, 6, 7, 8, 9 (only 8 implemented). */
#define AC_UART0_CHAR_SIZE 8
/** Parity : ODD, EVEN, NONE. */
@@ -91,7 +71,33 @@
#define AC_UART1_SEND_BUFFER_SIZE 32
#define AC_UART1_RECV_BUFFER_SIZE 32
#define AC_UART1_SEND_BUFFER_FULL WAIT
-#define AC_UART1_HOST_DRIVER STDIO
+#define AC_UART1_HOST_DRIVER PTS
+/* proto - Protocol module. */
+/** Maximum argument size. */
+#define AC_PROTO_ARGS_MAX_SIZE 32
+/** Callback function name. */
+#define AC_PROTO_CALLBACK proto_callback
+/** Putchar function name. */
+#define AC_PROTO_PUTC uart0_putc
+/** Support for quote parameter. */
+#define AC_PROTO_QUOTE 1
+
+/* twi - TWI module. */
+/** Driver to implement TWI: HARD, SOFT, or USI. */
+#define AC_TWI_DRIVER HARD
+/** Do not use interrupts. */
+#define AC_TWI_NO_INTERRUPT 0
+/** TWI frequency, should really be 100 kHz. */
+#define AC_TWI_FREQ 100000
+/** Enable slave part. */
+#define AC_TWI_SLAVE_ENABLE 0
+/** Enable master part. */
+#define AC_TWI_MASTER_ENABLE 1
+/** Master transfer completion callback, optionally defined by the user, called
+ * at end of master transfer. */
+#undef AC_TWI_MASTER_DONE
+/** Use internal pull up. */
+#define AC_TWI_PULL_UP 0
#endif /* avrconfig_h */
diff --git a/digital/avr/modules/twi/test/slave/Makefile b/digital/avr/modules/twi/test/slave/Makefile
new file mode 100644
index 00000000..fbabd11d
--- /dev/null
+++ b/digital/avr/modules/twi/test/slave/Makefile
@@ -0,0 +1,14 @@
+BASE = ../../../..
+PROGS = test_twi_slave
+test_twi_slave_SOURCES = test_twi.c
+MODULES = twi uart proto math/random utils
+CONFIGFILE = avrconfig.h
+# atmega8, atmega8535, atmega128...
+AVR_MCU = atmega128
+# -O2 : speed
+# -Os : size
+OPTIMIZE = -Os
+
+vpath %.c ..
+
+include $(BASE)/make/Makefile.gen
diff --git a/digital/avr/modules/twi/test/avrconfig_slave.h b/digital/avr/modules/twi/test/slave/avrconfig.h
index 2635810d..3d01c881 100644
--- a/digital/avr/modules/twi/test/avrconfig_slave.h
+++ b/digital/avr/modules/twi/test/slave/avrconfig.h
@@ -3,17 +3,17 @@
/* avrconfig.h */
/* avr.twi - TWI AVR module. {{{
*
- * Copyright (C) 2005 Demonchy Clément
+ * Copyright (C) 2010 Nicolas Schodet
*
- * Robot APB Team/Efrei 2006.
- * Web: http://assos.efrei.fr/robot/
- * Email: robot AT efrei DOT fr
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -25,31 +25,11 @@
*
* }}} */
-/* global */
+/* utils */
/** AVR Frequency : 1000000, 1843200, 2000000, 3686400, 4000000, 7372800,
* 8000000, 11059200, 14745600, 16000000, 18432000, 20000000. */
#define AC_FREQ 14745600
-/* twi - TWI module. */
-/** Activate master part. */
-#define AC_TWI_MASTER_ENABLE 0
-/** Activate slave part. */
-#define AC_TWI_SLAVE_ENABLE 1
-/** Slave recv buffer size. */
-#define AC_TWI_SL_RECV_BUFFER_SIZE 16
-/** Slave send buffer size. */
-#define AC_TWI_SL_SEND_BUFFER_SIZE 16
-
-/* proto - Protocol module. */
-/** Maximum argument size. */
-#define AC_PROTO_ARGS_MAX_SIZE 8
-/** Callback function name. */
-#define AC_PROTO_CALLBACK proto_callback
-/** Putchar function name. */
-#define AC_PROTO_PUTC uart0_putc
-/** Support for quote parameter. */
-#define AC_PROTO_QUOTE 1
-
/* uart - UART module. */
/** Select hardware uart for primary uart: 0, 1 or -1 to disable. */
#define AC_UART0_PORT 1
@@ -59,9 +39,9 @@
/** Send mode:
* - POLLING: no interrupts.
* - RING: interrupts, ring buffer. */
-#define AC_UART0_SEND_MODE POLLING
+#define AC_UART0_SEND_MODE RING
/** Recv mode, same as send mode. */
-#define AC_UART0_RECV_MODE POLLING
+#define AC_UART0_RECV_MODE RING
/** Character size: 5, 6, 7, 8, 9 (only 8 implemented). */
#define AC_UART0_CHAR_SIZE 8
/** Parity : ODD, EVEN, NONE. */
@@ -91,7 +71,40 @@
#define AC_UART1_SEND_BUFFER_SIZE 32
#define AC_UART1_RECV_BUFFER_SIZE 32
#define AC_UART1_SEND_BUFFER_FULL WAIT
-#define AC_UART1_HOST_DRIVER STDIO
+#define AC_UART1_HOST_DRIVER PTS
+/* proto - Protocol module. */
+/** Maximum argument size. */
+#define AC_PROTO_ARGS_MAX_SIZE 32
+/** Callback function name. */
+#define AC_PROTO_CALLBACK proto_callback
+/** Putchar function name. */
+#define AC_PROTO_PUTC uart0_putc
+/** Support for quote parameter. */
+#define AC_PROTO_QUOTE 1
+
+/* twi - TWI module. */
+/** Driver to implement TWI: HARD, SOFT, or USI. */
+#define AC_TWI_DRIVER HARD
+/** Do not use interrupts. */
+#define AC_TWI_NO_INTERRUPT 0
+/** TWI frequency, should really be 100 kHz. */
+#define AC_TWI_FREQ 100000
+/** Enable slave part. */
+#define AC_TWI_SLAVE_ENABLE 1
+/** Enable master part. */
+#define AC_TWI_MASTER_ENABLE 0
+/** Use polled slave mode: received data is stored in a buffer which can be
+ * polled using twi_slave_poll. */
+#define AC_TWI_SLAVE_POLLED 1
+/** Slave reception callback to be defined by the user when not in polled
+ * mode. */
+#undef AC_TWI_SLAVE_RECV
+/** Use internal pull up. */
+#define AC_TWI_PULL_UP 0
+/** Slave reception buffer size. */
+#define AC_TWI_SLAVE_RECV_BUFFER_SIZE 16
+/** Slave transmission buffer size. */
+#define AC_TWI_SLAVE_SEND_BUFFER_SIZE 16
#endif /* avrconfig_h */
diff --git a/digital/avr/modules/twi/test/test_twi_master.c b/digital/avr/modules/twi/test/test_twi.c
index ff3a570a..f3656b20 100644
--- a/digital/avr/modules/twi/test/test_twi_master.c
+++ b/digital/avr/modules/twi/test/test_twi.c
@@ -1,17 +1,18 @@
-/* test_twi_master.c */
-/* avr.twi.master - TWI master module. {{{
+/* test_twi.c */
+/* avr.twi - TWI AVR module. {{{
*
- * Copyright (C) 2005 Clément Demonchy
+ * Copyright (C) 2005 Clément Demonchy
+ * Copyright (C) 2010 Nicolas Schodet
*
- * Robot APB Team/Efrei 2006.
- * Web: http://assos.efrei.fr/robot/
- * Email: robot AT efrei DOT fr
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -22,7 +23,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* }}} */
-
#include "common.h"
#include "modules/twi/twi.h"
#include "modules/proto/proto.h"
@@ -41,77 +41,45 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
#define c(cmd, size) (cmd << 8 | size)
switch (c (cmd, size))
{
- case c ('s', 2):
- /* Send one byte to a slave address.
- * 2 parameters:
- * - slave address;
- * - data.
- */
- twi_ms_send (args[0], &args[1], 1);
- while (!twi_ms_is_finished ())
- ;
- break;
- case c ('r', 1):
- /* Read one byte from an address slave
- * 1 parameter:
- * - slave address.
- */
- {
- uint8_t data = 0x00;
- int8_t d = twi_ms_read (args[0], &data, 1);
- if (d != 0)
- proto_send0 ('e');
- else
- {
- while (!twi_ms_is_finished ())
- ;
- proto_send1b ('R', data);
- }
- }
+ case c ('z', 0):
+ /* Reset. */
+ utils_reset ();
break;
+#if AC_TWI_MASTER_ENABLE
case c ('r', 2):
- /* Read n bytes from an address slave
- * 2 parameter:
- * - slave address.
- * - nb of bytes.
- */
+ /* Read n bytes from a slave.
+ * - b: slave address.
+ * - b: 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);
- }
+ uint8_t data[args[1]];
+ twi_master_recv (args[0], data, args[1]);
+ uint8_t r = twi_master_wait ();
+ proto_send ('R', r, data);
}
break;
- case c ('t', 2):
+ case c ('t', 3):
/* Test for sending and receiving multiple data.
* It sends a random number of bytes to the slave and then read back
* from it the same number, checking the data are the same as the sent
* ones.
- * 2 parameters:
- * - slave address;
- * - number of iterations to try on.
+ * - slave address.
+ * - maximum nb of bytes.
+ * - number of iterations to try on.
*/
{
int error = 0;
- uint8_t compt = args[1];
- while (compt-- != 0)
+ uint8_t max_byte_number = args[1];
+ uint8_t compt = args[2];
+ while (compt-- != 0 && !error)
{
/* Maximum number of bytes of the message */
- static const uint8_t max_byte_number =
- AC_TWI_SL_RECV_BUFFER_SIZE;
/* Get a random number */
uint32_t random = random_u32 ();
/* Extract a number under max_byte_number */
uint8_t byte_number = random % max_byte_number + 1;
/* Table which contains the random bytes */
uint8_t random_bytes[max_byte_number];
- uint8_t i;
+ uint8_t i, ret;
for (i = 0; i < byte_number; i++)
{
uint8_t mod = i % 4;
@@ -122,65 +90,61 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
random_bytes[i] = (random >> (mod * 8)) & 0xFF;
}
/* Send data */
- twi_ms_send (args[0], random_bytes, byte_number);
- while (!twi_ms_is_finished ())
- ;
+ twi_master_send (args[0], random_bytes, byte_number);
+ ret = twi_master_wait ();
+ /* Check return */
+ if (ret != byte_number)
+ {
+ /* Error */
+ proto_send3b ('S', compt, ret, byte_number);
+ error = 1;
+ break;
+ }
#ifdef HOST
/* Give time to slave to copy data. */
mex_node_wait_date (mex_node_date () + 2);
#endif
-
/* Received buffer */
uint8_t received_buffer[max_byte_number];
/* Receive data */
- int8_t ret = twi_ms_read (args[0], received_buffer,
- byte_number);
+ twi_master_recv (args[0], received_buffer, byte_number);
+ ret = twi_master_wait ();
/* Check return */
- if (ret != 0)
+ if (ret != byte_number)
{
/* Error */
- proto_send0 ('e');
+ proto_send3b ('R', compt, ret, byte_number);
error = 1;
break;
}
- while (!twi_ms_is_finished ())
- ;
for (i = 0; i < byte_number; i++)
{
if (received_buffer[i] != random_bytes[i])
{
+ /* Error */
+ proto_send3b ('C', compt, i, byte_number);
error = 1;
break;
}
}
- if (error != 0)
- break;
- }
- /* Check for error */
- if (error == 0)
- {
- proto_send1b ('T', args[1]);
}
}
break;
- case c ('z', 0):
- /* Reset */
- utils_reset ();
- break;
+#endif /* AC_TWI_MASTER_ENABLE */
default:
/* Variable number of arguments. */
+#if AC_TWI_MASTER_ENABLE
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 ())
- ;
+ /* Send n bytes to a slave.
+ * - b: slave address.
+ * - xb: x data. */
+ twi_master_send (args[0], &args[1], size - 1);
+ uint8_t r = twi_master_wait ();
+ proto_send1b ('S', r);
}
else
+#endif /* AC_TWI_MASTER_ENABLE */
{
/* Error */
proto_send0 ('?');
@@ -199,25 +163,40 @@ main (int argc, char **argv)
#ifdef HOST
mex_node_connect ();
#endif
- /* Enable interruptions */
+ /* Enable interruptions. */
sei ();
- /* Initialize serial port */
+ /* Initialize serial port. */
uart0_init ();
- /* We have successfully boot */
+ /* We have successfully boot. */
proto_send0 ('z');
- /* Initialize TWI */
+ /* Initialize TWI. */
twi_init (0x04);
- /* I am a master */
+#if AC_TWI_MASTER_ENABLE
+ /* I am a master. */
proto_send0 ('M');
+#endif
+#if AC_TWI_SLAVE_ENABLE
+ /* I am a slave. */
+ proto_send0 ('S');
+#endif
while (42)
{
#ifdef HOST
mex_node_wait_date (mex_node_date () + 1);
+#endif
+#if AC_TWI_SLAVE_ENABLE
+ uint8_t data[AC_TWI_SLAVE_RECV_BUFFER_SIZE];
+ uint8_t data_len;
+ /* Check for data. */
+ data_len = twi_slave_poll (data, AC_TWI_SLAVE_RECV_BUFFER_SIZE);
+ if (data_len)
+ {
+ /* Echo them back.*/
+ twi_slave_update (data, data_len);
+ }
+#endif
while (uart0_poll ())
proto_accept (uart0_getc ());
-#else
- proto_accept (uart0_getc ());
-#endif
}
- return 0;
}
+
diff --git a/digital/avr/modules/twi/test/test_twi_host.py b/digital/avr/modules/twi/test/test_twi.py
index 94cd9628..3b227f5b 100644
--- a/digital/avr/modules/twi/test/test_twi_host.py
+++ b/digital/avr/modules/twi/test/test_twi.py
@@ -5,23 +5,20 @@ from mex.msg import Msg
from mex.node import Node
from utils.forked import Forked
-def log (x):
- print x
-
-h = Hub (min_clients = 3, log = log)
+h = Hub (min_clients = 3)
fh = Forked (h.wait)
n = Node ()
def nf ():
while True:
time.sleep (1)
- n.wait (n.date + 1)
+ n.wait (n.date + 1000)
fn = Forked (nf)
-slave = os.popen ('./test_twi_sl.host', 'w')
+slave = os.popen ('./slave/test_twi_slave.host', 'w')
try:
- os.system ('./test_twi_master.host')
+ os.system ('./master/test_twi_master.host')
finally:
fn.kill ()
fh.kill ()
diff --git a/digital/avr/modules/twi/test/test_twi_sl.c b/digital/avr/modules/twi/test/test_twi_sl.c
deleted file mode 100644
index e52d914f..00000000
--- a/digital/avr/modules/twi/test/test_twi_sl.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/* test_twi_slave.c */
-/* avr.twi.slave - TWI slave module. {{{
- *
- * Copyright (C) 2005 Clément Demonchy
- *
- * Robot APB Team/Efrei 2006.
- * Web: http://assos.efrei.fr/robot/
- * Email: robot AT efrei DOT fr
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * }}} */
-
-#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"
-
-#ifdef HOST
-# include "modules/host/mex.h"
-#endif
-
-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 (int argc, char **argv)
-{
- avr_init (argc, argv);
-#ifdef HOST
- mex_node_connect ();
-#endif
- /* Enable interruptions */
- sei ();
- /* Initialize serial port */
- uart0_init ();
- /* We have successfully boot */
- proto_send0 ('z');
- /* Initialize TWI */
- twi_init (0x02);
- /* I am a slave */
- proto_send0 ('S');
- while (42)
- {
-#ifdef HOST
- mex_node_wait_date (mex_node_date () + 1);
-#endif
- uint8_t data[AC_TWI_SL_RECV_BUFFER_SIZE];
- data[0] = 0;
- /* Check for data */
- if (twi_sl_poll (data, AC_TWI_SL_RECV_BUFFER_SIZE))
- {
- /* Receive and store them */
- twi_sl_update (data, AC_TWI_SL_RECV_BUFFER_SIZE);
- }
- while (uart0_poll ())
- proto_accept (uart0_getc ());
- }
- return 0;
-}