//------------------------------------------------------------------------- //------------------------------------------------------------------------- extern void PUT32 ( unsigned int, unsigned int ); extern void PUT16 ( unsigned int, unsigned int ); extern unsigned int GET32 ( unsigned int ); extern void BRANCHTO ( unsigned int ); extern void dummy ( unsigned int ); #define GPFSEL1 0x20200004 #define GPSET0 0x2020001C #define GPCLR0 0x20200028 #define GPPUD 0x20200094 #define GPPUDCLK0 0x20200098 #define AUX_ENABLES 0x20215004 #define AUX_MU_IO_REG 0x20215040 #define AUX_MU_IER_REG 0x20215044 #define AUX_MU_IIR_REG 0x20215048 #define AUX_MU_LCR_REG 0x2021504C #define AUX_MU_MCR_REG 0x20215050 #define AUX_MU_LSR_REG 0x20215054 #define AUX_MU_MSR_REG 0x20215058 #define AUX_MU_SCRATCH 0x2021505C #define AUX_MU_CNTL_REG 0x20215060 #define AUX_MU_STAT_REG 0x20215064 #define AUX_MU_BAUD_REG 0x20215068 //GPIO14 TXD0 and TXD1 //GPIO15 RXD0 and RXD1 //------------------------------------------------------------------------ unsigned int uart_recv ( void ) { while(1) { if(GET32(AUX_MU_LSR_REG)&0x01) break; } return(GET32(AUX_MU_IO_REG)&0xFF); } //------------------------------------------------------------------------ void uart_send ( unsigned int c ) { while(1) { if(GET32(AUX_MU_LSR_REG)&0x20) break; } PUT32(AUX_MU_IO_REG,c); } //------------------------------------------------------------------------ void hexstrings ( unsigned int d ) { //unsigned int ra; unsigned int rb; unsigned int rc; rb=32; while(1) { rb-=4; rc=(d>>rb)&0xF; if(rc>9) rc+=0x37; else rc+=0x30; uart_send(rc); if(rb==0) break; } uart_send(0x20); } //------------------------------------------------------------------------ void hexstring ( unsigned int d ) { hexstrings(d); uart_send(0x0D); uart_send(0x0A); } //------------------------------------------------------------------------ // Packet Format // [0] 0x7C start sync // [1] datalen // [2] ~datalen // datalen bytes: // [3] type // [4] sequence // [5] pass=0/fail!=0 // [6] // [7] // [8] payload starts // ... // datalen ends // [n-2] 0x7D end sync // [n-1] checksum //------------------------------------------------------------------------ unsigned char xstring[512]; //------------------------------------------------------------------------ int recv_packet ( void ) { unsigned int len; unsigned int ra; unsigned int rb; unsigned int rc; while(1) { ra=uart_recv(); if(ra!=0x7C) { continue; } ra=0; xstring[ra++]=0x7C; //sync xstring[ra++]=uart_recv(); //datalen xstring[ra++]=uart_recv(); //~datalen if(xstring[ra-2]!=(~xstring[ra-1]&0xFF)) { continue; } len=xstring[ra-2]; while(len--) xstring[ra++]=uart_recv(); xstring[ra++]=uart_recv(); //sync xstring[ra++]=uart_recv(); //checksum if(xstring[ra-2]!=0x7D) { continue; } for(rb=0,rc=0x00;rb