/******************************************************************************/ /* Copyright 2003 MBARI - Monterey Bay Aquarium Research Institute */ /******************************************************************************/ /******************************************************************************/ /* Summary : Routines to access Memory Mapped USB Module and cfg Chip-Select */ /* Filename : IO_USB.C */ /* Author : Luke Coletti */ /* Project : */ /* Version : 1.0 */ /* Compiler : Aztec C68k/ROM v5.2D */ /* Created : 01/01/05 HAPPY NEW YEAR! */ /* Archived : */ /******************************************************************************/ /* Modification History: */ /* */ /******************************************************************************/ #include /* Tattletale Model 8 Definitions */ #include /* Onset Model 8 C functions and typedefs */ #include /* 68332 System Integration Module Definitions */ #include /* Pico DOS Definitions */ #include #include #include #include "lobo.h" extern ushort WrLatch2Val; extern ulong CS0Base; extern ulong CS1Base; extern ulong CS10Base; /****************************************************************************/ /* USB Module Status Lines */ /****************************************************************************/ // SLEEP line, pin 8 on the DLP USB Module (output) // SLEEP HI indicates the USB link is in suspend mode, give up, e.g. CD in RS232 speeak // SLEEP LO indicates the USB link is actice, all systems go // RXF line, pin 13 on the DLP USB Module (output) // RXF HI indicates Rx FIFO is empty // RXF LO indicates Rx FIFO has at least one char // FIFO depth is 128 BYTES // TXE line, pin 14 on the DLP USB Module (output) // TXE HI indicates Tx FIFO is full, don't write any more data // TXE LO indicates device can be written to // FIFO depth is 384 BYTES /****************************************************************************/ /* USB Module Control Lines */ /****************************************************************************/ // SEND line, pin 9 on the DLP USB Module (input) // SEND HI (rising edge) forces data in USB Tx FIFO to be sent on the next USB Data-In request /****************************************************************************/ void InitUSB_IO(void) { #asm CSPAR1 equ $FFFA46 ;Chip Select Pin Assignment Register 1 CSBAR10 equ $FFFA74 ;Chip Select 10 Base Address Register CSOR10 equ $FFFA76 ;Chip Select 10 Option Register move.w CSPAR1,d0 ;get contents of CS Pin Assignment Reg 1 andi.w #$00FF,d0 ;preserve states of CS6-CS9 ori.w #$0300,d0 ;set CS10 (16-Bit Port) move.w d0,CSPAR1 ;update CS Pin Assignment Reg 1 move.w #$4010,CSBAR10 ;set base of CS10 to 0x40,1000 move.w #$7C30,CSOR10 ;set option of CS10 #endasm CS10Base = BASEADDR(*CSBAR10); } uchar UsbGetByte(void) { #asm RDUSBDAT equ $401000 ;memory mapped USB Module, CS10 move.w RDUSBDAT,d0 ;get contents of latch andi.w #$00FF,d0 ;make it a BYTE ;return from C function call #endasm } void UsbPutByte(uchar val) { ; #asm WRUSBDAT equ $401000 ;memory mapped USB Module, CS10 move.b %%val,WRUSBDAT ;load contents into latch ;return from C function call #endasm } int UsbActive(void) { register ushort *USBstatus; USBstatus = (ushort *) CS0Base; if(*USBstatus & 0x0040) return(FALSE); //USB module is in Standby Mode else return(TRUE); } int UsbByteAvail(void) { register ushort *USBstatus; USBstatus = (ushort *) CS0Base; if(*USBstatus & 0x0040) return( -1 ); //USB module is in Standby Mode if(*USBstatus & 0x0020) return(FALSE); //Rx Buffer is Empty else return(TRUE); } int UsbOutFull(void) { register ushort *USBstatus; USBstatus = (ushort *) CS0Base; if(*USBstatus & 0x0040) return( -1 ); //USB module is in Standby Mode if(*USBstatus & 0x0010) return(TRUE); //Tx Buffer is Full else return(FALSE); } int UsbInFlush(void) { register char c; register char *USBdata; register ushort *USBstatus; register ulong msTimeout; USBstatus = (ushort *) CS0Base; USBdata = (char *) CS10Base; if(*USBstatus & 0x0040) return( -1 ); //USB module is in Standby Mode if( *USBstatus & 0x0020 ) return( TRUE ); else{ msTimeout = MilliSecs() + 5000L; //set the timeout value in millisecs do{ if(MilliSecs() > msTimeout) return( -2 ); c = *USBdata; }while( !(*USBstatus & 0x0020) ); } return( TRUE ); } void UsbOutFlush(void) { register ushort *USBcontrol; USBcontrol = (ushort *) CS1Base; *USBcontrol = WrLatch2Val | FLUSH_USB_BUFFER; //assert USB xmit immediate *USBcontrol = WrLatch2Val; } int putsUSB(char * str) { register char *USBdata; // compile without -so register char *ptr; // use -su and rest of -so list register ushort *USBstatus; register ushort *USBcontrol; register ulong msTimeout; USBcontrol = (ushort *) CS1Base; USBstatus = (ushort *) CS0Base; USBdata = (char *) CS10Base; if( *USBstatus & 0x0040 ){ //read SLEEP, is USB module active printf("\n USB is in Standby, transmission disabled\n"); return( FALSE ); } ptr = str; while (*ptr) { if( *USBstatus & 0x0010 ){ //read TXE, is USB module's Tx FIFO full msTimeout = MilliSecs() + 5000L; //set the timeout value in millisecs do{ if(MilliSecs() > msTimeout) return( -1 ); }while( *USBstatus & 0x0010 ); } if( *ptr == '\n' ) *USBdata = '\r'; *USBdata = *ptr++; } *USBcontrol = WrLatch2Val | FLUSH_USB_BUFFER; //assert USB xmit immediate *USBcontrol = WrLatch2Val; return(TRUE); } int printfUSB(char * str, ...) { char fstr[1024]; int ret; va_list ap; va_start(ap, str); vsprintf(fstr, str, ap); va_end(ap); ret = putsUSB(fstr); return(ret); } int Send_USB_File(char *fname, ulong *bytes, ulong *time) { register char *USBdata; // compile without -so register char *ptr; // use -su and rest of -so list register char *buf; register ushort *USBstatus; register ushort *USBcontrol; register long length; register ulong ctr = 0; register ulong msTimeout; register FILE *in; int Eofseen; size_t blklen = 16384; //can't be more than 16384 with Aztec fread(); USBcontrol = (ushort *) CS1Base; USBstatus = (ushort *) CS0Base; USBdata = (char *) CS10Base; if(*USBstatus & 0x0040) //check SLEEP, pin8 of USB module return(-1); // execstr("OPT ON"); //enable PicoDOS optimaztion prior to fopen buf = malloc(blklen); if( buf == NULL ) return(-2); in = fopen(fname, "rb"); if( in == NULL ){ free(buf); return(-3); } if( setvbuf(in, buf, _IOFBF, blklen) != OK ) { fclose(in); free(buf); return(-4); } Eofseen = 0; StopWatchStart(); while(Eofseen == 0){ length = (long)fast_fread(NULL, sizeof(char), blklen, in); ///length = (long)fread(buf, 1, blklen, in); if(length == 0) break; //no data to send if(length < blklen) Eofseen = 1; ptr = (char*)in->_bp; for (;--length >= 0; ptr++) { if( *USBstatus & 0x0010 ){ //read TXE, is USB module's Tx FIFO full msTimeout = MilliSecs() + 5000L; //set the timeout value in millisecs do{ if(MilliSecs() > msTimeout) return( -5 ); }while( *USBstatus & 0x0010 ); } *USBdata = *ptr; ++ctr; } *USBcontrol = WrLatch2Val | FLUSH_USB_BUFFER; //assert USB xmit immediate *USBcontrol = WrLatch2Val; (char*)in->_bp = ptr; } //end Eof while *time = StopWatchTime(); *bytes = ctr; fclose(in); free(buf); return( TRUE ); }