There is a pair of parentheses missing in the
MAX_SECTORS macro.
As it is, the
Code:
#define MAX_BLKS (MAX_SECTORS * (DATA_FLASH_SECTOR_SIZE / BLK_SIZE))
macro expands to
Code:
#define MAX_BLKS (((DATA_FLASH_END +1 - DATA_FLASH_START)/DATA_FLASH_SECTOR_SIZE) - NVRAM_SECTORS_RESERVE * (DATA_FLASH_SECTOR_SIZE / BLK_SIZE))
so only NVRAM_SECTORS_RESERVE gets multiplied and not the value of NVRAM_SECTORS_RESERVE.
In general in C all but the most simple macros should start with a opening paranthesis and close with a closing one. In addition for macros with arguments, the argument should be enclosed in parentheses too.
So MAX_SECTORS should be defined as:
Code:
#define MAX_SECTORS (((DATA_FLASH_END +1 - DATA_FLASH_START)/DATA_FLASH_SECTOR_SIZE) - NVRAM_SECTORS_RESERVE)
As additional tip, if anything looks wrong with macros, always check the preprocessor output.
Daniel