int main(void) { firmware_signature = FIRMWARE_SIGNATURE; initialize_board(); #if defined(BUSPIRATEV4) BP_LEDUSB_DIR = OUTPUT; BP_USBLED_ON(); #ifdef USB_INTERRUPTS EnableUsbPerifInterrupts(USB_TRN | USB_SOF | USB_UERR | USB_URST); EnableUsbGlobalInterrupt(); #endif /* USB_INTERRUPTS */ /* Wait until the USB interface is configured. */ do { #ifndef USB_INTERRUPTS usb_handler(); #endif /* !USB_INTERRUPTS */ } while (usb_device_state < CONFIGURED_STATE); BP_USBLED_OFF(); usb_register_sof_handler(CDCFlushOnTimeout); #endif /* BUSPIRATEV4 */ /* Starts processing user requests. */ serviceuser(); return 0; }
int main(void) { Initialize(); //setup bus pirate //wait for the USB connection to enumerate #if defined (BUSPIRATEV4) && !defined (BPV4_DEBUG) BP_LEDUSB_DIR = 0; //BP_LEDUSB = 1; BP_USBLED_ON(); //BP_VREGEN_DIR = 0; // BP_VREGEN = 1; //BP_LEDMODE_DIR = 0; //BP_LEDMODE = 1; #ifdef USB_INTERRUPTS EnableUsbPerifInterrupts(USB_TRN + USB_SOF + USB_UERR + USB_URST); EnableUsbGlobalInterrupt(); #endif do { #ifndef USB_INTERRUPTS // if (!TestGlobalUsbInterruptEnable()) //JTR3 added usb_handler(); ////service USB tasks Guaranteed one pass in polling mode even when usb_device_state == CONFIGURED_STATE #endif // if ((usb_device_state < DEFAULT_STATE)) { // JTR2 no suspendControl available yet || (USBSuspendControl==1) ){ // } else if (usb_device_state < CONFIGURED_STATE) { // } } while (usb_device_state < CONFIGURED_STATE); // JTR addition. Do not proceed until device is configured. BP_USBLED_OFF(); usb_register_sof_handler(CDCFlushOnTimeout); // For timeout value see: cdc_config.h -> BPv4 -> CDC_FLUSH_MS #endif serviceuser(); return 0; }
//setup for USB2UART void Usb2UartSetup(void) { BYTE temp; DisableEachInterrupt(); // PIE1 = {SPPI EADIE RCIE TXIE SSPIE CCP1IE TMR2IE TMR1IE}, IRFREQ_CAPIE, T0_IE, IRRXIE, IRRAWINTIE RcIf = 0; temp = 0x8; // baud16 #ifdef USE_HNDSHK_POL_INV INTCON2bits.RBPU = 0; HNDSHK_INV_TRISpin = 1; TXRX_INV_TRISpin = 1; RTSTRISpin = 0; DTRTRISpin = 0; if (HNDSHK_INV_PORTpin) { Hold_pol = 0; } else { Hold_pol = 1; } if (!TXRX_INV_PORTpin) temp |= 0x30; #endif /* Signon not used in stand alone USB-UART mode*/ #ifndef UARTONLY putc_cdc('U'); putc_cdc('0'); putc_cdc('1'); CDC_Flush_In_Now(); #endif TRISC |= 0xC0; TXSTA = 0x24; //baudrate high RCSTA = 0x90; BAUDCON = temp; PIE1 = 0x20; IPR1bits.RCIP = 1; usb_register_sof_handler(CDCFlushOnTimeout); // For timeout value see: cdc_config.h -> IRTOY -> CDC_FLUSH_MS }
int main(void) #endif { BYTE RecvdByte; initCDC(); // setup the CDC state machine SetupBoard(); //setup the hardware, customize for your hardware usb_init(cdc_device_descriptor, cdc_config_descriptor, cdc_str_descs, USB_NUM_STRINGS); // initialize USB. TODO: Remove magic with macro usb_start(); //start the USB peripheral // PIC18 INTERRUPTS // It is the users resposibility to set up high, low or legacy mode // interrupt operation. The following macros for high and low interrupt // setup have been removed: //#define EnableUsbHighPriInterrupt() do { RCONbits.IPEN = 1; IPR2bits.USBIP = 1; INTCONbits.GIEH = 1;} while(0) // JTR new //#define EnableUsbLowPriInterrupt() do { RCONbits.IPEN = 1; IPR2bits.USBIP = 0; INTCONbits.GIEL = 1;} while(0) // JTR new // By default, the interrupt mode will be LEGACY (ISR Vector 0x08) // (Same as high priority vector wise but the operation (latency) is // not the same. Consult the data sheet for details.) // If a priority mode is enabled then this affects ALL other interrupt // sources therefore it does not belong to the usb stack to be // doing this. It is a global, user application choice. #if defined USB_INTERRUPTS // See the prj_usb_config.h file. EnableUsbPerifInterrupts(USB_TRN + USB_SOF + USB_UERR + USB_URST); #if defined __18CXX //turn on interrupts for PIC18 INTCONbits.PEIE = 1; INTCONbits.GIE = 1; #endif EnableUsbGlobalInterrupt(); // Only enables global USB interrupt. Chip interrupts must be enabled by the user (PIC18) #endif // Wait for USB to connect do { #ifndef USB_INTERRUPTS usb_handler(); #endif } while (usb_device_state < CONFIGURED_STATE); usb_register_sof_handler(CDCFlushOnTimeout); // Register our CDC timeout handler after device configured // Main echo loop do { // If USB_INTERRUPT is not defined each loop should have at least one additional call to the usb handler to allow for control transfers. #ifndef USB_INTERRUPTS usb_handler(); #endif // Receive and send method 1 // The CDC module will call usb_handler each time a BULK CDC packet is sent or received. // If there is a byte ready will return with the number of bytes available and received byte in RecvdByte if (poll_getc_cdc(&RecvdByte)) putc_cdc(RecvdByte+1); // // Receive and send method 2 // Same as poll_getc_cdc except that byte is NOT removed from queue. // This function will wait for a byte and return and remove it from the queue when it arrives. if (peek_getc_cdc(&RecvdByte)) { RecvdByte = getc_cdc(); putc_cdc(RecvdByte+1); } // Receive and send method 3 // If there is a byte ready will return with the number of bytes available and received byte in RecvdByte // use CDC_Flush_In_Now(); when it has to be sent immediately and not wait for a timeout condition. if (poll_getc_cdc(&RecvdByte)) { putc_cdc(RecvdByte+1); // CDC_Flush_In_Now(); } } while (1); } //end main