update headers

This commit is contained in:
2022-07-07 18:00:11 +02:00
parent 11e6c6a0fc
commit 8cced68543
23 changed files with 134 additions and 673 deletions

View File

@ -30,7 +30,6 @@
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "ADCD_AdcDriver.h"
// Drivers

View File

@ -28,11 +28,8 @@
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "ANPI_AnalogPortsIn.h"
//Application
#include "../Application/VARH_VariableHandler.h"

View File

@ -30,7 +30,6 @@
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "ANPO_AnalogPortsOut.h"
// Toolbox

View File

@ -30,7 +30,6 @@
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "CAND_CanDriver.h"
// Toolbox

View File

@ -7,7 +7,7 @@
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<EFBFBD> (noah.pique@psi.ch)
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
@ -34,7 +34,6 @@
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "DIPO_DigitalPorts.h"
//Application

View File

@ -30,7 +30,6 @@
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "ERRH_ErrorHandler.h"
// Toolbox

View File

@ -30,7 +30,6 @@
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "SPID_SpiDriver.h"
// Application

View File

@ -28,7 +28,6 @@
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "TEMP_Temperature.h"
// Application
@ -38,7 +37,7 @@
#include "../Toolbox/UTIL_Utility.h"
// Drivers
#include "ADCD_ADCDriver.h"
#include "ADCD_AdcDriver.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"

View File

@ -45,11 +45,10 @@
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "USFL_UserFlash.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
#include "../Application/VARH_VariableHandler.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
@ -64,9 +63,11 @@
#define USERFLASHSIZE (2000/4) // Bytes -> 64 Bits
#define USERFLASHPAGE (63)
#define STARTDEF 0xAA01F055
#define VARDEF 0xABCDEF
#define STARTDEF (((U64)0xAA01F055 << 32) + (VARDEF << 2))
#define VARDEF 0xABCDEF00
//=================================================================================================
// Section: MACROS
@ -100,7 +101,7 @@ FLASH_EraseInitTypeDef stEreaseInit = {
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
U32 u32VarPointer = 0;
//=================================================================================================
// Section: LOCAL CONSTANTS
@ -116,6 +117,8 @@ __attribute__((__section__(".user_data"))) const U64 UserFlash[USERFLASHSIZE];
BOOL vEreaseUserFlash( void );
U32 vFindNextFreePointer( void );
U32 u32FindLastPointer( void );
U8 u8ConvertWordsToDoubleWords( U8 u8Words );
//=================================================================================================
// Section: GLOBAL FUNCTIONS
@ -142,6 +145,14 @@ BOOL USFL_boInitializeModule( VOID )
return( boOK );
}
VARH_UVariable USFL_uGetVariable ( void ){
if( u32VarPointer == 0 ) u32VarPointer = u32FindLastPointer();
}
//=================================================================================================
@ -150,27 +161,27 @@ BOOL USFL_boInitializeModule( VOID )
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: vFindNextFreePointer
// Description: Ereases the User Flash Sector
// Function: u32FindNextFreePointer
// Description: Finds the next free sector in the flash for saving variables
// Parameters: None
// Returns: Boolean TRUE if successful
// Returns: U32 next free pointer
//-------------------------------------------------------------------------------------------------
U32 vFindNextFreePointer( void ){
U32 u32FindNextFreePointer( void ){
BOOL boFound = FALSE;
U32 u32Pointer = 1; // 0 is StartDef
U32 u32Pointer = u32VarPointer;
while(!boFound){
if( (UserFlash[u32Pointer] & 0xFFFFFF00) == VARDEF ){
if( ( ( UserFlash[u32Pointer] >> 8 ) & 0xFFFFFF ) == VARDEF ){
U8 u8Size = UserFlash[u32Pointer] & 0xFF;
if( u8Size == 0 ){
boFound = TRUE;
} else {
u32Pointer += u8Size + 1;
u32Pointer += u8ConvertWordsToDoubleWords(u8Size);
}
} else {
return 0;
u32Pointer += 1;
}
if( u32Pointer >= USERFLASHSIZE ){
@ -182,6 +193,58 @@ U32 vFindNextFreePointer( void ){
}
//-------------------------------------------------------------------------------------------------
// Function: u32FindLastPointer
// Description: Finds the next free sector in the flash for saving variables
// Parameters: None
// Returns: U32 next free pointer
//-------------------------------------------------------------------------------------------------
U32 u32FindLastPointer( void ){
BOOL boFound = FALSE;
U32 u32Pointer = 0;
U8 u8LastSize = 0;
while(!boFound){
if( ( UserFlash[u32Pointer] >> 40) == VARDEF ){
U8 u8Size = UserFlash[u32Pointer] & 0xFF;
if( u8Size == 0 ){
boFound = TRUE;
u32Pointer -= u8ConvertWordsToDoubleWords(u8LastSize);
} else {
u32Pointer += u8ConvertWordsToDoubleWords(u8Size);
u8LastSize = u8Size;
}
} else {
u32Pointer += 1;
}
if( u32Pointer >= USERFLASHSIZE ){
u32Pointer = 1;
break;
}
}
return u32Pointer;
}
//-------------------------------------------------------------------------------------------------
// Function: u8ConvertWordsToDoubleWords
// Description: Converts 32Bit Word size to 64 Bit Double Word size for saving Vars
// Parameters: U8 u8Words
// Returns: U8 Double Words
//-------------------------------------------------------------------------------------------------
U8 u8ConvertWordsToDoubleWords( U8 u8Words ) {
U8 u8DWords;
u8Words += 1; // + VARDEF
u8DWords = u8Words / 2;
u8DWords += u8Words % 2;
return u8DWords;
}
//-------------------------------------------------------------------------------------------------
// Function: vEreaseUserFlash
// Description: Ereases the User Flash Sector
@ -191,10 +254,19 @@ U32 vFindNextFreePointer( void ){
BOOL vEreaseUserFlash( void ){
uint32_t u32PageError = 0;
if( HAL_FLASHEx_Erase(&stEreaseInit, &u32PageError) != HAL_OK ){
BOOL boOK = TRUE;
HAL_FLASH_Unlock();
boOK &= HAL_FLASHEx_Erase(&stEreaseInit, &u32PageError) == HAL_OK ? TRUE : FALSE;
if( !boOK ){
return FALSE;
}
HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, (U32) &UserFlash[0], STARTDEF);
HAL_FLASH_Lock();
return TRUE;
}