⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arm7tdmi.c

📁 ARM的Flash烧写程序代码
💻 C
字号:
//------------------------------------------------------------------------------// 拳老疙   : arm7tdmi.c// 橇肺璃飘 : jflash-s3c44b0x// 汲  疙   : jflash-s3c44b0x 狼 ARM7TDMI 贸府 风凭捞促. // // 盔历磊   : 蜡康芒 (林)力捞村叼矩萍 frog@falinux.com// 盔历磊 	: ATMEL Co, LTD - flash uploader// 盔历磊 	: (c) R.Longo - tp_003.c// 荐沥		: 辣傣硅 (林)硅崔沥焊烹脚 dadpeat@naver.com// 荐沥老	: 2003 斥 9岿 7老// 盔历累鼻 : (林)力捞村叼矩萍 //            捞 橇肺弊伐 筋胶狼 俺累 棺 犁 硅器甫 倾侩 钦聪促.//            俺累等 橇肺弊伐狼 惑诀利 捞侩档 倾侩 钦聪促. //            俺累等 橇肺弊伐狼 傍俺绰 鞘夸窍促搁 窍瘤 臼酒档 邓聪促. // 犁历累鼻 : GPL俊 蝶抚聪促.// 林  狼   : //------------------------------------------------------------------------------//******************************************************************************//// 庆歹 沥狼////******************************************************************************
#include <stdio.h>#include <stdlib.h>#include <asm/io.h>#include <unistd.h>#include <string.h>#include <memory.h>

#include	"jtag.h"
#include	"arm7tdmi.h"

//* Define Watchdog
#define WATCHDOG	100

#define	ADD_WAIT_STATE	16

//*----------------------------------------------------------------------------
//* Function Name       : JTAG_Select_Scan_Chain
//* Object              : Select the Scan Chain
//* Input Parameters    : sc
//* Output Parameters   : none
//* Functions called    : JTAG_Shift_ir, JTAG_Shift_dr_4_bits
//*----------------------------------------------------------------------------
void JTAG_Select_Scan_Chain(unsigned int sc)
{

	//* Shift SCAN_N instruction
	JTAG_Shift_ir(SCAN_N, NO_IDLE);

	//* Shift the number of the scan chain
	JTAG_Shift_dr_4_bits(sc);

	//* Shift INTEST instruction
	JTAG_Shift_ir(INTEST, NO_IDLE);

}

//*----------------------------------------------------------------------------
//* Function Name       : JTAG_Read_Debug_Status
//* Object              : Read the Debug Status register of the ICEBreaker 
//* 					  Module
//* Input Parameters    : none
//* Output Parameters   : none
//* Functions called    : JTAG_Select_Scan_Chain, JTAG_Read_ICEBreaker
//*----------------------------------------------------------------------------
unsigned int JTAG_Read_Debug_Status(void)
{
	
	unsigned int value;
	
	//* Select ICEBreaker Scan Chain
	JTAG_Select_Scan_Chain(ICE_BREAKER);
	
	//* Read the Debug Status register
	JTAG_Read_Bkru(ICE_DBG_STS, &value);

	return (value & ICE_DBG_STS_MASK);
}

//*----------------------------------------------------------------------------
//* Function Name       : JTAG_Test_Is_Breaked
//* Object              : Test if the core is in debug mode 
//* Input Parameters    : value max of the watchdog
//* Output Parameters   : none
//* Functions called    : JTAG_Select_Scan_Chain, JTAG_Read_ICEBreaker
//*----------------------------------------------------------------------------
unsigned int JTAG_Test_Is_Breaked(unsigned int value)
{
	unsigned int temp;
	unsigned int watchdog = 0;

	//* Polling of the bits DBGACK and nMREQ 	
	while ((watchdog < value) && ((JTAG_Read_Debug_Status() & READ_DEBUG_STATUS_MASK)
			!= READ_DEBUG_STATUS_MASK))
	{
		watchdog++;
	}
	
	//* Test if the core is breaked
	if (watchdog < value)
	{
		return TRUE;	
	}
	else 
	{
		return FALSE;
	}
}

void JTAG_Write_Memory(unsigned int address, unsigned int value, unsigned int halfword)
{
	
	unsigned int null;

	JTAG_Select_Scan_Chain(DEBUG);

    JTAG_Step(LDMIA_R0_R0_R1, &null);

	JTAG_Step(NOP, &null);

	JTAG_Step(NOP, &null);

	JTAG_Step(address, &null);

	JTAG_Step(value, &null);
	
	JTAG_Step(NOP, &null);

	JTAG_Step(NOP, &null);

	JTAG_Step(NOP, &null);

    JTAG_Step_System_Speed(NOP);

	if(halfword)
	{
		JTAG_Step(WRITE_MEM_HALFWORD, &null);
	}
	else
	{
		JTAG_Step(WRITE_MEM, &null);
	}

	JTAG_Step(NOP, &null);

	JTAG_Shift_ir(RESTART, IDLE);	//* Shift RESTART instruction	

	for(null = 0; null < ADD_WAIT_STATE; null++);	
	
}

void JTAG_Read_Memory(unsigned int address, unsigned int *value, unsigned int halfword)
{

	unsigned int null;

	
	JTAG_Select_Scan_Chain(DEBUG);

    JTAG_Step(WRITE_REG, &null);

	JTAG_Step(NOP, &null);

	JTAG_Step(NOP, &null);

	JTAG_Step(address, &null);
	
	JTAG_Step(NOP, &null);

	JTAG_Step(NOP, &null);

	JTAG_Step(NOP, &null);

    JTAG_Step_System_Speed(NOP);

	if(halfword)
	{
		JTAG_Step(READ_MEM_HALFWORD, &null);
	}
	else
	{
		JTAG_Step(READ_MEM, &null);
	}

	JTAG_Shift_ir(RESTART, IDLE);	//* Shift RESTART instruction	
	
	for(null = 0; null < ADD_WAIT_STATE; null++);	
	
	JTAG_Select_Scan_Chain(DEBUG);

    JTAG_Step(READ_REG|(R1<<12), &null);

	JTAG_Step(NOP, &null);

	JTAG_Step(NOP, &null);

	JTAG_Step(NOP, value);

	JTAG_Step(NOP, &null);

	JTAG_Step(NOP, &null);
}


//*----------------------------------------------------------------------------
//* Function Name       : JTAG_Stop
//* Object              : Stop the core and put it in debug mode
//* Input Parameters    : none
//* Output Parameters   : none
//* Functions called    : JTAG_Write_ICEBreaker
//*----------------------------------------------------------------------------
unsigned int JTAG_Stop(void)
{
	unsigned int null;

	JTAG_Write_ICEBreaker(ICE_WTP0_ADDR_VAL, 0x00000000);
	JTAG_Write_ICEBreaker(ICE_WTP0_ADDR_MASK, 0xFFFFFFFF);	
	
	// Set a break on all data activity
	JTAG_Write_ICEBreaker(ICE_WTP0_DATA_VAL, 0x00000000);
	JTAG_Write_ICEBreaker(ICE_WTP0_DATA_MASK, 0xFFFFFFFF);

	// Set the Control registers
	JTAG_Write_ICEBreaker(ICE_WTP0_CTRL_VAL, 0x00000100);	// Enable bit
	JTAG_Write_ICEBreaker(ICE_WTP0_CTRL_MASK, 0xFFFFFFF7);  
	
		
	//* Polling of the bits DBGACK and nMREQ 	
	if (JTAG_Test_Is_Breaked(WATCHDOG) == TRUE)
	{
		printf("  The ARM is in debug mode\n");
		printf("  The value in the debug status register is 0x%08X \n", JTAG_Read_Debug_Status());
		
		//* Set the Control registers
		JTAG_Write_ICEBreaker(ICE_WTP0_CTRL_VAL, 0x00000000);	// Enable bit
	}	
	else
	{
		printf("  The core is NOT stopped !!!\n");
		return(FALSE);	
	}

	return(TRUE);

}

//*----------------------------------------------------------------------------
//* Function Name       : JTAG_Write_ICEBreaker
//* Object              : Write a data in the register specified by the address
//* Input Parameters    : address, data
//* Output Parameters   : none
//* Functions called    : JTAG_Select_Scan_Chain, JTAG_Write_Bkru
//*----------------------------------------------------------------------------
void JTAG_Write_ICEBreaker(unsigned int address, unsigned int data)
{

	//* Select ICE Breaker Scan Chain
	JTAG_Select_Scan_Chain(ICE_BREAKER);

	//* Write data in the specified register
	JTAG_Write_Bkru(address, data);

}

//*----------------------------------------------------------------------------
//* Function Name       : JTAG_Read_ICEBreaker
//* Object              : Read a data in the register specified by the address
//* Input Parameters    : address, data
//* Output Parameters   : none
//* Functions called    : JTAG_Select_Scan_Chain, JTAG_Write_Bkru
//*----------------------------------------------------------------------------
void JTAG_Read_ICEBreaker(unsigned int address, unsigned int *data)
{

	//* Select ICE Breaker Scan Chain
	JTAG_Select_Scan_Chain(ICE_BREAKER);

	//* Write data in the specified register
	JTAG_Read_Bkru(address, data);

}

//*----------------------------------------------------------------------------
//* Function Name       : Read_ID_Code
//* Object              : read the ID Code of the core
//* Input Parameters    : none
//* Output Parameters   : TRUE
//* Functions called    : at91_pio_open, at91_pio_write
//*----------------------------------------------------------------------------
unsigned int Read_ID_Code(void)
{

	unsigned int code;
	
   	//* Reset the TAP controller
   	JTAG_Reset();
   	//* Shift IDCode instruction
   	JTAG_Shift_ir(IDCODE, NO_IDLE);
   	//* Get the ID code of the target
   	JTAG_IDCode(&code);
	printf("  The target's ID code is : 0x%08X\n", code);
   	if(code == CORE_IDCODE) return(TRUE);
   	else return(FALSE);
}

//*----------------------------------------------------------------------------
//* Function Name       : Reset
//* Object              : Reset the JTAG
//* Input Parameters    : none
//* Output Parameters   : none
//* Functions called    : JTAG_Reset
//*----------------------------------------------------------------------------
void Reset(void)
{
	
	JTAG_Reset();

	printf("  The value in the debug status register is 0x%08X \n", JTAG_Read_Debug_Status());
   	
}


void JTAG_Go(unsigned int *context)
{
	unsigned int i, null;

	JTAG_Select_Scan_Chain(DEBUG);

    JTAG_Step(0xE89EFFFF, &null);

	JTAG_Step(NOP, &null);

	JTAG_Step(NOP, &null);
	
	for(i = 0; i < 16; i++)	JTAG_Step(context[i], &null);
	
	JTAG_Step(NOP, &null);

	JTAG_Step(NOP, &null);

    JTAG_Step_System_Speed(NOP);

    JTAG_Step(BRANCH_PC, &null);

	JTAG_Shift_ir(RESTART, IDLE);	//* Shift RESTART instruction	

	for(null = 0; null < ADD_WAIT_STATE; null++);	
	
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -