45 lines
1.9 KiB
C
45 lines
1.9 KiB
C
/* Private PM35 FC03 EEPROM window; not standard Modbus register quantities.
|
|
* AT25256B keeps its existing 0x8000..0xBFFF / count 1..120 requests.
|
|
* M95M02 uses four 64-KiB windows: count bit15 marks the profile, bits9:8
|
|
* select bank 0..3, bits7:0 carry word count. Address 0x8000..0xFFFF is
|
|
* the word offset within a bank. Every request is self-contained; no global
|
|
* bank register can be changed by another client. Old firmware rejects the
|
|
* marked quantity. Neither profile silently reads the other memory type.
|
|
*/
|
|
#ifndef BALSAM167_EEPROM_BLOCK_H
|
|
#define BALSAM167_EEPROM_BLOCK_H
|
|
#include "balsam167_eeprom_layout.h"
|
|
#define BALSAM167_EEPROM_RTU_BASE 0x8000U
|
|
#define BALSAM167_EEPROM_BLOCK_WORDS 120U
|
|
#define BALSAM167_EEPROM_M95_MARKER 0x8000U
|
|
#define BALSAM167_EEPROM_WRITE_M95 0x44U
|
|
static unsigned long balsam167_eeprom_capacity(unsigned profile)
|
|
{
|
|
return profile == 0 ? 32768UL : (profile == 1 ? 262144UL : 0UL);
|
|
}
|
|
static unsigned long balsam167_eeprom_block_word(unsigned address, unsigned count)
|
|
{
|
|
return ((unsigned long)(count & 0x0300U) << 7) + (address - 0x8000U);
|
|
}
|
|
static unsigned balsam167_eeprom_block_valid_profile(unsigned fn, unsigned address,
|
|
unsigned count, unsigned profile)
|
|
{
|
|
unsigned n = count & 255U;
|
|
unsigned long word;
|
|
if (fn != 3 || address < 0x8000U || !n || n > 120U) return 0;
|
|
if (profile == 0) return count == n && address < 0xC000U && n <= 0xC000U-address;
|
|
if (profile != 1 || (count & 0xFC00U) != 0x8000U) return 0;
|
|
word = balsam167_eeprom_block_word(address, count);
|
|
return n <= 0x10000UL-address && word+n <= 131072UL;
|
|
}
|
|
static unsigned balsam167_eeprom_block_valid(unsigned fn, unsigned address, unsigned count)
|
|
{
|
|
#if EEPROM_M95M02
|
|
return balsam167_eeprom_block_valid_profile(fn, address, count, 1);
|
|
#else
|
|
return fn == 3 && address >= 0x8000U && address < 0xC000U &&
|
|
count && count <= 120U && count <= 0xC000U-address;
|
|
#endif
|
|
}
|
|
#endif
|