📄 write_idblock.c
字号:
/********************************************************************
write_idblock.c
Writes product ID to top of flash and verifies.
This version modified for Dynamic C 7.04P2 and later.
This program is intended to write a System_ID Block on boards
that don't have a System_ID block or that have a version 2
system_ID block. If your board has a version 3 or 4 system_ID
block then you should use the idblock_recovery.c utility program
for proper recovery of your data from the userblock data area.
This program will automatically prompt you if it detects
a version 3 or 4 system_ID block to see if you want to
continue with writing the system_ID block.
Version 1.6
********************************************************************
Instructions:
1. Uncomment the MYBOARD macro below for the board you are writing to.
2. Enter the MAC address of the board you are writing to if it is
Ethernet capable. For Z-World products, the first three hex
digits are always 0x00, 0x90, 0xC2. The last three digits should
be on a sticker on your product. NOTE that OP6700 and Rabbit
TCP/IP Development Kit boards already have MAC addresses in an
onboard EEPROM and versions 1.1 or later of this program will not
write a MAC address to the ID block even if supplied.
3. Define the USERBLOCK macro to 1 to have a user block, or 0 for no
userblock.
4. Run the program. The contents of the ID block will be printed
(or any errors reported) to stdio.
********************************************************************
History:
1.6
- Added board: LP3510.
- Added RCM3200 to HasEthernet() macro.
- Forces version 2 ID Block for Dynamic C 7.25 and earlier.
- Added detection of system ID blocks of version 3 or
higher to prompt the user to use the idblock_recovery
program.
1.5
- Separated ifndef board type groups into individual board
ID macros.
- Conditionally defined GCPU, GREV register addresses.
1.4
- Added more boards: BL21xx, LP3500, and OP72xx.
- Bug with reading divider19200 fixed in Dynamic C 7.30;
needed to modify routine to do it the right way.
- Made ID block version dependent on Dynamic C version
program is compiled with:
7.06 or earlier will write a type 2 ID block
7.20 or later will write type 4
1.3
- Added Rabbit 3000 cores (RCM3xxx series).
1.2
- Updated for version 4 ID block (new fields).
- Improved support for older Dynamic C versions.
1.1
- Fixed a small bug in getFlashID().
- Added RCM3000 core modules.
- Fixed problem with writing MAC address in ID block to
OP6700 and RTDKs, which would override the MAC address
in the on-board EEPROM.
1.0
- Corresponds to initwrid.c version 3.14.
********************************************************************/
#define VERSION "1.6"
#define PROGRAM_NAME "write_idblock.c"
/********************************************************************/
/** STEP ONE: uncomment the macro for the board you are using. **/
/********************************************************************/
// Core modules
//#define MYBOARD RCM2020 // 18MHz Core Module
//#define MYBOARD RCM2010 // 25MHz Core Module, 128k SRAM
//#define MYBOARD RCM2000 // 25MHz Core Module, 512k SRAM
//#define MYBOARD RCM2100 // RCM2100 RabbitCore, Ethernet, 512k SRAM, 2x256k flash
//#define MYBOARD RCM2110 // RCM2110 RabbitCore, Ethernet, 128k SRAM, 1x256k flash
//#define MYBOARD RCM2120 // RCM2120 RabbitCore, no Ethernet, 512k SRAM, 2x256k flash
//#define MYBOARD RCM2130 // RCM2130 RabbitCore, no Ethernet, 128k SRAM, 2x256k flash
//#define MYBOARD RCM2200 // RCM2200/2210 RabbitCore
//#define MYBOARD RCM2250 // RCM2250 RabbitCore
//#define MYBOARD RCM2300 // RCM2300 RabbitCore
//#define MYBOARD RCM3000 // RCM3000 RabbitCore
//#define MYBOARD RCM3010 // RCM3010 RabbitCore
//#define MYBOARD RCM3100 // RCM3100 RabbitCore
//#define MYBOARD RCM3110 // RCM3110 RabbitCore
//#define MYBOARD RCM3200 // RCM3200 RabbitCore, Ethernet, 512K flash, 256K+512K SRAM
// Single-board computers
//
//#define MYBOARD BL1810 // 14MHz Jackrabbit
//#define MYBOARD BL1800 // 29MHz Jackrabbit
//#define MYBOARD BL1820 // 14MHz Jackrabbit, 32k SRAM
//#define MYBOARD BL2000 // Wildcat, Ethernet, high-quality analog
//#define MYBOARD BL2010 // Wildcat, Ethernet, analog+digital
//#define MYBOARD BL2020 // Wildcat, no Ethernet, high-quality analog
//#define MYBOARD BL2030 // Wildcat, no Ethernet, analog+digital
//#define MYBOARD BL2040 // Wildcat, no Ethernet, digital only
#define MYBOARD BL2100 // Smartcat, Ethernet and analog I/O
//#define MYBOARD BL2110 // Smartcat, Ethernet, no analog I/O
//#define MYBOARD BL2120 // Smartcat, no Ethernet and analog I/O
//#define MYBOARD BL2130 // Smartcat, no Ethernet, no analog I/O
//#define MYBOARD BL2105 // Smartcat w. RCM2250 and analog I/O
//#define MYBOARD BL2115 // Smartcat w. RCM2250, no analog I/O
//#define MYBOARD BL2101 // Smartcat w. RCM2200 and 10V analog I/O
//#define MYBOARD BL2111 // Smartcat w. RCM2250 and 10V analog I/O
//#define MYBOARD BL2121 // Smartcat w. RCM2300 and 10V analog I/O
//#define MYBOARD LP3500 // Low-power controller, 512K flash, 512K SRAM, AD, relay
//#define MYBOARD LP3510 // Low-power controller, 256K flash, 128K SRAM
// Embedded control systems
//#define MYBOARD SR9100 // SmartStar
//#define MYBOARD SR9150 // MiniStar
// Operator interfaces
//#define MYBOARD OP6600 // Intellicom, no Ethernet
//#define MYBOARD OP6700 // Intellicom, Ethernet
//#define MYBOARD OP6800 // Minicom, Ethernet (with RCM2200)
//#define MYBOARD OP6810 // Minicom, no Ethernet (with RCM2300)
//#define MYBOARD OP7200 // Ethernet interface w/ analog & touchscreen
//#define MYBOARD OP7210 // Ethernet interface, no analog or touchscreen
// Other products
//#define MYBOARD RTDK // TCP/IP Development Kit
//#define MYBOARD RABLINK // RabbitLink
/********************************************************************/
/** STEP TWO: enter the MAC address of the board if it is **/
/** Ethernet-capable. the first three digits are **/
/** fixed; the last three should be on a sticker on **/
/** the board. **/
/********************************************************************/
const char MAC[6] = { 0x00, 0x90, 0xC2,
0x33, 0x00, 0x00 };
/********************************************************************/
/** STEP THREE: set the HASUSERBLOCK macro to 1 to add a user **/
/** block, or to 0 to remove a user block. **/
/********************************************************************/
#define HASUSERBLOCK 1
/********************************************************************/
/** END OF USER-CUSTOMIZABLE SECTION **/
/********************************************************************/
// check for undefined register macros
// (R2000C and up has these, prior R2000s always return 0s)
#ifndef GCPU
#define GCPU 0x2E
#endif
#ifndef GREV
#define GREV 0x2F
#endif
// check for undefined board types
#ifndef BL2100
#define BL2100 0x0B00
#endif
#ifndef BL2101
#define BL2101 0x0B06
#endif
#ifndef BL2105
#define BL2105 0x0B04
#endif
#ifndef BL2110
#define BL2110 0x0B02
#endif
#ifndef BL2111
#define BL2111 0x0B08
#endif
#ifndef BL2115
#define BL2115 0x0B05
#endif
#ifndef BL2121
#define BL2121 0x0B07
#endif
#ifndef LP3500
#define LP3500 0x1200
#endif
#ifndef LP3510
#define LP3510 0x1201
#endif
#ifndef OP6800
#define OP6800 0x0D00
#endif
#ifndef OP7200
#define OP7200 0x1100
#endif
#ifndef OP7210
#define OP7210 0x1101
#endif
#ifndef RCM2250
#define RCM2250 0x0E00
#endif
#ifndef RCM3000
#define RCM3000 0x0F00
#endif
#ifndef RCM3010
#define RCM3010 0x0F01
#endif
#ifndef RCM3100
#define RCM3100 0x1000
#endif
#ifndef RCM3110
#define RCM3110 0x1001
#endif
#ifndef RCM3200
#define RCM3200 0x1300
#endif
#ifndef SR9150
#define SR9150 0x0C00
#endif
// check for several potential problems
#ifndef _FLASH_
#error "This program _must_ be run in flash."
#endif
#ifndef MYBOARD
#error "MYBOARD must be set to the proper board type."
#endif
// some useful macros
#define Has2Flash() \
( (MYBOARD == RCM2100) || (MYBOARD == RCM2120) || \
(MYBOARD == RCM2130) || (MYBOARD == RCM2250) || \
(MYBOARD == SR9100) || (MYBOARD == SR9150) || \
(MYBOARD == OP6600) || (MYBOARD == OP6700) || \
(MYBOARD == RTDK) || (MYBOARD == RABLINK) || \
(MYBOARD == BL2105) || (MYBOARD == BL2115) || \
(MYBOARD == RCM3000) \
)
#define HasEthernet() \
( (MYBOARD == RCM2100) || (MYBOARD == RCM2110) || \
(MYBOARD == RCM2200) || (MYBOARD == RCM2250) || \
(MYBOARD == BL2000) || (MYBOARD == BL2010) || \
(MYBOARD == BL2100) || (MYBOARD == BL2110) || \
(MYBOARD == OP6700) || (MYBOARD == OP6800) || \
(MYBOARD == RTDK) || (MYBOARD == RABLINK) || \
(MYBOARD == BL2101) || (MYBOARD == BL2111) || \
(MYBOARD == BL2105) || (MYBOARD == BL2115) || \
(MYBOARD == RCM3000) || (MYBOARD == RCM3010) || \
(MYBOARD == OP7200) || (MYBOARD == OP7210) || \
(MYBOARD == RCM3200) \
)
#define HasEEPROM() \
( (MYBOARD == OP6700) || (MYBOARD == RTDK) \
)
// function prototypes
int writeIDBlock();
int getFlashID();
int calcCRC(int initCRC, void *data, int blocksize);
int setTimeStamp();
/********************************************************************/
main()
{
static int i, crc;
int saveMB1;
char *div19200ptr;
char ch;
if(SysIDBlock.tableVersion > 2 && CC_VER < 0x0726)
{
printf("\n\n");
printf("Detected a version %d SystemID block\n", SysIDBlock.tableVersion);
printf("Recommend the %s utility for proper Userblock data recovery.\n", PROGRAM_NAME);
printf("(i.e. Z-World calibration constants or User application code data)\n\n");
printf("Do you still want to overwrite your SystemID block (Y/N)? ") ;
ch = getchar();
if(ch == 'N' || ch == 'n')
{
printf("\n\n");
printf("Exiting without making any changes...\n\n");
exit(0);
}
printf("\n\n");
}
printf("WRITE_IDBLOCK, version %s\n", VERSION);
//////////////////////////////////////////////////
// map first two quadrants to flash on /CS0
// make sure A18 NOT inverted on MB1 (handles bank select)
saveMB1 = MB1CRShadow;
WrPortI(MB1CR, &MB1CRShadow, FLASH_WSTATES | 0x00);
_InitFlashDriver(0x01 | 0x02);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -