Skip to content

Commit

Permalink
support saving into SmartEEPROM
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre d Alton <alex@alexdalton.org>
  • Loading branch information
daltona committed Jun 7, 2019
1 parent 44f4338 commit ca9816a
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions tmk_core/common/arm_atsam/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,41 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "samd51j18a.h"
#include "eeprom.h"
#include "core_cm4.h"
#include "component/nvmctrl.h"

#define EEPROM_SIZE 32

static uint8_t buffer[EEPROM_SIZE];
volatile uint8_t *SmartEEPROM8 = (uint8_t *) 0x44000000;
uint8_t buffer[EEPROM_SIZE];

uint8_t eeprom_read_byte(const uint8_t *addr) {
uintptr_t offset = (uintptr_t)addr;
return buffer[offset];

if (NVMCTRL->SEESTAT.bit.PSZ == 0 || NVMCTRL->SEESTAT.bit.SBLK == 0)
return buffer[offset];

int timeout = 10000;
while (NVMCTRL->SEESTAT.bit.BUSY && timeout-- > 0)
;
return SmartEEPROM8[offset];
}

void eeprom_write_byte(uint8_t *addr, uint8_t value) {
uintptr_t offset = (uintptr_t)addr;
buffer[offset] = value;

if (NVMCTRL->SEESTAT.bit.PSZ == 0 || NVMCTRL->SEESTAT.bit.SBLK == 0) {
buffer[offset] = value;
return;
}

int timeout = 10000;
while (NVMCTRL->SEESTAT.bit.BUSY && timeout-- > 0)
;

SmartEEPROM8[offset] = value;
}

uint16_t eeprom_read_word(const uint16_t *addr) {
Expand Down

0 comments on commit ca9816a

Please sign in to comment.