Rev Author Line No. Line
615 kaklik 1 #include <avr/pgmspace.h>
2 #include "eeprom.h"
3 #include "common.h"
4  
5 void EEPROM::Wait() {
6 while(TESTBIT(EECR,(1<<EEPE)));
7 }
8  
9 uint8_t EEPROM::GetByte(uint16_t aOfs) {
10 // Wait for any pending writes to finish
11 while(TESTBIT(EECR,(1<<EEPE)));
12 EEARL = aOfs & 0x00ff;
13 #ifdef EEARH
14 EEARH = 0;
15 #endif
16 SETBIT(EECR,(1 << EERE));
17 uint8_t RetVal = EEDR;
18 return RetVal;
19 }
20  
21 void EEPROM::SetByte(uint16_t aOfs,uint8_t aData) {
22 // Wait for any pending writes to finish
23 while(TESTBIT(EECR,(1<<EEPE)));
24 EEARL = aOfs & 0x00ff;
25 #ifdef EEARH
26 EEARH = 0;
27 #endif
28 EEDR = aData;
29 SETBIT(EECR,(1<<EEMPE));
30 SETBIT(EECR,(1<<EEPE));
31 }
32  
33 uint16_t EEPROM::GetWord(uint16_t aOfs) {
34 uint16_t RetVal;
35 ((uint8_t *)(&RetVal))[0] = GetByte(aOfs+0);
36 ((uint8_t *)(&RetVal))[1] = GetByte(aOfs+1);
37 return RetVal;
38 }
39  
40 void EEPROM::SetWord(uint16_t aOfs,uint16_t aData) {
41 SetByte(aOfs+0,((uint8_t *)(&aData))[0]);
42 SetByte(aOfs+1,((uint8_t *)(&aData))[1]);
43 }