avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] Adding (some) Procyon AVRlibfunctionalitytoavr-libc


From: Mike Perks
Subject: Re: [avr-libc-dev] Adding (some) Procyon AVRlibfunctionalitytoavr-libc
Date: Sat, 19 Sep 2009 18:45:07 -0500
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)

Eric,
Unfortunately, this is just a hisorical problem that we have to live with. 
<snip> We just have to accept this fact and move on the best we can.
Absolutely. At least Atmel seems to be getting better now.
Would you be willing to describe in more detail about what you do to solve this problem? I think it would be good if we heard from others' experience.
Ruud and Frédéric described it pretty well. The idea (which is not new) is to virtualize a device definition. It will need iterating on and may or may be done automatically. I'm not tied to the process of getting there but I think virtualization is the only way to do go to make the library code easy to write and maintain. It could be something simple like this:

   #if defined(__AVR_ATmega128__) || defined(__AVR_ATmega644P__) ||
   defined(__AVR_ATmega328P__)
   #elif defined(__AVR_ATmega644__)
       #define SPCR    SPCR0
       #define SPDR    SPDR0
       #define SPSR    SPSR0
       #define SPE     SPE0
       #define SPIF    SPIF0
       #define MSTR    MSTR0
   #else
       #error "no SPI definition for MCU"
   #endif

where the port names are left asis for most of the devices and only the exceptions are dealt with or it could be something a little more complex where everything is virtualized:

   #define EEPROM_ADDR_REG   EEAR
   #define EEPROM_DATA_REG   EEDR
   #define EEPROM_CTL_REG    EECR

   #if defined(__AVR_ATmega128__)
       #define EEPROM_MASTER_WRITE  EEMWE
       #define EEPROM_WRITE         EEWE
   #elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) ||
   defined(__AVR_ATmega328P__)
       #define EEPROM_MASTER_WRITE  EEMPE
       #define EEPROM_WRITE         EEPE
   #else
       #error "no EEPROM definition for MCU"
   #endif

   void eeprom_write_byte(uint16_t address, uint8_t byte)
   {
       /* wait until any other writes are complete */
       loop_until_bit_is_clear(EECR, EEPROM_WRITE);

       /* set up registers for write - master write enable is
   required    */
       EEPROM_ADDR_REG = address;
       EEPROM_DATA_REG = byte;
       EEPROM_CTL_REG |= _BV(EEPROM_MASTER_WRITE) | _BV(EEPROM_WRITE);
   }

Mike Perks
Oak Micros (oakmicros.com)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]