ParaLib 2.0.15-master SHA: 2e03d68caa
PARA_Flash_ATSAM.c File Reference

Flash parameter storage for Microchip / Atmel ATSAM70E Series. More...

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "flash_efc.h"
#include "project_config.h"
#include "lib/Para/PARA_Lib.h"
#include "lib/Para/PARA_ID_System.h"
#include "lib/Error/LogMessage.h"
#include "lib/Error/Error_ID_System.h"
#include "lib/Error/Error.h"

Data Structures

struct  t_ParaFlashDataset
 Datastructure of one flash block. More...
 
struct  tFlashInformation
 Information stored in flash about the contents of the flash page. More...
 

Macros

#define NV_CMD_Successful   0
 
#define NV_CMD_SaveNV   1
 
#define NV_CMD_Bussy   2
 
#define NV_CMD_Failed   3
 
#define NV_CMD_ResetToDefault1   0x55AA
 
#define NV_CMD_ResetToDefault2   0xAA55
 
#define NV_CMD_SaveFactoryNV   12345
 
#define NV_CMD_SaveUserregister   7319
 
#define PARAMETER_FLASH_MAX_SIZE   ( 0x20000 )
 
#define PARA_FLASH_SIZE_DATA   ( 24 )
 
#define PARA_FLASH_SIZE_BLOCK   ( 32 )
 
#define PARAMETER_FLASH_VERSION   ( 1 )
 
#define MAXIMUM_PARAMETER_DATAPOINTER   ((PARAMETER_FLASH_MAX_SIZE - PARA_FLASH_SIZE_BLOCK) /PARA_FLASH_SIZE_BLOCK)
 

Functions

bool RestoreParameterDefaults (uint16_t location, ParameterAccessSource Access, uint8_t AccessLevel)
 Restores all Parameters with the given storage location to their default value. More...
 
bool IsInSaveState (void)
 If save to flash is allowed return true. More...
 
static bool VerifyBackupArea (void *FlashData, tFlashInformation *FlashDataLocation)
 The Backup-Area in flash is verified. More...
 
void PARA_FlashReadFromBackup (uint16_t location, ParameterAccessSource Access, uint8_t AccessLevel)
 Reads backup-values from flash and stores them into parameter values. More...
 
bool PARA_FlashWriteToBackup (uint16_t location)
 Writes backup-values into flash All parameters with storage-location selected in parameter location are processed, all others are ignored. More...
 
void PARA_FlashInit (void)
 Initialization of parameter flash interface needs to be called before: More...
 
static int32_t WriteFunction_PARA_FlashCmd (Parameter *this, uint16_t SubID, void *data, int32_t MaxCount, uint32_t offset, ParameterAccessSource Access, unsigned char AccessLevel)
 

Variables

uint32_t g_ui32NvCmd
 Actual running Non-Volatile Memory command. More...
 
static bool g_bFlashParasetValid
 Flag if the parameterset is read succerssful out of Flash. More...
 
tFlashInformation FlashData1
 Information about actual used Flash page. More...
 

Detailed Description

Flash parameter storage for Microchip / Atmel ATSAM70E Series.


© Copyright 2017-2022 Copyright: Retostronik GmbH Stütingstraße 30 58285 Gevelsberg

Macro Definition Documentation

◆ MAXIMUM_PARAMETER_DATAPOINTER

#define MAXIMUM_PARAMETER_DATAPOINTER   ((PARAMETER_FLASH_MAX_SIZE - PARA_FLASH_SIZE_BLOCK) /PARA_FLASH_SIZE_BLOCK)

◆ NV_CMD_Bussy

#define NV_CMD_Bussy   2

◆ NV_CMD_Failed

#define NV_CMD_Failed   3

◆ NV_CMD_ResetToDefault1

#define NV_CMD_ResetToDefault1   0x55AA

◆ NV_CMD_ResetToDefault2

#define NV_CMD_ResetToDefault2   0xAA55

◆ NV_CMD_SaveFactoryNV

#define NV_CMD_SaveFactoryNV   12345

◆ NV_CMD_SaveNV

#define NV_CMD_SaveNV   1

◆ NV_CMD_SaveUserregister

#define NV_CMD_SaveUserregister   7319

◆ NV_CMD_Successful

#define NV_CMD_Successful   0

◆ PARA_FLASH_SIZE_BLOCK

#define PARA_FLASH_SIZE_BLOCK   ( 32 )

◆ PARA_FLASH_SIZE_DATA

#define PARA_FLASH_SIZE_DATA   ( 24 )

◆ PARAMETER_FLASH_MAX_SIZE

#define PARAMETER_FLASH_MAX_SIZE   ( 0x20000 )

◆ PARAMETER_FLASH_VERSION

#define PARAMETER_FLASH_VERSION   ( 1 )

Function Documentation

◆ IsInSaveState()

bool IsInSaveState ( void  )

If save to flash is allowed return true.

Function must be defined in main project. Flash storage takes a long time, while no other function is allowed to call. Diue to this, the device must not run any time critical function.

◆ PARA_FlashInit()

void PARA_FlashInit ( void  )

Initialization of parameter flash interface needs to be called before:

  • HAL Init
  • PARA_Init
  • Error_Init
  • SystemMessage_Init
  • PARA_Backup_Init

◆ PARA_FlashReadFromBackup()

void PARA_FlashReadFromBackup ( uint16_t  location,
ParameterAccessSource  Access,
uint8_t  AccessLevel 
)

Reads backup-values from flash and stores them into parameter values.

All parameters with storage-location selected in parameter location are processed, all others are ignored. The parameter values are written with the OnWrite-function defined in the parameter itself. In case of an error, the default value is set.

Parameters
locationselects the storage location
AccessSource of access (see Access restrictions).
AccessLevelActual AccessLevel (see Access restrictions).

◆ PARA_FlashWriteToBackup()

bool PARA_FlashWriteToBackup ( uint16_t  location)

Writes backup-values into flash All parameters with storage-location selected in parameter location are processed, all others are ignored.

Parameters
locationselects the storage location
Return values
Trueif successfull.

◆ RestoreParameterDefaults()

bool RestoreParameterDefaults ( uint16_t  location,
ParameterAccessSource  Access,
uint8_t  AccessLevel 
)

Restores all Parameters with the given storage location to their default value.

All parameters with storage-location selected in parameter location are processed, all others are ignored. The parameter values are written with the OnWrite-function defined in the parameter itself. In case of an error, the default value is set.

Parameters
locationselects the storage location
AccessSource of access (see Access restrictions).
AccessLevelActual AccessLevel (see Access restrictions).

◆ VerifyBackupArea()

static bool VerifyBackupArea ( void *  FlashData,
tFlashInformation FlashDataLocation 
)
static

The Backup-Area in flash is verified.

A 32-Bit CRC is calculated and compared to the stored value in zhe stored flashInformation. If CRC is matching, true is returned.

Parameters
FlashDataActual Address of Flash
FlashDataLocationPointer to the flash-information stored in flash.
Return values
Trueif successfull.

◆ WriteFunction_PARA_FlashCmd()

static int32_t WriteFunction_PARA_FlashCmd ( Parameter this,
uint16_t  SubID,
void *  data,
int32_t  MaxCount,
uint32_t  offset,
ParameterAccessSource  Access,
unsigned char  AccessLevel 
)
static

Variable Documentation

◆ FlashData1

tFlashInformation FlashData1

Information about actual used Flash page.

◆ g_bFlashParasetValid

bool g_bFlashParasetValid
static

Flag if the parameterset is read succerssful out of Flash.

◆ g_ui32NvCmd

uint32_t g_ui32NvCmd

Actual running Non-Volatile Memory command.

The command is set by parameterinterface to trigger storage to NVRam. The store-procedure sets the result.