Skip to content

Commit 3ca20d9

Browse files
bigdinotechcalvinatintel
authored andcommitted
ATLEDGE-487 CurieEEPROM library
-Initial commit for CurieEEPROM library -Implements EEPROM functionality using an available area of the ROM -supports both BYTE and DWORD reading/writing
1 parent b195624 commit 3ca20d9

File tree

11 files changed

+724
-0
lines changed

11 files changed

+724
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* EEPROM Clear
3+
*
4+
* Sets all of the bytes of the EEPROM to 0xFF.
5+
* Please see eeprom_iteration for a more in depth
6+
* look at how to traverse the EEPROM.
7+
*
8+
* This example code is in the public domain.
9+
*/
10+
11+
#include <CurieEEPROM.h>
12+
13+
void setup() {
14+
// initialize the LED pin as an output.
15+
pinMode(13, OUTPUT);
16+
17+
EEPROM.clear();
18+
19+
// turn the LED on when we're done
20+
digitalWrite(13, HIGH);
21+
}
22+
23+
void loop() {
24+
/** Empty loop. **/
25+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/***
2+
Written by Christopher Andrews.
3+
CRC algorithm generated by pycrc, MIT licence ( https://github.com/tpircher/pycrc ).
4+
5+
A CRC is a simple way of checking whether data has changed or become corrupted.
6+
This example calculates a CRC value directly on the EEPROM values.
7+
The purpose of this example is to highlight how the EEPROM object can be used just like an array.
8+
9+
01/05/2016 - Modified for Arduino 101 - Dino Tinitigan <dino.tinitigan@intel.com>
10+
***/
11+
12+
#include <CurieEEPROM.h>
13+
14+
void setup() {
15+
16+
//Start serial
17+
Serial.begin(9600);
18+
while (!Serial) {
19+
; // wait for serial port to connect. Needed for native USB port only
20+
}
21+
22+
//Print length of data to run CRC on.
23+
Serial.print("EEPROM length: ");
24+
Serial.println(EEPROM.length());
25+
26+
//Print the result of calling eeprom_crc()
27+
Serial.print("CRC32 of EEPROM data: 0x");
28+
Serial.println(eeprom_crc(), HEX);
29+
Serial.print("\n\nDone!");
30+
}
31+
32+
void loop() {
33+
/* Empty loop */
34+
}
35+
36+
unsigned long eeprom_crc(void) {
37+
38+
const unsigned long crc_table[16] = {
39+
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
40+
0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
41+
0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
42+
0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
43+
};
44+
45+
unsigned long crc = ~0L;
46+
47+
for (int index = 0 ; index < EEPROM.length()/4 ; ++index) {
48+
crc = crc_table[(crc ^ EEPROM[index]) & 0x0f] ^ (crc >> 4);
49+
crc = crc_table[(crc ^ (EEPROM[index] >> 4)) & 0x0f] ^ (crc >> 4);
50+
crc = ~crc;
51+
}
52+
return crc;
53+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/***
2+
eeprom_get example.
3+
4+
This shows how to use the EEPROM.get() method.
5+
6+
To pre-set the EEPROM data, run the example sketch eeprom_put.
7+
This sketch will run without it, however, the values shown
8+
will be shown from what ever is already on the EEPROM.
9+
10+
This may cause the serial object to print out a large string
11+
of garbage if there is no null character inside one of the strings
12+
loaded.
13+
14+
Written by Christopher Andrews 2015
15+
Released under MIT licence.
16+
***/
17+
18+
#include <CurieEEPROM.h>
19+
20+
void setup() {
21+
22+
float f = 0.00f; //Variable to store data read from EEPROM.
23+
int eeAddress = 0; //EEPROM address to start reading from
24+
25+
Serial.begin(9600);
26+
while (!Serial) {
27+
; // wait for serial port to connect. Needed for native USB port only
28+
}
29+
Serial.print("Read float from EEPROM: ");
30+
31+
//Get the float data from the EEPROM at position 'eeAddress'
32+
EEPROM.get(eeAddress, f);
33+
Serial.println(f, 3); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float.
34+
35+
/***
36+
As get also returns a reference to 'f', you can use it inline.
37+
E.g: Serial.print( EEPROM.get( eeAddress, f ) );
38+
***/
39+
40+
/***
41+
Get can be used with custom structures too.
42+
I have separated this into an extra function.
43+
***/
44+
45+
secondTest(); //Run the next test.
46+
}
47+
48+
struct MyObject {
49+
float field1;
50+
byte field2;
51+
char name[10];
52+
};
53+
54+
void secondTest() {
55+
int eeAddress = sizeof(float); //Move address to the next byte after float 'f'.
56+
57+
MyObject customVar; //Variable to store custom object read from EEPROM.
58+
EEPROM.get(eeAddress, customVar);
59+
60+
Serial.println("Read custom object from EEPROM: ");
61+
Serial.println(customVar.field1);
62+
Serial.println(customVar.field2);
63+
Serial.println(customVar.name);
64+
}
65+
66+
void loop() {
67+
/* Empty loop */
68+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/***
2+
eeprom_put example.
3+
4+
This shows how to use the EEPROM.put() method.
5+
Also, this sketch will pre-set the EEPROM data for the
6+
example sketch eeprom_get.
7+
8+
Note, unlike the single byte version EEPROM.write(),
9+
the put method will use update semantics. As in a byte
10+
will only be written to the EEPROM if the data is actually
11+
different.
12+
13+
Written by Christopher Andrews 2015
14+
Released under MIT licence.
15+
***/
16+
17+
#include <CurieEEPROM.h>
18+
19+
struct MyObject {
20+
float field1;
21+
byte field2;
22+
char name[10];
23+
};
24+
25+
void setup() {
26+
27+
Serial.begin(9600);
28+
while (!Serial) {
29+
; // wait for serial port to connect. Needed for native USB port only
30+
}
31+
32+
float f = 123.456f; //Variable to store in EEPROM.
33+
int eeAddress = 0; //Location we want the data to be put.
34+
35+
36+
//One simple call, with the address first and the object second.
37+
EEPROM.put(eeAddress, f);
38+
39+
Serial.println("Written float data type!");
40+
41+
/** Put is designed for use with custom structures also. **/
42+
43+
//Data to store.
44+
MyObject customVar = {
45+
3.14f,
46+
65,
47+
"Working!"
48+
};
49+
50+
eeAddress += sizeof(float); //Move address to the next byte after float 'f'.
51+
52+
EEPROM.put(eeAddress, customVar);
53+
Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!");
54+
}
55+
56+
void loop() {
57+
/* Empty loop */
58+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* EEPROM Read
3+
*
4+
* Reads the value of each DWORD of the EEPROM and prints it
5+
* to the computer.
6+
* This example code is in the public domain.
7+
* 01/05/2016 - Modified for Arduino 101 - Dino Tinitigan <dino.tinitigan@intel.com>
8+
*/
9+
10+
#include <CurieEEPROM.h>
11+
12+
// start reading from the first byte (address 0) of the EEPROM
13+
int address = 0;
14+
unsigned long value;
15+
16+
void setup() {
17+
// initialize serial and wait for port to open:
18+
Serial.begin(9600);
19+
while (!Serial) {
20+
; // wait for serial port to connect. Needed for native USB port only
21+
}
22+
}
23+
24+
void loop() {
25+
// read a byte from the current address of the EEPROM
26+
value = EEPROM.read(address);
27+
28+
Serial.print(address);
29+
Serial.print("\t");
30+
Serial.print(value, DEC);
31+
Serial.println();
32+
33+
//increment address by 4 since we are using DWORDs and we have a granularity of a DWORD or 4 bytes
34+
address = address + 4;
35+
if (address == EEPROM.length()) {
36+
address = 0;
37+
}
38+
39+
delay(500);
40+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* EEPROM Write
3+
*
4+
* Stores values read from analog input 0 into the EEPROM.
5+
* These values will stay in the EEPROM when the board is
6+
* turned off and may be retrieved later by another sketch.
7+
* 01/05/2016 - Modified for Arduino 101 - Dino Tinitigan <dino.tinitigan@intel.com>
8+
*/
9+
10+
#include <CurieEEPROM.h>
11+
12+
/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
13+
int addr = 0;
14+
15+
void setup() {
16+
Serial.begin(9600);
17+
while (!Serial) {
18+
; // wait for serial port to connect. Needed for native USB port only
19+
}
20+
//use write for the first half of the EEPROM area
21+
Serial.println("Writing with write()");
22+
for(int i = 0; i < EEPROM.length()/8; i++)
23+
{
24+
unsigned long val = analogRead(0);
25+
addr +=4; //increment address by 4 since we are using DWORDs
26+
Serial.print("Addr:\t");
27+
Serial.print(addr);
28+
Serial.print("\tWriting: ");
29+
Serial.println(val);
30+
EEPROM.write(addr, val);
31+
delay(100);
32+
}
33+
34+
//use write8 for the second half of the EEPROM area
35+
Serial.println("Writing with write8()");
36+
for(int i = EEPROM.length()/2; i < EEPROM.length(); i++)
37+
{
38+
byte val8 = analogRead(0)/4;
39+
addr++;
40+
Serial.print("Addr:\t");
41+
Serial.print(addr);
42+
Serial.print("\tWriting: ");
43+
Serial.println(val8);
44+
EEPROM.write(addr, val8);
45+
delay(100);
46+
}
47+
48+
Serial.println("done writing");
49+
}
50+
51+
void loop() {
52+
53+
}

libraries/CurieEEPROM/keywords.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#######################################
2+
# Syntax Coloring Map For EEPROM
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
CurieEEPROM KEYWORD1
10+
EEPROM KEYWORD1
11+
12+
#######################################
13+
# Methods and Functions (KEYWORD2)
14+
#######################################
15+
16+
write KEYWORD2
17+
write8 KEYWORD2
18+
update KEYWORD2
19+
update8 KEYWORD2
20+
clear KEYWORD2
21+
begin KEYWORD2
22+
end KEYWORD2
23+
length KEYWORD2
24+
put KEYWORD2
25+
get KEYWORD2
26+
#######################################
27+
# Constants (LITERAL1)
28+
#######################################
29+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=CurieEEPROM
2+
version=1.0
3+
author=Intel
4+
maintainer=Intel <dino.tinitigan@intel.com>
5+
sentence=Enables reading and writing to OTP flash area of Curie
6+
paragraph=
7+
category=Data Storage
8+
url=http://www.arduino.cc/en/Reference/EEPROM
9+
architectures=arc32
10+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
01/05/2016 v1.0
2+
3+
-Initial commit for CurieEEPROM library
4+
-Implements EEPROM functionality using an available area of the ROM
5+
-supports both BYTE and DWORD reading/writing
6+
-EEPROM[] currently only supports reading
7+
-an empty DWORD cell has a value of 0xFFFFFFFF

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy