From: Michel Pollet Date: Fri, 6 Apr 2012 15:31:10 +0000 (+0100) Subject: i2ctest: Collapsed both i2ctests into one X-Git-Tag: v1.0b1~5 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=82f36e2c5b3436a12499b7d8ca3b09f0e0ab1b85;p=sx%2Fsimavr.git i2ctest: Collapsed both i2ctests into one Just need one of these Signed-off-by: Michel Pollet --- diff --git a/examples/board_i2ctest/Makefile b/examples/board_i2ctest/Makefile index 689d113..651f081 100644 --- a/examples/board_i2ctest/Makefile +++ b/examples/board_i2ctest/Makefile @@ -19,26 +19,28 @@ target= i2ctest firm_src = ${wildcard at*${board}.c} firmware = ${firm_src:.c=.axf} -simavr = ../../ +simavr = ../.. SHELL = /bin/bash IPATH = . -IPATH += ../parts +IPATH += ${simavr}/examples/shared +IPATH += ${simavr}/examples/parts IPATH += ${simavr}/include IPATH += ${simavr}/simavr/sim VPATH = . -VPATH += ../parts -VPATH += ../shared +VPATH += ${simavr}/examples/shared +VPATH += ${simavr}/examples/parts -all: obj atmega48_${target}.axf ${target} +all: obj ${firmware} ${target} include ${simavr}/Makefile.common -atmega48_${target}.axf: atmega48_${target}.c -atmega48_${target}.axf: avr_twi_master.c avr_twi_master.h +atmega1280_${target}.axf: atmega1280_${target}.c +atmega1280_${target}.axf: ${simavr}/examples/shared/avr_twi_master.c +atmega1280_${target}.axf: ${simavr}/examples/shared/avr_twi_master.h board = ${OBJ}/${target}.elf diff --git a/examples/board_i2ctest/atmega1280_i2ctest.c b/examples/board_i2ctest/atmega1280_i2ctest.c new file mode 100644 index 0000000..e40e73f --- /dev/null +++ b/examples/board_i2ctest/atmega1280_i2ctest.c @@ -0,0 +1,86 @@ +/* + atmega48_i2ctest.c + + Copyright 2008-2011 Michel Pollet + + This file is part of simavr. + + simavr 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 3 of the License, or + (at your option) any later version. + + simavr 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 simavr. If not, see . + */ + +#include +#include +#include + +// for linker, emulator, and programmer's sake +#include "avr_mcu_section.h" +AVR_MCU(F_CPU, "atmega1280"); + +#include "../shared/avr_twi_master.h" + +#include + +static int uart_putchar(char c, FILE *stream) { + if (c == '\n') + uart_putchar('\r', stream); + loop_until_bit_is_set(UCSR0A, UDRE0); + UDR0 = c; + return 0; +} + +static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, + _FDEV_SETUP_WRITE); + +int main() +{ + stdout = &mystdout; + + sei(); + + TWI_Master_Initialise(); + + { // write 2 bytes at some random address + uint8_t msg[8] = { + 0xa0, // TWI address, + 0xaa, 0x01, // eeprom address, in little endian + 0xde, 0xad, // data bytes + }; + TWI_Start_Transceiver_With_Data(msg, 5, 1); + + while (TWI_Transceiver_Busy()) + sleep_mode(); + } + { + uint8_t msg[8] = { + 0xa0, // TWI address, + 0xa8, 0x01, // eeprom address, in little endian + }; + TWI_Start_Transceiver_With_Data(msg, 3, 0); // dont send stop! + + while (TWI_Transceiver_Busy()) + sleep_mode(); + } + { + uint8_t msg[9] = { + 0xa0 + 1, // TWI address, + }; + TWI_Start_Transceiver_With_Data(msg, 9, 1); // write 1 byte, read 8, send stop + + while (TWI_Transceiver_Busy()) + sleep_mode(); + } + cli(); + sleep_mode(); +} + diff --git a/examples/board_i2ctest/atmega48_i2ctest.c b/examples/board_i2ctest/atmega48_i2ctest.c deleted file mode 100644 index 5a91326..0000000 --- a/examples/board_i2ctest/atmega48_i2ctest.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - atmega48_i2ctest.c - - Copyright 2008-2011 Michel Pollet - - This file is part of simavr. - - simavr 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 3 of the License, or - (at your option) any later version. - - simavr 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 simavr. If not, see . - */ - -#include -#include -#include - -// for linker, emulator, and programmer's sake -#include "avr_mcu_section.h" -AVR_MCU(F_CPU, "atmega48"); - -#include "avr_twi_master.h" - -#include - -static int uart_putchar(char c, FILE *stream) { - if (c == '\n') - uart_putchar('\r', stream); - loop_until_bit_is_set(UCSR0A, UDRE0); - UDR0 = c; - return 0; -} - -static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, - _FDEV_SETUP_WRITE); - -int main() -{ - stdout = &mystdout; - - sei(); - TWI_Master_Initialise(); - - { // write 2 bytes at some random address - uint8_t msg[8] = { - 0xa0, // TWI address, - 0xaa, 0x01, // eeprom address, in little endian - 0xde, 0xad, // data bytes - }; - TWI_Start_Transceiver_With_Data(msg, 5, 1); - - while (TWI_Transceiver_Busy()) - sleep_mode(); - } - { - uint8_t msg[8] = { - 0xa0, // TWI address, - 0xa8, 0x01, // eeprom address, in little endian - }; - TWI_Start_Transceiver_With_Data(msg, 3, 0); // dont send stop! - - while (TWI_Transceiver_Busy()) - sleep_mode(); - } - { - uint8_t msg[9] = { - 0xa0 + 1, // TWI address, - }; - TWI_Start_Transceiver_With_Data(msg, 9, 1); // write 1 byte, read 8, send stop - - while (TWI_Transceiver_Busy()) - sleep_mode(); - } - cli(); - sleep_mode(); -} - diff --git a/examples/board_i2ctest/i2ctest.c b/examples/board_i2ctest/i2ctest.c index 7cb80d3..7d191de 100644 --- a/examples/board_i2ctest/i2ctest.c +++ b/examples/board_i2ctest/i2ctest.c @@ -39,7 +39,7 @@ i2c_eeprom_t ee; int main(int argc, char *argv[]) { elf_firmware_t f; - const char * fname = "atmega48_i2ctest.axf"; + const char * fname = "atmega1280_i2ctest.axf"; printf("Firmware pathname is %s\n", fname); elf_read_firmware(fname, &f); @@ -74,16 +74,17 @@ int main(int argc, char *argv[]) * Pressing "r" and "s" during the demo will start and stop recording * the pin changes */ - avr_vcd_init(avr, "gtkwave_output.vcd", &vcd_file, 100000 /* usec */); - avr_vcd_add_signal(&vcd_file, - avr_io_getirq(avr, AVR_IOCTL_TWI_GETIRQ(0), TWI_IRQ_STATUS), 8 /* bits */ , - "TWSR" ); +// avr_vcd_init(avr, "gtkwave_output.vcd", &vcd_file, 100000 /* usec */); +// avr_vcd_add_signal(&vcd_file, +// avr_io_getirq(avr, AVR_IOCTL_TWI_GETIRQ(0), TWI_IRQ_STATUS), 8 /* bits */ , +// "TWSR" ); - printf( "Demo launching:\n"); + printf( "\nDemo launching:\n"); - while (1) { - int state = avr_run(avr); - if ( state == cpu_Done || state == cpu_Crashed) - break; - } + int state = cpu_Running; + while((state!= cpu_Done)&&(state != cpu_Crashed )) + state = avr_run(avr); + + printf("\n\nPress enter to terminate the program."); + getchar(); } diff --git a/examples/board_i2ctest_atmega1280/Makefile b/examples/board_i2ctest_atmega1280/Makefile deleted file mode 100644 index 0cbef69..0000000 --- a/examples/board_i2ctest_atmega1280/Makefile +++ /dev/null @@ -1,55 +0,0 @@ -# -# Copyright 2008-2012 Michel Pollet -# -# This file is part of simavr. -# -# simavr 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 3 of the License, or -# (at your option) any later version. -# -# simavr 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 simavr. If not, see . - -target= i2ctest -firm_src = ${wildcard at*${board}.c} -firmware = ${firm_src:.c=.axf} -simavr = ../.. -#simavr = /usr/local/lib/simavr - -SHELL = /bin/bash - -IPATH = . -#IPATH += ../parts -IPATH += ${simavr}/examples/parts -IPATH += ${simavr}/include -IPATH += ${simavr}/simavr/sim - -VPATH = . -VPATH += ../parts -VPATH += ../shared - - -all: obj atmega1280_${target}.axf ${target} - -include ${simavr}/Makefile.common - -atmega1280_${target}.axf: atmega1280_${target}.c -atmega1280_${target}.axf: avr_twi_master.c avr_twi_master.h - -board = ${OBJ}/${target}.elf - -${board} : ${OBJ}/${target}.o -${board} : ${OBJ}/i2c_eeprom.o -${board} : ${simavr}/simavr/${OBJ}/libsimavr.a - -${target}: ${board} - @echo $@ done - -clean: clean-${OBJ} - rm -rf *.hex *.a *.axf ${target} *.vcd .*.swo .*.swp .*.swm .*.swn diff --git a/examples/board_i2ctest_atmega1280/README b/examples/board_i2ctest_atmega1280/README deleted file mode 100644 index f65bc4e..0000000 --- a/examples/board_i2ctest_atmega1280/README +++ /dev/null @@ -1,15 +0,0 @@ - -This contains a sample program to demonstrate the use of simavr -using 'custom' code, and own "peripherals". It shows how it is -possible to "hook" code to the AVR pins, and also how to make -"peripherals" and also hook them up to AVR pins. - -This demo demonstrate how to write a i2c/twi "peripheral" and hook it to -an AVR, and then run a firmware that behaves as a TWI "master" to talk to it. - -The code uses a generic i2c "eeprom" were the AVR writes some bytes, -then read them again. The AVR code is based on the Atmel reference -implementation, with quite a few changes to make it more functional. - -Thid "board" doesn't use opengl, the eeprom will display what the -transactions are. \ No newline at end of file diff --git a/examples/board_i2ctest_atmega1280/atmega1280_i2ctest.c b/examples/board_i2ctest_atmega1280/atmega1280_i2ctest.c deleted file mode 100644 index 168bda7..0000000 --- a/examples/board_i2ctest_atmega1280/atmega1280_i2ctest.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - atmega48_i2ctest.c - - Copyright 2008-2011 Michel Pollet - - This file is part of simavr. - - simavr 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 3 of the License, or - (at your option) any later version. - - simavr 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 simavr. If not, see . - */ - -#include -#include -#include - -// for linker, emulator, and programmer's sake -#include "avr_mcu_section.h" -AVR_MCU(F_CPU, "atmega1280"); - -#include "avr_twi_master.h" - -#include - -static int uart_putchar(char c, FILE *stream) { - if (c == '\n') - uart_putchar('\r', stream); - loop_until_bit_is_set(UCSR0A, UDRE0); - UDR0 = c; - return 0; -} - -static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, - _FDEV_SETUP_WRITE); - -int main() -{ - stdout = &mystdout; - - sei(); - - TWI_Master_Initialise(); - - { // write 2 bytes at some random address - uint8_t msg[8] = { - 0xa0, // TWI address, - 0xaa, 0x01, // eeprom address, in little endian - 0xde, 0xad, // data bytes - }; - TWI_Start_Transceiver_With_Data(msg, 5, 1); - - while (TWI_Transceiver_Busy()) - sleep_mode(); - } - { - uint8_t msg[8] = { - 0xa0, // TWI address, - 0xa8, 0x01, // eeprom address, in little endian - }; - TWI_Start_Transceiver_With_Data(msg, 3, 0); // dont send stop! - - while (TWI_Transceiver_Busy()) - sleep_mode(); - } - { - uint8_t msg[9] = { - 0xa0 + 1, // TWI address, - }; - TWI_Start_Transceiver_With_Data(msg, 9, 1); // write 1 byte, read 8, send stop - - while (TWI_Transceiver_Busy()) - sleep_mode(); - } - cli(); - sleep_mode(); -} - diff --git a/examples/board_i2ctest_atmega1280/i2ctest.c b/examples/board_i2ctest_atmega1280/i2ctest.c deleted file mode 100644 index 7d191de..0000000 --- a/examples/board_i2ctest_atmega1280/i2ctest.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - i2ctest.c - - Copyright 2008-2011 Michel Pollet - - This file is part of simavr. - - simavr 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 3 of the License, or - (at your option) any later version. - - simavr 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 simavr. If not, see . - */ - -#include -#include -#include -#include - -#include "sim_avr.h" -#include "avr_twi.h" -#include "sim_elf.h" -#include "sim_gdb.h" -#include "sim_vcd_file.h" -#include "i2c_eeprom.h" - -avr_t * avr = NULL; -avr_vcd_t vcd_file; - -i2c_eeprom_t ee; - -int main(int argc, char *argv[]) -{ - elf_firmware_t f; - const char * fname = "atmega1280_i2ctest.axf"; - - printf("Firmware pathname is %s\n", fname); - elf_read_firmware(fname, &f); - - printf("firmware %s f=%d mmcu=%s\n", fname, (int)f.frequency, f.mmcu); - - avr = avr_make_mcu_by_name(f.mmcu); - if (!avr) { - fprintf(stderr, "%s: AVR '%s' now known\n", argv[0], f.mmcu); - exit(1); - } - avr_init(avr); - avr_load_firmware(avr, &f); - - // initialize our 'peripheral' - i2c_eeprom_init(avr, &ee, 0xa0, 0xfe, NULL, 1024); - - i2c_eeprom_attach(avr, &ee, AVR_IOCTL_TWI_GETIRQ(0)); - ee.verbose = 1; - - // even if not setup at startup, activate gdb if crashing - avr->gdb_port = 1234; - if (0) { - //avr->state = cpu_Stopped; - avr_gdb_init(avr); - } - - /* - * VCD file initialization - * - * This will allow you to create a "wave" file and display it in gtkwave - * Pressing "r" and "s" during the demo will start and stop recording - * the pin changes - */ -// avr_vcd_init(avr, "gtkwave_output.vcd", &vcd_file, 100000 /* usec */); -// avr_vcd_add_signal(&vcd_file, -// avr_io_getirq(avr, AVR_IOCTL_TWI_GETIRQ(0), TWI_IRQ_STATUS), 8 /* bits */ , -// "TWSR" ); - - printf( "\nDemo launching:\n"); - - int state = cpu_Running; - while((state!= cpu_Done)&&(state != cpu_Crashed )) - state = avr_run(avr); - - printf("\n\nPress enter to terminate the program."); - getchar(); -}