00001 /* PICCOLO project 00002 * Copyright (c) 2009 Istvan Cserny (cserny@atomki.hu) 00003 * Ez az állomány a Microchip FSUSB keretrendszeréből átvett 00004 * elemeket is tartalmaz! 00005 */ 00006 00007 #include "piccolo_config.h" 00008 #include "GenericTypeDefs.h" 00009 #include "Compiler.h" 00010 #include "usb_config.h" 00011 #include "./USB/usb_device.h" 00012 #include "./USB/usb.h" 00013 #include "./USB/usb_function_cdc.h" 00014 #include "HardwareProfile.h" 00020 /* GLOBÁLIS VÁLTOZÓK az USB kommunikációhoz **************************/ 00021 #pragma udata 00022 00023 char USB_In_Buffer[64]; 00024 char USB_Out_Buffer[64]; 00025 BYTE numBytesRead=0; 00026 BYTE numBytesToSend=0; 00027 BYTE Buffercp=0; 00030 BYTE BlinkUSBStatus_enabled=Blinking_at_start; 00031 00032 /* FÜGGVÉNY PROTOTÍPUSOK *********************************************/ 00033 00034 void InitializeSystem(void); 00035 void ProcessIO(void); 00036 void USBDeviceTasks(void); 00037 void BlinkUSBStatus(void); 00038 unsigned int ReadPOT(void); 00039 int _user_putc(char c); 00040 void outString(const rom char* psz_s); 00041 char usb_cdc_getc(void); 00042 void outdec(long data, unsigned int ndigits); 00043 void out4hex(unsigned int t); 00044 unsigned int get4hex(void); 00045 unsigned char get2hex(void); 00046 void delay_ms(unsigned int d); 00048 #pragma code 00049 00056 int _user_putc(char c) 00057 { 00058 while (numBytesToSend>60) 00059 { 00060 ProcessIO(); 00061 } 00062 USB_In_Buffer[numBytesToSend++]=c; 00063 return (int)c; 00064 } 00065 00070 void outString(const rom char* psz_s) 00071 { 00072 char c; 00073 while ((c=*psz_s)) 00074 { 00075 if (c == '\n') 00076 { 00077 _user_putc(0x0D); 00078 } 00079 _user_putc(c); 00080 psz_s++; 00081 } 00082 } 00083 00090 char usb_cdc_getc(void) 00091 { 00092 while (Buffercp==numBytesRead) 00093 { 00094 ProcessIO(); 00095 } 00096 return(USB_Out_Buffer[Buffercp++]); 00097 } 00098 00103 void outdec(long data, unsigned int ndigits) { 00104 static char sign, s[12]; 00105 unsigned int i; 00106 i=0; sign='+'; 00107 if(data<0) { sign='-'; data = -data;} 00108 do { 00109 s[i]=data%10 + '0'; 00110 data=data/10; 00111 i++; 00112 if(i==ndigits) {s[i]='.'; i++;} 00113 } while(data>0); 00114 _user_putc(sign); 00115 do{ 00116 _user_putc(s[--i]); 00117 } while(i); 00118 } 00119 00120 00125 unsigned int get4hex(void) 00126 { 00127 char c,i; 00128 unsigned int t; 00129 t=0; 00130 for (i=0; i<4; i++) 00131 { 00132 c=usb_cdc_getc(); 00133 _user_putc(c); 00134 if (c>0x40) 00135 { 00136 c -=7; 00137 } 00138 t= (t<<4) + (c & 0x0F); 00139 } 00140 return t; 00141 } 00142 00147 void out4hex(unsigned int t) 00148 { 00149 char c; 00150 c=(char)((t>>12) & 0x0F); 00151 if (c>9) c+=7; 00152 _user_putc(c+'0'); 00153 c=(char)((t>>8) & 0x0F); 00154 if (c>9) c+=7; 00155 _user_putc(c+'0'); 00156 c=(char)((t>>4) & 0x0F); 00157 if (c>9) c+=7; 00158 _user_putc(c+'0'); 00159 c=(char)(t & 0x0F); 00160 if (c>9) c+=7; 00161 _user_putc(c+'0'); 00162 } 00163 00168 unsigned char get2hex(void) 00169 { 00170 char c,i; 00171 unsigned char t; 00172 t=0; 00173 for (i=0; i<2; i++) 00174 { 00175 c=usb_cdc_getc(); 00176 _user_putc(c); 00177 if (c>0x40) 00178 { 00179 c -=7; 00180 } 00181 t= (t<<4) + (c & 0x0F); 00182 } 00183 return t; 00184 } 00185 00190 void delay_ms(unsigned int d) { 00191 unsigned int i,j; 00192 for(i=0; i<d; i++) { 00193 for(j=0; j<85; j++) { 00194 ProcessIO(); 00195 } 00196 } 00197 } 00198 00199 /*****************************************************************************/ 00200 /*** Az alábbi függvények a Microchip FSUSB programcsomagból vannak átvéve ***/ 00201 /*****************************************************************************/ 00202 00203 /****************************************************************************** 00204 * Function: void InitializeSystem(void) 00205 * Overview: InitializeSystem is a centralized initialization 00206 * routine. All required USB initialization routines 00207 * are called from here. 00208 * 00209 * User application initialization routine should 00210 * also be called from here. 00211 *****************************************************************************/ 00212 void InitializeSystem(void) 00213 { 00214 #if defined(__18F4550) 00215 ADCON1 |= 0x0F; // Default all pins to digital 00216 #endif 00217 00218 00219 // The USB specifications require that USB peripheral devices must never source 00220 // current onto the Vbus pin. Additionally, USB peripherals should not source 00221 // current on D+ or D- when the host/hub is not actively powering the Vbus line. 00222 // When designing a self powered (as opposed to bus powered) USB peripheral 00223 // device, the firmware should make sure not to turn on the USB module and D+ 00224 // or D- pull up resistor unless Vbus is actively powered. Therefore, the 00225 // firmware needs some means to detect when Vbus is being powered by the host. 00226 // A 5V tolerant I/O pin can be connected to Vbus (through a resistor), and 00227 // can be used to detect when Vbus is high (host actively powering), or low 00228 // (host is shut down or otherwise not supplying power). The USB firmware 00229 // can then periodically poll this I/O pin to know when it is okay to turn on 00230 // the USB module/D+/D- pull up resistor. When designing a purely bus powered 00231 // peripheral device, it is not possible to source current on D+ or D- when the 00232 // host is not actively providing power on Vbus. Therefore, implementing this 00233 // bus sense feature is optional. This firmware can be made to use this bus 00234 // sense feature by making sure "USE_USB_BUS_SENSE_IO" has been defined in the 00235 // HardwareProfile.h file. 00236 #if defined(USE_USB_BUS_SENSE_IO) 00237 tris_usb_bus_sense = INPUT_PIN; // See HardwareProfile.h 00238 #endif 00239 00240 // If the host PC sends a GetStatus (device) request, the firmware must respond 00241 // and let the host know if the USB peripheral device is currently bus powered 00242 // or self powered. See chapter 9 in the official USB specifications for details 00243 // regarding this request. If the peripheral device is capable of being both 00244 // self and bus powered, it should not return a hard coded value for this request. 00245 // Instead, firmware should check if it is currently self or bus powered, and 00246 // respond accordingly. If the hardware has been configured like demonstrated 00247 // on the PICDEM FS USB Demo Board, an I/O pin can be polled to determine the 00248 // currently selected power source. On the PICDEM FS USB Demo Board, "RA2" 00249 // is used for this purpose. If using this feature, make sure "USE_SELF_POWER_SENSE_IO" 00250 // has been defined in HardwareProfile.h, and that an appropriate I/O pin has been mapped 00251 // to it in HardwareProfile.h. 00252 #if defined(USE_SELF_POWER_SENSE_IO) 00253 tris_self_power = INPUT_PIN; // See HardwareProfile.h 00254 #endif 00255 00256 mInitAllLEDs(); //Initialize all of the LED pins 00257 00258 USBDeviceInit(); //usb_device.c. Initializes USB module SFRs and 00259 //firmware variables to known states. 00260 #if defined(USB_INTERRUPT) 00261 USBDeviceAttach(); //USB eszköz csatlakoztatása 00262 #endif 00263 00264 stdout=_H_USER; //standard output átirányítása _user_putc()-re 00265 stderr=_H_USER; //standard error átirányítása _user_putc()-re 00266 //--- Globális változók inicializálása--------------------------------- 00267 numBytesRead=0; //A vett karakterek száma 00268 numBytesToSend=0; //Az elküldendő karakterek száma 00269 Buffercp=0; //Mutató a buffer kiolvasásához 00270 BlinkUSBStatus_enabled=Blinking_at_start; //USB státusz kijelzése: 00271 }//end InitializeSystem 00272 00273 00274 /******************************************************************** 00275 * Function: void ProcessIO(void) 00276 * 00277 * Overview: This function is used to move data between the USB 00278 * memory and the application character buffers 00279 * It should be called periodically in order to 00280 * activate the CDCTxService() status machine. 00281 *******************************************************************/ 00282 void ProcessIO(void) 00283 { 00284 #if defined(USB_POLLING) 00285 USBDeviceTasks(); //Handle USB I/O 00286 #endif 00287 //-- Blink the LEDs according to the USB device status 00288 if (BlinkUSBStatus_enabled) 00289 { 00290 BlinkUSBStatus(); 00291 } 00292 if ((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return; 00293 //-- Read data from host if the input buffer is empty 00294 if (USBUSARTIsTxTrfReady() && (numBytesRead==Buffercp)) 00295 { 00296 numBytesRead = getsUSBUSART(USB_Out_Buffer,64); 00297 Buffercp=0; 00298 } 00299 //-- Send data to host if the output buffer is not empty 00300 if (USBUSARTIsTxTrfReady() && (numBytesToSend!=0)) 00301 { 00302 putUSBUSART(USB_In_Buffer,numBytesToSend); 00303 numBytesToSend=0; 00304 } 00305 CDCTxService(); 00306 } //end ProcessIO 00307 00308 /******************************************************************** 00309 * Function: void BlinkUSBStatus(void) 00310 * Overview: BlinkUSBStatus turns on and off LEDs 00311 * corresponding to the USB device state. 00312 * 00313 * Note: mLED macros can be found in HardwareProfile.h 00314 * USBDeviceState is declared and updated in 00315 * usb_device.c. 00316 *******************************************************************/ 00317 void BlinkUSBStatus(void) 00318 { 00319 static WORD led_count=0; 00320 00321 if (led_count == 0)led_count = 10000U; 00322 led_count--; 00323 00324 #define mLED_Both_Off() {mLED_1_Off();mLED_2_Off();} 00325 #define mLED_Both_On() {mLED_1_On();mLED_2_On();} 00326 #define mLED_Only_1_On() {mLED_1_On();mLED_2_Off();} 00327 #define mLED_Only_2_On() {mLED_1_Off();mLED_2_On();} 00328 00329 if (USBSuspendControl == 1) 00330 { 00331 if (led_count==0) 00332 { 00333 mLED_1_Toggle(); 00334 if (mGetLED_1()) 00335 { 00336 mLED_2_On(); 00337 } 00338 else 00339 { 00340 mLED_2_Off(); 00341 } 00342 }//end if 00343 } 00344 else 00345 { 00346 if (USBDeviceState == DETACHED_STATE) 00347 { 00348 mLED_Both_Off(); 00349 } 00350 else if (USBDeviceState == ATTACHED_STATE) 00351 { 00352 mLED_Both_On(); 00353 } 00354 else if (USBDeviceState == POWERED_STATE) 00355 { 00356 mLED_Only_1_On(); 00357 } 00358 else if (USBDeviceState == DEFAULT_STATE) 00359 { 00360 mLED_Only_2_On(); 00361 } 00362 else if (USBDeviceState == ADDRESS_STATE) 00363 { 00364 if (led_count == 0) 00365 { 00366 mLED_1_Toggle(); 00367 mLED_2_Off(); 00368 }//end if 00369 } 00370 else if (USBDeviceState == CONFIGURED_STATE) 00371 { 00372 if (led_count==0) 00373 { 00374 mLED_1_Toggle(); 00375 if (mGetLED_1()) 00376 { 00377 mLED_2_Off(); 00378 } 00379 else 00380 { 00381 mLED_2_On(); 00382 } 00383 }//end if 00384 }//end if(...) 00385 }//end if(UCONbits.SUSPND...) 00386 00387 }//end BlinkUSBStatus 00388 00389 /****************************************************************************** 00390 * Function: WORD_VAL ReadPOT(void) 00391 * Output: WORD_VAL - the 10-bit right justified POT value 00392 * 00393 * Side Effects: ADC buffer value updated 00394 * 00395 * Overview: This function reads the POT and leaves the value in the 00396 * ADC buffer register 00397 *****************************************************************************/ 00398 unsigned int ReadPOT(void) 00399 { 00400 unsigned int w; 00401 mInitPOT(); 00402 ADCON0bits.GO = 1; // Start AD conversion 00403 while (ADCON0bits.NOT_DONE); // Wait for conversion 00404 w = ADRESH; 00405 w = (w<<8) + ADRESL; 00406 return w; 00407 }//end ReadPOT 00408 00409 // ****************************************************************************************************** 00410 // ************** USB Callback Functions **************************************************************** 00411 // ****************************************************************************************************** 00412 // The USB firmware stack will call the callback functions USBCBxxx() in response to certain USB related 00413 // events. For example, if the host PC is powering down, it will stop sending out Start of Frame (SOF) 00414 // packets to your device. In response to this, all USB devices are supposed to decrease their power 00415 // consumption from the USB Vbus to <2.5mA each. The USB module detects this condition (which according 00416 // to the USB specifications is 3+ms of no bus activity/SOF packets) and then calls the USBCBSuspend() 00417 // function. You should modify these callback functions to take appropriate actions for each of these 00418 // conditions. For example, in the USBCBSuspend(), you may wish to add code that will decrease power 00419 // consumption from Vbus to <2.5mA (such as by clock switching, turning off LEDs, putting the 00420 // microcontroller to sleep, etc.). Then, in the USBCBWakeFromSuspend() function, you may then wish to 00421 // add code that undoes the power saving things done in the USBCBSuspend() function. 00422 00423 // The USBCBSendResume() function is special, in that the USB stack will not automatically call this 00424 // function. This function is meant to be called from the application firmware instead. See the 00425 // additional comments near the function. 00426 00427 /****************************************************************************** 00428 * Function: void USBCBSuspend(void) 00429 * 00430 * Overview: Call back that is invoked when a USB suspend is detected 00431 * 00432 * Note: None 00433 *****************************************************************************/ 00434 void USBCBSuspend(void) 00435 { 00436 //Example power saving code. Insert appropriate code here for the desired 00437 //application behavior. If the microcontroller will be put to sleep, a 00438 //process similar to that shown below may be used: 00439 00440 //ConfigureIOPinsForLowPower(); 00441 //SaveStateOfAllInterruptEnableBits(); 00442 //DisableAllInterruptEnableBits(); 00443 //EnableOnlyTheInterruptsWhichWillBeUsedToWakeTheMicro(); //should enable at least USBActivityIF as a wake source 00444 //Sleep(); 00445 //RestoreStateOfAllPreviouslySavedInterruptEnableBits(); //Preferrably, this should be done in the USBCBWakeFromSuspend() function instead. 00446 //RestoreIOPinsToNormal(); //Preferrably, this should be done in the USBCBWakeFromSuspend() function instead. 00447 00448 //IMPORTANT NOTE: Do not clear the USBActivityIF (ACTVIF) bit here. This bit is 00449 //cleared inside the usb_device.c file. Clearing USBActivityIF here will cause 00450 //things to not work as intended. 00451 00452 00453 // #if defined(__C30__) 00454 // #if 0 00455 // U1EIR = 0xFFFF; 00456 // U1IR = 0xFFFF; 00457 // U1OTGIR = 0xFFFF; 00458 // IFS5bits.USB1IF = 0; 00459 // IEC5bits.USB1IE = 1; 00460 // U1OTGIEbits.ACTVIE = 1; 00461 // U1OTGIRbits.ACTVIF = 1; 00462 // Sleep(); 00463 // #endif 00464 // #endif 00465 } 00466 00467 00468 /****************************************************************************** 00469 * Function: void _USB1Interrupt(void) 00470 * Overview: This function is called when the USB interrupt bit is set 00471 * In this example the interrupt is only used when the device 00472 * goes to sleep when it receives a USB suspend command 00473 *****************************************************************************/ 00474 #if 0 00475 void __attribute__ ((interrupt)) _USB1Interrupt(void) 00476 { 00477 #if !defined(self_powered) 00478 if (U1OTGIRbits.ACTVIF) 00479 { 00480 IEC5bits.USB1IE = 0; 00481 U1OTGIEbits.ACTVIE = 0; 00482 IFS5bits.USB1IF = 0; 00483 00484 //USBClearInterruptFlag(USBActivityIFReg,USBActivityIFBitNum); 00485 USBClearInterruptFlag(USBIdleIFReg,USBIdleIFBitNum); 00486 //USBSuspendControl = 0; 00487 } 00488 #endif 00489 } 00490 #endif 00491 00492 /****************************************************************************** 00493 * Function: void USBCBWakeFromSuspend(void) 00494 * Overview: The host may put USB peripheral devices in low power 00495 * suspend mode (by "sending" 3+ms of idle). Once in suspend 00496 * mode, the host may wake the device back up by sending non- 00497 * idle state signalling. 00498 * 00499 * This call back is invoked when a wakeup from USB suspend 00500 * is detected. 00501 *****************************************************************************/ 00502 void USBCBWakeFromSuspend(void) 00503 { 00504 // If clock switching or other power savings measures were taken when 00505 // executing the USBCBSuspend() function, now would be a good time to 00506 // switch back to normal full power run mode conditions. The host allows 00507 // a few milliseconds of wakeup time, after which the device must be 00508 // fully back to normal, and capable of receiving and processing USB 00509 // packets. In order to do this, the USB module must receive proper 00510 // clocking (IE: 48MHz clock must be available to SIE for full speed USB 00511 // operation). 00512 } 00513 00514 /******************************************************************** 00515 * Function: void USBCB_SOF_Handler(void) 00516 * 00517 * 00518 * Overview: The USB host sends out a SOF packet to full-speed 00519 * devices every 1 ms. This interrupt may be useful 00520 * for isochronous pipes. End designers should 00521 * implement callback routine as necessary. 00522 * 00523 * Note: None 00524 *******************************************************************/ 00525 void USBCB_SOF_Handler(void) 00526 { 00527 // No need to clear UIRbits.SOFIF to 0 here. 00528 // Callback caller is already doing that. 00529 } 00530 00531 /******************************************************************* 00532 * Function: void USBCBErrorHandler(void) 00533 * 00534 * Overview: The purpose of this callback is mainly for 00535 * debugging during development. Check UEIR to see 00536 * which error causes the interrupt. 00537 *******************************************************************/ 00538 void USBCBErrorHandler(void) 00539 { 00540 // No need to clear UEIR to 0 here. 00541 // Callback caller is already doing that. 00542 00543 // Typically, user firmware does not need to do anything special 00544 // if a USB error occurs. For example, if the host sends an OUT 00545 // packet to your device, but the packet gets corrupted (ex: 00546 // because of a bad connection, or the user unplugs the 00547 // USB cable during the transmission) this will typically set 00548 // one or more USB error interrupt flags. Nothing specific 00549 // needs to be done however, since the SIE will automatically 00550 // send a "NAK" packet to the host. In response to this, the 00551 // host will normally retry to send the packet again, and no 00552 // data loss occurs. The system will typically recover 00553 // automatically, without the need for application firmware 00554 // intervention. 00555 00556 // Nevertheless, this callback function is provided, such as 00557 // for debugging purposes. 00558 } 00559 00560 00561 /******************************************************************* 00562 * Function: void USBCBCheckOtherReq(void) 00563 * 00564 * PreCondition: None 00565 * 00566 * Input: None 00567 * 00568 * Output: None 00569 * 00570 * Side Effects: None 00571 * 00572 * Overview: When SETUP packets arrive from the host, some 00573 * firmware must process the request and respond 00574 * appropriately to fulfill the request. Some of 00575 * the SETUP packets will be for standard 00576 * USB "chapter 9" (as in, fulfilling chapter 9 of 00577 * the official USB specifications) requests, while 00578 * others may be specific to the USB device class 00579 * that is being implemented. For example, a HID 00580 * class device needs to be able to respond to 00581 * "GET REPORT" type of requests. This 00582 * is not a standard USB chapter 9 request, and 00583 * therefore not handled by usb_device.c. Instead 00584 * this request should be handled by class specific 00585 * firmware, such as that contained in usb_function_hid.c. 00586 * 00587 * Note: None 00588 *******************************************************************/ 00589 void USBCBCheckOtherReq(void) 00590 { 00591 USBCheckCDCRequest(); 00592 }//end 00593 00594 00595 /******************************************************************* 00596 * Function: void USBCBStdSetDscHandler(void) 00597 * Overview: The USBCBStdSetDscHandler() callback function is 00598 * called when a SETUP, bRequest: SET_DESCRIPTOR request 00599 * arrives. Typically SET_DESCRIPTOR requests are 00600 * not used in most applications, and it is 00601 * optional to support this type of request. 00602 *******************************************************************/ 00603 void USBCBStdSetDscHandler(void) 00604 { 00605 // Must claim session ownership if supporting this request 00606 }//end 00607 00608 00609 /******************************************************************* 00610 * Function: void USBCBInitEP(void) 00611 * Side Effects: None 00612 * 00613 * Overview: This function is called when the device becomes 00614 * initialized, which occurs after the host sends a 00615 * SET_CONFIGURATION (wValue not = 0) request. This 00616 * callback function should initialize the endpoints 00617 * for the device's usage according to the current 00618 * configuration. 00619 *******************************************************************/ 00620 void USBCBInitEP(void) 00621 { 00622 CDCInitEP(); 00623 } 00624 00625 /******************************************************************** 00626 * Function: void USBCBSendResume(void) 00627 * Overview: The USB specifications allow some types of USB 00628 * peripheral devices to wake up a host PC (such 00629 * as if it is in a low power suspend to RAM state). 00630 * This can be a very useful feature in some 00631 * USB applications, such as an Infrared remote 00632 * control receiver. If a user presses the "power" 00633 * button on a remote control, it is nice that the 00634 * IR receiver can detect this signalling, and then 00635 * send a USB "command" to the PC to wake up. 00636 * 00637 * The USBCBSendResume() "callback" function is used 00638 * to send this special USB signalling which wakes 00639 * up the PC. This function may be called by 00640 * application firmware to wake up the PC. This 00641 * function should only be called when: 00642 * 00643 * 1. The USB driver used on the host PC supports 00644 * the remote wakeup capability. 00645 * 2. The USB configuration descriptor indicates 00646 * the device is remote wakeup capable in the 00647 * bmAttributes field. 00648 * 3. The USB host PC is currently sleeping, 00649 * and has previously sent your device a SET 00650 * FEATURE setup packet which "armed" the 00651 * remote wakeup capability. 00652 * 00653 * This callback should send a RESUME signal that 00654 * has the period of 1-15ms. 00655 * 00656 * Note: Interrupt vs. Polling 00657 * -Primary clock 00658 * -Secondary clock ***** MAKE NOTES ABOUT THIS ******* 00659 * > Can switch to primary first by calling USBCBWakeFromSuspend() 00660 00661 * The modifiable section in this routine should be changed 00662 * to meet the application needs. Current implementation 00663 * temporary blocks other functions from executing for a 00664 * period of 1-13 ms depending on the core frequency. 00665 * 00666 * According to USB 2.0 specification section 7.1.7.7, 00667 * "The remote wakeup device must hold the resume signaling 00668 * for at lest 1 ms but for no more than 15 ms." 00669 * The idea here is to use a delay counter loop, using a 00670 * common value that would work over a wide range of core 00671 * frequencies. 00672 * That value selected is 1800. See table below: 00673 * ========================================================== 00674 * Core Freq(MHz) MIP RESUME Signal Period (ms) 00675 * ========================================================== 00676 * 48 12 1.05 00677 * 4 1 12.6 00678 * ========================================================== 00679 * * These timing could be incorrect when using code 00680 * optimization or extended instruction mode, 00681 * or when having other interrupts enabled. 00682 * Make sure to verify using the MPLAB SIM's Stopwatch 00683 * and verify the actual signal on an oscilloscope. 00684 *******************************************************************/ 00685 void USBCBSendResume(void) 00686 { 00687 static WORD delay_count; 00688 00689 USBResumeControl = 1; // Start RESUME signaling 00690 00691 delay_count = 1800U; // Set RESUME line for 1-13 ms 00692 do 00693 { 00694 delay_count--; 00695 } 00696 while (delay_count); 00697 USBResumeControl = 0; 00698 } 00699 00700 00701 /******************************************************************* 00702 * Function: void USBCBEP0DataReceived(void) 00703 * 00704 * PreCondition: ENABLE_EP0_DATA_RECEIVED_CALLBACK must be 00705 * defined already (in usb_config.h) 00706 * Overview: This function is called whenever a EP0 data 00707 * packet is received. This gives the user (and 00708 * thus the various class examples a way to get 00709 * data that is received via the control endpoint. 00710 * This function needs to be used in conjunction 00711 * with the USBCBCheckOtherReq() function since 00712 * the USBCBCheckOtherReq() function is the apps 00713 * method for getting the initial control transfer 00714 * before the data arrives. 00715 *******************************************************************/ 00716 #if defined(ENABLE_EP0_DATA_RECEIVED_CALLBACK) 00717 void USBCBEP0DataReceived(void) 00718 { 00719 } 00720 #endif 00721 00722 /******************************************************************* 00723 * Function: BOOL USER_USB_CALLBACK_EVENT_HANDLER( 00724 * USB_EVENT event, void *pdata, WORD size) 00725 * Input: USB_EVENT event - the type of event 00726 * void *pdata - pointer to the event data 00727 * WORD size - size of the event data 00728 * Overview: This function is called from the USB stack to 00729 * notify a user application that a USB event 00730 * occured. This callback is in interrupt context 00731 * when the USB_INTERRUPT option is selected. 00732 *******************************************************************/ 00733 BOOL USER_USB_CALLBACK_EVENT_HANDLER(USB_EVENT event, void *pdata, WORD size) 00734 { 00735 switch (event) 00736 { 00737 case EVENT_CONFIGURED: 00738 USBCBInitEP(); 00739 break; 00740 case EVENT_SET_DESCRIPTOR: 00741 USBCBStdSetDscHandler(); 00742 break; 00743 case EVENT_EP0_REQUEST: 00744 USBCBCheckOtherReq(); 00745 break; 00746 case EVENT_SOF: 00747 USBCB_SOF_Handler(); 00748 break; 00749 case EVENT_SUSPEND: 00750 USBCBSuspend(); 00751 break; 00752 case EVENT_RESUME: 00753 USBCBWakeFromSuspend(); 00754 break; 00755 case EVENT_BUS_ERROR: 00756 USBCBErrorHandler(); 00757 break; 00758 case EVENT_TRANSFER: 00759 Nop(); 00760 break; 00761 default: 00762 break; 00763 } 00764 return TRUE; 00765 } 00766