static int dsp5680xx_halt(struct target *target){
int retval;
- uint8_t jtag_status;
uint16_t eonce_status;
if(target->state == TARGET_HALTED){
LOG_USER("Target already halted.");
}
retval = eonce_enter_debug_mode(target,&eonce_status);
err_check_propagate(retval);
- retval = dsp5680xx_jtag_status(target,&jtag_status);
- err_check_propagate(retval);
retval = eonce_pc_store(target);
err_check_propagate(retval);
//TODO is it useful to store the pc?
return ERROR_OK;
}
int retval;
- uint8_t jtag_status;
- uint16_t eonce_status;
-
- // Verify that EOnCE is enabled (enable it if necessary)
- uint16_t data_read_from_dr = 0;
- retval = eonce_read_status_reg(target,&data_read_from_dr);
- err_check_propagate(retval);
- if((data_read_from_dr&DSP5680XX_ONCE_OSCR_DEBUG_M) != DSP5680XX_ONCE_OSCR_DEBUG_M){
- retval = eonce_enter_debug_mode(target,NULL);
- err_check_propagate(retval);
- }
+ uint8_t eonce_status;
if(!current){
retval = eonce_move_value_to_pc(target,address);
err_check_propagate(retval);
int retry = 20;
while(retry-- > 1){
- retval = eonce_exit_debug_mode(target,(uint8_t *)&eonce_status );
+ retval = eonce_exit_debug_mode(target,&eonce_status );
err_check_propagate(retval);
- retval = dsp5680xx_jtag_status(target,&jtag_status);
- err_check_propagate(retval);
- if((jtag_status & 0xff) == JTAG_STATUS_NORMAL){
+ if(eonce_status == DSP5680XX_ONCE_OSCR_NORMAL_M)
break;
- }
}
if(retry == 0){
retval = ERROR_TARGET_FAILURE;
err_check(retval,"Failed to resume...");
}else{
target->state = TARGET_RUNNING;
- };
- LOG_DEBUG("JTAG status: 0x%02X.",jtag_status);
+ }
LOG_DEBUG("EOnCE status: 0x%02X.",eonce_status);
return ERROR_OK;
}
retval = dsp5680xx_convert_address(&address, &pmem);
err_check_propagate(retval);
+ context.flush = 0;
+ int counter = FLUSH_COUNT_READ_WRITE;
+
for (unsigned i=0; i<count; i++){
+ if(--counter==0){
+ context.flush = 1;
+ counter = FLUSH_COUNT_FLASH;
+ }
switch (size){
case 1:
if(!(i%2)){
break;
}
err_check_propagate(retval);
+ context.flush = 0;
}
+
+ context.flush = 1;
+ retval = dsp5680xx_execute_queue();
+ err_check_propagate(retval);
+
return retval;
}
return ERROR_FAIL;
}
-// Writes to pram at address
-// r3 holds the destination address-> p:(r3)
-// r2 hold 0xf151 to flash a led (probably cannot see it due to high freq.)
-// r0 holds TX/RX address.
-//0x00000073 0x8A44FFFE017B brclr #1,X:(R0-2),*-2
-//0x00000076 0xE700 nop
-//0x00000077 0xF514 move.w X:(R0),Y0
-//0x00000078 0xE700 nop
-//0x00000079 0x8563 move.w Y0,P:(R3)+
-//0x0000007A 0x84420003 bfchg #3,X:(R2)
-//0x0000007C 0xA976 bra *-9
-uint16_t pgm_write_pram[] = {0x8A44,0xFFFE,0x017D,0xE700,0xF514,0xE700,0x8563,0x8442,0x0003,0xA976};
-uint16_t pgm_write_pram_length = 10;
-
static int dsp5680xx_write_buffer(struct target * target, uint32_t address, uint32_t size, const uint8_t * buffer){
- // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
- // this solution works, but it's slow. it flushes USB all the time.
+ if(target->state != TARGET_HALTED){
+ LOG_USER("Target must be halted.");
+ return ERROR_OK;
+ }
return dsp5680xx_write(target, address, 1, size, buffer);
- // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
}
static int dsp5680xx_read_buffer(struct target * target, uint32_t address, uint32_t size, uint8_t * buffer){
LOG_USER("Target must be halted.");
return ERROR_OK;
}
- // byte addressing!
- int retval = ERROR_OK;
- int pmem = 1;
- uint16_t tmp_wrd= 0;
-
- retval = dsp5680xx_convert_address(&address, &pmem);
- err_check_propagate(retval);
-
- for (unsigned i=0; i<size; i++)
- if(!(i%2)){
- retval = dsp5680xx_read_16_single(target, address + i/2, &tmp_wrd, pmem);
- err_check_propagate(retval);
- //TODO find a better solution. endiannes differs from normal read, otherwise the openocd crc would do weird stuff.
- buffer[i+1] = (uint8_t) (tmp_wrd>>8);
- buffer[i] = (uint8_t) (tmp_wrd&0xff);
- }
- return retval;
+ // read_buffer is called when the verify_image command is executed.
+ // The "/2" solves the byte/word addressing issue.
+ return dsp5680xx_read(target,address,2,size/2,buffer);
}
static int dsp5680xx_checksum_memory(struct target * target, uint32_t address, uint32_t size, uint32_t * checksum){
- //TODO implement.
- //This will make openocd do the work, but it will fail because of the word/byte addressing issues.
- int retval;
- struct working_area * crc_algorithm;
- retval = target_alloc_working_area(target, 20, &crc_algorithm);
- if(retval != ERROR_OK)
- return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
- retval = target_free_working_area(target, crc_algorithm);
- return ERROR_FAIL;
+ return ERROR_FAIL;// This will make OpenOCD do the read out the data and verify it.
}
// Data signature algorithm used by the core FM (flash module)
err_check(retval,"FM execute command failed.");
}
}while (!(i&0x40)); // wait until current command is complete
+
+ context.flush = 0;
+
retval = eonce_move_value_at_r2_disp(target,0x00,HFM_CNFG); // write to HFM_CNFG (lock=0, select bank) -- flash_desc.bank&0x03,0x01 == 0x00,0x01 ???
err_check_propagate(retval);
retval = eonce_move_value_at_r2_disp(target,0x04,HFM_USTAT); // write to HMF_USTAT, clear PVIOL, ACCERR & BLANK bits
err_check_propagate(retval);
retval = eonce_move_value_at_r2_disp(target,0x80,HFM_USTAT); // start the command
err_check_propagate(retval);
+
+ context.flush = 1;
+ retval = dsp5680xx_execute_queue();
+ err_check_propagate(retval);
+
watchdog = 100;
do{
retval = eonce_move_at_r2_disp_to_y0(target,HFM_USTAT); // read HMF_USTAT
}
}while (!(i&0x40)); // wait until the command is complete
*hfm_ustat = i;
+ if (i&HFM_USTAT_MASK_PVIOL_ACCER){
+ retval = ERROR_TARGET_FAILURE;
+ err_check(retval,"pviol and/or accer bits set. HFM command execution error");
+ }
return ERROR_OK;
}
}
retval = dsp5680xx_f_execute_command(target,HFM_CALCULATE_DATA_SIGNATURE,address,words,&hfm_ustat,1);
err_check_propagate(retval);
- if (hfm_ustat&HFM_USTAT_MASK_PVIOL_ACCER){
- retval = ERROR_TARGET_FAILURE;
- err_check(retval,"HFM exec error:pviol and/or accer bits set.");
- }
retval = dsp5680xx_read_16_single(target, HFM_BASE_ADDR|HFM_DATA, signature, 0);
return retval;
}
// Check if chip is already erased.
retval = dsp5680xx_f_execute_command(target,HFM_ERASE_VERIFY,HFM_FLASH_BASE_ADDR+sector*HFM_SECTOR_SIZE/2,0,&hfm_ustat,1); // blank check
err_check_propagate(retval);
- if (hfm_ustat&HFM_USTAT_MASK_PVIOL_ACCER){
- retval = ERROR_TARGET_FAILURE;
- err_check(retval,"pviol and/or accer bits set. EraseVerify HFM command execution error");;
- }
if(erased!=NULL)
*erased = (uint8_t)(hfm_ustat&HFM_USTAT_MASK_BLANK);
return retval;