📄 cmd_processing.c
字号:
case CMD_WRITE_MEM32: /* write a double-word to memory; parameter 32bit address & a 32-bit value to be written to the address */
bdmcf_tx_msg(BDMCF_CMD_WRITE32); /* send the command */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+2))); /* the address */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+4)));
bdmcf_tx_msg(*((unsigned int *)(command_buffer+6))); /* and the data to be written */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+8)));
#ifdef CMD_COMPLETE_CHECK
if (bdmcf_complete_chk_rx()) break;
#endif
return(1);
case CMD_READ_MEMBLOCK8: /* reads a block of bytes; parameter 32bit address; the number of bytes to read is given by command_size (the number of bytes requested by the host -1) */
{
unsigned char i;
unsigned char *ptr;
bdmcf_tx_msg(BDMCF_CMD_READ8); /* send read byte command */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+2))); /* and the address */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+4)));
i=command_size;
ptr=command_buffer+1; /* where first result should go */
do {
i--; /* decrement the number of bytes to read */
if (i) {
if (bdmcf_rxtx(1,ptr,BDMCF_CMD_DUMP8)) break; /* get the result & send in new DUMP command */
} else {
if (bdmcf_rx(1,ptr)) { /* read the result (and send NOP) */
i=1; /* make i non-zero */
break;
}
}
*(ptr)=*(ptr+1); /* the byte is LSB of the received word, copy it to the right place */
ptr++;
} while(i);
if (i) break; /* an error has occured */
return(command_size+1);
}
case CMD_READ_MEMBLOCK16: /* reads a block of words; parameter 32bit address; the number of bytes to read is given by command_size (the number of bytes requested by the host -1) */
{
unsigned char i;
unsigned char *ptr;
bdmcf_tx_msg(BDMCF_CMD_READ16); /* send read byte command */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+2))); /* and the address */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+4)));
i=(command_size>>1); /* the number of words is the bytecount/2 */
ptr=command_buffer+1; /* where first result should go */
do {
i--; /* decrement the number of bytes to read */
if (i) {
if (bdmcf_rxtx(1,ptr,BDMCF_CMD_DUMP16)) break; /* get the result & send in new DUMP command */
} else {
if (bdmcf_rx(1,ptr)) { /* read the result (and send NOP) */
i=1; /* make i non-zero */
break;
}
}
ptr+=2;
} while(i);
if (i) break; /* an error has occured */
return(command_size+1);
}
case CMD_READ_MEMBLOCK32: /* reads a block of dwords; parameter 32bit address; the number of bytes to read is given by command_size (the number of bytes requested by the host -1) */
{
unsigned char i;
unsigned char *ptr;
bdmcf_tx_msg(BDMCF_CMD_READ32); /* send read byte command */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+2))); /* and the address */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+4)));
i=(command_size>>2); /* the number of dwords is the bytecount/4 */
ptr=command_buffer+1; /* where first result should go */
do {
i--; /* decrement the number of bytes to read */
if (i) {
if (bdmcf_rxtx(2,ptr,BDMCF_CMD_DUMP32)) break; /* get the result & send in new DUMP command */
} else {
if (bdmcf_rx(2,ptr)) { /* read the result (and send NOP) */
i=1; /* make i non-zero */
break;
}
}
ptr+=4;
} while(i);
if (i) break; /* an error has occured */
return(command_size+1);
}
case CMD_WRITE_MEMBLOCK8: /* writes a block of words; parameters 32bit address & data to write; the number of bytes to write is given by command_size */
{
unsigned char i;
unsigned char *ptr;
bdmcf_tx_msg(BDMCF_CMD_WRITE8); /* send write byte command */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+2))); /* the address */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+4)));
bdmcf_tx_msg(*(command_buffer+6)); /* and the data */
i=command_size-4-1; /* the address has 4 bytes & done 1 byte already */
ptr=command_buffer+7;
while(i) {
if (bdmcf_complete_chk(BDMCF_CMD_FILL8)) break; /* send write byte command */
bdmcf_tx_msg(*ptr); /* and the data */
ptr++;
i--;
}
if (i) break; /* an error has occured */
#ifdef CMD_COMPLETE_CHECK
if (bdmcf_complete_chk_rx()) break;
#endif
return(1);
}
case CMD_WRITE_MEMBLOCK16: /* writes a block of words; parameters 32bit address & data to write; the number of bytes to write is given by command_size */
{
unsigned char i;
unsigned char *ptr;
bdmcf_tx_msg(BDMCF_CMD_WRITE16); /* send write byte command */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+2))); /* the address */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+4)));
bdmcf_tx_msg(*((unsigned int *)(command_buffer+6))); /* and the data */
i=(command_size-4-2)>>1; /* the address has 4 bytes & done 1 word already, every word has 2 bytes */
ptr=command_buffer+8;
while(i) {
if (bdmcf_complete_chk(BDMCF_CMD_FILL16)) break; /* send write word command */
bdmcf_tx_msg(*(unsigned int *)ptr); /* and the data */
ptr+=2;
i--;
}
if (i) break; /* an error has occured */
#ifdef CMD_COMPLETE_CHECK
if (bdmcf_complete_chk_rx()) break;
#endif
return(1);
}
case CMD_WRITE_MEMBLOCK32: /* writes a block of dwords; parameters 32bit address & data to write; the number of bytes to write is given by command_size */
{
unsigned char i;
unsigned char *ptr;
bdmcf_tx_msg(BDMCF_CMD_WRITE32); /* send write byte command */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+2))); /* the address */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+4)));
bdmcf_tx_msg(*((unsigned int *)(command_buffer+6))); /* and the data */
bdmcf_tx_msg(*((unsigned int *)(command_buffer+8)));
i=(command_size-4-4)>>2; /* the address has 4 bytes & done 1 dword already, every dword has 4 bytes */
ptr=command_buffer+10;
while(i) {
if (bdmcf_complete_chk(BDMCF_CMD_FILL32)) break; /* send write dword command */
bdmcf_tx_msg(*(unsigned int *)(ptr+0)); /* and the data */
bdmcf_tx_msg(*(unsigned int *)(ptr+2));
ptr+=4;
i--;
}
if (i) break; /* an error has occured */
#ifdef CMD_COMPLETE_CHECK
if (bdmcf_complete_chk_rx()) break;
#endif
return(1);
}
case CMD_RESYNCHRONIZE: /* resync communication with the target MCU */
if (bdmcf_resync()) break; /* try to resynchronize */
return(1);
case CMD_ASSERT_TA: /* assert the TA signal, parameter: 8-bit number of 10us ticks - duration of the TA assertion */
bdmcf_ta(command_buffer[2]);
return(1);
default: /* unknown command */
command_buffer[0] = CMD_UNKNOWN;
return(1);
}
bdmcf_complete_chk_rx(); /* send at least 2 nops to purge the BDM of the offending command */
bdmcf_complete_chk_rx();
} else if (cable_status.target_type==JTAG) {
switch (command_buffer[1]) {
case CMD_JTAG_GOTORESET: /* no parameters, takes the TAP to TEST-LOGIC-RESET state, re-select the JTAG target to take TAP back to RUN-TEST/IDLE */
jtag_transition_reset();
return(1);
case CMD_JTAG_GOTOSHIFT: /* parameters 8-bit path option; path option ==0 : go to SHIFT-DR, !=0 : go to SHIFT-IR (requires the tap to be in RUN-TEST/IDLE) */
jtag_transition_shift(command_buffer[2]);
return(1);
case CMD_JTAG_WRITE: /* parameters 8-bit exit option, 8-bit count of bits to shift in, and the data to be shifted in (shifted in LSB (last byte) first, unused bits (if any) are in the MSB (first) byte; exit option ==0 : stay in SHIFT-xx, !=0 : go to RUN-TEST/IDLE when finished */
jtag_write(command_buffer[2], command_buffer[3], command_buffer+4);
return(1);
case CMD_JTAG_READ: /* parameters 8-bit exit option, 8-bit count of bits to shift out; exit option ==0 : stay in SHIFT-xx, !=0 : go to RUN-TEST/IDLE when finished, returns the data read out of the device (first bit in LSB of the last byte in the buffer) */
{
unsigned char i;
i=command_buffer[3]>>3; /* calculate the number of bytes to return */
if ((command_buffer[3]&0x07)==0) i++;
jtag_read(command_buffer[2], command_buffer[3], command_buffer+1);
return(i+1);
}
default: /* unknown command */
command_buffer[0] = CMD_UNKNOWN;
return(1);
}
} else {
command_buffer[0] = CMD_UNKNOWN;
return(1);
}
}
command_buffer[0] = CMD_FAILED; /* if any of the case statements falls through, the command has failed */
return(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -