Eeprom-test example modified
This patch improves the eeprom-test example adding more tests on the eeprom read/write procedures.
This commit is contained in:
parent
10c7066035
commit
8de0380efe
|
@ -1,5 +1,6 @@
|
||||||
CONTIKI_PROJECT = eeprom-test
|
CONTIKI_PROJECT = eeprom-test
|
||||||
all: $(CONTIKI_PROJECT)
|
all: $(CONTIKI_PROJECT)
|
||||||
|
TARGET=mbxxx
|
||||||
|
|
||||||
CONTIKI = ../..
|
CONTIKI = ../..
|
||||||
include $(CONTIKI)/Makefile.include
|
include $(CONTIKI)/Makefile.include
|
||||||
|
|
|
@ -43,32 +43,68 @@
|
||||||
|
|
||||||
#include <stdio.h> /* For printf() */
|
#include <stdio.h> /* For printf() */
|
||||||
|
|
||||||
|
void
|
||||||
|
print_content()
|
||||||
|
{
|
||||||
|
eeprom_addr_t addr_row = 0, j;
|
||||||
|
uint8_t i;
|
||||||
|
uint8_t byte;
|
||||||
|
|
||||||
|
printf("\t");
|
||||||
|
for(i = 0; i < 16; i++)
|
||||||
|
printf("0x%x\t", i);
|
||||||
|
printf
|
||||||
|
("\n-----------------------------------------------------------------------------------------------------------------------------------------\n");
|
||||||
|
|
||||||
|
for(addr_row = 0; addr_row < EEPROM_SIZE / 16; ++addr_row) {
|
||||||
|
printf("0x%x\t|", addr_row * 16);
|
||||||
|
|
||||||
|
for(j = 0; j < 16; j++) {
|
||||||
|
eeprom_read(addr_row * 16 + j, &byte, 1);
|
||||||
|
printf("0x%x\t", byte);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
erase_content()
|
||||||
|
{
|
||||||
|
static eeprom_addr_t addr = 0;
|
||||||
|
|
||||||
|
for(addr = 0; addr < EEPROM_SIZE; ++addr) {
|
||||||
|
eeprom_write(addr, 0, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
PROCESS(eeprom_test_process, "EEPROM Test Process");
|
PROCESS(eeprom_test_process, "EEPROM Test Process");
|
||||||
AUTOSTART_PROCESSES(&eeprom_test_process);
|
AUTOSTART_PROCESSES(&eeprom_test_process);
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
PROCESS_THREAD(eeprom_test_process, ev, data)
|
PROCESS_THREAD(eeprom_test_process, ev, data)
|
||||||
{
|
{
|
||||||
static uint8_t counter = 0;
|
static uint8_t counter = 0, error = 0;
|
||||||
|
|
||||||
static eeprom_addr_t addr = 0;
|
static eeprom_addr_t addr = 0;
|
||||||
|
uint8_t byte;
|
||||||
|
|
||||||
|
uint8_t buffer[] =
|
||||||
|
{ 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xCC, 0xCC, 0xCC, 0xBB,
|
||||||
|
0xBB, 0xBB, 0xAA, 0xAA, 0xAA, 0xFF, 0xAA, 0xAA, 0xAA, 0xBB,
|
||||||
|
0xBB, 0xBB, 0xCC, 0xCC, 0xCC, 0xBB, 0xBB, 0xBB, 0xAA, 0xAA,
|
||||||
|
0xAA, 0xFF, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xCC, 0xCC,
|
||||||
|
0xCC, 0xBB, 0xBB, 0xBB, 0xAA, 0xAA, 0xAA, 0xFF
|
||||||
|
};
|
||||||
|
|
||||||
PROCESS_BEGIN();
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
printf("eeprom-test: Size = %d bytes\n", EEPROM_SIZE);
|
printf("eeprom-test: Size = %d bytes\n", EEPROM_SIZE);
|
||||||
|
|
||||||
/* Check to see if the EEPROM is empty */
|
print_content();
|
||||||
for(addr = 0; addr < EEPROM_SIZE; ++addr) {
|
|
||||||
uint8_t byte;
|
|
||||||
|
|
||||||
eeprom_read(addr, &byte, 1);
|
printf("\nErase EEPROM content\n");
|
||||||
if(byte != 0xFF) {
|
erase_content();
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(addr == EEPROM_SIZE) {
|
print_content();
|
||||||
printf("eeprom-test: EEPROM is empty. Proceding with write test...\n");
|
|
||||||
|
|
||||||
counter = 0;
|
counter = 0;
|
||||||
for(addr = 0; addr < EEPROM_SIZE; ++addr) {
|
for(addr = 0; addr < EEPROM_SIZE; ++addr) {
|
||||||
|
@ -78,21 +114,43 @@ PROCESS_THREAD(eeprom_test_process, ev, data)
|
||||||
|
|
||||||
counter = 0;
|
counter = 0;
|
||||||
for(addr = 0; addr < EEPROM_SIZE; ++addr) {
|
for(addr = 0; addr < EEPROM_SIZE; ++addr) {
|
||||||
uint8_t byte;
|
byte = 0;
|
||||||
|
|
||||||
eeprom_read(addr, &byte, 1);
|
eeprom_read(addr, &byte, 1);
|
||||||
if(byte != counter) {
|
if(byte != counter) {
|
||||||
printf("eeprom-test: EEPROM write failure!\n");
|
error++;
|
||||||
|
eeprom_read(addr, &byte, 1);
|
||||||
|
printf
|
||||||
|
("eeprom-test: EEPROM write failure! 0x%x =/= 0x%x at address 0x%x\n",
|
||||||
|
byte, counter, addr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
counter += 1;
|
counter += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(error)
|
||||||
|
printf("eeprom-test: EEPROM write test FAIL!\n%d errors", error);
|
||||||
|
else
|
||||||
printf("eeprom-test: EEPROM write test success!\n");
|
printf("eeprom-test: EEPROM write test success!\n");
|
||||||
} else {
|
|
||||||
printf("eeprom-test: EEPROM is NOT empty! Skipping write test.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
print_content();
|
||||||
|
|
||||||
|
printf("Fill memory with buffer\n");
|
||||||
|
|
||||||
|
for(addr = 0; addr < EEPROM_SIZE; addr += sizeof(buffer)) {
|
||||||
|
eeprom_write(addr, ((unsigned char *)buffer), sizeof(buffer));
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
printf("Write data buffer %d at address 0x0\n", sizeof(buffer));
|
||||||
|
eeprom_write(0x0, ((unsigned char *)buffer), sizeof(buffer));
|
||||||
|
|
||||||
|
printf("Write data buffer %d at address 0x40\n", sizeof(buffer));
|
||||||
|
eeprom_write(0x40, ((unsigned char *)buffer), sizeof(buffer));
|
||||||
|
|
||||||
|
printf("Write data buffer %d at address 0x95\n", sizeof(buffer));
|
||||||
|
eeprom_write(0x95, ((unsigned char *)buffer), sizeof(buffer));
|
||||||
|
*/
|
||||||
|
print_content();
|
||||||
PROCESS_END();
|
PROCESS_END();
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
Loading…
Reference in a new issue