?? arm7tdmi.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 + -