Skip to content

Commit

Permalink
arm-teensy3: add eeprom primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
quozl committed Dec 27, 2016
1 parent d16f411 commit e2b4266
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/app/arm-teensy3/app.fth
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ fl ../../lib/dl.fth
#7 ccall: get-usecs { -- n }
#8 ccall: delay { n -- }
#9 ccall: bye { -- }
#10 ccall: /eeprom { -- n }
#11 ccall: eeprom-base { -- n }
#12 ccall: eeprom-length { -- n }
#13 ccall: eeprom@ { i.adr -- i.val }
#14 ccall: eeprom! { i.val i.adr -- }

fl ../../platform/arm-teensy3/watchdog.fth
fl ../../platform/arm-teensy3/timer.fth
Expand Down
21 changes: 21 additions & 0 deletions src/platform/arm-teensy3/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "kinetis.h"
#include <stdint.h>
#include <string.h>
//#include "HardwareSerial.h"

// The EEPROM is really RAM with a hardware-based backup system to
Expand All @@ -42,6 +43,10 @@
//
#define EEPROM_SIZE 2048

uint32_t eeprom_size() {
return EEPROM_SIZE;
}

// Writing unaligned 16 or 32 bit data is handled automatically when
// this is defined, but at a cost of extra code size. Without this,
// any unaligned write will cause a hard fault exception! If you're
Expand Down Expand Up @@ -100,6 +105,22 @@ void eeprom_initialize(void)

#define FlexRAM ((uint8_t *)0x14000000)

uint32_t eeprom_base()
{
return 0x14000000;
}

uint32_t eeprom_length()
{
uint32_t offset;
if (!(FTFL_FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
if (FlexRAM[0] == 0xff) return 0; /* not initialised */
for(offset=0; offset<EEPROM_SIZE; offset++) {
if (FlexRAM[offset] == 0) break;
}
return offset;
}

uint8_t eeprom_read_byte(const uint8_t *addr)
{
uint32_t offset = (uint32_t)addr;
Expand Down
10 changes: 10 additions & 0 deletions src/platform/arm-teensy3/textend.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ cell pinMode();
cell micros();
cell delay();
cell _reboot_Teensyduino_();
cell eeprom_size();
cell eeprom_base();
cell eeprom_length();
cell eeprom_read_byte();
cell eeprom_write_byte();

cell ((* const ccalls[])()) = {
(cell (*)())spins, // Entry # 0
Expand All @@ -28,6 +33,11 @@ cell ((* const ccalls[])()) = {
(cell (*)())micros, // Entry # 7
(cell (*)())delay, // Entry # 8 // fixme: hangs
(cell (*)())_reboot_Teensyduino_, // Entry # 9
(cell (*)())eeprom_size,
(cell (*)())eeprom_base,
(cell (*)())eeprom_length,
(cell (*)())eeprom_read_byte,
(cell (*)())eeprom_write_byte,
};

// Forth words to call the above routines may be created by:
Expand Down

0 comments on commit e2b4266

Please sign in to comment.