|
在我的代码中,.c文件中不出现任何寄存器。
截取一段JTAG操作的底层函数: RAMFUNC uint16 JTAG_TAP_HS_Operate(uint16 tdi, uint16 tms) { JTAG_TAP_HS_Out(tms, tdi);
JTAG_TAP_HS_WaitRxReady();
return JTAG_TAP_HS_In(); }
RAMFUNC uint16 JTAG_TAP_HS_Operate_Asyn(uint16 tdi, uint16 tms) { uint16 tdo;
JTAG_TAP_HS_WaitRxReady(); tdo = JTAG_TAP_HS_In();
JTAG_TAP_HS_Out(tms, tdi);
return tdo; }
RAMFUNC void JTAG_TAP_HS_RW(uint8 *tdo, uint8 *tdi, uint8 tms_before, uint8 tms_after0, uint8 tms_after1, uint16 dat_byte_len) { uint8 tdo_tmp; uint16 ret_len = 0, cur_pos = 0;
if(dat_byte_len & 0x8000) { JTAG_TAP_HS_Operate_Asyn(tdi[cur_pos++], tms_before); ret_len++; dat_byte_len &= 0x7FFF; dat_byte_len--; }
JTAG_TAP_DR_IR_PREPARE_DLY(); dat_byte_len--; while(dat_byte_len-- > 0) { tdo_tmp = JTAG_TAP_HS_Operate_Asyn(tdi[cur_pos++], 0); if(ret_len > 0) { tdo[ret_len - 1] = tdo_tmp; } ret_len++; } tdo_tmp = JTAG_TAP_HS_Operate_Asyn(tdi[cur_pos], tms_after0); if(ret_len > 0) { tdo[ret_len - 1] = tdo_tmp; } tdo_tmp = JTAG_TAP_HS_Operate_Asyn(0, tms_after1); tdo[ret_len] = tdo_tmp; }
其中,很多都是宏定义,在app_cfg.h中: #define JTAG_TAP_HS_SPI_M SPI2 #define JTAG_TAP_HS_SPI_S SPI1 #define JTAG_TAP_HS_MPORT GPIOB #define JTAG_TAP_HS_MPINS (GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15) #define JTAG_TAP_HS_SPORT GPIOB #define JTAG_TAP_HS_SPINS (GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5)
#define JTAG_TAP_HS_PortInit() do{ GPIO_Dir(JTAG_TAP_HS_MPORT, GPIO_Mode_AF_PP, JTAG_TAP_HS_MPINS); GPIO_Dir(JTAG_TAP_HS_SPORT, GPIO_Mode_AF_PP, JTAG_TAP_HS_SPINS); }while(0) #define JTAG_TAP_HS_PortFini() do{ GPIO_Dir(JTAG_TAP_HS_MPORT, GPIO_Mode_IN_FLOATING, JTAG_TAP_HS_MPINS); GPIO_Dir(JTAG_TAP_HS_SPORT, GPIO_Mode_IN_FLOATING, JTAG_TAP_HS_SPINS); }while(0)
#define JTAG_TAP_HS_SetSpeed(speed) SPI_Configuration(JTAG_TAP_HS_SPI_M,SPI_Mode_Master,speed, SPI_FirstBit_LSB,SPI_CPOL_High,SPI_CPHA_2Edge)
#define JTAG_TAP_HS_Out(tms, tdi) do{JTAG_TAP_HS_SPI_S->DR = tms;JTAG_TAP_HS_SPI_M->DR = tdi;}while(0) #define JTAG_TAP_HS_In() JTAG_TAP_HS_SPI_M->DR
#define JTAG_TAP_HS_WaitTxReady() while(JTAG_TAP_HS_SPI_M->SR & SPI_I2S_FLAG_TXE) #define JTAG_TAP_HS_WaitRxReady() while(!(JTAG_TAP_HS_SPI_M->SR & SPI_I2S_FLAG_RXNE)) #define JTAG_TAP_HS_WaitReady() while(JTAG_TAP_HS_SPI_M->SR & SPI_I2S_FLAG_BSY)
这种方式,代码移植非常简单,既是不同平台。 我以前的AVRminiProg,最近移植到另外2个别人自己做的硬件上,修改的只是app_cfg.h中的宏而已。 |
|