📄 hal_diag.c
字号:
*/
#define BSP_EXC_INT 0
#define BSP_EXC_TLBMOD 1
#define BSP_EXC_TLBL 2
#define BSP_EXC_TLBS 3
#define BSP_EXC_ADEL 4
#define BSP_EXC_ADES 5
#define BSP_EXC_IBE 6
#define BSP_EXC_DBE 7
#define BSP_EXC_SYSCALL 8
#define BSP_EXC_BREAK 9
#define BSP_EXC_ILL 10
#define BSP_EXC_CPU 11
#define BSP_EXC_OV 12
#define BSP_EXC_TRAP 13
#define BSP_EXC_VCEI 14
#define BSP_EXC_FPE 15
#define BSP_EXC_RSV16 16
#define BSP_EXC_RSV17 17
#define BSP_EXC_RSV18 18
#define BSP_EXC_RSV19 19
#define BSP_EXC_RSV20 20
#define BSP_EXC_RSV21 21
#define BSP_EXC_RSV22 22
#define BSP_EXC_WATCH 23
#define BSP_EXC_RSV24 24
#define BSP_EXC_RSV25 25
#define BSP_EXC_RSV26 26
#define BSP_EXC_RSV27 27
#define BSP_EXC_RSV28 28
#define BSP_EXC_RSV29 29
#define BSP_EXC_RSV30 30
#define BSP_EXC_VCED 31
/* tx39 debug exception */
#define BSP_EXC_DEBUG 32
#define BSP_EXC_TLB 33
#define BSP_EXC_NMI 34
/*
* Hack for eCos on tx39 to set an async breakpoint.
*/
#define BSP_VEC_BP_HOOK 35
#define BSP_EXC_XTLB 36
#define BSP_EXC_CACHE 37
#define BSP_MAX_EXCEPTIONS 38
/*
* Another hack for tx39 eCos compatibility.
*/
#if defined(__CPU_R3900__)
#define BSP_VEC_MT_DEBUG 15
#else
#define BSP_VEC_MT_DEBUG 38
#endif
#define BSP_VEC_STUB_ENTRY 39
#define BSP_VEC_BSPDATA 40
#define BSP_VEC_MAGIC 41
#define BSP_VEC_IRQ_CHECK 42
#define BSP_VEC_PAD 43
#define NUM_VTAB_ENTRIES 44
#define BSP_MAGIC_VAL 0x55aa4321
#define SYS_interrupt 1000
// These vectors should be called with:
//
// k0 - Exception Number
#define CYGMON_VECTOR_TABLE_BASE 0x80000100
#define CYGMON_VECTOR_TABLE ((CYG_ADDRESS *)CYGMON_VECTOR_TABLE_BASE)
#if 0 // UNUSED
static int
hal_bsp_set_debug_comm(int arg)
{
bsp_shared_t *shared;
shared = (bsp_shared_t *)
(CYGMON_VECTOR_TABLE[ BSP_VEC_BSPDATA ]);
if (0 != shared->__set_debug_comm) {
return (*(shared->__set_debug_comm))(arg);
}
return 0;
}
static int
hal_bsp_set_console_comm(int arg)
{
bsp_shared_t *shared;
shared = (bsp_shared_t *)
(CYGMON_VECTOR_TABLE[ BSP_VEC_BSPDATA ]);
if (0 != shared->__set_console_comm) {
return (*(shared->__set_console_comm))(arg);
}
return 0;
}
#endif // 0 UNUSED
static void bsp_trap(int trap_num);
static int
hal_bsp_console_write(const void *p, int len)
{
bsp_shared_t *shared;
struct bsp_comm_procs *com;
int magic;
/*hal_bsp_set_console_comm(0);*/
/* If this is not a BSP-based CygMon, return 0 */
magic = (int)(CYGMON_VECTOR_TABLE[ BSP_VEC_MAGIC ]);
if (magic != BSP_MAGIC_VAL)
return 0;
shared = (bsp_shared_t *)
(CYGMON_VECTOR_TABLE[ BSP_VEC_BSPDATA ]);
com = shared->__console_procs;
if (0 != com) {
shared->__console_interrupt_flag = 0;
com->__write(com->ch_data, p, len);
if (shared->__console_interrupt_flag) {
/* debug interrupt; stop here */
bsp_trap(SYS_interrupt);
}
return 1;
}
return 0;
}
static void
bsp_trap(int trap_num)
{
asm("syscall\n");
}
static void
hal_dumb_serial_write(const char *p, int len)
{
int i;
for ( i = 0 ; i < len; i++ ) {
hal_diag_dumb_write_char(p[i]);
}
}
void hal_diag_write_char(char c)
{
static char line[100];
static int pos = 0;
// No need to send CRs
if( c == '\r' ) return;
line[pos++] = c;
if( c == '\n' || pos == sizeof(line) ) {
CYG_INTERRUPT_STATE old;
// Disable interrupts. This prevents GDB trying to interrupt us
// while we are in the middle of sending a packet. The serial
// receive interrupt will be seen when we re-enable interrupts
// later.
HAL_DISABLE_INTERRUPTS(old);
if ( ! hal_bsp_console_write( line, pos ) )
// then there is no function registered, just spew it out serial
hal_dumb_serial_write( line, pos );
pos = 0;
// And re-enable interrupts
HAL_RESTORE_INTERRUPTS(old);
}
}
int
hal_diag_irq_check(int vector)
{
typedef int irq_check_fn(int irq_nr);
irq_check_fn *fn = (irq_check_fn *)(CYGMON_VECTOR_TABLE[ BSP_VEC_IRQ_CHECK ]);
int magic;
/* If this is not a BSP-based CygMon, return 0 */
magic = (int)(CYGMON_VECTOR_TABLE[ BSP_VEC_MAGIC ]);
if (magic != BSP_MAGIC_VAL)
return 0;
#if defined(CYGPKG_HAL_MIPS_TX3904)
/* convert vector to BSP irq number */
if (vector == 16)
vector = 2;
else
vector += 3;
#endif
return fn(vector);
}
#endif // defined(CYG_KERNEL_DIAG_CYGMON) *only*
/*---------------------------------------------------------------------------*/
#if defined(CYGPKG_HAL_MIPS_TX39_JMR3904) && defined(CYG_KERNEL_DIAG_LCD)
/* ----------------------------------------------------------- */
#define ISA_BASE 0xA0000000
#define LCD_DATA *(volatile unsigned char*)(0x13400000+ISA_BASE)
#define LCD_CMD *(volatile unsigned char*)(0x13000000+ISA_BASE)
#define DISPCLR 0x01 /* Display Clear */
#define ECURINC 0x06 /* Cursor Increment */
#define DISPCONT 0x08 /* Display Control */
#define BLINK 0x01 /* Blink */
#define CURON 0x02 /* Cursor ON */
#define DISPON 0x04 /* Display ON */
#define INITCMD 0x38 /* Initial Command */
#define DDRAM 0x80 /* DDRAM address */
#define LCDBUSY 0x80 /* Busy */
/* ----------------------------------------------------------- */
/* */
/* JMZ-LCD202 LCD Display Unit */
/* - Sample Program (for JMR-TX3904) - */
/* */
static void readyLCD(){
while(LCD_CMD & LCDBUSY);
}
static void outLCD(unsigned char d){
readyLCD();
LCD_DATA = d;
}
static void outLCD_CMD(unsigned char d){
readyLCD();
LCD_CMD = d;
}
static void INIT_LCD(){
outLCD_CMD(INITCMD);
outLCD_CMD(DISPCONT);
outLCD_CMD(DISPCLR);
outLCD_CMD(ECURINC);
outLCD_CMD(DISPCONT|BLINK|CURON|DISPON);
}
#if 0
static void MAIN(){
int i;
static char c[]="JMZ-LCD202 LCD UNIT";
static char d[]="Display Test Sample";
INIT_LCD();
outLCD_CMD(DDRAM);
for (i=0;i<20;i++) outLCD(c[i]);
outLCD_CMD(DDRAM+0x40);
for (i=0;i<20;i++) outLCD(d[i]);
}
#endif
#define LCD_LINE0 0x00
#define LCD_LINE1 0x40
#define LCD_LINE_LENGTH 20
static char lcd_line0[LCD_LINE_LENGTH+1];
static char lcd_line1[LCD_LINE_LENGTH+1];
static char *lcd_line[2] = { lcd_line0, lcd_line1 };
static int lcd_curline = 0;
static int lcd_linepos = 0;
static void lcd_dis(int add, char *string);
void hal_diag_init()
{
int i;
//hal_diag_led(0x10);
INIT_LCD();
lcd_curline = 0;
lcd_linepos = 0;
for( i = 0; i < LCD_LINE_LENGTH; i++ )
lcd_line[0][i] = lcd_line[1][i] = ' ';
lcd_line[0][LCD_LINE_LENGTH] = lcd_line[1][LCD_LINE_LENGTH] = 0;
lcd_dis( LCD_LINE0, lcd_line[0] );
lcd_dis( LCD_LINE1, lcd_line[1] );
#if 0
{
int i;
static char c[]="JMZ-LCD202 LCD UNIT";
static char d[]="Display Test Sample";
outLCD_CMD(DDRAM);
for (i=0;i<20;i++) outLCD(c[i]);
outLCD_CMD(DDRAM+0x40);
for (i=0;i<20;i++) outLCD(d[i]);
}
#endif
//hal_diag_led(0x10);
}
/* this routine writes the string to the LCD */
/* display after setting the address to add */
static void lcd_dis(int add, char *string)
{
int i;
outLCD_CMD(DDRAM+add);
for (i=0 ; i<LCD_LINE_LENGTH ; i++) outLCD(string[i]);
}
void hal_diag_write_char( char c)
{
int i;
//hal_diag_led(0x20);
// Truncate long lines
if( lcd_linepos >= LCD_LINE_LENGTH ) return;
// ignore CR
if( c == '\r' ) return;
if( c == '\n' )
{
lcd_dis( LCD_LINE0, &lcd_line[lcd_curline^1][0] );
lcd_dis( LCD_LINE1, &lcd_line[lcd_curline][0] );
// Do a line feed
lcd_curline ^= 1;
lcd_linepos = 0;
for( i = 0; i < LCD_LINE_LENGTH; i++ )
lcd_line[lcd_curline][i] = ' ';
return;
}
lcd_line[lcd_curline][lcd_linepos++] = c;
//hal_diag_led(0x20);
}
void hal_diag_read_char(char *c)
{
//hal_diag_led(0x40);
//hal_diag_led(0x40);
}
#endif
/*---------------------------------------------------------------------------*/
/* End of hal_diag.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -