#include "main.h" #include "smpc.h" /**********************************************************/ const int HZ = 1000000; void reset_timer(void) { REG16(0x25807008) = 0; } u32 get_timer(void) { u32 high1, high2, low; u32 timer; high1 = REG16(0x25807008); low = REG16(0x2580700a); high2 = REG16(0x25807008); if(high1!=high2){ low = REG16(0x2580700a); } timer = (high2<<16) | low; return timer; } void usleep(u32 us) { u32 now, end; if(us==0) us = 1; end = us*(HZ/1000000); reset_timer(); while(1){ now = get_timer(); if(now>=end) break; } } void msleep(u32 ms) { u32 now, end; if(ms==0) ms = 1; end = ms*(HZ/1000); reset_timer(); while(1){ now = get_timer(); if(now>=end) break; } } /**********************************************************/ void sci_init(void) { SCR = 0x00; /* set TE,RE to 0 */ SMR = 0x00; /* set SMR to 8n1 async mode */ BRR = 0x15; /* set BRR to 9600 bps */ SCR = 0xcd; /* set TIE RIE MPIE TEIE CKE1 CKE0 */ SCR = 0x31; /* set TE RE to 1 */ printk_putc = sci_putc; } void sci_putc(int ch) { while((SSR&0x80)==0); TDR = ch; SSR &= 0x7f; } int sci_getc(int timeout) { int ch; timeout *= 1500; while(timeout){ if(SSR&0x40){ ch = RDR; SSR &= 0xbf; return ch; } timeout -= 1; } return -1; } /**********************************************************/ int gets(char *buf, int len) { int n, ch; printk("rboot> "); n = 0; while(1){ while((ch=sci_getc(10))<0); if(ch==0x0d) break; printk("%c", ch); buf[n] = ch; n++; if(n==len) break; } printk("\n"); buf[n] = 0; return n; } int parse_arg(char *str, char *argv[]) { int n; n = 0; while(1){ while(*str==0x20) str++; if(*str==0) break; argv[n] = str; n++; while(*str!=' ' && *str!=0) str++; if(*str==0) break; *str = 0; str++; } return n; } /**********************************************************/ unsigned int dump_address; int mem_width = 1; void dump(int argc, char *argv[]) { int i, address, len; if(argc==1){ address = dump_address; len = 256; }else{ address = strtoul(argv[1], 0, 0, 0); } if(argc==3){ len = strtoul(argv[2], 0, 0, 0); }else{ len = 256; } if(argv[0][1]=='b') mem_width = 1; else if(argv[0][1]=='w') mem_width = 2; else if(argv[0][1]=='d') mem_width = 4; for(i=0; i %02x\n", address, (unsigned char)data); }else if(mem_width==2){ *(volatile unsigned short*)(address) = (unsigned short)data; printk("%08X -> %04x\n", address, (unsigned short)data); }else if(mem_width==4){ *(volatile unsigned int*)(address) = (unsigned int)data; printk("%08X -> %08x\n", address, (unsigned int)data); } dump_address = address; } void command_go(int go_addr) { void (*go)(void); go = (void*)go_addr; printk("Jump to %08x ...\n", go); msleep(1000); go(); } void mem_dump(char *str, void *addr, int size) { int i, j; if(str){ printk("%s:\n", str); } for(i=0; i