/******************************************************************************

	Samples\OP7200\UserBlockInfor.c

   Z-World, 2002
	This sample program is for the OP7200 series controllers.
	
   This program will display the amount of userblock memory that is available
   for application code usage. For controllers that have the analog option
   installed, the program will display the amount of memory space reserved 
   for calibration data constants.  
 	     		
*********************************************************************************/
#class auto

void main(void)
{
	struct userBlockInfo ub;
	long totalblock_size;
	long userblock_size;
	long calib_size;
	long sysid_size;

	if (SysIDBlock.tableVersion >= 3) {
		GetUserBlockInfo(&ub);
		totalblock_size = ub.blockSize;
	}
	else {
		totalblock_size = 4096L*GetIDBlockSize();
	}
	sysid_size = sizeof(SysIDBlock);
#ifdef ANALOG
	calib_size = 0x400 - sysid_size;
	userblock_size = totalblock_size - 0x400;
#else
	calib_size = 0;
	userblock_size = totalblock_size - calib_size - sysid_size;
#endif
	
	printf("System ID block version: %d\n\n", SysIDBlock.tableVersion);

	if (SysIDBlock.tableVersion >= 3) {
		printf("Contains a mirrored user block, which ensures that there is always\n");
		printf("a correct version of the user block information written.\n\n");
	}
	else {
		printf("Does not contain a mirrored user block.  A power cycle while the\n");
		printf("user block is being written can leave the user block in an\n");
		printf("inconsistent state.\n\n");
	}
	printf("Total system ID + calibration constants + user block size: %ld\n\n",
	       totalblock_size);
	printf("User block size:            %5ld\n", userblock_size);
	printf("Calibration constants size: %5ld\n", calib_size);
	printf("System ID size:             %5ld\n\n", sysid_size);
	printf("UserBlock Address range for your application program is 0x0000 - 0x%x\n",
	        userblock_size - 1);
}
