Re: [avr-libc-dev] [RFC] New eeprom.h
Weddington, Eric schreef: Mainly because this is a total rewrite of the implementation. The API (interface) stays the same. I'm certainly fine with putting the old copyrights back on. I thought the address thingy was taken from Bjoern Haasse's implementation. So that's why I thought he should at least be there. But I am no lawyer, and personally I do not mind. This sounds promising. Do you care to modify the header? I did. See attachment. (if they do not get to the list, please notify me) No guarantees. But for me it saves up to 50 bytes testing read/write pairs per type. The only thing I can't make gcc do in a proper manner is the read block. GCC just uses to many instructions. That is a candidate for a special assembler routine. There is a loop, or should be. The loop is checking the EEWE flag (or equivalent) to make sure that a read or write is possible. And the old code is not disabling interrupts during eeprom write... which is no good! Maybe this was the problem of the report for the tiny13? No, the old code is disabling the interrupts for the write routines. You have to look in the libc/misc/eeprom.S file in the avr-libc source. Right, I forgot about the assembler file... shame on me! Sorry for the fuzz. Wouter /* Copyright (c) 2007 Atmel Corporation All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* $Id$ */ #ifndef _AVR_EEPROM_H_ #define _AVR_EEPROM_H_ 1 #include avr/io.h #include stdint.h /** \def EEMEM \ingroup avr_eeprom Attribute expression causing a variable to be allocated within the .eeprom section. */ #define EEMEM __attribute__((section(.eeprom))) /* Register definitions */ /* Check for existence of EEPROM peripheral. */ #if E2END == 0 #error Device does not have EEPROM available! #endif /* Check for aliases. */ #if !defined(EEWE) defined(EEPE) #define EEWE EEPE #endif #if !defined(EEMWE) defined(EEMPE) #define EEMWE EEMPE #endif #if !defined(EECR) defined(DEECR) /* AT86RF401 */ #define EECR DEECR #define EEAR DEEAR #define EEARL DEEAR #define EEDR DEEDR #define EERE EER #define EEWE EEL #define EEMWE EEU #endif #if !defined(EECR) || !defined(EEDR) || !defined(EEARL) #ifndef __EEPROM_REG_LOCATIONS__ /* 6-byte string denoting where to find the EEPROM registers in memory space. Adresses denoted in hex syntax with uppercase letters. Used by the EEPROM subroutines. First two letters: EECR address. Second two letters: EEDR address. Last two letters: EEAR address. */ #define __EEPROM_REG_LOCATIONS__ 1C1D1E #endif /* If needed, override the locations defined in the IO headers. */ #ifdef EEPROM_REG_LOCATIONS_OVERRIDE #undef __EEPROM_REG_LOCATIONS__ #define __EEPROM_REG_LOCATIONS__ EEPROM_REG_LOCATIONS_OVERRIDE #endif #define CONCAT1(a, b) CONCAT2(a, b) #define CONCAT2(a, b) a ## b #define HEXNR CONCAT1(0x, __EEPROM_REG_LOCATIONS__) #undef EECR #define EECR _SFR_IO8((HEXNR 16) 0xFF) #undef EEDR #define EEDR _SFR_IO8((HEXNR 8) 0xFF ) #undef EEAR #define EEAR _SFR_IO8(HEXNR 0xFF) #undef EEARH #undef EEARL #define EEARL EEAR #endif /** \def eeprom_is_ready \ingroup avr_eeprom \returns 1 if EEPROM is ready for a new read/write operation, 0 if not. */ #if defined(__DOXYGEN__) # define eeprom_is_ready() #elif defined(DEECR) # define eeprom_is_ready() bit_is_clear(DEECR, BSY) #else # define eeprom_is_ready()
[avr-libc-dev] [bug #22163] Everytime ATOMIC_BLOCK(ATOMIC_RESTORESTATE) compiler generates warning - unused variable 'sreg_save'
Follow-up Comment #1, bug #22163 (project avr-libc): Tomasz, Could you please post a small test case that gives this warning? ___ Reply to this item at: http://savannah.nongnu.org/bugs/?22163 ___ Message sent via/by Savannah http://savannah.nongnu.org/ ___ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-libc-dev
[avr-libc-dev] [bug #22163] Everytime ATOMIC_BLOCK(ATOMIC_RESTORESTATE) compiler generates warning - unused variable 'sreg_save'
Follow-up Comment #2, bug #22163 (project avr-libc): I have not seen this warning despite having used this macro in several projects. Are you using C++ Tomasz (I only have C projects)? ___ Reply to this item at: http://savannah.nongnu.org/bugs/?22163 ___ Message sent via/by Savannah http://savannah.nongnu.org/ ___ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-libc-dev
[avr-libc-dev] [bug #22182] -mint8 kills stdio
URL: http://savannah.nongnu.org/bugs/?22182 Summary: -mint8 kills stdio Project: AVR C Runtime Library Submitted by: jnweiger Submitted on: Wednesday 01/30/2008 at 20:58 Category: Library Severity: 3 - Normal Priority: 5 - Normal Item Group: None Status: None Percent Complete: 0% Assigned to: None Originator Email: Open/Closed: Open Discussion Lock: Any ___ Details: printf() putchar() and friends, using static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE); crash, when the code is compiled with -mint8. My tests run fine without -mint8. I suggest to add a guard against -mint8 to stdio.h early, if this is nontrivial to fix. #if __INT_MAX__ == 127 # error stdio is incompatible with -mint8 #endif ___ Reply to this item at: http://savannah.nongnu.org/bugs/?22182 ___ Message sent via/by Savannah http://savannah.nongnu.org/ ___ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-libc-dev
[avr-libc-dev] [bug #22182] -mint8 kills stdio
Follow-up Comment #1, bug #22182 (project avr-libc): This happened with avr-libc-1.4.6 ___ Reply to this item at: http://savannah.nongnu.org/bugs/?22182 ___ Message sent via/by Savannah http://savannah.nongnu.org/ ___ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-libc-dev
[avr-libc-dev] [bug #22182] -mint8 kills stdio
Update of bug #22182 (project avr-libc): Status:None = Wont Fix Assigned to:None = arcanum Open/Closed:Open = Closed ___ Follow-up Comment #2: Acording to the avr-libc user manual here: http://www.nongnu.org/avr-libc/user-manual/using_tools.html The -mint8 flag is not supported by avr-libc and should not be used with any avr-libc routines. There are no plans to support -mint8 in the future. Closing bug. ___ Reply to this item at: http://savannah.nongnu.org/bugs/?22182 ___ Message sent via/by Savannah http://savannah.nongnu.org/ ___ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-libc-dev
[avr-libc-dev] [bug #22163] Everytime ATOMIC_BLOCK(ATOMIC_RESTORESTATE) compiler generates warning - unused variable 'sreg_save'
Follow-up Comment #3, bug #22163 (project avr-libc): Sorry, but mistake I didn't mention that I'm using avr-g++ compiler. When using avr-gcc everything is working perfectly, but in g++ the following code produces warning: #include util/atomic.h int main() { volatile int b,a; a=0; b=0; ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { if(b==0) a++; } } I don't know if you consider it as a bug, but it would be great if ATOMIC_BLOCK could be used in c++. ___ Reply to this item at: http://savannah.nongnu.org/bugs/?22163 ___ Message sent via/by Savannah http://savannah.nongnu.org/ ___ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-libc-dev
[avr-libc-dev] Re: C++ Interrupts
IMHO the only way is to define the interrupt method in the class with interrupt attributes and then alias the mangled name to the AVR vector so the compiler can find it during global name reconciliation. This would be very neat and simple if we could develop a simple name mangling macro. Ron With advise from Daniel Lohmann, Andrew Haley and Brian Dessent over on the gcc-help list (Mangle functions), using the gcc asm keyword considerably simplifies defining interrupt methods in C++ classes. The asm keyword as it applies to function names is described in 5.37 of the gcc manual, and essentially specifies the equivalent assembler name for the target function name. Its use allows the user to use his or her own names for class interrupt methods. For avr-gcc it requires two new macros: #define STRINGIFY(name) #name #define CLASS_IRQ(name, vector) \ static void name(void) asm(STRINGIFY(vector)) \ __attribute__ ((signal, __INTR_ATTRS)) Using the simple example of previous posts on this topic, the interrupt class header for a '128 TIMER0 overflow looks like: class CTimer0Interrupt { public: CTimer0Interrupt(); ~CTimer0Interrupt(); private: CLASS_IRQ(OverflowInterrupt, TIMER0_OVF_vect); }; The macro declares the interrupt handler as static because providing a non-static signal function with a this pointer seems rather hit and miss for gcc. Mandating a static declaration ensures the programmer is not tempted to manipulate any local data. Of course there should never be any local data. The cpp implementation file looks like: //*** // Timer0Interrupt.cpp // #include Timer0.h #include Timer0Interrupt.h extern CTimer0 Timer0; //--- CTimer0Interrupt::CTimer0Interrupt() { TCNT0 = TIMER0_TIMEOUT; TCCR0 = 0x04; TIMSK |= (1TOIE0);// enable overflow interrupts } //--- CTimer0Interrupt::~CTimer0Interrupt() { TIMSK = ~(1TOIE0); // disable Timer0 timeout interrupt } //--- void CTimer0Interrupt::OverflowInterrupt(void) { TCNT0 = TIMER0_TIMEOUT; // restart the timeout Timer0.SetOverflowFlag(); // tell our friend of the event } Note that the interrupt handler is declared just like any other method. All processing associated with the interrupt is performed in the class associated with, and responsible for, controlling the peripheral. In this case the CTimer0 class of which the CTimer0Interrupt class is both class data and a friend: class CTimer0 { friend class CTimer0Interrupt; public: CTimer0(); ~CTimer0(); int GetTimer0Flags(void); private: void SetOverflowFlag(void); private: volatile intmTimer0Flags; CTimer0InterruptmTimer0Interrupt; }; Where speed is of the essence, the interrupt class can directly modify the owning peripheral class data. A simple example is: void CTimer0Interrupt::OverflowInterrupt(void) { TCNT0 = TIMER0_TIMEOUT; // restart the timeout Timer0.mTimer0Flags |= TIMER0_OVERFLOW; } To me this seems a good solution for handling interrupts in avr-gcc C++ projects by integrating the handlers into the peripheral class and keeping with the spirit of C++. Ron E-mail message checked by Spyware Doctor (5.5.0.178) Database version: 5.09100 http://www.pctools.com/spyware-doctor/ ___ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-libc-dev