Make EEPROM transfers receive an operation and a buffer id parameter. This allows reading and writing both staging and validated user configurations which will aid future debugging. This API is also cleaner.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#include "config_globals.h"
|
#include "config_globals.h"
|
||||||
#include "attributes.h"
|
#include "attributes.h"
|
||||||
|
#include "eeprom.h"
|
||||||
|
|
||||||
static uint8_t hardwareConfig[HARDWARE_CONFIG_SIZE];
|
static uint8_t hardwareConfig[HARDWARE_CONFIG_SIZE];
|
||||||
static uint8_t ATTR_DATA2 stagingUserConfig[USER_CONFIG_SIZE];
|
static uint8_t ATTR_DATA2 stagingUserConfig[USER_CONFIG_SIZE];
|
||||||
@@ -10,3 +11,17 @@ config_buffer_t StagingUserConfigBuffer = { stagingUserConfig };
|
|||||||
config_buffer_t ValidatedUserConfigBuffer = { validatedUserConfig };
|
config_buffer_t ValidatedUserConfigBuffer = { validatedUserConfig };
|
||||||
|
|
||||||
bool ParserRunDry;
|
bool ParserRunDry;
|
||||||
|
|
||||||
|
config_buffer_t* ConfigBufferIdToConfigBuffer(config_buffer_id_t configBufferId)
|
||||||
|
{
|
||||||
|
switch (configBufferId) {
|
||||||
|
case ConfigBufferId_HardwareConfig:
|
||||||
|
return &HardwareConfigBuffer;
|
||||||
|
case ConfigBufferId_StagingUserConfig:
|
||||||
|
return &StagingUserConfigBuffer;
|
||||||
|
case ConfigBufferId_ValidatedUserConfig:
|
||||||
|
return &ValidatedUserConfigBuffer;
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,14 +4,8 @@
|
|||||||
// Includes:
|
// Includes:
|
||||||
|
|
||||||
#include "fsl_common.h"
|
#include "fsl_common.h"
|
||||||
#include "eeprom.h"
|
|
||||||
#include "basic_types.h"
|
#include "basic_types.h"
|
||||||
|
|
||||||
// Macros:
|
|
||||||
|
|
||||||
#define HARDWARE_CONFIG_SIZE 64
|
|
||||||
#define USER_CONFIG_SIZE (EEPROM_SIZE - HARDWARE_CONFIG_SIZE)
|
|
||||||
|
|
||||||
// Typedefs:
|
// Typedefs:
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -27,4 +21,8 @@
|
|||||||
extern config_buffer_t StagingUserConfigBuffer;
|
extern config_buffer_t StagingUserConfigBuffer;
|
||||||
extern config_buffer_t ValidatedUserConfigBuffer;
|
extern config_buffer_t ValidatedUserConfigBuffer;
|
||||||
|
|
||||||
|
// Functions:
|
||||||
|
|
||||||
|
config_buffer_t* ConfigBufferIdToConfigBuffer(config_buffer_id_t configBufferId);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,9 +3,11 @@
|
|||||||
#include "i2c_addresses.h"
|
#include "i2c_addresses.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "eeprom.h"
|
#include "eeprom.h"
|
||||||
|
#include "config_parser/config_globals.h"
|
||||||
|
|
||||||
bool IsEepromBusy;
|
bool IsEepromBusy;
|
||||||
eeprom_transfer_t CurrentEepromTransfer;
|
static eeprom_operation_t CurrentEepromOperation;
|
||||||
|
static config_buffer_id_t CurrentConfigBufferId;
|
||||||
status_t LastEepromTransferStatus;
|
status_t LastEepromTransferStatus;
|
||||||
void (*SuccessCallback)();
|
void (*SuccessCallback)();
|
||||||
|
|
||||||
@@ -54,10 +56,8 @@ static void i2cCallback(I2C_Type *base, i2c_master_handle_t *handle, status_t st
|
|||||||
{
|
{
|
||||||
LastEepromTransferStatus = status;
|
LastEepromTransferStatus = status;
|
||||||
|
|
||||||
bool isHardwareConfig = CurrentEepromTransfer == EepromTransfer_ReadHardwareConfiguration;
|
switch (CurrentEepromOperation) {
|
||||||
switch (CurrentEepromTransfer) {
|
case EepromOperation_Read:
|
||||||
case EepromTransfer_ReadHardwareConfiguration:
|
|
||||||
case EepromTransfer_ReadUserConfiguration:
|
|
||||||
if (isReadSent) {
|
if (isReadSent) {
|
||||||
IsEepromBusy = false;
|
IsEepromBusy = false;
|
||||||
if (SuccessCallback) {
|
if (SuccessCallback) {
|
||||||
@@ -66,14 +66,13 @@ static void i2cCallback(I2C_Type *base, i2c_master_handle_t *handle, status_t st
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LastEepromTransferStatus = i2cAsyncRead(
|
LastEepromTransferStatus = i2cAsyncRead(
|
||||||
isHardwareConfig ? HardwareConfigBuffer.buffer : ValidatedUserConfigBuffer.buffer,
|
ConfigBufferIdToConfigBuffer(CurrentConfigBufferId)->buffer,
|
||||||
isHardwareConfig ? HARDWARE_CONFIG_SIZE : USER_CONFIG_SIZE
|
CurrentConfigBufferId == ConfigBufferId_HardwareConfig ? HARDWARE_CONFIG_SIZE : USER_CONFIG_SIZE
|
||||||
);
|
);
|
||||||
IsEepromBusy = true;
|
IsEepromBusy = true;
|
||||||
isReadSent = true;
|
isReadSent = true;
|
||||||
break;
|
break;
|
||||||
case EepromTransfer_WriteHardwareConfiguration:
|
case EepromOperation_Write:
|
||||||
case EepromTransfer_WriteUserConfiguration:
|
|
||||||
if (status == kStatus_Success) {
|
if (status == kStatus_Success) {
|
||||||
sourceOffset += writeLength;
|
sourceOffset += writeLength;
|
||||||
}
|
}
|
||||||
@@ -97,29 +96,28 @@ void EEPROM_Init(void)
|
|||||||
I2C_MasterTransferCreateHandle(I2C_EEPROM_BUS_BASEADDR, &i2cHandle, i2cCallback, NULL);
|
I2C_MasterTransferCreateHandle(I2C_EEPROM_BUS_BASEADDR, &i2cHandle, i2cCallback, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t EEPROM_LaunchTransfer(eeprom_transfer_t transferType, void (*successCallback))
|
status_t EEPROM_LaunchTransfer(eeprom_operation_t operation, config_buffer_id_t config_buffer_id, void (*successCallback))
|
||||||
{
|
{
|
||||||
if (IsEepromBusy) {
|
if (IsEepromBusy) {
|
||||||
return kStatus_I2C_Busy;
|
return kStatus_I2C_Busy;
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentEepromTransfer = transferType;
|
CurrentEepromOperation = operation;
|
||||||
|
CurrentConfigBufferId = config_buffer_id;
|
||||||
|
|
||||||
SuccessCallback = successCallback;
|
SuccessCallback = successCallback;
|
||||||
bool isHardwareConfig = CurrentEepromTransfer == EepromTransfer_ReadHardwareConfiguration ||
|
bool isHardwareConfig = CurrentConfigBufferId == ConfigBufferId_HardwareConfig;
|
||||||
CurrentEepromTransfer == EepromTransfer_WriteHardwareConfiguration;
|
|
||||||
eepromStartAddress = isHardwareConfig ? 0 : HARDWARE_CONFIG_SIZE;
|
eepromStartAddress = isHardwareConfig ? 0 : HARDWARE_CONFIG_SIZE;
|
||||||
addressBuffer[0] = eepromStartAddress >> 8;
|
addressBuffer[0] = eepromStartAddress >> 8;
|
||||||
addressBuffer[1] = eepromStartAddress & 0xff;
|
addressBuffer[1] = eepromStartAddress & 0xff;
|
||||||
|
|
||||||
switch (transferType) {
|
switch (CurrentEepromOperation) {
|
||||||
case EepromTransfer_ReadHardwareConfiguration:
|
case EepromOperation_Read:
|
||||||
case EepromTransfer_ReadUserConfiguration:
|
|
||||||
isReadSent = false;
|
isReadSent = false;
|
||||||
LastEepromTransferStatus = i2cAsyncWrite(addressBuffer, EEPROM_ADDRESS_LENGTH);
|
LastEepromTransferStatus = i2cAsyncWrite(addressBuffer, EEPROM_ADDRESS_LENGTH);
|
||||||
break;
|
break;
|
||||||
case EepromTransfer_WriteHardwareConfiguration:
|
case EepromOperation_Write:
|
||||||
case EepromTransfer_WriteUserConfiguration:
|
sourceBuffer = ConfigBufferIdToConfigBuffer(CurrentConfigBufferId)->buffer;
|
||||||
sourceBuffer = isHardwareConfig ? HardwareConfigBuffer.buffer : ValidatedUserConfigBuffer.buffer;
|
|
||||||
sourceOffset = 0;
|
sourceOffset = 0;
|
||||||
sourceLength = isHardwareConfig ? HARDWARE_CONFIG_SIZE : USER_CONFIG_SIZE;
|
sourceLength = isHardwareConfig ? HARDWARE_CONFIG_SIZE : USER_CONFIG_SIZE;
|
||||||
LastEepromTransferStatus = writePage();
|
LastEepromTransferStatus = writePage();
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
#ifndef __EEPROM_H__
|
#ifndef __EEPROM_H__
|
||||||
#define __EEPROM_H__
|
#define __EEPROM_H__
|
||||||
|
|
||||||
|
// Includes:
|
||||||
|
|
||||||
|
#include "config_parser/config_globals.h"
|
||||||
|
|
||||||
// Macros:
|
// Macros:
|
||||||
|
|
||||||
#define EEPROM_SIZE (32*1024)
|
#define EEPROM_SIZE (32*1024)
|
||||||
|
#define HARDWARE_CONFIG_SIZE 64
|
||||||
|
#define USER_CONFIG_SIZE (EEPROM_SIZE - HARDWARE_CONFIG_SIZE)
|
||||||
|
|
||||||
#define EEPROM_ADDRESS_LENGTH 2
|
#define EEPROM_ADDRESS_LENGTH 2
|
||||||
#define EEPROM_PAGE_SIZE 64
|
#define EEPROM_PAGE_SIZE 64
|
||||||
#define EEPROM_BUFFER_SIZE (EEPROM_ADDRESS_LENGTH + EEPROM_PAGE_SIZE)
|
#define EEPROM_BUFFER_SIZE (EEPROM_ADDRESS_LENGTH + EEPROM_PAGE_SIZE)
|
||||||
@@ -11,21 +18,18 @@
|
|||||||
// Typedefs:
|
// Typedefs:
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
EepromTransfer_ReadHardwareConfiguration,
|
EepromOperation_Read,
|
||||||
EepromTransfer_WriteHardwareConfiguration,
|
EepromOperation_Write,
|
||||||
EepromTransfer_ReadUserConfiguration,
|
} eeprom_operation_t;
|
||||||
EepromTransfer_WriteUserConfiguration,
|
|
||||||
} eeprom_transfer_t;
|
|
||||||
|
|
||||||
// Variables:
|
// Variables:
|
||||||
|
|
||||||
extern bool IsEepromBusy;
|
extern bool IsEepromBusy;
|
||||||
extern eeprom_transfer_t CurrentEepromTransfer;
|
|
||||||
extern status_t EepromTransferStatus;
|
extern status_t EepromTransferStatus;
|
||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
void EEPROM_Init(void);
|
void EEPROM_Init(void);
|
||||||
status_t EEPROM_LaunchTransfer(eeprom_transfer_t transferType, void (*successCallback));
|
status_t EEPROM_LaunchTransfer(eeprom_operation_t operation, config_buffer_id_t config_buffer_id, void (*successCallback));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -70,14 +70,14 @@ void userConfigurationReadFinished(void)
|
|||||||
|
|
||||||
void hardwareConfigurationReadFinished(void)
|
void hardwareConfigurationReadFinished(void)
|
||||||
{
|
{
|
||||||
EEPROM_LaunchTransfer(EepromTransfer_ReadUserConfiguration, userConfigurationReadFinished);
|
EEPROM_LaunchTransfer(EepromOperation_Read, ConfigBufferId_StagingUserConfig, userConfigurationReadFinished);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
InitClock();
|
InitClock();
|
||||||
InitPeripherals();
|
InitPeripherals();
|
||||||
EEPROM_LaunchTransfer(EepromTransfer_ReadHardwareConfiguration, hardwareConfigurationReadFinished);
|
EEPROM_LaunchTransfer(EepromOperation_Read, ConfigBufferId_HardwareConfig, hardwareConfigurationReadFinished);
|
||||||
|
|
||||||
#ifdef FORCE_BUSPAL
|
#ifdef FORCE_BUSPAL
|
||||||
Wormhole.magicNumber = WORMHOLE_MAGIC_NUMBER;
|
Wormhole.magicNumber = WORMHOLE_MAGIC_NUMBER;
|
||||||
|
|||||||
@@ -158,10 +158,23 @@ void getAdcValue(void)
|
|||||||
GenericHidOutBuffer[3] = adcValue >> 24;
|
GenericHidOutBuffer[3] = adcValue >> 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
void launchEepromTransfer(void)
|
void legacyLaunchEepromTransfer(void)
|
||||||
{
|
{
|
||||||
eeprom_transfer_t transferType = GenericHidInBuffer[1];
|
uint8_t legacyEepromTransferId = GenericHidInBuffer[1];
|
||||||
EEPROM_LaunchTransfer(transferType, NULL);
|
switch (legacyEepromTransferId) {
|
||||||
|
case 0:
|
||||||
|
EEPROM_LaunchTransfer(EepromOperation_Read, ConfigBufferId_HardwareConfig, NULL);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
EEPROM_LaunchTransfer(EepromOperation_Write, ConfigBufferId_HardwareConfig, NULL);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
EEPROM_LaunchTransfer(EepromOperation_Read, ConfigBufferId_ValidatedUserConfig, NULL);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
EEPROM_LaunchTransfer(EepromOperation_Write, ConfigBufferId_StagingUserConfig, NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void readConfiguration(bool isHardware)
|
void readConfiguration(bool isHardware)
|
||||||
@@ -174,7 +187,7 @@ void readConfiguration(bool isHardware)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *buffer = isHardware ? HardwareConfigBuffer.buffer : StagingUserConfigBuffer.buffer;
|
uint8_t *buffer = isHardware ? HardwareConfigBuffer.buffer : ValidatedUserConfigBuffer.buffer;
|
||||||
uint16_t bufferLength = isHardware ? HARDWARE_CONFIG_SIZE : USER_CONFIG_SIZE;
|
uint16_t bufferLength = isHardware ? HARDWARE_CONFIG_SIZE : USER_CONFIG_SIZE;
|
||||||
|
|
||||||
if (offset + length > bufferLength) {
|
if (offset + length > bufferLength) {
|
||||||
@@ -281,7 +294,7 @@ void UsbProtocolHandler(void)
|
|||||||
getAdcValue();
|
getAdcValue();
|
||||||
break;
|
break;
|
||||||
case UsbCommand_LaunchEepromTransfer:
|
case UsbCommand_LaunchEepromTransfer:
|
||||||
launchEepromTransfer();
|
legacyLaunchEepromTransfer();
|
||||||
break;
|
break;
|
||||||
case UsbCommand_ReadHardwareConfiguration:
|
case UsbCommand_ReadHardwareConfiguration:
|
||||||
readConfiguration(true);
|
readConfiguration(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user