eeprom:[#22] fix lib to be compatible for 11u6x
This commit is contained in:
parent
b7980537dc
commit
1b6cbdb725
@ -1,28 +1,11 @@
|
||||
/*
|
||||
* EEPROMWrapper.cpp
|
||||
* EEPROMio.cpp
|
||||
*
|
||||
* Created on: Dec 4, 2022
|
||||
* Author: tylen
|
||||
*/
|
||||
|
||||
#include <EEPROMWrapper.h>
|
||||
|
||||
// Remove this when code will be reworked.
|
||||
#ifndef EEPROMWRAPPER_NOT_FIXED
|
||||
// Remove this when code will be reworked.
|
||||
|
||||
EEPROM_Wrapper::EEPROM_Wrapper ()
|
||||
{
|
||||
/* Enable EEPROM clock and reset EEPROM controller */
|
||||
Chip_Clock_EnablePeriphClock (SYSCTL_CLOCK_EEPROM);
|
||||
Chip_SYSCTL_PeriphReset (RESET_EEPROM);
|
||||
iap_exec = reinterpret_cast<IAP_call> (IAP_ENTRY_LOCATION);
|
||||
}
|
||||
|
||||
EEPROM_Wrapper::~EEPROM_Wrapper ()
|
||||
{
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
#include <EEPROMio.h>
|
||||
|
||||
static void
|
||||
e_memcpy (void *from, void *to, unsigned int n)
|
||||
@ -39,24 +22,25 @@ e_memcpy (void *from, void *to, unsigned int n)
|
||||
}
|
||||
|
||||
void
|
||||
EEPROM_Wrapper::eeprom_execute (EEPROM *rom)
|
||||
EEPROMio::eeprom_execute (EEPROM *rom)
|
||||
{
|
||||
command[0] = rom->mode;
|
||||
command[1] = rom->addr;
|
||||
command[2] = rom->data;
|
||||
command[3] = rom->size;
|
||||
command[4] = rom->clock;
|
||||
this->iap_exec (command, result);
|
||||
iap_entry(command, result);
|
||||
}
|
||||
|
||||
void
|
||||
EEPROM_Wrapper::eeprom_use (uint8_t *data, uint32_t addr, uint32_t size,
|
||||
EEPROMio::eeprom_use (uint8_t *data, uint32_t addr, uint32_t size,
|
||||
bool mode)
|
||||
{
|
||||
rom.addr = addr;
|
||||
rom.data = (uint32_t)data;
|
||||
rom.mode = (mode) ? IAP_EEPROM_READ : IAP_EEPROM_WRITE;
|
||||
rom.size = size;
|
||||
rom.clock = SystemCoreClock / 1000;
|
||||
#if INCLUDE_vTaskSuspend
|
||||
vTaskSuspendAll ();
|
||||
#endif
|
||||
@ -68,36 +52,25 @@ EEPROM_Wrapper::eeprom_use (uint8_t *data, uint32_t addr, uint32_t size,
|
||||
assert (result[0] == IAP_CMD_SUCCESS);
|
||||
}
|
||||
|
||||
std::string
|
||||
EEPROM_Wrapper::str_read_from (uint32_t addr, uint32_t amount)
|
||||
{
|
||||
eeprom_use (buffer, addr, amount, READ);
|
||||
std::string str = (char *)buffer;
|
||||
return str;
|
||||
}
|
||||
|
||||
void
|
||||
EEPROM_Wrapper::write_to (uint32_t addr, std::string str)
|
||||
EEPROMio::write_to (uint32_t addr, std::string str)
|
||||
{
|
||||
std::copy (str.begin (), str.end (), std::begin (buffer));
|
||||
eeprom_use (buffer, addr, str.length (), WRITE);
|
||||
}
|
||||
|
||||
void *
|
||||
EEPROM_Wrapper::read_from (uint32_t addr, uint32_t amount)
|
||||
EEPROMio::read_from (uint32_t addr, uint32_t amount)
|
||||
{
|
||||
eeprom_use (buffer, addr, amount, READ);
|
||||
void *data = (void *)buffer;
|
||||
return data;
|
||||
}
|
||||
void
|
||||
EEPROM_Wrapper::write_to (uint32_t addr, void *data, uint32_t size_of_data)
|
||||
EEPROMio::write_to (uint32_t addr, void *data, uint32_t size_of_data)
|
||||
{
|
||||
assert (size_of_data < EEPROM_MAX_BUFER_SIZE);
|
||||
e_memcpy (data, buffer, size_of_data);
|
||||
eeprom_use (buffer, addr, size_of_data, WRITE);
|
||||
}
|
||||
|
||||
// Remove this when code will be reworked.
|
||||
#endif /* EEPROMWRAPPER_NOT_FIXED */
|
||||
// Remove this when code will be reworked.
|
||||
@ -1,58 +1,39 @@
|
||||
/*
|
||||
* EEPROMWrapper.h
|
||||
* EEPROMio.h
|
||||
*
|
||||
* Created on: Dec 4, 2022
|
||||
* Author: tylen
|
||||
*/
|
||||
|
||||
#ifndef EEPROMWRAPPER_H_
|
||||
#define EEPROMWRAPPER_H_
|
||||
|
||||
// Remove this when code will be reworked.
|
||||
#define EEPROMWRAPPER_NOT_FIXED
|
||||
#ifndef EEPROMWRAPPER_NOT_FIXED
|
||||
// Remove this when code will be reworked.
|
||||
|
||||
#ifndef EEPROMIO_H_
|
||||
#define EEPROMIO_H_
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "chip.h"
|
||||
#include "board.h"
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
typedef void (*IAP_call) (uint32_t[], uint32_t[]);
|
||||
|
||||
typedef struct _eeprom
|
||||
{
|
||||
uint32_t data;
|
||||
uint32_t addr;
|
||||
uint32_t size;
|
||||
uint32_t mode;
|
||||
uint32_t clock;
|
||||
} EEPROM;
|
||||
#include <map>
|
||||
|
||||
#define READ true
|
||||
#define WRITE false
|
||||
#define EEPROM_MAX_BUFER_SIZE 1000
|
||||
#define EEPROM_START_ADDR 0x00000100
|
||||
|
||||
class EEPROM_Wrapper
|
||||
class EEPROMio
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new eeprom wrapper object
|
||||
*
|
||||
*/
|
||||
EEPROM_Wrapper ();
|
||||
virtual ~EEPROM_Wrapper ();
|
||||
/**
|
||||
* @brief Read a string from EEPROM
|
||||
*
|
||||
* @param addr - address to read from
|
||||
* @param amount - amount of bytes to read
|
||||
* @return std::string - that was read
|
||||
*/
|
||||
std::string str_read_from (uint32_t addr, uint32_t amount);
|
||||
EEPROMio ()
|
||||
{
|
||||
SystemCoreClockUpdate();
|
||||
SysTick_Config(SystemCoreClock / 10);
|
||||
}
|
||||
virtual ~EEPROMio () = default;
|
||||
/**
|
||||
* @brief Write a string to EEPROM
|
||||
*
|
||||
@ -78,16 +59,20 @@ public:
|
||||
void write_to (uint32_t addr, void *data, uint32_t size_of_data);
|
||||
|
||||
private:
|
||||
IAP_call iap_exec;
|
||||
uint32_t command[5], result[5];
|
||||
typedef struct _eeprom
|
||||
{
|
||||
uint32_t data;
|
||||
uint32_t addr;
|
||||
uint32_t size;
|
||||
uint32_t mode;
|
||||
uint32_t clock;
|
||||
} EEPROM;
|
||||
|
||||
unsigned int command[5], result[4];
|
||||
EEPROM rom = { 0, 0, 0, 0, 72000 };
|
||||
void eeprom_execute (EEPROM *rom);
|
||||
void eeprom_use (uint8_t *data, uint32_t addr, uint32_t size, bool mode);
|
||||
uint8_t buffer[EEPROM_MAX_BUFER_SIZE] = { 0 };
|
||||
};
|
||||
|
||||
// Remove this when code will be reworked.
|
||||
#endif /* EEPROMWRAPPER_NOT_FIXED */
|
||||
// Remove this when code will be reworked.
|
||||
|
||||
#endif /* EEPROMWRAPPER_H_ */
|
||||
#endif /* EEPROMIO_H_ */
|
||||
Loading…
x
Reference in New Issue
Block a user