📄 jtag.c
字号:
#include <tm1/mmio.h>
/* macros */
#define MAGIC_NUMBER 0x12345678
#define SWAPPED_MAGIC 0x78563412
#define GOOD_BYE 0x00dead00
#define SWAPPED_BYE 0x00adde00
#define OFULL 0x1
#define IFULL 0x2
#define SLEEPLESS 0x4
#define JTAG_INTERRUPT_NO 18
void waitForIFullBit()
{
int bit = 0;
do {
bit = MMIO(JTAG_CTL);
/* Keep waiting until Ifull bit is set by the host side */
} while((bit & IFULL) == 0);
}
int main()
{
int data;
static int flag = 0;
MMIO(JTAG_DATA_IN) = 0;
while (1) {
if (flag == 0 ) {
flag = 1;
/* Send out the magic number to host side progam */
MMIO(JTAG_DATA_OUT) = MAGIC_NUMBER;
}
else {
flag = 0;
/* Send out the swapped magic number to host side progam */
MMIO(JTAG_DATA_OUT) = SWAPPED_MAGIC;
}
/* Set the Ofull Bit after writing to JTAG_DATA_OUT register */
/* This signals the host side that valid/readable data exists in */
/* MMIO(JTAG_DATA_OUT) register. Setting sleepless bit is always */
/* good. */
MMIO(JTAG_CTL) = (OFULL | SLEEPLESS);
/* wait for host to send data into JTAG_DATA_IN register */
/* This is signalled by host setting the MMIO(JTAG_CTL).IFullBit */
waitForIFullBit();
data = MMIO(JTAG_DATA_IN);
/* Clear the IFull bit after reading from JTAG_DATA_IN */
MMIO(JTAG_CTL) = SLEEPLESS;
if ( data == SWAPPED_MAGIC || data == MAGIC_NUMBER ) {
/* setting IFull bit results in a Pending JTAG interrupt */
/* so clear the interrupt just for good programming's sake */
MMIO(ICLEAR) = (1 << JTAG_INTERRUPT_NO);
continue;
}
else if (data == GOOD_BYE || data == SWAPPED_BYE)
break;
else {
MMIO(ICLEAR) = (1 << JTAG_INTERRUPT_NO);
return -1;
}
}
/* Doesn't matter but still clear the interrupt */
MMIO(ICLEAR) = (1 << JTAG_INTERRUPT_NO);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -