📄 565cmf_dbug.c
字号:
/* ===========================================================================
C3F Programming functions for 565mon.c
============================================================================*/
#include "src/include/dbug.h"
#include "gmd_C3F.h"
#include "gmd_internal.h"
#include "565cmf.h"
//#define BUFFER_SIZE 256 /* number of 32-bit words */
#define BUFFER_SIZE 4 /* number of bytes */
//#define BUFFER_SIZE 32 /* number of bytes */
//#define OUTBUFSIZE 64
#define OUTBUFSIZE 4
//#define OUTBUFSIZE 32
UINT8 outbuf[OUTBUFSIZE];
/************************************************************/
#ifndef CMF_FLASH_DEVICES
#define CMF_FLASH_DEVICES 1
#endif
UINT32 *pUC3F;
static CMF_BLOCK_INFO uc3f_a[8];
static CMF_BLOCK_INFO uc3f_b[8];
/************************************************************/
/*
* CMF sector definitions
*/
uint8 block_mask[] =
{
{0x80}, /* block 0 */
{0x40}, /* block 1 */
{0x20}, /* block 2 */
{0x10}, /* block 3 */
{0x08}, /* block 4 */
{0x04}, /* block 5 */
{0x02}, /* block 6 */
{0x01} /* block 7 */
};
uint8 sm_block_mask[] =
{
{0x80}, /* small block 0 */
{0x40}, /* small block 1 */
};
#if (defined (CPU_MPC565) || defined (CPU_MPC566) || defined (CPU_MPC563) || defined (CPU_MPC564))
#define CMF_BASE 0x00000000;
const CMF_BLOCK_INFO cmf_block_a[] =
{
{64*1024, 0x000000}, /*Module A with no Small Blocks enabled*/
{64*1024, 0x010000},
{64*1024, 0x020000},
{64*1024, 0x030000},
{64*1024, 0x040000},
{64*1024, 0x050000},
{64*1024, 0x060000},
{64*1024, 0x070000}
};
const CMF_BLOCK_INFO cmf_sm_blocks_a[] =
{
{16*1024, 0x000000},
{16*1024, 0x01C000},
};
const CMF_BLOCK_INFO cmf_block_a_sben[] =
{
{48*1024, 0x004000}, /*Module A with both Small Blocks enabled*/
{48*1024, 0x010000},
{16*1024, 0x01C000},
{64*1024, 0x020000},
{64*1024, 0x030000},
{64*1024, 0x040000},
{64*1024, 0x050000},
{64*1024, 0x060000},
{64*1024, 0x070000}
};
const CMF_BLOCK_INFO cmf_block_a_sben0[] =
{
{48*1024, 0x004000}, /*Module A with only Small Block 0 enabled*/
{64*1024, 0x010000},
{64*1024, 0x020000},
{64*1024, 0x030000},
{64*1024, 0x040000},
{64*1024, 0x050000},
{64*1024, 0x060000},
{64*1024, 0x070000}
};
const CMF_BLOCK_INFO cmf_block_a_sben1[] =
{
{64*1024, 0x000000}, /*Module A with only Small Block 1 enabled*/
{48*1024, 0x010000},
{64*1024, 0x020000},
{64*1024, 0x030000},
{64*1024, 0x040000},
{64*1024, 0x050000},
{64*1024, 0x060000},
{64*1024, 0x070000}
};
#if (defined (CPU_MPC565) || defined (CPU_MPC566))
const CMF_BLOCK_INFO cmf_block_b[]=
{
{64*1024, 0x080000}, /*Module B no Small Blocks enabled*/
{64*1024, 0x090000},
{64*1024, 0x0A0000},
{64*1024, 0x0B0000},
{64*1024, 0x0C0000},
{64*1024, 0x0D0000},
{64*1024, 0x0E0000},
{64*1024, 0x0F0000}
};
const CMF_BLOCK_INFO cmf_sm_blocks_b[] =
{
{16*1024, 0x0E0000},
{16*1024, 0x0FC000},
};
const CMF_BLOCK_INFO cmf_block_b_sben[]=
{
{64*1024, 0x080000}, /*Module B with both Small Blocks enabled*/
{64*1024, 0x090000},
{64*1024, 0x0A0000},
{64*1024, 0x0B0000},
{64*1024, 0x0C0000},
{64*1024, 0x0D0000},
{48*1024, 0x0E4000},
{48*1024, 0x0F0000}
};
const CMF_BLOCK_INFO cmf_block_b_sben0[]=
{
{64*1024, 0x080000}, /*Module B with Small Block 0 enabled*/
{64*1024, 0x090000},
{64*1024, 0x0A0000},
{64*1024, 0x0B0000},
{64*1024, 0x0C0000},
{64*1024, 0x0D0000},
{48*1024, 0x0E4000},
{64*1024, 0x0F0000}
};
const CMF_BLOCK_INFO cmf_block_b_sben1[]=
{
{64*1024, 0x080000}, /*Module B with Small Block 1 enabled*/
{64*1024, 0x090000},
{64*1024, 0x0A0000},
{64*1024, 0x0B0000},
{64*1024, 0x0C0000},
{64*1024, 0x0D0000},
{64*1024, 0x0E0000},
{48*1024, 0x0F0000}
};
#endif
#else
#error "Device does not support UC3F flash"
#endif
struct C3F_tag *C3F[C3F_MAX_MODULES];
int sm_block_a0_enabled = FALSE;
int sm_block_a1_enabled = FALSE;
int sm_block_b0_enabled = FALSE;
int sm_block_b1_enabled = FALSE;
//UINT32 testAddress, testData, testSourceData;
UINT32 programWord, size;
uint8 enabledBDM;
UINT32 arrayBase;
C3F_RESULT returnCode; /* Return value to the users */
UINT32 numModules; // Number of Flash Modules
UINT8 shadow, // C3F shadow select flag
enabledBDM, // BDM select flag
enabledBlocks[C3F_MAX_MODULES], // Enabled array blocks
enabledSBlocks[C3F_MAX_MODULES];// Enabled array small blocks
UINT32 sum; // Check sum result
UINT32 i, // Index
m, // Module Index
dest, // Relative address for C3F
source, // Source address for program and verify
size; // C3F size operation applicable
UINT32 compareAddress, // Store the check, program or verify result
compareData,
compareSourceData;
UINT8 module, // C3F module ChangeCensor applied
censorValue, // CENSOR[0:1] bits intend to change
deviceMode; // Censor status of the given device
/**************************************************************************/
asm UINT32 FetchIMMR(void)
{
mfspr r3,638
}
/********************************************************************/
void CallBack (void)
{
}
/********************************************************************/
extern const unsigned int FlashInit_C[];
extern const unsigned int FlashCheckShadow_C[];
extern const unsigned int FlashErase_C[];
extern const unsigned int BlankCheck_C[];
extern const unsigned int FlashProgram_C[];
extern const unsigned int FlashVerify_C[];
extern const unsigned int ChangeCensor_C[];
extern const unsigned int CheckSum_C[];
/* Define function pointers of GMD for C3F */
typedef C3F_RESULT (*pFLASHINIT)( UINT8 enabledBDM,
UINT32 *arrayPointer);
typedef C3F_RESULT (*pFLASHCHECKSHADOW)( UINT8 enabledBDM,
uint8 shadow,
UINT32 dest,
UINT32 size,
UINT32 arrayBase);
typedef C3F_RESULT (*pFLASHERASE)(UINT8 enabledBDM,
void (*CallBack)(void),
UINT8 *enabledBlock,
UINT8 *enabledSBlock,
UINT32 arrayBase);
typedef C3F_RESULT (*pBLANKCHECK)(UINT8 enabledBDM,
void (*CallBack)(void),
UINT32 dest,
UINT32 size,
UINT32 *compareAddress,
UINT32 *compareData,
UINT32 arrayBase);
typedef C3F_RESULT (*pFLASHPROGRAM)(UINT8 enabledBDM,
void(*CallBack)(void),
UINT32 dest,
UINT32 size,
UINT32 source,
UINT32 arrayBase);
typedef C3F_RESULT (*pFLASHVERIFY) (UINT8 enabledBDM,
void (*CallBack)(void),
UINT32 dest,
UINT32 size,
UINT32 source,
UINT32 *compareAddress,
UINT32 *compareData,
UINT32 *compareSourceData,
UINT32 arrayBase);
typedef C3F_RESULT (*pCHANGECENSOR)(UINT8 enabledBDM,
void(*CallBack)(void),
UINT8 module ,
UINT8 censorValue,
UINT8 deviceMode,
UINT32 arrayBase);
typedef C3F_RESULT (*pCHECKSUM)(UINT8 enabledBDM,
void (*callBack)(void),
UINT32 dest,
UINT32 size,
UINT32 *sum,
UINT32 arrayBase);
/********************************************************************/
UINT32
C3F_init (ADDRESS base)
{
// Assign function pointers
pFLASHINIT FlashInit = (pFLASHINIT) FlashInit_C;
pUC3F = (UINT32 *)base;
board_irq_disable();
/*
Initialize Part - first check for MPC56x part type
*/
#if (defined (CPU_MPC565) || defined (CPU_MPC566))
numModules = C3F_MODULES_MPC565; /* MPC565 has 2 flash modules */
UC3F_A.UC3FMCR.R = 0x40FF0000; /* UC3FMCR Module A - Un-Protect all blocks */
UC3F_B.UC3FMCR.R = 0x40FF0000; /* UC3FMCR Module B - Un-Protect all blocks */
#else
numModules = C3F_MODULES_MPC563; /* MPC563 has 1 flash module */
UC3F_A.UC3FMCR.R = 0x40FF0000; /* UC3FMCR Module A - Un-Protect all blocks */
#endif
enabledBDM = 0; /* Not enter into BDM after each opration */
arrayBase = 0; /* Default value of starting point of C3F */
C3F_module_setup(); /* Checks for small blocks, etc. */
/*
Call FlashInit
*/
returnCode = (*FlashInit)( enabledBDM, &arrayBase);
if(returnCode != C3F_OK)
{
if (returnCode == 0x00000200)
{
returnCode = C3F_ChangeCensor();
if (returnCode != C3F_OK){
failmessage("Changing Censor Bit",returnCode);
return returnCode;
}
}
else{
failmessage("Initializing",returnCode);
return returnCode;
}
}
return(C3F_OK);
}
/********************************************************************/
void
C3F_module_setup()
{
switch( UC3F_A.UC3FMCRE.B.SBEN )
{
case 0x0: /*no small blocks enabled*/
for (i = 0; i < 8; i++)
{
uc3f_a[i].size = cmf_block_a[i].size;
uc3f_a[i].offset = cmf_block_a[i].offset;
}
sm_block_a0_enabled = FALSE;
sm_block_a1_enabled = FALSE;
break;
case 0x1: /*small block 1 enabled*/
for (i = 0; i < 8; i++)
{
uc3f_a[i].size = cmf_block_a_sben1[i].size;
uc3f_a[i].offset = cmf_block_a_sben1[i].offset;
}
sm_block_a1_enabled = TRUE;
sm_block_a0_enabled = FALSE;
break;
case 0x2: /*small block 0 enabled*/
for (i = 0; i < 8; i++)
{
uc3f_a[i].size = cmf_block_a_sben0[i].size;
uc3f_a[i].offset = cmf_block_a_sben0[i].offset;
}
sm_block_a0_enabled = TRUE;
sm_block_a1_enabled = FALSE;
break;
case 0x3: /*both small blocks enabled*/
for (i = 0; i < 8; i++)
{
uc3f_a[i].size = cmf_block_a_sben[i].size;
uc3f_a[i].offset = cmf_block_a_sben[i].offset;
}
sm_block_a0_enabled = TRUE;
sm_block_a1_enabled = TRUE;
break;
}
#if (defined (CPU_MPC565) || defined (CPU_MPC566))
switch( UC3F_B.UC3FMCRE.B.SBEN )
{
case 0: /*no small blocks enabled*/
for (i = 0; i < 8; i++)
{
uc3f_b[i].size = cmf_block_b[i].size;
uc3f_b[i].offset = cmf_block_b[i].offset;
}
sm_block_b0_enabled = FALSE;
sm_block_b1_enabled = FALSE;
break;
case 1: /*small block 1 enabled*/
for (i = 0; i < 8; i++)
{
uc3f_b[i].size = cmf_block_b_sben1[i].size;
uc3f_b[i].offset = cmf_block_b_sben1[i].offset;
}
sm_block_b1_enabled = TRUE;
sm_block_b0_enabled = FALSE;
break;
case 2: /*small block 0 enabled*/
for (i = 0; i < 8; i++)
{
uc3f_b[i].size = cmf_block_b_sben0[i].size;
uc3f_b[i].offset = cmf_block_b_sben0[i].offset;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -