📄 jflash.cpp
字号:
// "Write Buffer" flow.
// This uses almost half the cycles required by "word programming" flow
// Status register is not read to save time. There is also no checking to see
// if maximum "Write Buffer Program Time" is violated. However even with the
// fastest parallel port bus speed this should not be a problem
// (i.e. 16 words * 300 JTAG chain length * 4 parallel port cycles * 1uS fast
// parallel port cycle = 19mS, typical write buffer program times are in the 200uS range).
if(!PlatformIs16bit)
write_word_count = (max_write_buffer - 1) + ((max_write_buffer - 1) << 16);
else
write_word_count = max_write_buffer - 1;
time(&start);
for(lj = base_address; lj < fsize + base_address; lj = lj + max_write_buffer)
{
access_rom(WRITE, lj, F_WRITE_BUFFER, IGNORE_PORT); // write buffer command
access_rom(HOLD, lj, F_WRITE_BUFFER, IGNORE_PORT);
access_rom(WRITE, lj, write_word_count, IGNORE_PORT); // write word count (max write buffer size)
access_rom(HOLD, lj, write_word_count, IGNORE_PORT);
time(&now);
if(difftime(now,start) > STATUS_UPDATE) // Update status every 2 seconds
{
printf("Writing flash at hex address %8lx, %5.2f%% done \r"
,lj * ADDR_MULT ,(float)(lj - base_address)/(float)fsize*100.0);
time(&start);
}
if(!PlatformIs16bit)
{
for(DWORD lk = 0; lk < max_write_buffer; lk++)
{
fread((DWORD *)&li_DWORD, sizeof(DWORD) , 1, in_file);
access_rom(WRITE, lj+lk, li_DWORD, IGNORE_PORT); // Write buffer data
access_rom(HOLD, lj+lk, li_DWORD, IGNORE_PORT); // New
// printf("writing %x at address %x\n", li_DWORD, lj+lk);
}
}
else
{
for(DWORD lk = 0; lk < max_write_buffer; lk++)
{
fread((WORD *)&li_WORD, sizeof(WORD) , 1, in_file);
access_rom(WRITE, lj+lk, li_WORD, IGNORE_PORT); // Write buffer data
access_rom(HOLD, lj+lk, li_WORD, IGNORE_PORT); // New
}
}
// No need to diferentiate between 16 and 32 bit access_rom functions anymore!
access_rom(WRITE, 0, F_BLOCK_ERASE_2ND, IGNORE_PORT); // Program Buffer to Flash Confirm
access_rom(HOLD, 0, F_BLOCK_ERASE_2ND, IGNORE_PORT); //New
}
Write_Rom(lj, F_READ_ARRAY);
}
printf("\nProgramming done\n");
rewind(in_file);
}
/*
*******************************************************************************
*
* FUNCTION: verify_flash
*
* DESCRIPTION: compares data programmed in flash with the original binary file.
*
* INPUT PARAMETERS: DWORD base_address
* DWORD flash_size
*
* RETURNS: void
*
*******************************************************************************
*/
void verify_flash(DWORD base_address, DWORD fsize)
{
time_t start, now;
DWORD li_DWORD, li1_DWORD;
WORD li_WORD, li1_WORD;
rewind(in_file);
printf("Starting Verify\n");
time(&start);
if(PlatformIs16bit)
{
for(DWORD lj = base_address + 1; lj <= fsize + base_address; lj++)
{
if (lj != base_address) DebugProgress |= firstWordVerified;
fread((WORD *)&li_WORD, sizeof(WORD) , 1, in_file);
// toggle the chip select for K3 flash
if (K3_STABILITY_FIX_ENABLE) access_rom(RS, lj, 0x0L, READ_PORT);
li1_WORD = (WORD) Read_Rom(lj);
if (K3_STABILITY_FIX_ENABLE) Read_Rom(lj); //hack to fix K3
time(&now);
if(difftime(now,start) > STATUS_UPDATE) // Update status every 2 seconds
{
printf("Verifying flash at hex address %8lx, %5.2f%% done \r"
,lj*ADDR_MULT ,(float)(lj - base_address)/(float)fsize*100.0);
time(&start);
}
if(li_WORD != li1_WORD)
{
printf("verify error at address = %lx exp_dat = %lx act_dat = %lx\n",(lj - 1)*ADDR_MULT, li_WORD,li1_WORD);
error_out("");
}
}
}
else
{
for(DWORD lj = base_address + 1; lj <= fsize + base_address; lj++)
{
if (lj != base_address) DebugProgress |= firstWordVerified;
fread((DWORD *)&li_DWORD, sizeof(DWORD) , 1, in_file);
// toggle the chip select for K3 flash
if (K3_STABILITY_FIX_ENABLE) access_rom(RS, lj, 0x0L, READ_PORT);
li1_DWORD = Read_Rom(lj);
// li1_DWORD = Read_Rom(lj);
time(&now);
if(difftime(now,start) > STATUS_UPDATE) // Update status every 2 seconds
{
printf("Verifying flash at hex address %8lx, %5.2f%% done \r"
,lj*ADDR_MULT ,(float)(lj - base_address)/(float)fsize*100.0);
time(&start);
}
if(li_DWORD != li1_DWORD)
{
printf("verify error at address = %lx exp_dat = %lx act_dat = %lx\n",(lj - 1) *ADDR_MULT,li_DWORD,li1_DWORD);
error_out("");
}
}
}
DebugProgress |= lastWordVerified;
printf("\nVerification successful! \n");
}
/*
*******************************************************************************
*
* FUNCTION: test_logic_reset
*
* DESCRIPTION: initializes the JTAG state machine to a known state
*
* INPUT PARAMETERS: void
*
* RETURNS: void
*
*******************************************************************************
*/
void test_logic_reset(void)
{
if(Debug_Mode)
printf("begin test logic reset\n");
// keep TMS set to 1 force a test logic reset
// no matter where you are in the TAP controller
for(int i=0; i < 6; ++i)
putp(1,1,IGNORE_PORT);
if(Debug_Mode)
printf("finish test logic reset\n");
}
/*
*******************************************************************************
*
* FUNCTION: set_lock_flash
*
* DESCRIPTION: sets locks bits in specified block
*
* INPUT PARAMETERS: DWORD base_address of flash
* DWORD fsize - size of flash
* DWORD block_size - block size of flash
* DWORD max_erase_time - used for a timeout
* int block_number - block number of interest
*
* RETURNS: void
*
*******************************************************************************
*/
void set_lock_flash(DWORD base_address, DWORD fsize, DWORD block_size, DWORD max_erase_time, int block_number)
{
time_t start, now;
printf("Starting set block lock bit\n");
for(DWORD lj = base_address; lj < fsize + base_address; lj = lj + block_size) // locks only blocks to be programmed
{
// Rami: Should this be lj instead of 0 ???
Write_Rom(0, F_SET_BLOCK_LOCK); // block lock bit command
Write_Rom(lj, F_SET_BLOCK_LOCK_2ND); // Confirm
time(&start);
printf("Erasing block %3d \r",block_number++);
while(access_rom(RS, 0, 0, READ_PORT) != F_STATUS_READY) // Loop until successful status return
{
Read_Rom(0);
time(&now);
if(difftime(now,start) > max_erase_time + 1) // Check for status timeout
error_out("Error, Clear lock timed out");
}
}
printf("Set lock bit done \n");
}
/*
*******************************************************************************
*
* FUNCTION: set_address
*
* DESCRIPTION: Loads the address into the address bits
*
* INPUT PARAMETERS: address
*
* RETURNS: void
*
* GLOBAL EFFECTS: None
*
* ASSUMPTIONS: None
*
* CALLS: None
*
* CALLED BY: Anyone
*
* PROTOTYPE: void set_address(unsigned int address);
*
*******************************************************************************
*/
void set_address (DWORD address)
{
DWORD i;
for (i = 0; i < 26; i++)
{
pin[addr_order[i]] = ((address >> i) & 1);
}
}
/*
*******************************************************************************
*
* FUNCTION: set_data
*
* DESCRIPTION: Fills the chain with the data bits
*
* INPUT PARAMETERS: DWORD data
*
* RETURNS: void
*
*******************************************************************************
*/
void set_data(DWORD data)
{
DWORD i;
for(i = 0; i < 32; i++)
{
pin[dat_order[i]] = ((data >> i) & 1); // set data pins
}
}
/*
*******************************************************************************
*
* FUNCTION: set_pin_chip_select
*
* DESCRIPTION: Sets chip selects depending on the address and the platform
*
* INPUT PARAMETERS: DWORD address
*
* RETURNS: void
*
*******************************************************************************
*/
void set_pin_chip_select(DWORD address)
{
if((address >= CSR_LADDR[0]) && (address < CSR_HADDR[0])) pin[CSR1] = 0;
else if((address >= CSR_LADDR[1]) && (address < CSR_HADDR[1])) pin[CSR2] = 0;
else if((address >= CSR_LADDR[2]) && (address < CSR_HADDR[2])) pin[CSR3] = 0;
else if((address >= CSR_LADDR[3]) && (address < CSR_HADDR[3])) pin[CSR4] = 0;
else if((address >= CSR_LADDR[4]) && (address < CSR_HADDR[4])) pin[CSR5] = 0;
else if((address >= CSR_LADDR[5]) && (address < CSR_HADDR[5])) pin[CSR6] = 0;
pin[p_nsdcas] = 0;
}
/*
*******************************************************************************
*
* FUNCTION: clear_chip_selects
*
* DESCRIPTION: reset all chip selects
*
* INPUT PARAMETERS: None
*
* RETURNS: none
*
*******************************************************************************
*/
void clear_chip_selects()
{
// Preset to default values
pin[ChipSelect0] = 1;
pin[ChipSelect1] = 1;
pin[ChipSelect2] = 1;
pin[ChipSelect3] = 1;
pin[ChipSelect4] = 1;
pin[ChipSelect5] = 1;
pin[p_nsdcas] = 1;
}
/*
*******************************************************************************
*
* FUNCTION: mem_output_enable
*
* DESCRIPTION: enable or disable memory output. This pin is connected to
* the output enables of the memory device.
*
* INPUT PARAMETERS: int - enable or disable
*
* RETURNS: void
*
*******************************************************************************
*/
void mem_output_enable(int endis)
{
if (endis == ENABLE)
pin[OutputEnable] = 0;
else
pin[OutputEnable] = 1;
}
/*
*******************************************************************************
*
* FUNCTION: mem_write_enable
*
* DESCRIPTION: enable or disable memory writes. This pin is connected to
* the write enables of the memory device.
*
* INPUT PARAMETERS: int - enable or disable
*
* RETURNS: void
*
*******************************************************************************
*/
void mem_write_enable(int endis)
{
if (endis == ENABLE)
pin[WriteEnable] = 0;
else
pin[WriteEnable] = 1;
}
/*
*******************************************************************************
*
* FUNCTION: mem_data_driver
*
* DESCRIPTION: Sets memory data pins to DRIVE or HIZ.
*
* INPUT PARAMETERS: int - drive or highz
*
* RETURNS: void
*
*******************************************************************************
*/
void mem_data_driver(int df)
{
if (df == DRIVE)
{
pin[MdUpperControl] = 1;
pin[MdLowerControl] = 1; // Note for Assabet: MdLowerControl = MdUpperControl
}
else
{
pin[MdUpperControl] = 0;
pin[MdLowerControl] = 0; // Note for Assabet: MdLowerControl = MdUpperControl
}
}
/*
*******************************************************************************
*
* FUNCTION: mem_rw_mode
*
* DESCRIPTION: Sets memory mode to READ or WRITE.
*
* INPUT PARAMETERS: int - READ or WRITE
*
* RETURNS: void
*
*******************************************************************************
*/
void mem_rw_mode(int rw)
{
if (rw == WRITE)
pin[ReadWriteMode] = 0;
else
pin[ReadWriteMod
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -