Files
AUTOM/workspace/AUTOM10/Core/Src/eeprom.h

185 lines
4.7 KiB
C
Raw Normal View History

2025-12-07 21:39:26 +01:00
/*
* 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
{
2025-12-08 13:48:52 +01:00
EE_STATUS_OK = 0,
EE_STATUS_ERROR,
EE_STATUS_NOT_FOUND,
EE_STATUS_NO_SPACE
2025-12-07 21:39:26 +01:00
} EE_Status;
2026-06-16 01:12:52 +02:00
#ifdef TH250
#ifdef T1S
2026-06-04 18:30:48 +02:00
#define VERSIONE 0x01 //versione software
2026-06-16 01:12:52 +02:00
#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
2025-12-08 13:48:52 +01:00
/* 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)
2025-12-07 21:39:26 +01:00
/* 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 */
2026-04-29 23:10:16 +02:00
#define EE_NUM_VIRTUAL_ADDR 64U
#define EEW_ADDR(i) ((uint16_t)(0x0001U + (uint16_t)(i))) // i = 0..63
2025-12-07 21:39:26 +01:00
2026-04-15 23:12:13 +02:00
#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
2026-05-02 13:05:31 +02:00
#define M1TIMEOUTMAN 12 //timeout M1 manuale
#define M2TIMEOUTMAN 13 //timeout M2 manuale
#define M3TIMEOUTMAN 14 //timeout M3 manuale
#define M4TIMEOUTMAN 15 //timeout M4 manuale
2026-04-27 22:04:15 +02:00
2026-05-26 04:31:23 +02:00
#define THANEM 24 //thanem
#define TANEM 25 //tanem
2026-04-27 22:04:15 +02:00
#define M1PWMMAN 26 //m1pwmMan
#define M2PWMMAN 27 //m2pwmMan
#define M3PWMMAN 28 //m3pwmMan
#define M4PWMMAN 29 //m4pwmMan
#define TRAMPMAN 30 //trampman
2026-04-15 23:12:13 +02:00
#define TRAMP 31 //tramp
2026-05-02 13:05:31 +02:00
#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;
2026-05-26 04:31:23 +02:00
#define FLAGPAR 63//flagpar
2026-04-15 23:12:13 +02:00
2025-12-07 21:39:26 +01:00
/* Virtual address table (defined in eeprom.c, can be customized) */
extern const uint16_t EE_VirtAddrs[EE_NUM_VIRTUAL_ADDR];
2025-12-08 13:48:52 +01:00
/* 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);
2026-04-15 23:12:13 +02:00
void loadEE(void);
2026-05-26 04:31:23 +02:00
void loadDefault(void);
2025-12-08 13:48:52 +01:00
/* Pseudo-array accessor EEW[idx] */
static inline uint16_t EEW_Read(uint8_t idx, uint16_t *value)
2025-12-07 21:39:26 +01:00
{
return EE_ReadVariable(EEW_ADDR(idx), value);
}
2025-12-08 13:48:52 +01:00
static inline uint16_t EEW_Write(uint8_t idx, uint16_t value)
2025-12-07 21:39:26 +01:00
{
return EE_WriteVariable(EEW_ADDR(idx), value);
}
2025-12-08 13:48:52 +01:00
2025-12-07 21:39:26 +01:00
#ifdef __cplusplus
}
#endif
#endif /* __EEPROM_H */