Files
AUTOM/workspace/AUTOM10/Core/Src/eeprom.h
andrea 687c222259 wip
2026-06-16 01:12:52 +02:00

185 lines
4.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* eeprom.h
*
* Created on: Dec 7, 2025
* Author: user
*/
#ifndef __EEPROM_H
#define __EEPROM_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f1xx_hal.h"
/*
* Simple EEPROM emulation for STM32F103C8T6 (medium density).
* - Uses 2 Flash pages (1 kB each) at the end of Flash.
* - Stores variables as 16-bit values identified by 16-bit "virtual addresses".
*
* You must define the list of virtual addresses in eeprom.c: EE_VirtAddrs[].
*/
typedef enum
{
EE_STATUS_OK = 0,
EE_STATUS_ERROR,
EE_STATUS_NOT_FOUND,
EE_STATUS_NO_SPACE
} EE_Status;
#ifdef TH250
#ifdef T1S
#define VERSIONE 0x01 //versione software
#endif
#ifdef T2S
#define VERSIONE 0x02 //versione software
#endif
#ifdef T4S
#define VERSIONE 0x03 //versione software
#endif
#endif
#ifdef TH500
#ifdef T1S
#define VERSIONE 0x04 //versione software
#endif
#ifdef T2S
#define VERSIONE 0x05 //versione software
#endif
#ifdef T4S
#define VERSIONE 0x06 //versione software
#endif
#endif
#ifdef TH1000
#ifdef T1S
#define VERSIONE 0x07 //versione software
#endif
#ifdef T2S
#define VERSIONE 0x08 //versione software
#endif
#ifdef T4S
#define VERSIONE 0x09 //versione software
#endif
#endif
#ifdef TH2000
#ifdef T1S
#define VERSIONE 0x0a //versione software
#endif
#ifdef T2S
#define VERSIONE 0x0b //versione software
#endif
#ifdef T4S
#define VERSIONE 0x0c //versione software
#endif
#endif
/* For compatibility with ST style uint16_t return codes */
#define EE_OK ((uint16_t)EE_STATUS_OK)
#define EE_ERROR ((uint16_t)EE_STATUS_ERROR)
#define EE_NOT_FOUND ((uint16_t)EE_STATUS_NOT_FOUND)
#define EE_NO_SPACE ((uint16_t)EE_STATUS_NO_SPACE)
/* Flash parameters for STM32F103C8T6 */
#define EE_FLASH_BASE_ADDR 0x08000000U
#define EE_PAGE_SIZE 0x400U /* 1 kB pages */
/*
* Here we assume a 64 kB Flash device (STM32F103C8T6):
* Flash range: 0x0800 0000 - 0x0800 FFFF
* Pages: 0..63 (64 pages)
* We use the last 2 pages for EEPROM:
* - Page 62: 0x0800 F800
* - Page 63: 0x0800 FC00
*/
#define EE_PAGE0_BASE (EE_FLASH_BASE_ADDR + (62U * EE_PAGE_SIZE))
#define EE_PAGE1_BASE (EE_FLASH_BASE_ADDR + (63U * EE_PAGE_SIZE))
/* Page status markers (stored in the first halfword of each page) */
#define EE_PAGE_STATUS_ERASED 0xFFFFU
#define EE_PAGE_STATUS_VALID 0xAAAAU
#define EE_PAGE_STATUS_RECEIVE 0x5555U
/*
* Configure how many virtual variables you have.
* Example: bytes, words, and array elements mapped to 16-bit variables.
* Set EE_NUM_VIRTUAL_ADDR and define EE_VirtAddrs[] in eeprom.c.
*/
/* 32 virtual variables, sequential addresses */
#define EE_NUM_VIRTUAL_ADDR 64U
#define EEW_ADDR(i) ((uint16_t)(0x0001U + (uint16_t)(i))) // i = 0..63
#define M1PWMAP 0 //m1pwmap
#define M1PWMCH 1 //m1pwmch
#define M2PWMAP 2 //m2pwmap
#define M2PWMCH 3 //m2pwmch
#define M3PWMAP 4 //m3pwmap
#define M3PWMCH 5 //m3pwmch
#define M4PWMAP 6 //m4pwmap
#define M4PWMCH 7 //m4pwmch
#define M1RAMPSTART 8 //m1rampstart
#define M2RAMPSTART 9 //m2rampstart
#define M3RAMPSTART 10 //m3rampstart
#define M4RAMPSTART 11 //m4rampstart
#define M1TIMEOUTMAN 12 //timeout M1 manuale
#define M2TIMEOUTMAN 13 //timeout M2 manuale
#define M3TIMEOUTMAN 14 //timeout M3 manuale
#define M4TIMEOUTMAN 15 //timeout M4 manuale
#define THANEM 24 //thanem
#define TANEM 25 //tanem
#define M1PWMMAN 26 //m1pwmMan
#define M2PWMMAN 27 //m2pwmMan
#define M3PWMMAN 28 //m3pwmMan
#define M4PWMMAN 29 //m4pwmMan
#define TRAMPMAN 30 //trampman
#define TRAMP 31 //tramp
#define APM1START 32 //apM1start;
#define APM1STOP 33 //apM1stop;
#define APM2START 34 //apM2start;
#define APM2STOP 35 //apM2stop;
#define APM3START 36 //apM3start;
#define APM3STOP 37 //apM3stop;
#define APM4START 38 //apM4start;
#define APM4STOP 39 //apM4stop;
#define CHM1START 40 //chM1start;
#define CHM1STOP 41 //chM1stop;
#define CHM2START 42 //chM2start;
#define CHM2STOP 43 //chM2stop;
#define CHM3START 44 //chM3start;
#define CHM3STOP 45 //chM3stop;
#define CHM4START 46 //chM4start;
#define CHM4STOP 47 //chM4stop;
#define FLAGPAR 63//flagpar
/* Virtual address table (defined in eeprom.c, can be customized) */
extern const uint16_t EE_VirtAddrs[EE_NUM_VIRTUAL_ADDR];
/* Public API now using uint16_t like ST examples */
uint16_t EE_Init(void);
uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t *Data);
uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);
void loadEE(void);
void loadDefault(void);
/* Pseudo-array accessor EEW[idx] */
static inline uint16_t EEW_Read(uint8_t idx, uint16_t *value)
{
return EE_ReadVariable(EEW_ADDR(idx), value);
}
static inline uint16_t EEW_Write(uint8_t idx, uint16_t value)
{
return EE_WriteVariable(EEW_ADDR(idx), value);
}
#ifdef __cplusplus
}
#endif
#endif /* __EEPROM_H */