On Wed, Apr 27, 2005 at 05:31:13PM -0000, arhodes19044 wrote:
>
> In the Disasm, I can see that the interrupts are cleared. I could
> not see where they were set again, but in the original source you
> include, I see that a register is used to store SREG, and then to
> restore it.
Thats how its done. In a generic library such as avr-libc one does not
want the global interrupt flag to be different on exit than on entry. So
SREG is stashed, cli, bits twiddled, and SREG restored to return to
whatever was originally in effect.
> THANKS! You helped me a lot, and also saved me some time trying to
> write my own stuff.
Its more fun to write your own. :-)
Spent some time playing and my C routines are only a couple of bytes
larger than the handcrafted assembly. I'll keep my C versions in my
project, partly because everything one uses in a library becomes a risk
5, 10, or 20 years down the road. Partly because I want a wdt_reset().
Partly because I also want an ee_compare() to verify the contents of
SRAM and EEPROM match:
//
// Compare EEPROM contents against SRAM
// addr is the address within the EEPROM
// cp is what to compare in RAM
// n is the number of 8 bit octets to compare
//
// Returns 0 if contents match, following memcmp() precedent.
// (this code is almost exactly ee_reads().
//
int
ee_compare(void *addr, const void *cp, uint16_t n)
{
int tmp;
for( ; n ; n-- ) {
wdt_reset();
while( EECR & (1<<EEWE) ) // wait until ready
;
EEAR = (uint16_t)addr;
EECR |= (1<<EERE); // start the read
tmp = *((uint8_t*)(cp)++) - EEDR; // read
if( tmp )
return(tmp); // fail, difference between
addr++;
}
return(0); // pass
}
--
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.Message
Re: [AVR-Chat] Re: was eeprom ? Now about disasm
2005-04-27 by David Kelly
Attachments
- No local attachments were found for this message.