📄 jtag.h
字号:
// jtag.h: interface for the jtag class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_JTAG_H__FF9AF16B_35A2_45B7_8CC4_0AF96A5187FB__INCLUDED_)
#define AFX_JTAG_H__FF9AF16B_35A2_45B7_8CC4_0AF96A5187FB__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "C8051.h"
#include "stdafx.h"
class jtag
{
// Construction
public:
jtag();
//电缆型号;
int m_iCcabletype;
//获得数据端口地址
WORD m_nPort;
//FLASHCON 的最高位,=1 说明读取高的128字节,否则读取flash
unsigned char ucFCONBIT7;
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(jtag)
//}}AFX_VIRTUAL
// Implementation
public:
//选择CPU型号
int SelectCPU(unsigned int uiCouType);
void ResetCpu();
//得到CPU ID 号
unsigned long JtagGetIDCode();
//设置电缆
unsigned char CableSetup(unsigned char ucCabtype);
//------------------------------------------------------------------------------------
// JTAG_Reset
//------------------------------------------------------------------------------------
// This routine places the JTAG state machine on the target system in
// the Test Logic Reset state by strobing TCK 5 times while leaving
// TMS high. Leaves the JTAG state machine in the Run_Test/Idle state.
void JTAG_Reset (void);
virtual ~jtag();
// Generated message map functions
//------------------------------------------------------------------------------------
// FLASH_ByteRead
//------------------------------------------------------------------------------------
// This routine reads the byte at <addr> and stores it at the address pointed to by
// <pdat>.
// Returns TRUE if the operation was successful; FALSE otherwise (page read-protected).
int FLASH_ByteRead (unsigned long addr, unsigned char *pdat);
//------------------------------------------------------------------------------------
// FLASH_PageErase
//------------------------------------------------------------------------------------
// This routine performs an erase of the page in which <addr> is contained.
// This routine assumes that no FLASH operations are currently in progress.
// This routine exits with no FLASH operations currently in progress.
// Returns TRUE if the operation was successful; FALSE otherwise (page protected).
int FLASH_PageErase (unsigned long addr);
//------------------------------------------------------------------------------------
// FLASH_ByteWrite
//------------------------------------------------------------------------------------
// This routine writes the data <dat> to FLASH at the address <addr>.
// Returns TRUE if the operation was successful; FALSE otherwise (page
// write-protected).
int FLASH_ByteWrite (unsigned long addr, unsigned char dat);
//------------------------------------------------------------------------------------
// JTAG_IRead
//------------------------------------------------------------------------------------
// This routine performs an indirect read of register <ireg>, of <num_bits> in length.
// It follows the read operation with a polling operation, and returns when the
// operation is completed. Note: the polling implemented here refers to the JTAG
// register read operation being completed, NOT the FLASH read operation.
// Polling for the FLASH read operation is handled at a higher level.
// Examples of valid indirect registers are:
// FLCN - FLASH Control
// FLSC - FLASH Scale
// FLA - FLASH Address
// FLD - FLASH Data
// Leaves in the Run_Test/Idle state.
unsigned long JTAG_IRead (unsigned int ireg, int num_bits);
//------------------------------------------------------------------------------------
// JTAG_IWrite
//------------------------------------------------------------------------------------
// This routine performs an indirect write to register <ireg>, containing <dat>, of
// <num_bits> in length. It follows the write operation with a polling operation, and
// returns when the operation is completed. Note: the polling implemented here refers
// to the JTAG register write operation being completed, NOT the FLASH write operation.
// Polling for the FLASH write operation is handled at a higher level
// Examples of valid indirect registers are:
// FLCN - FLASH Control
// FLSC - FLASH Scale
// FLA - FLASH Address
// FLD - FLASH Data
// Leaves in the Run_Test/Idle state.
void JTAG_IWrite (unsigned int ireg, unsigned long dat, int num_bits);
//{{AFX_MSG(jtag)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
protected:
//返回TDO引脚的信息
bool TDO(void);
//TDI引脚波形发生函数
void TDI(bool bValue);
//TCK函数,生成TCK,参数为TCK的高 or 低
void TCK(bool bValue);
//TMS函数.生产TMS信号
void TMS(bool bValue);
//TCK引脚;对PC而言,输出引脚D0-D7;以下输入输出均对于PC
WORD m_woTCKPin;
//TMS引脚;输出
WORD m_woTMSPin;
//TDI引脚;输出
WORD m_woTDIPin;
//TDO 引脚;输入
WORD m_wiTDOPin;
//TDO引脚所在的基地址偏移量
int m_iTDOAddP;
//获得要写入数据端口的值WriteValue,数据口(DB25)(数据范围为0~255)
unsigned char m_ucWriteValue;
//TDO引脚输出是否颠倒;
bool b_TDONoInv;
int FLCN_LEN; // 8 // number of bits in FLASHCON
int FLD_RDLEN; //10 // number of bits in an FLASHDAT read
int FLD_WRLEN; //8 // number of bits in an FLASHDAT write
int FLA_LEN ; //16 // number of bits in FLASHADR
int FLSC_LEN; //8 // number of bits in FLASHSCL
private:
//------------------------------------------------------------------------------------
// JTAG_StrobeTCK
//------------------------------------------------------------------------------------
// This routine strobes the TCK pin (brings high then back low again)
// on the target system.
void JTAG_StrobeTCK(void);
//------------------------------------------------------------------------------------
// JTAG_DR_Scan
//------------------------------------------------------------------------------------
// This routine shifts <num_bits> of <data> into the Data Register, and returns
// up to 32-bits of data read from the Data Register.
// Leaves in the Run_Test/Idle state.
// Assumes the JTAG state machine starts in the Run_Test/Idle state.
unsigned long JTAG_DR_Scan (unsigned long dat, int num_bits);
//------------------------------------------------------------------------------------
// JTAG_IR_Scan
//------------------------------------------------------------------------------------
// This routine loads the supplied <instruction> of <num_bits> length into the JTAG
// Instruction Register on the target system. Leaves in the Run_Test/Idle state.
// The return value is the n-bit value read from the IR.
// Assumes the JTAG state machine starts in the Run_Test/Idle state.
unsigned int JTAG_IR_Scan (unsigned int instruction, int num_bits);
};
#endif // !defined(AFX_JTAG_H__FF9AF16B_35A2_45B7_8CC4_0AF96A5187FB__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -