From cff54ceef2c904a72511ce4f73c66d93eb3516ca Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 29 Nov 2010 23:07:55 +0100 Subject: digital/avr/modules/twi: implement USI slave, closes #142 --- digital/avr/modules/twi/test/usi/Makefile | 12 ++++++ digital/avr/modules/twi/test/usi/avrconfig.h | 57 +++++++++++++++++++++++++ digital/avr/modules/twi/test/usi/test_twi_usi.c | 49 +++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 digital/avr/modules/twi/test/usi/Makefile create mode 100644 digital/avr/modules/twi/test/usi/avrconfig.h create mode 100644 digital/avr/modules/twi/test/usi/test_twi_usi.c (limited to 'digital/avr/modules/twi/test') diff --git a/digital/avr/modules/twi/test/usi/Makefile b/digital/avr/modules/twi/test/usi/Makefile new file mode 100644 index 00000000..e37c3f8c --- /dev/null +++ b/digital/avr/modules/twi/test/usi/Makefile @@ -0,0 +1,12 @@ +BASE = ../../../.. +AVR_PROGS = test_twi_usi +test_twi_usi_SOURCES = test_twi_usi.c +MODULES = twi +CONFIGFILE = avrconfig.h +# atmega8, atmega8535, atmega128... +AVR_MCU = attiny85 +# -O2 : speed +# -Os : size +OPTIMIZE = -Os + +include $(BASE)/make/Makefile.gen diff --git a/digital/avr/modules/twi/test/usi/avrconfig.h b/digital/avr/modules/twi/test/usi/avrconfig.h new file mode 100644 index 00000000..183064e0 --- /dev/null +++ b/digital/avr/modules/twi/test/usi/avrconfig.h @@ -0,0 +1,57 @@ +#ifndef avrconfig_h +#define avrconfig_h +/* avrconfig.h */ +/* avr.twi - TWI AVR module. {{{ + * + * Copyright (C) 2010 Nicolas Schodet + * + * 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 + * 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. + * + * }}} */ + +/* utils */ +/** AVR Frequency : 1000000, 1843200, 2000000, 3686400, 4000000, 7372800, + * 8000000, 11059200, 14745600, 16000000, 18432000, 20000000. */ +#define AC_FREQ 1000000 + +/* twi - TWI module. */ +/** Driver to implement TWI: HARD, SOFT, or USI. */ +#define AC_TWI_DRIVER USI +/** Do not use interrupts. */ +#define AC_TWI_NO_INTERRUPT 1 +/** 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/usi/test_twi_usi.c b/digital/avr/modules/twi/test/usi/test_twi_usi.c new file mode 100644 index 00000000..d55456a9 --- /dev/null +++ b/digital/avr/modules/twi/test/usi/test_twi_usi.c @@ -0,0 +1,49 @@ +/* test_twi_usi.c */ +/* avr.twi - TWI AVR module. {{{ + * + * Copyright (C) 2010 Nicolas Schodet + * + * 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 + * 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 "io.h" + +int +main (int argc, char **argv) +{ + /* Initialize TWI. */ + twi_init (0x04); + while (42) + { + /* Simulate interrupts. */ + twi_update (); + /* Check for data. */ + uint8_t data[AC_TWI_SLAVE_RECV_BUFFER_SIZE]; + uint8_t data_len; + data_len = twi_slave_poll (data, AC_TWI_SLAVE_RECV_BUFFER_SIZE); + if (data_len) + { + /* Echo them back.*/ + twi_slave_update (data, data_len); + } + } +} + -- cgit v1.2.3