Do the eeprom_write_xyz() functions disable interrupts during execution?

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, i guess it's all said in the title. Since there's a strict timing between setting EEMPE and EEPE which could be disturbed by an int firing, I'd like to know if the eeprom routines provided in the library (avr-libc) disable ints before entering the register setup stuff. And of course i'd expect to see the int enable/disable state being the same as it was when entering those eeprom_* routines?

 

Of course I could simply surround the eeprom write by a pair of cli()/sei(), but that would disable ints for a complete EEPROM write cycle of >3 ms.

 

Thanks,

 

-- Thilo

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."

Last Edited: Mon. May 15, 2017 - 08:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, interrupts are disabled, and state is restored.

 

BTW: I would use eeprom_update_* instead.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess you'd need to say which toolchain and version, wouldn't you?  That said, I'd guess GCC.

 

Now, I'd expect the GCC gurus that generate those tools to be aware of the critical spots where no interrupt servicing can be done.  If that >>weren't<< the case, then wouldn't there be anomalies continually popping up in the millions of deployed AVRs.

 

I don't know if the online docs expand those macros as some do.  But wouldn't it be straightforward to generate a nearly-trivial program and look at the generated code?

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a bunch sternst for the ultrafast reply. Just to clarify: those routines do disable ints only for the duration of setting up the registers for the write, not for the whole time it takes to actually complete a write to the EEPROM?

 

@Theusch: cool, man. I did state the tool chain (although not the version). The doc itself states that it is a simple implementation, therefore i don't know how much effort the GCC gurus really spent to make those routines as robust as possible (given the language and the grammar errors of the documentation, it seems they had a bad day...). And yes, i could have created a simple test program. But then again i wouldn't know if that certain generated code/behavior would be version-dependant. In asking, i hoped to get a statement telling me the intended behavior of those routines.

 

Anyways, thanks!

 

-- Thilo

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DO1THL wrote:
those routines do disable ints only for the duration of setting up the registers for the write, not for the whole time it takes to actually complete a write to the EEPROM?

00000108 <eeprom_write_byte>:
 108:	26 2f       	mov	r18, r22

0000010a <eeprom_write_r18>:
 10a:	f9 99       	sbic	0x1f, 1	; 31
 10c:	fe cf       	rjmp	.-4      	; 0x10a <eeprom_write_r18>
 10e:	1f ba       	out	0x1f, r1	; 31
 110:	92 bd       	out	0x22, r25	; 34
 112:	81 bd       	out	0x21, r24	; 33
 114:	20 bd       	out	0x20, r18	; 32
 116:	0f b6       	in	r0, 0x3f	; 63
 118:	f8 94       	cli
 11a:	fa 9a       	sbi	0x1f, 2	; 31
 11c:	f9 9a       	sbi	0x1f, 1	; 31
 11e:	0f be       	out	0x3f, r0	; 63
 120:	01 96       	adiw	r24, 0x01	; 1
 122:	08 95       	ret

116: save state

118: disable interrupts

11e: restore state

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#include <avr/io.h>
#include <avr/eeprom.h>

volatile unsigned char frog;



int main(void)
{
	frog = 2;
	eeprom_write_byte((unsigned char *)1,frog);
	frog = eeprom_read_byte((unsigned char *)1);
	while(1)
	{
		PORTD++;
	}
}
000000ac <eeprom_read_byte>:
  ac:	f9 99       	sbic	0x1f, 1	; 31
  ae:	fe cf       	rjmp	.-4      	; 0xac <eeprom_read_byte>
  b0:	92 bd       	out	0x22, r25	; 34
  b2:	81 bd       	out	0x21, r24	; 33
  b4:	f8 9a       	sbi	0x1f, 0	; 31
  b6:	99 27       	eor	r25, r25
  b8:	80 b5       	in	r24, 0x20	; 32
  ba:	08 95       	ret

000000bc <eeprom_write_byte>:
  bc:	26 2f       	mov	r18, r22

000000be <eeprom_write_r18>:
  be:	f9 99       	sbic	0x1f, 1	; 31
  c0:	fe cf       	rjmp	.-4      	; 0xbe <eeprom_write_r18>
  c2:	1f ba       	out	0x1f, r1	; 31
  c4:	92 bd       	out	0x22, r25	; 34
  c6:	81 bd       	out	0x21, r24	; 33
  c8:	20 bd       	out	0x20, r18	; 32
  ca:	0f b6       	in	r0, 0x3f	; 63
  cc:	f8 94       	cli
  ce:	fa 9a       	sbi	0x1f, 2	; 31
  d0:	f9 9a       	sbi	0x1f, 1	; 31
  d2:	0f be       	out	0x3f, r0	; 63
  d4:	01 96       	adiw	r24, 0x01	; 1
  d6:	08 95       	ret

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.