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