📄 jflash.cpp
字号:
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;
if (is_jtag_debug && nPWE_OUT)
pin[nPWE_OUT]=0;
}
else
{
pin[WriteEnable] = 1;
if (is_jtag_debug && nPWE_OUT)
pin[nPWE_OUT]=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[ReadWriteMode] = 1;
}
/*
*******************************************************************************
*
* FUNCTION: gpio_unlock_flash
*
* DESCRIPTION: Sets the GPIO bits on the Mainstone that are keeping the
* K3 flash locked.
*
* INPUT PARAMETERS: void
*
* RETURNS: void
*
*******************************************************************************
*/
void gpio_unlock_flash()
{
if (UnlockFlashCtrl1 != 9999)
pin[UnlockFlashCtrl1] = UnlockFlashCtrl1Lev;
if (UnlockFlashCtrl2 != 9999)
pin[UnlockFlashCtrl2] = UnlockFlashCtrl2Lev;
if (UnlockFlashCtrl3 != 9999)
pin[UnlockFlashCtrl3] = UnlockFlashCtrl3Lev;
if (UnlockFlashCtrl4 != 9999)
pin[UnlockFlashCtrl4] = UnlockFlashCtrl4Lev;
}
/*
*******************************************************************************
*
* FUNCTION: gpio_lock_flash
*
* DESCRIPTION: Clears the GPIO bits on the Mainstone to re-lock the
* K3 flash.
*
* INPUT PARAMETERS: void
*
* RETURNS: void
*
*******************************************************************************
*/
void gpio_lock_flash()
{
if (UnlockFlashCtrl1 != 9999)
pin[UnlockFlashCtrl1] = LockFlashCtrl1Lev;
if (UnlockFlashCtrl2 != 9999)
pin[UnlockFlashCtrl2] = LockFlashCtrl2Lev;
if (UnlockFlashCtrl3 != 9999)
pin[UnlockFlashCtrl3] = LockFlashCtrl3Lev;
if (UnlockFlashCtrl4 != 9999)
pin[UnlockFlashCtrl4] = LockFlashCtrl4Lev;
}
/*
*******************************************************************************
*
* FUNCTION: pre_IRSCAN
*
* DESCRIPTION: Sets up the state machine to accept an IR SCAN
*
* INPUT PARAMETERS: void
*
* RETURNS: void
*
*******************************************************************************
*/
void pre_IRSCAN()
{
if(Debug_Mode)
printf("begin pre-IR scan code\n");
putp(1,0,IGNORE_PORT); //Run-Test/Idle
putp(1,0,IGNORE_PORT); //Run-Test/Idle
putp(1,0,IGNORE_PORT); //Run-Test/Idle
putp(1,0,IGNORE_PORT); //Run-Test/Idle
putp(1,1,IGNORE_PORT);
putp(1,1,IGNORE_PORT); //select IR scan
putp(1,0,IGNORE_PORT); //capture IR
putp(1,0,IGNORE_PORT); //shift IR
}
/*
*******************************************************************************
*
* FUNCTION: post_IRSCAN
*
* DESCRIPTION: Get back to IDLE after scanning in the instruction
*
* INPUT PARAMETERS: void
*
* RETURNS: void
*
*******************************************************************************
*/
void post_IRSCAN()
{
if(Debug_Mode)
printf("begin post-IR scan code\n");
//putp(1,1,IGNORE_PORT); //Exit1-IR
putp(1,1,IGNORE_PORT); //Update-IR
putp(1,0,IGNORE_PORT); //Run-Test/Idle
putp(1,0,IGNORE_PORT); //Run-Test/Idle
putp(1,0,IGNORE_PORT); //Run-Test/Idle
}
/*
*******************************************************************************
*
* FUNCTION: pre_DRSCAN
*
* DESCRIPTION: Sets up the state machine to accept an DR SCAN
*
* INPUT PARAMETERS: void
*
* RETURNS: void
*
*******************************************************************************
*/
void pre_DRSCAN()
{
if(Debug_Mode)
printf("begin pre-DR scan code\n");
putp(1,0,IGNORE_PORT); //Run-Test/Idle
putp(1,0,IGNORE_PORT); //Run-Test/Idle
putp(1,0,IGNORE_PORT); //Run-Test/Idle
putp(1,0,IGNORE_PORT); //Run-Test/Idle
putp(1,1,IGNORE_PORT); //select DR scan
putp(1,0,IGNORE_PORT); //capture DR
// putp(1,0,IGNORE_PORT); //shift DR
}
/*
*******************************************************************************
*
* FUNCTION: post_DRSCAN
*
* DESCRIPTION: Get back to IDLE after scanning in the data register
*
* INPUT PARAMETERS: void
*
* RETURNS: void
*
*******************************************************************************
*/
void post_DRSCAN()
{
if(Debug_Mode)
printf("begin post-DR scan code\n");
putp(1,1,IGNORE_PORT); //Exit1-DR
putp(1,1,IGNORE_PORT); //Update-DR
putp(1,0,IGNORE_PORT); //Run-Test/Idle
putp(1,0,IGNORE_PORT); //Run-Test/Idle
putp(1,0,IGNORE_PORT); //Run-Test/Idle
}
/*
*******************************************************************************
*
* FUNCTION: controller_scan_code
*
* DESCRIPTION: clocks in a specified cotulla IR scan code
*
* INPUT PARAMETERS: int instruction code
* int read or ignore port
* int continue or terminate instruction stream
*
* RETURNS: void
*
*******************************************************************************
*/
// NOTE: I think there is a bug here somewhere. This procedure seems to work,
// but I think the count is off. Future debugging work required. The problem is
// that a 0x1 should be returned from the instruction register after each
// valid instruction. I'm not getting this value back, but the instructions
// appear to be valid because the system works. If this bug can be found, then
// the JTAG_TEST procedure could be used again.
int controller_scan_code(int code, int rp, int ct)
{
int i;
int outval = 0;
int tms = 0;
// int codebit;
if(Debug_Mode)
printf("begin controller scan code = %x\n", code);
for (i = 0; i < IrLength; i++)
{
if (ct == TERMINATE)
{
if (i == IrLength -1)
{
tms = 1;
}
}
outval |= putp(((code & (1 << i)) >> i), tms, rp) << (IrLength - i - 1);
// codebit = code & 1<<(IrLength -1 -i);
// outval |= putp(codebit, tms, rp) << (IrLength -1 -i);
}
if(Debug_Mode)
printf("Controller IR value: %X\n", outval);
return outval;
}
/*
*******************************************************************************
*
* FUNCTION: PZ_scan_code
*
* DESCRIPTION: clocks in a specified PZxxxx IR scan code
*
* INPUT PARAMETERS: int code
*
* RETURNS: void
*
*******************************************************************************
*/
int PZ_scan_code(int code, int rp, int ct)
{
int i;
i
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -