MP2COD 4.00, COFF to COD File Converter Copyright (c) 2005 Microchip Technology Inc. Listing File Generated: Mon Jul 17 16:40:41 2006 Address Value Disassembly Source File ------- ------- ----------------------- ------------------------------------------------------------------------------- ----- /* $Id: c018i.c,v 1.3 2004/07/30 17:28:43 ConnerJ Exp $ */ C:\MCC18\src\traditional\startup\c018i.c C:\MCC18\src\traditional\startup\c018i.c /* Copyright (c)1999 Microchip Technology */ C:\MCC18\src\traditional\startup\c018i.c C:\MCC18\src\traditional\startup\c018i.c /* MPLAB-C18 startup code, including initialized data */ C:\MCC18\src\traditional\startup\c018i.c C:\MCC18\src\traditional\startup\c018i.c /* external reference to the user's main routine */ C:\MCC18\src\traditional\startup\c018i.c extern void main (void); C:\MCC18\src\traditional\startup\c018i.c /* prototype for the startup function */ C:\MCC18\src\traditional\startup\c018i.c void _entry (void); C:\MCC18\src\traditional\startup\c018i.c void _startup (void); C:\MCC18\src\traditional\startup\c018i.c /* prototype for the initialized data setup */ C:\MCC18\src\traditional\startup\c018i.c void _do_cinit (void); C:\MCC18\src\traditional\startup\c018i.c C:\MCC18\src\traditional\startup\c018i.c extern volatile near unsigned long short TBLPTR; C:\MCC18\src\traditional\startup\c018i.c extern near unsigned FSR0; C:\MCC18\src\traditional\startup\c018i.c extern near char FPFLAGS; C:\MCC18\src\traditional\startup\c018i.c #define RND 6 C:\MCC18\src\traditional\startup\c018i.c C:\MCC18\src\traditional\startup\c018i.c #pragma code _entry_scn=0x000000 C:\MCC18\src\traditional\startup\c018i.c void C:\MCC18\src\traditional\startup\c018i.c _entry (void) C:\MCC18\src\traditional\startup\c018i.c { C:\MCC18\src\traditional\startup\c018i.c 000000 ef0f GOTO 0x161e _asm goto _startup _endasm C:\MCC18\src\traditional\startup\c018i.c 000002 f00b C:\MCC18\src\traditional\startup\c018i.c 000004 0012 RETURN 0x0 } C:\MCC18\src\traditional\startup\c018i.c #pragma code _startup_scn C:\MCC18\src\traditional\startup\c018i.c void C:\MCC18\src\traditional\startup\c018i.c _startup (void) C:\MCC18\src\traditional\startup\c018i.c { C:\MCC18\src\traditional\startup\c018i.c _asm C:\MCC18\src\traditional\startup\c018i.c // Initialize the stack pointer C:\MCC18\src\traditional\startup\c018i.c 00161e ee13 LFSR 0x1,0x300 lfsr 1, _stack C:\MCC18\src\traditional\startup\c018i.c 001620 f000 001622 ee23 LFSR 0x2,0x300 lfsr 2, _stack C:\MCC18\src\traditional\startup\c018i.c 001624 f000 C:\MCC18\src\traditional\startup\c018i.c 001626 6af8 CLRF 0xf8,0x0 clrf TBLPTRU, 0 // 1st silicon doesn't do this on POR C:\MCC18\src\traditional\startup\c018i.c C:\MCC18\src\traditional\startup\c018i.c 001628 9c01 BCF 0x1,0x6,0x0 bcf FPFLAGS,RND,0 // Initialize rounding flag for floating point libs C:\MCC18\src\traditional\startup\c018i.c C:\MCC18\src\traditional\startup\c018i.c _endasm C:\MCC18\src\traditional\startup\c018i.c 00162a eca6 CALL 0x154c,0x0 _do_cinit (); C:\MCC18\src\traditional\startup\c018i.c 00162c f00a C:\MCC18\src\traditional\startup\c018i.c loop: C:\MCC18\src\traditional\startup\c018i.c C:\MCC18\src\traditional\startup\c018i.c // Call the user's main routine C:\MCC18\src\traditional\startup\c018i.c 00162e ecf5 CALL 0x15ea,0x0 main (); C:\MCC18\src\traditional\startup\c018i.c 001630 f00a C:\MCC18\src\traditional\startup\c018i.c 001632 d7fd BRA 0x162e goto loop; C:\MCC18\src\traditional\startup\c018i.c 001634 0012 RETURN 0x0 } /* end _startup() */ C:\MCC18\src\traditional\startup\c018i.c C:\MCC18\src\traditional\startup\c018i.c /* MPLAB-C18 initialized data memory support */ C:\MCC18\src\traditional\startup\c018i.c /* The linker will populate the _cinit table */ C:\MCC18\src\traditional\startup\c018i.c extern far rom struct C:\MCC18\src\traditional\startup\c018i.c { C:\MCC18\src\traditional\startup\c018i.c unsigned short num_init; C:\MCC18\src\traditional\startup\c018i.c struct _init_entry C:\MCC18\src\traditional\startup\c018i.c { C:\MCC18\src\traditional\startup\c018i.c unsigned long from; C:\MCC18\src\traditional\startup\c018i.c unsigned long to; C:\MCC18\src\traditional\startup\c018i.c unsigned long size; C:\MCC18\src\traditional\startup\c018i.c } C:\MCC18\src\traditional\startup\c018i.c entries[]; C:\MCC18\src\traditional\startup\c018i.c } C:\MCC18\src\traditional\startup\c018i.c _cinit; C:\MCC18\src\traditional\startup\c018i.c C:\MCC18\src\traditional\startup\c018i.c #pragma code _cinit_scn C:\MCC18\src\traditional\startup\c018i.c void C:\MCC18\src\traditional\startup\c018i.c _do_cinit (void) C:\MCC18\src\traditional\startup\c018i.c { C:\MCC18\src\traditional\startup\c018i.c /* we'll make the assumption in the following code that these statics C:\MCC18\src\traditional\startup\c018i.c * will be allocated into the same bank. C:\MCC18\src\traditional\startup\c018i.c */ C:\MCC18\src\traditional\startup\c018i.c static short long prom; C:\MCC18\src\traditional\startup\c018i.c static unsigned short curr_byte; C:\MCC18\src\traditional\startup\c018i.c static unsigned short curr_entry; C:\MCC18\src\traditional\startup\c018i.c static short long data_ptr; C:\MCC18\src\traditional\startup\c018i.c C:\MCC18\src\traditional\startup\c018i.c // Initialized data... C:\MCC18\src\traditional\startup\c018i.c 00154c 0e2a MOVLW 0x2a TBLPTR = (short long)&_cinit; C:\MCC18\src\traditional\startup\c018i.c 00154e 6ef6 MOVWF 0xf6,0x0 001550 0e08 MOVLW 0x8 001552 6ef7 MOVWF 0xf7,0x0 001554 0e00 MOVLW 0x0 001556 6ef8 MOVWF 0xf8,0x0 _asm C:\MCC18\src\traditional\startup\c018i.c 001558 0101 MOVLB 0x1 movlb data_ptr C:\MCC18\src\traditional\startup\c018i.c 00155a 0009 TBLRDPOSTINC tblrdpostinc C:\MCC18\src\traditional\startup\c018i.c 00155c 50f5 MOVF 0xf5,0x0,0x0 movf TABLAT, 0, 0 C:\MCC18\src\traditional\startup\c018i.c 00155e 6f05 MOVWF 0x5,0x1 movwf curr_entry, 1 C:\MCC18\src\traditional\startup\c018i.c 001560 0009 TBLRDPOSTINC tblrdpostinc C:\MCC18\src\traditional\startup\c018i.c 001562 50f5 MOVF 0xf5,0x0,0x0 movf TABLAT, 0, 0 C:\MCC18\src\traditional\startup\c018i.c 001564 6f06 MOVWF 0x6,0x1 movwf curr_entry+1, 1 C:\MCC18\src\traditional\startup\c018i.c _endasm C:\MCC18\src\traditional\startup\c018i.c //while (curr_entry) C:\MCC18\src\traditional\startup\c018i.c //{ C:\MCC18\src\traditional\startup\c018i.c test: C:\MCC18\src\traditional\startup\c018i.c _asm C:\MCC18\src\traditional\startup\c018i.c 001566 e103 BNZ 0x156e bnz 3 C:\MCC18\src\traditional\startup\c018i.c 001568 6705 TSTFSZ 0x5,0x1 tstfsz curr_entry, 1 C:\MCC18\src\traditional\startup\c018i.c 00156a d001 BRA 0x156e bra 1 C:\MCC18\src\traditional\startup\c018i.c _endasm C:\MCC18\src\traditional\startup\c018i.c 00156c d03d BRA 0x15e8 goto done; C:\MCC18\src\traditional\startup\c018i.c /* Count down so we only have to look up the data in _cinit C:\MCC18\src\traditional\startup\c018i.c * once. C:\MCC18\src\traditional\startup\c018i.c * C:\MCC18\src\traditional\startup\c018i.c * At this point we know that TBLPTR points to the top of the current C:\MCC18\src\traditional\startup\c018i.c * entry in _cinit, so we can just start reading the from, to, and C:\MCC18\src\traditional\startup\c018i.c * size values. C:\MCC18\src\traditional\startup\c018i.c */ C:\MCC18\src\traditional\startup\c018i.c _asm C:\MCC18\src\traditional\startup\c018i.c /* read the source address */ C:\MCC18\src\traditional\startup\c018i.c 00156e 0009 TBLRDPOSTINC tblrdpostinc C:\MCC18\src\traditional\startup\c018i.c 001570 50f5 MOVF 0xf5,0x0,0x0 movf TABLAT, 0, 0 C:\MCC18\src\traditional\startup\c018i.c 001572 6f00 MOVWF 0x0,0x1 movwf prom, 1 C:\MCC18\src\traditional\startup\c018i.c 001574 0009 TBLRDPOSTINC tblrdpostinc C:\MCC18\src\traditional\startup\c018i.c 001576 50f5 MOVF 0xf5,0x0,0x0 movf TABLAT, 0, 0 C:\MCC18\src\traditional\startup\c018i.c 001578 6f01 MOVWF 0x1,0x1 movwf prom+1, 1 C:\MCC18\src\traditional\startup\c018i.c 00157a 0009 TBLRDPOSTINC tblrdpostinc C:\MCC18\src\traditional\startup\c018i.c 00157c 50f5 MOVF 0xf5,0x0,0x0 movf TABLAT, 0, 0 C:\MCC18\src\traditional\startup\c018i.c 00157e 6f02 MOVWF 0x2,0x1 movwf prom+2, 1 C:\MCC18\src\traditional\startup\c018i.c /* skip a byte since it's stored as a 32bit int */ C:\MCC18\src\traditional\startup\c018i.c 001580 0009 TBLRDPOSTINC tblrdpostinc C:\MCC18\src\traditional\startup\c018i.c /* read the destination address directly into FSR0 */ C:\MCC18\src\traditional\startup\c018i.c 001582 0009 TBLRDPOSTINC tblrdpostinc C:\MCC18\src\traditional\startup\c018i.c 001584 50f5 MOVF 0xf5,0x0,0x0 movf TABLAT, 0, 0 C:\MCC18\src\traditional\startup\c018i.c 001586 6ee9 MOVWF 0xe9,0x0 movwf FSR0L, 0 C:\MCC18\src\traditional\startup\c018i.c 001588 0009 TBLRDPOSTINC tblrdpostinc C:\MCC18\src\traditional\startup\c018i.c 00158a 50f5 MOVF 0xf5,0x0,0x0 movf TABLAT, 0, 0 C:\MCC18\src\traditional\startup\c018i.c 00158c 6eea MOVWF 0xea,0x0 movwf FSR0H, 0 C:\MCC18\src\traditional\startup\c018i.c /* skip two bytes since it's stored as a 32bit int */ C:\MCC18\src\traditional\startup\c018i.c 00158e 0009 TBLRDPOSTINC tblrdpostinc C:\MCC18\src\traditional\startup\c018i.c 001590 0009 TBLRDPOSTINC tblrdpostinc C:\MCC18\src\traditional\startup\c018i.c /* read the destination address directly into FSR0 */ C:\MCC18\src\traditional\startup\c018i.c 001592 0009 TBLRDPOSTINC tblrdpostinc C:\MCC18\src\traditional\startup\c018i.c 001594 50f5 MOVF 0xf5,0x0,0x0 movf TABLAT, 0, 0 C:\MCC18\src\traditional\startup\c018i.c 001596 6f03 MOVWF 0x3,0x1 movwf curr_byte, 1 C:\MCC18\src\traditional\startup\c018i.c 001598 0009 TBLRDPOSTINC tblrdpostinc C:\MCC18\src\traditional\startup\c018i.c 00159a 50f5 MOVF 0xf5,0x0,0x0 movf TABLAT, 0, 0 C:\MCC18\src\traditional\startup\c018i.c 00159c 6f04 MOVWF 0x4,0x1 movwf curr_byte+1, 1 C:\MCC18\src\traditional\startup\c018i.c /* skip two bytes since it's stored as a 32bit int */ C:\MCC18\src\traditional\startup\c018i.c 00159e 0009 TBLRDPOSTINC tblrdpostinc C:\MCC18\src\traditional\startup\c018i.c 0015a0 0009 TBLRDPOSTINC tblrdpostinc C:\MCC18\src\traditional\startup\c018i.c _endasm C:\MCC18\src\traditional\startup\c018i.c //prom = data_ptr->from; C:\MCC18\src\traditional\startup\c018i.c //FSR0 = data_ptr->to; C:\MCC18\src\traditional\startup\c018i.c //curr_byte = (unsigned short) data_ptr->size; C:\MCC18\src\traditional\startup\c018i.c /* the table pointer now points to the next entry. Save it C:\MCC18\src\traditional\startup\c018i.c * off since we'll be using the table pointer to do the copying C:\MCC18\src\traditional\startup\c018i.c * for the entry. C:\MCC18\src\traditional\startup\c018i.c */ C:\MCC18\src\traditional\startup\c018i.c 0015a2 cff6 MOVFF 0xff6,0x107 data_ptr = TBLPTR; C:\MCC18\src\traditional\startup\c018i.c 0015a4 f107 0015a6 cff7 MOVFF 0xff7,0x108 0015a8 f108 0015aa cff8 MOVFF 0xff8,0x109 0015ac f109 C:\MCC18\src\traditional\startup\c018i.c /* now assign the source address to the table pointer */ C:\MCC18\src\traditional\startup\c018i.c 0015ae c100 MOVFF 0x100,0xff6 TBLPTR = prom; C:\MCC18\src\traditional\startup\c018i.c 0015b0 fff6 0015b2 c101 MOVFF 0x101,0xff7 0015b4 fff7 0015b6 c102 MOVFF 0x102,0xff8 0015b8 fff8 C:\MCC18\src\traditional\startup\c018i.c /* do the copy loop */ C:\MCC18\src\traditional\startup\c018i.c _asm C:\MCC18\src\traditional\startup\c018i.c // determine if we have any more bytes to copy C:\MCC18\src\traditional\startup\c018i.c 0015ba 0101 MOVLB 0x1 movlb curr_byte C:\MCC18\src\traditional\startup\c018i.c 0015bc 5303 MOVF 0x3,0x1,0x1 movf curr_byte, 1, 1 C:\MCC18\src\traditional\startup\c018i.c copy_loop: C:\MCC18\src\traditional\startup\c018i.c 0015be e102 BNZ 0x15c4 bnz 2 // copy_one_byte C:\MCC18\src\traditional\startup\c018i.c 0015c0 5304 MOVF 0x4,0x1,0x1 movf curr_byte + 1, 1, 1 C:\MCC18\src\traditional\startup\c018i.c 0015c2 e007 BZ 0x15d2 bz 7 // done_copying C:\MCC18\src\traditional\startup\c018i.c C:\MCC18\src\traditional\startup\c018i.c copy_one_byte: C:\MCC18\src\traditional\startup\c018i.c 0015c4 0009 TBLRDPOSTINC tblrdpostinc C:\MCC18\src\traditional\startup\c018i.c 0015c6 50f5 MOVF 0xf5,0x0,0x0 movf TABLAT, 0, 0 C:\MCC18\src\traditional\startup\c018i.c 0015c8 6eee MOVWF 0xee,0x0 movwf POSTINC0, 0 C:\MCC18\src\traditional\startup\c018i.c C:\MCC18\src\traditional\startup\c018i.c // decrement byte counter C:\MCC18\src\traditional\startup\c018i.c 0015ca 0703 DECF 0x3,0x1,0x1 decf curr_byte, 1, 1 C:\MCC18\src\traditional\startup\c018i.c 0015cc e2f8 BC 0x15be bc -8 // copy_loop C:\MCC18\src\traditional\startup\c018i.c 0015ce 0704 DECF 0x4,0x1,0x1 decf curr_byte + 1, 1, 1 C:\MCC18\src\traditional\startup\c018i.c 0015d0 d7f9 BRA 0x15c4 bra -7 // copy_one_byte C:\MCC18\src\traditional\startup\c018i.c C:\MCC18\src\traditional\startup\c018i.c done_copying: C:\MCC18\src\traditional\startup\c018i.c C:\MCC18\src\traditional\startup\c018i.c _endasm C:\MCC18\src\traditional\startup\c018i.c /* restore the table pointer for the next entry */ C:\MCC18\src\traditional\startup\c018i.c 0015d2 c107 MOVFF 0x107,0xff6 TBLPTR = data_ptr; C:\MCC18\src\traditional\startup\c018i.c 0015d4 fff6 0015d6 c108 MOVFF 0x108,0xff7 0015d8 fff7 0015da c109 MOVFF 0x109,0xff8 0015dc fff8 /* next entry... */ C:\MCC18\src\traditional\startup\c018i.c 0015de 0101 MOVLB 0x1 curr_entry--; C:\MCC18\src\traditional\startup\c018i.c 0015e0 0705 DECF 0x5,0x1,0x1 0015e2 0e00 MOVLW 0x0 0015e4 5b06 SUBWFB 0x6,0x1,0x1 0015e6 d7bf BRA 0x1566 goto test; C:\MCC18\src\traditional\startup\c018i.c done: C:\MCC18\src\traditional\startup\c018i.c ; C:\MCC18\src\traditional\startup\c018i.c 0015e8 0012 RETURN 0x0 } C:\MCC18\src\traditional\startup\c018i.c /********************************************************************* C:\C\main.c * C:\C\main.c * Microchip USB C18 Firmware Version 1.0 C:\C\main.c * C:\C\main.c ********************************************************************* C:\C\main.c * FileName: main.c C:\C\main.c * Dependencies: See INCLUDES section below C:\C\main.c * Processor: PIC18 C:\C\main.c * Compiler: C18 2.30.01+ C:\C\main.c * Company: Microchip Technology, Inc. C:\C\main.c * C:\C\main.c * Software License Agreement C:\C\main.c * C:\C\main.c * The software supplied herewith by Microchip Technology Incorporated C:\C\main.c * (the “Company”) for its PICmicro® Microcontroller is intended and C:\C\main.c * supplied to you, the Company’s customer, for use solely and C:\C\main.c * exclusively on Microchip PICmicro Microcontroller products. The C:\C\main.c * software is owned by the Company and/or its supplier, and is C:\C\main.c * protected under applicable copyright laws. All rights are reserved. C:\C\main.c * Any use in violation of the foregoing restrictions may subject the C:\C\main.c * user to criminal sanctions under applicable laws, as well as to C:\C\main.c * civil liability for the breach of the terms and conditions of this C:\C\main.c * license. C:\C\main.c * C:\C\main.c * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, C:\C\main.c * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED C:\C\main.c * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A C:\C\main.c * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, C:\C\main.c * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR C:\C\main.c * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. C:\C\main.c * C:\C\main.c * Author Date Comment C:\C\main.c *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C:\C\main.c * Rawin Rojvanit 11/19/04 Original. C:\C\main.c ********************************************************************/ C:\C\main.c C:\C\main.c /** I N C L U D E S **********************************************************/ C:\C\main.c #include C:\C\main.c #include "system\typedefs.h" // Required C:\C\main.c #include "system\usb\usb.h" // Required C:\C\main.c #include "io_cfg.h" // Required C:\C\main.c C:\C\main.c #include "system\usb\usb_compile_time_validation.h" // Optional C:\C\main.c #include "user\user.h" // Modifiable C:\C\main.c C:\C\main.c /** V A R I A B L E S ********************************************************/ C:\C\main.c #pragma udata C:\C\main.c C:\C\main.c /** P R I V A T E P R O T O T Y P E S ***************************************/ C:\C\main.c static void InitializeSystem(void); C:\C\main.c void USBTasks(void); C:\C\main.c C:\C\main.c /** V E C T O R R E M A P P I N G *******************************************/ C:\C\main.c C:\C\main.c extern void _startup (void); // See c018i.c in your C18 compiler dir C:\C\main.c #pragma code _RESET_INTERRUPT_VECTOR = 0x000800 C:\C\main.c void _reset (void) C:\C\main.c { C:\C\main.c 000800 ef0f GOTO 0x161e _asm goto _startup _endasm C:\C\main.c 000802 f00b 000804 0012 RETURN 0x0 } C:\C\main.c #pragma code C:\C\main.c C:\C\main.c /** D E C L A R A T I O N S **************************************************/ C:\C\main.c #pragma code C:\C\main.c /****************************************************************************** C:\C\main.c * Function: void main(void) C:\C\main.c * C:\C\main.c * PreCondition: None C:\C\main.c * C:\C\main.c * Input: None C:\C\main.c * C:\C\main.c * Output: None C:\C\main.c * C:\C\main.c * Side Effects: None C:\C\main.c * C:\C\main.c * Overview: Main program entry point. C:\C\main.c * C:\C\main.c * Note: None C:\C\main.c *****************************************************************************/ C:\C\main.c void main(void) C:\C\main.c { C:\C\main.c 0015ea d805 RCALL 0x15f6 InitializeSystem(); C:\C\main.c 0015f2 d7fc BRA 0x15ec while(1) C:\C\main.c { C:\C\main.c 0015ec d810 RCALL 0x160e USBTasks(); // USB Tasks C:\C\main.c 0015ee ecab CALL 0x1356,0x0 ProcessIO(); // See user\user.c & .h C:\C\main.c 0015f0 f009 }//end while C:\C\main.c 0015f4 0012 RETURN 0x0 }//end main C:\C\main.c C:\C\main.c /****************************************************************************** C:\C\main.c * Function: static void InitializeSystem(void) C:\C\main.c * C:\C\main.c * PreCondition: None C:\C\main.c * C:\C\main.c * Input: None C:\C\main.c * C:\C\main.c * Output: None C:\C\main.c * C:\C\main.c * Side Effects: None C:\C\main.c * C:\C\main.c * Overview: InitializeSystem is a centralize initialization routine. C:\C\main.c * All required USB initialization routines are called from C:\C\main.c * here. C:\C\main.c * C:\C\main.c * User application initialization routine should also be C:\C\main.c * called from here. C:\C\main.c * C:\C\main.c * Note: None C:\C\main.c *****************************************************************************/ C:\C\main.c static void InitializeSystem(void) C:\C\main.c { C:\C\main.c 0015f6 0e0f MOVLW 0xf ADCON1 |= 0x0F; // Default all pins to digital C:\C\main.c 0015f8 12c1 IORWF 0xc1,0x1,0x0 C:\C\main.c 0015fa 0e14 MOVLW 0x14 mInitializeUSBDriver(); // See usbdrv.h C:\C\main.c 0015fc 6e6f MOVWF 0x6f,0x0 0015fe 0101 MOVLB 0x1 001600 6b12 CLRF 0x12,0x1 001602 0101 MOVLB 0x1 001604 6b13 CLRF 0x13,0x1 001606 0101 MOVLB 0x1 001608 6b14 CLRF 0x14,0x1 C:\C\main.c 00160a ef9c GOTO 0x1338 UserInit(); // See user.c & .h C:\C\main.c 00160c f009 C:\C\main.c }//end InitializeSystem C:\C\main.c C:\C\main.c /****************************************************************************** C:\C\main.c * Function: void USBTasks(void) C:\C\main.c * C:\C\main.c * PreCondition: InitializeSystem has been called. C:\C\main.c * C:\C\main.c * Input: None C:\C\main.c * C:\C\main.c * Output: None C:\C\main.c * C:\C\main.c * Side Effects: None C:\C\main.c * C:\C\main.c * Overview: Service loop for USB tasks. C:\C\main.c * C:\C\main.c * Note: None C:\C\main.c *****************************************************************************/ C:\C\main.c void USBTasks(void) C:\C\main.c { C:\C\main.c /* C:\C\main.c * Servicing Hardware C:\C\main.c */ C:\C\main.c 00160e ecde CALL 0x11bc,0x0 USBCheckBusStatus(); // Must use polling method C:\C\main.c 001610 f008 001612 be6f BTFSC 0x6f,0x7,0x0 if(UCFGbits.UTEYE!=1) C:\C\main.c 001614 d002 BRA 0x161a 001616 ecfd CALL 0x11fa,0x0 USBDriverService(); // Interrupt or polling method C:\C\main.c 001618 f008 C:\C\main.c #if defined(USB_USE_CDC) C:\C\main.c 00161a ef61 GOTO 0xac2 CDCTxService(); C:\C\main.c 00161c f005 #endif C:\C\main.c C:\C\main.c }// end USBTasks C:\C\main.c C:\C\main.c /** EOF main.c ***************************************************************/ C:\C\main.c /********************************************************************* C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * Microchip USB C18 Firmware Version 1.0 C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c ********************************************************************* C:\C\system\usb\usbmmap.c * FileName: usbmmap.c C:\C\system\usb\usbmmap.c * Dependencies: See INCLUDES section below C:\C\system\usb\usbmmap.c * Processor: PIC18 C:\C\system\usb\usbmmap.c * Compiler: C18 2.30.01+ C:\C\system\usb\usbmmap.c * Company: Microchip Technology, Inc. C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * Software License Agreement C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * The software supplied herewith by Microchip Technology Incorporated C:\C\system\usb\usbmmap.c * (the “Company”) for its PICmicro® Microcontroller is intended and C:\C\system\usb\usbmmap.c * supplied to you, the Company’s customer, for use solely and C:\C\system\usb\usbmmap.c * exclusively on Microchip PICmicro Microcontroller products. The C:\C\system\usb\usbmmap.c * software is owned by the Company and/or its supplier, and is C:\C\system\usb\usbmmap.c * protected under applicable copyright laws. All rights are reserved. C:\C\system\usb\usbmmap.c * Any use in violation of the foregoing restrictions may subject the C:\C\system\usb\usbmmap.c * user to criminal sanctions under applicable laws, as well as to C:\C\system\usb\usbmmap.c * civil liability for the breach of the terms and conditions of this C:\C\system\usb\usbmmap.c * license. C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, C:\C\system\usb\usbmmap.c * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED C:\C\system\usb\usbmmap.c * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A C:\C\system\usb\usbmmap.c * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, C:\C\system\usb\usbmmap.c * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR C:\C\system\usb\usbmmap.c * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * Author Date Comment C:\C\system\usb\usbmmap.c *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C:\C\system\usb\usbmmap.c * Rawin Rojvanit 11/19/04 Original. C:\C\system\usb\usbmmap.c ********************************************************************/ C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c /****************************************************************************** C:\C\system\usb\usbmmap.c * -usbmmap.c- C:\C\system\usb\usbmmap.c * USB Memory Map C:\C\system\usb\usbmmap.c * This file is the USB memory manager; it serves as a compile-time memory C:\C\system\usb\usbmmap.c * allocator for the USB endpoints. It uses the compile time options passed C:\C\system\usb\usbmmap.c * from usbcfg.h to instantiate endpoints and endpoint buffer. C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * Each endpoint requires to have a set of Buffer Descriptor registers(BDT). C:\C\system\usb\usbmmap.c * A BDT is 4-byte long and has a specific RAM location for each endpoint. C:\C\system\usb\usbmmap.c * The BDT for endpoint 0 out is located at address 0x400 to 0x403. C:\C\system\usb\usbmmap.c * The BDT for endpoint 0 in is located at address 0x404 to 0x407. C:\C\system\usb\usbmmap.c * The BDT for endpoint 1 out is located at address 0x408 to 0x40B. C:\C\system\usb\usbmmap.c * and so on... The above allocation assumes the Ping-Pong Buffer Mode 0 is C:\C\system\usb\usbmmap.c * used. These locations are already hard-wired in the silicon. The point C:\C\system\usb\usbmmap.c * of doing instantiation, i.e. volatile far BDT ep0Bo;, is to provide the C:\C\system\usb\usbmmap.c * C compiler a way to address each variable directly. This is very important C:\C\system\usb\usbmmap.c * because when a register can be accessed directly, it saves execution time C:\C\system\usb\usbmmap.c * and reduces program size. C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * Endpoints are defined using the endpoint number and the direction C:\C\system\usb\usbmmap.c * of transfer. For simplicity, usbmmap.c only uses the endpoint number C:\C\system\usb\usbmmap.c * in the BDT register allocation scheme. This means if the usbcfg.h states C:\C\system\usb\usbmmap.c * that the MAX_EP_NUMBER is number 1, then four BDTs will be C:\C\system\usb\usbmmap.c * instantiated: one each for endpoint0 in and endpoint0 out, which must C:\C\system\usb\usbmmap.c * always be instantiated for control transfer by default, and one each sets C:\C\system\usb\usbmmap.c * for endpoint1 in and endpoint1 out. The naming convention for instantiating C:\C\system\usb\usbmmap.c * BDT is C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * ep<#>B C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * where # is the endpoint number, and d is the direction of C:\C\system\usb\usbmmap.c * transfer, which could be either or . C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * The USB memory manager uses MAX_EP_NUMBER, as defined in usbcfg.h, to define C:\C\system\usb\usbmmap.c * the endpoints to be instantiated. This represents the highest endpoint C:\C\system\usb\usbmmap.c * number to be allocated, not how many endpoints are used. Since the BDTs for C:\C\system\usb\usbmmap.c * endpoints have hardware-assigned addresses in Bank 4, setting this value too C:\C\system\usb\usbmmap.c * high may lead to inefficient use of data RAM. For example, if an application C:\C\system\usb\usbmmap.c * uses only endpoints EP0 and EP4, then the MAX_EP_NUMBER is 4, and not 2. C:\C\system\usb\usbmmap.c * The in-between endpoint BDTs in this example (EP1, EP2, and EP3) go unused, C:\C\system\usb\usbmmap.c * and the 24 bytes of memory associated with them are wasted. It does not make C:\C\system\usb\usbmmap.c * much sense to skip endpoints, but the final decision lies with the user. C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * The next step is to assign the instantiated BDTs to different C:\C\system\usb\usbmmap.c * USB functions. The firmware framework fundamentally assumes that every USB C:\C\system\usb\usbmmap.c * function should know which endpoint it is using, i.e., the default control C:\C\system\usb\usbmmap.c * transfer should know that it is using endpoint 0 in and endpoint 0 out. C:\C\system\usb\usbmmap.c * A HID class can choose which endpoint it wants to use, but once chosen, it C:\C\system\usb\usbmmap.c * should always know the number of the endpoint. C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * The assignment of endpoints to USB functions is managed centrally C:\C\system\usb\usbmmap.c * in usbcfg.h. This helps prevent the mistake of having more C:\C\system\usb\usbmmap.c * than one USB function using the same endpoint. The "Endpoint Allocation" C:\C\system\usb\usbmmap.c * section in usbcfg.h provides examples for how to map USB endpoints to USB C:\C\system\usb\usbmmap.c * functions. C:\C\system\usb\usbmmap.c * Quite a few things can be mapped in that section. There is no C:\C\system\usb\usbmmap.c * one correct way to do the mapping and the user has the choice to C:\C\system\usb\usbmmap.c * choose a method that is most suitable to the application. C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * Typically, however, a user will want to map the following for a given C:\C\system\usb\usbmmap.c * USB interface function: C:\C\system\usb\usbmmap.c * 1. The USB interface ID C:\C\system\usb\usbmmap.c * 2. The endpoint control registers (UEPn) C:\C\system\usb\usbmmap.c * 3. The BDT registers (ep<#>B) C:\C\system\usb\usbmmap.c * 4. The endpoint size C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * Example: Assume a USB device class "foo", which uses one out endpoint C:\C\system\usb\usbmmap.c * of size 64-byte and one in endpoint of size 64-byte, then: C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * #define FOO_INTF_ID 0x00 C:\C\system\usb\usbmmap.c * #define FOO_UEP UEP1 C:\C\system\usb\usbmmap.c * #define FOO_BD_OUT ep1Bo C:\C\system\usb\usbmmap.c * #define FOO_BD_IN ep1Bi C:\C\system\usb\usbmmap.c * #define FOO_EP_SIZE 64 C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * The mapping above has chosen class "foo" to use endpoint 1. C:\C\system\usb\usbmmap.c * The names are arbitrary and can be anything other than FOO_??????. C:\C\system\usb\usbmmap.c * For abstraction, the code for class "foo" should use the abstract C:\C\system\usb\usbmmap.c * definitions of FOO_BD_OUT,FOO_BD_IN, and not ep1Bo or ep1Bi. C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * Note that the endpoint size defined in the usbcfg.h file is again C:\C\system\usb\usbmmap.c * used in the usbmmap.c file. This shows that the relationship between C:\C\system\usb\usbmmap.c * the two files are tightly related. C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * The endpoint buffer for each USB function must be located in the C:\C\system\usb\usbmmap.c * dual-port RAM area and has to come after all the BDTs have been C:\C\system\usb\usbmmap.c * instantiated. An example declaration is: C:\C\system\usb\usbmmap.c * volatile far unsigned char[FOO_EP_SIZE] data; C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * The 'volatile' keyword tells the compiler not to perform any code C:\C\system\usb\usbmmap.c * optimization on this variable because its content could be modified C:\C\system\usb\usbmmap.c * by the hardware. The 'far' keyword tells the compiler that this variable C:\C\system\usb\usbmmap.c * is not located in the Access RAM area (0x000 - 0x05F). C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * For the variable to be globally accessible by other files, it should be C:\C\system\usb\usbmmap.c * declared in the header file usbmmap.h as an extern definition, such as C:\C\system\usb\usbmmap.c * extern volatile far unsigned char[FOO_EP_SIZE] data; C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * Conclusion: C:\C\system\usb\usbmmap.c * In a short summary, the dependencies between usbcfg and usbmmap can C:\C\system\usb\usbmmap.c * be shown as: C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * usbcfg[MAX_EP_NUMBER] -> usbmmap C:\C\system\usb\usbmmap.c * usbmmap[ep<#>B] -> usbcfg C:\C\system\usb\usbmmap.c * usbcfg[EP size] -> usbmmap C:\C\system\usb\usbmmap.c * usbcfg[abstract ep definitions] -> usb9/hid/cdc/etc class code C:\C\system\usb\usbmmap.c * usbmmap[endpoint buffer variable] -> usb9/hid/cdc/etc class code C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * Data mapping provides a means for direct addressing of BDT and endpoint C:\C\system\usb\usbmmap.c * buffer. This means less usage of pointers, which equates to a faster and C:\C\system\usb\usbmmap.c * smaller program code. C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c *****************************************************************************/ C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c /** I N C L U D E S **********************************************************/ C:\C\system\usb\usbmmap.c #include "system\typedefs.h" C:\C\system\usb\usbmmap.c #include "system\usb\usb.h" C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c /** U S B G L O B A L V A R I A B L E S ************************************/ C:\C\system\usb\usbmmap.c #pragma udata C:\C\system\usb\usbmmap.c byte usb_device_state; // Device States: DETACHED, ATTACHED, ... C:\C\system\usb\usbmmap.c USB_DEVICE_STATUS usb_stat; // Global USB flags C:\C\system\usb\usbmmap.c byte usb_active_cfg; // Value of current configuration C:\C\system\usb\usbmmap.c byte usb_alt_intf[MAX_NUM_INT]; // Array to keep track of the current alternate C:\C\system\usb\usbmmap.c // setting for each interface ID C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c /** U S B F I X E D L O C A T I O N V A R I A B L E S *********************/ C:\C\system\usb\usbmmap.c #pragma udata usbram4=0x400 //See Linker Script,usb4:0x400-0x4FF(256-byte) C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c /****************************************************************************** C:\C\system\usb\usbmmap.c * Section A: Buffer Descriptor Table C:\C\system\usb\usbmmap.c * - 0x400 - 0x4FF(max) C:\C\system\usb\usbmmap.c * - MAX_EP_NUMBER is defined in autofiles\usbcfg.h C:\C\system\usb\usbmmap.c * - BDT data type is defined in system\usb\usbmmap.h C:\C\system\usb\usbmmap.c *****************************************************************************/ C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(0 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep0Bo; //Endpoint #0 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep0Bi; //Endpoint #0 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(1 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep1Bo; //Endpoint #1 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep1Bi; //Endpoint #1 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(2 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep2Bo; //Endpoint #2 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep2Bi; //Endpoint #2 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(3 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep3Bo; //Endpoint #3 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep3Bi; //Endpoint #3 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(4 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep4Bo; //Endpoint #4 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep4Bi; //Endpoint #4 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(5 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep5Bo; //Endpoint #5 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep5Bi; //Endpoint #5 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(6 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep6Bo; //Endpoint #6 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep6Bi; //Endpoint #6 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(7 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep7Bo; //Endpoint #7 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep7Bi; //Endpoint #7 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(8 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep8Bo; //Endpoint #8 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep8Bi; //Endpoint #8 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(9 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep9Bo; //Endpoint #9 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep9Bi; //Endpoint #9 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(10 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep10Bo; //Endpoint #10 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep10Bi; //Endpoint #10 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(11 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep11Bo; //Endpoint #11 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep11Bi; //Endpoint #11 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(12 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep12Bo; //Endpoint #12 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep12Bi; //Endpoint #12 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(13 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep13Bo; //Endpoint #13 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep13Bi; //Endpoint #13 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(14 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep14Bo; //Endpoint #14 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep14Bi; //Endpoint #14 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c #if(15 <= MAX_EP_NUMBER) C:\C\system\usb\usbmmap.c volatile far BDT ep15Bo; //Endpoint #15 BD Out C:\C\system\usb\usbmmap.c volatile far BDT ep15Bi; //Endpoint #15 BD In C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c /****************************************************************************** C:\C\system\usb\usbmmap.c * Section B: EP0 Buffer Space C:\C\system\usb\usbmmap.c ****************************************************************************** C:\C\system\usb\usbmmap.c * - Two buffer areas are defined: C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * A. CTRL_TRF_SETUP C:\C\system\usb\usbmmap.c * - Size = EP0_BUFF_SIZE as defined in autofiles\usbcfg.h C:\C\system\usb\usbmmap.c * - Detailed data structure allows direct adddressing of bits and bytes. C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * B. CTRL_TRF_DATA C:\C\system\usb\usbmmap.c * - Size = EP0_BUFF_SIZE as defined in autofiles\usbcfg.h C:\C\system\usb\usbmmap.c * - Data structure allows direct adddressing of the first 8 bytes. C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c * - Both data types are defined in system\usb\usbdefs\usbdefs_ep0_buff.h C:\C\system\usb\usbmmap.c *****************************************************************************/ C:\C\system\usb\usbmmap.c volatile far CTRL_TRF_SETUP SetupPkt; C:\C\system\usb\usbmmap.c volatile far CTRL_TRF_DATA CtrlTrfData; C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c /****************************************************************************** C:\C\system\usb\usbmmap.c * Section C: CDC Buffer C:\C\system\usb\usbmmap.c ****************************************************************************** C:\C\system\usb\usbmmap.c * C:\C\system\usb\usbmmap.c *****************************************************************************/ C:\C\system\usb\usbmmap.c #pragma udata usbram5a=0x500 //See Linker Script,usb5:0x500-... C:\C\system\usb\usbmmap.c #if defined(USB_USE_CDC) C:\C\system\usb\usbmmap.c volatile far unsigned char cdc_notice[CDC_INT_EP_SIZE]; C:\C\system\usb\usbmmap.c volatile far unsigned char cdc_data_rx[CDC_BULK_OUT_EP_SIZE]; C:\C\system\usb\usbmmap.c volatile far unsigned char cdc_data_tx[CDC_BULK_IN_EP_SIZE]; C:\C\system\usb\usbmmap.c #endif C:\C\system\usb\usbmmap.c #pragma udata C:\C\system\usb\usbmmap.c C:\C\system\usb\usbmmap.c /** EOF usbmmap.c ************************************************************/ C:\C\system\usb\usbmmap.c /********************************************************************* C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Microchip USB C18 Firmware Version 1.0 C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c ********************************************************************* C:\C\system\usb\usbdrv\usbdrv.c * FileName: usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c * Dependencies: See INCLUDES section below C:\C\system\usb\usbdrv\usbdrv.c * Processor: PIC18 C:\C\system\usb\usbdrv\usbdrv.c * Compiler: C18 2.30.01+ C:\C\system\usb\usbdrv\usbdrv.c * Company: Microchip Technology, Inc. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Software License Agreement C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * The software supplied herewith by Microchip Technology Incorporated C:\C\system\usb\usbdrv\usbdrv.c * (the “Company”) for its PICmicro® Microcontroller is intended and C:\C\system\usb\usbdrv\usbdrv.c * supplied to you, the Company’s customer, for use solely and C:\C\system\usb\usbdrv\usbdrv.c * exclusively on Microchip PICmicro Microcontroller products. The C:\C\system\usb\usbdrv\usbdrv.c * software is owned by the Company and/or its supplier, and is C:\C\system\usb\usbdrv\usbdrv.c * protected under applicable copyright laws. All rights are reserved. C:\C\system\usb\usbdrv\usbdrv.c * Any use in violation of the foregoing restrictions may subject the C:\C\system\usb\usbdrv\usbdrv.c * user to criminal sanctions under applicable laws, as well as to C:\C\system\usb\usbdrv\usbdrv.c * civil liability for the breach of the terms and conditions of this C:\C\system\usb\usbdrv\usbdrv.c * license. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, C:\C\system\usb\usbdrv\usbdrv.c * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED C:\C\system\usb\usbdrv\usbdrv.c * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A C:\C\system\usb\usbdrv\usbdrv.c * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, C:\C\system\usb\usbdrv\usbdrv.c * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR C:\C\system\usb\usbdrv\usbdrv.c * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Author Date Comment C:\C\system\usb\usbdrv\usbdrv.c *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C:\C\system\usb\usbdrv\usbdrv.c * Rawin Rojvanit 11/19/04 Original. C:\C\system\usb\usbdrv\usbdrv.c ********************************************************************/ C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /** I N C L U D E S **********************************************************/ C:\C\system\usb\usbdrv\usbdrv.c #include C:\C\system\usb\usbdrv\usbdrv.c #include "system\typedefs.h" C:\C\system\usb\usbdrv\usbdrv.c #include "system\usb\usb.h" C:\C\system\usb\usbdrv\usbdrv.c #include "io_cfg.h" // Required for USBCheckBusStatus() C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /** V A R I A B L E S ********************************************************/ C:\C\system\usb\usbdrv\usbdrv.c #pragma udata C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /** P R I V A T E P R O T O T Y P E S ***************************************/ C:\C\system\usb\usbdrv\usbdrv.c void USBModuleEnable(void); C:\C\system\usb\usbdrv\usbdrv.c void USBModuleDisable(void); C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c void USBSuspend(void); C:\C\system\usb\usbdrv\usbdrv.c void USBWakeFromSuspend(void); C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c void USBProtocolResetHandler(void); C:\C\system\usb\usbdrv\usbdrv.c void USB_SOF_Handler(void); C:\C\system\usb\usbdrv\usbdrv.c void USBStallHandler(void); C:\C\system\usb\usbdrv\usbdrv.c void USBErrorHandler(void); C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /** D E C L A R A T I O N S **************************************************/ C:\C\system\usb\usbdrv\usbdrv.c #pragma code C:\C\system\usb\usbdrv\usbdrv.c /****************************************************************************** C:\C\system\usb\usbdrv\usbdrv.c * Function: void USBCheckBusStatus(void) C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * PreCondition: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Input: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Output: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Side Effects: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Overview: This routine enables/disables the USB module by monitoring C:\C\system\usb\usbdrv\usbdrv.c * the USB power signal. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Note: None C:\C\system\usb\usbdrv\usbdrv.c *****************************************************************************/ C:\C\system\usb\usbdrv\usbdrv.c void USBCheckBusStatus(void) C:\C\system\usb\usbdrv\usbdrv.c { C:\C\system\usb\usbdrv\usbdrv.c /************************************************************************** C:\C\system\usb\usbdrv\usbdrv.c * Bus Attachment & Detachment Detection C:\C\system\usb\usbdrv\usbdrv.c * usb_bus_sense is an i/o pin defined in io_cfg.h C:\C\system\usb\usbdrv\usbdrv.c *************************************************************************/ C:\C\system\usb\usbdrv\usbdrv.c #define USB_BUS_ATTACHED 1 C:\C\system\usb\usbdrv\usbdrv.c #define USB_BUS_DETACHED 0 C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c if(usb_bus_sense == USB_BUS_ATTACHED) // Is USB bus attached? C:\C\system\usb\usbdrv\usbdrv.c { C:\C\system\usb\usbdrv\usbdrv.c 0011bc a66d BTFSS 0x6d,0x3,0x0 if(UCONbits.USBEN == 0) // Is the module off? C:\C\system\usb\usbdrv\usbdrv.c 0011be d80f RCALL 0x11de USBModuleEnable(); // Is off, enable it C:\C\system\usb\usbdrv\usbdrv.c } C:\C\system\usb\usbdrv\usbdrv.c 0011c0 d002 BRA 0x11c6 else C:\C\system\usb\usbdrv\usbdrv.c { C:\C\system\usb\usbdrv\usbdrv.c 0011c2 b66d BTFSC 0x6d,0x3,0x0 if(UCONbits.USBEN == 1) // Is the module on? C:\C\system\usb\usbdrv\usbdrv.c 0011c4 d813 RCALL 0x11ec USBModuleDisable(); // Is on, disable it C:\C\system\usb\usbdrv\usbdrv.c }//end if(usb_bus_sense...) C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /* C:\C\system\usb\usbdrv\usbdrv.c * After enabling the USB module, it takes some time for the voltage C:\C\system\usb\usbdrv\usbdrv.c * on the D+ or D- line to rise high enough to get out of the SE0 condition. C:\C\system\usb\usbdrv\usbdrv.c * The USB Reset interrupt should not be unmasked until the SE0 condition is C:\C\system\usb\usbdrv\usbdrv.c * cleared. This helps preventing the firmware from misinterpreting this C:\C\system\usb\usbdrv\usbdrv.c * unique event as a USB bus reset from the USB host. C:\C\system\usb\usbdrv\usbdrv.c */ C:\C\system\usb\usbdrv\usbdrv.c 0011c6 0101 MOVLB 0x1 if(usb_device_state == ATTACHED_STATE) C:\C\system\usb\usbdrv\usbdrv.c 0011c8 0512 DECF 0x12,0x0,0x1 0011ca e108 BNZ 0x11dc { C:\C\system\usb\usbdrv\usbdrv.c 0011cc ba6d BTFSC 0x6d,0x5,0x0 if(!UCONbits.SE0) C:\C\system\usb\usbdrv\usbdrv.c 0011ce d006 BRA 0x11dc { C:\C\system\usb\usbdrv\usbdrv.c 0011d0 6a68 CLRF 0x68,0x0 UIR = 0; // Clear all USB interrupts C:\C\system\usb\usbdrv\usbdrv.c 0011d2 6a69 CLRF 0x69,0x0 UIE = 0; // Mask all USB interrupts C:\C\system\usb\usbdrv\usbdrv.c 0011d4 8069 BSF 0x69,0x0,0x0 UIEbits.URSTIE = 1; // Unmask RESET interrupt C:\C\system\usb\usbdrv\usbdrv.c 0011d6 8869 BSF 0x69,0x4,0x0 UIEbits.IDLEIE = 1; // Unmask IDLE interrupt C:\C\system\usb\usbdrv\usbdrv.c 0011d8 0e02 MOVLW 0x2 usb_device_state = POWERED_STATE; C:\C\system\usb\usbdrv\usbdrv.c 0011da 6f12 MOVWF 0x12,0x1 }//end if // else wait until SE0 is cleared C:\C\system\usb\usbdrv\usbdrv.c }//end if(usb_device_state == ATTACHED_STATE) C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c 0011dc 0012 RETURN 0x0 }//end USBCheckBusStatus C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /****************************************************************************** C:\C\system\usb\usbdrv\usbdrv.c * Function: void USBModuleEnable(void) C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * PreCondition: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Input: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Output: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Side Effects: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Overview: This routine enables the USB module. C:\C\system\usb\usbdrv\usbdrv.c * An end designer should never have to call this routine C:\C\system\usb\usbdrv\usbdrv.c * manually. This routine should only be called from C:\C\system\usb\usbdrv\usbdrv.c * USBCheckBusStatus(). C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Note: See USBCheckBusStatus() for more information. C:\C\system\usb\usbdrv\usbdrv.c *****************************************************************************/ C:\C\system\usb\usbdrv\usbdrv.c void USBModuleEnable(void) C:\C\system\usb\usbdrv\usbdrv.c { C:\C\system\usb\usbdrv\usbdrv.c 0011de 6a6d CLRF 0x6d,0x0 UCON = 0; C:\C\system\usb\usbdrv\usbdrv.c 0011e0 6a69 CLRF 0x69,0x0 UIE = 0; // Mask all USB interrupts C:\C\system\usb\usbdrv\usbdrv.c 0011e2 866d BSF 0x6d,0x3,0x0 UCONbits.USBEN = 1; // Enable module & attach to bus C:\C\system\usb\usbdrv\usbdrv.c 0011e4 0101 MOVLB 0x1 usb_device_state = ATTACHED_STATE; // Defined in usbmmap.c & .h C:\C\system\usb\usbdrv\usbdrv.c 0011e6 0e01 MOVLW 0x1 0011e8 6f12 MOVWF 0x12,0x1 0011ea 0012 RETURN 0x0 }//end USBModuleEnable C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /****************************************************************************** C:\C\system\usb\usbdrv\usbdrv.c * Function: void USBModuleDisable(void) C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * PreCondition: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Input: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Output: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Side Effects: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Overview: This routine disables the USB module. C:\C\system\usb\usbdrv\usbdrv.c * An end designer should never have to call this routine C:\C\system\usb\usbdrv\usbdrv.c * manually. This routine should only be called from C:\C\system\usb\usbdrv\usbdrv.c * USBCheckBusStatus(). C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Note: See USBCheckBusStatus() for more information. C:\C\system\usb\usbdrv\usbdrv.c *****************************************************************************/ C:\C\system\usb\usbdrv\usbdrv.c void USBModuleDisable(void) C:\C\system\usb\usbdrv\usbdrv.c { C:\C\system\usb\usbdrv\usbdrv.c 0011ec 6a6d CLRF 0x6d,0x0 UCON = 0; // Disable module & detach from bus C:\C\system\usb\usbdrv\usbdrv.c 0011ee 6a69 CLRF 0x69,0x0 UIE = 0; // Mask all USB interrupts C:\C\system\usb\usbdrv\usbdrv.c 0011f0 0101 MOVLB 0x1 usb_device_state = DETACHED_STATE; // Defined in usbmmap.c & .h C:\C\system\usb\usbdrv\usbdrv.c 0011f2 6b12 CLRF 0x12,0x1 0011f4 0012 RETURN 0x0 }//end USBModuleDisable C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /****************************************************************************** C:\C\system\usb\usbdrv\usbdrv.c * Function: void USBSoftDetach(void) C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * PreCondition: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Input: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Output: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Side Effects: The device will have to be re-enumerated to function again. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Overview: USBSoftDetach electrically disconnects the device from C:\C\system\usb\usbdrv\usbdrv.c * the bus. This is done by stop supplying Vusb voltage to C:\C\system\usb\usbdrv\usbdrv.c * pull-up resistor. The pull-down resistors on the host C:\C\system\usb\usbdrv\usbdrv.c * side will pull both differential signal lines low and C:\C\system\usb\usbdrv\usbdrv.c * the host registers the event as a disconnect. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Since the USB cable is not physically disconnected, the C:\C\system\usb\usbdrv\usbdrv.c * power supply through the cable can still be sensed by C:\C\system\usb\usbdrv\usbdrv.c * the device. The next time USBCheckBusStatus() function C:\C\system\usb\usbdrv\usbdrv.c * is called, it will reconnect the device back to the bus. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Note: None C:\C\system\usb\usbdrv\usbdrv.c *****************************************************************************/ C:\C\system\usb\usbdrv\usbdrv.c void USBSoftDetach(void) C:\C\system\usb\usbdrv\usbdrv.c { C:\C\system\usb\usbdrv\usbdrv.c 0011f6 eff6 GOTO 0x11ec USBModuleDisable(); C:\C\system\usb\usbdrv\usbdrv.c 0011f8 f008 }//end USBSoftDetach C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /****************************************************************************** C:\C\system\usb\usbdrv\usbdrv.c * Function: void USBDriverService(void) C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * PreCondition: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Input: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Output: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Side Effects: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Overview: This routine is the heart of this firmware. It manages C:\C\system\usb\usbdrv\usbdrv.c * all USB interrupts. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Note: Device state transitions through the following stages: C:\C\system\usb\usbdrv\usbdrv.c * DETACHED -> ATTACHED -> POWERED -> DEFAULT -> C:\C\system\usb\usbdrv\usbdrv.c * ADDRESS_PENDING -> ADDRESSED -> CONFIGURED -> READY C:\C\system\usb\usbdrv\usbdrv.c *****************************************************************************/ C:\C\system\usb\usbdrv\usbdrv.c void USBDriverService(void) C:\C\system\usb\usbdrv\usbdrv.c { C:\C\system\usb\usbdrv\usbdrv.c /* C:\C\system\usb\usbdrv\usbdrv.c * Pointless to continue servicing if USB cable is not even attached. C:\C\system\usb\usbdrv\usbdrv.c */ C:\C\system\usb\usbdrv\usbdrv.c 0011fa 0101 MOVLB 0x1 if(usb_device_state == DETACHED_STATE) return; C:\C\system\usb\usbdrv\usbdrv.c 0011fc 5112 MOVF 0x12,0x0,0x1 0011fe e101 BNZ 0x1202 001200 d03a BRA 0x1276 C:\C\system\usb\usbdrv\usbdrv.c /* C:\C\system\usb\usbdrv\usbdrv.c * Task A: Service USB Activity Interrupt C:\C\system\usb\usbdrv\usbdrv.c */ C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c 001202 5068 MOVF 0x68,0x0,0x0 if(UIRbits.ACTVIF && UIEbits.ACTVIE) USBWakeFromSuspend(); C:\C\system\usb\usbdrv\usbdrv.c 001204 0b04 ANDLW 0x4 001206 e004 BZ 0x1210 001208 5069 MOVF 0x69,0x0,0x0 00120a 0b04 ANDLW 0x4 00120c e001 BZ 0x1210 00120e d83c RCALL 0x1288 C:\C\system\usb\usbdrv\usbdrv.c /* C:\C\system\usb\usbdrv\usbdrv.c * Pointless to continue servicing if the device is in suspend mode. C:\C\system\usb\usbdrv\usbdrv.c */ C:\C\system\usb\usbdrv\usbdrv.c 001210 b26d BTFSC 0x6d,0x1,0x0 if(UCONbits.SUSPND==1) return; C:\C\system\usb\usbdrv\usbdrv.c 001212 d031 BRA 0x1276 C:\C\system\usb\usbdrv\usbdrv.c /* C:\C\system\usb\usbdrv\usbdrv.c * Task B: Service USB Bus Reset Interrupt. C:\C\system\usb\usbdrv\usbdrv.c * When bus reset is received during suspend, ACTVIF will be set first, C:\C\system\usb\usbdrv\usbdrv.c * once the UCONbits.SUSPND is clear, then the URSTIF bit will be asserted. C:\C\system\usb\usbdrv\usbdrv.c * This is why URSTIF is checked after ACTVIF. C:\C\system\usb\usbdrv\usbdrv.c */ C:\C\system\usb\usbdrv\usbdrv.c 001214 5068 MOVF 0x68,0x0,0x0 if(UIRbits.URSTIF && UIEbits.URSTIE) USBProtocolResetHandler(); C:\C\system\usb\usbdrv\usbdrv.c 001216 0b01 ANDLW 0x1 001218 e004 BZ 0x1222 00121a 5069 MOVF 0x69,0x0,0x0 00121c 0b01 ANDLW 0x1 00121e e001 BZ 0x1222 001220 d854 RCALL 0x12ca C:\C\system\usb\usbdrv\usbdrv.c /* C:\C\system\usb\usbdrv\usbdrv.c * Task C: Service other USB interrupts C:\C\system\usb\usbdrv\usbdrv.c */ C:\C\system\usb\usbdrv\usbdrv.c 001222 5068 MOVF 0x68,0x0,0x0 if(UIRbits.IDLEIF && UIEbits.IDLEIE) USBSuspend(); C:\C\system\usb\usbdrv\usbdrv.c 001224 0b10 ANDLW 0x10 001226 e004 BZ 0x1230 001228 5069 MOVF 0x69,0x0,0x0 00122a 0b10 ANDLW 0x10 00122c e001 BZ 0x1230 00122e d824 RCALL 0x1278 001230 5068 MOVF 0x68,0x0,0x0 if(UIRbits.SOFIF && UIEbits.SOFIE) USB_SOF_Handler(); C:\C\system\usb\usbdrv\usbdrv.c 001232 0b40 ANDLW 0x40 001234 e004 BZ 0x123e 001236 5069 MOVF 0x69,0x0,0x0 001238 0b40 ANDLW 0x40 00123a e001 BZ 0x123e 00123c d83b RCALL 0x12b4 00123e 5068 MOVF 0x68,0x0,0x0 if(UIRbits.STALLIF && UIEbits.STALLIE) USBStallHandler(); C:\C\system\usb\usbdrv\usbdrv.c 001240 0b20 ANDLW 0x20 001242 e004 BZ 0x124c 001244 5069 MOVF 0x69,0x0,0x0 001246 0b20 ANDLW 0x20 001248 e001 BZ 0x124c 00124a d836 RCALL 0x12b8 00124c 5068 MOVF 0x68,0x0,0x0 if(UIRbits.UERRIF && UIEbits.UERRIE) USBErrorHandler(); C:\C\system\usb\usbdrv\usbdrv.c 00124e 0b02 ANDLW 0x2 001250 e004 BZ 0x125a 001252 5069 MOVF 0x69,0x0,0x0 001254 0b02 ANDLW 0x2 001256 e001 BZ 0x125a 001258 d836 RCALL 0x12c6 C:\C\system\usb\usbdrv\usbdrv.c /* C:\C\system\usb\usbdrv\usbdrv.c * Pointless to continue servicing if the host has not sent a bus reset. C:\C\system\usb\usbdrv\usbdrv.c * Once bus reset is received, the device transitions into the DEFAULT C:\C\system\usb\usbdrv\usbdrv.c * state and is ready for communication. C:\C\system\usb\usbdrv\usbdrv.c */ C:\C\system\usb\usbdrv\usbdrv.c 00125a 0e03 MOVLW 0x3 if(usb_device_state < DEFAULT_STATE) return; C:\C\system\usb\usbdrv\usbdrv.c 00125c 0101 MOVLB 0x1 00125e 5d12 SUBWF 0x12,0x0,0x1 001260 e201 BC 0x1264 001262 d009 BRA 0x1276 C:\C\system\usb\usbdrv\usbdrv.c /* C:\C\system\usb\usbdrv\usbdrv.c * Task D: Servicing USB Transaction Complete Interrupt C:\C\system\usb\usbdrv\usbdrv.c */ C:\C\system\usb\usbdrv\usbdrv.c 001264 5068 MOVF 0x68,0x0,0x0 if(UIRbits.TRNIF && UIEbits.TRNIE) C:\C\system\usb\usbdrv\usbdrv.c 001266 0b08 ANDLW 0x8 001268 e006 BZ 0x1276 00126a 5069 MOVF 0x69,0x0,0x0 00126c 0b08 ANDLW 0x8 00126e e003 BZ 0x1276 { C:\C\system\usb\usbdrv\usbdrv.c /* C:\C\system\usb\usbdrv\usbdrv.c * USBCtrlEPService only services transactions over EP0. C:\C\system\usb\usbdrv\usbdrv.c * It ignores all other EP transactions. C:\C\system\usb\usbdrv\usbdrv.c */ C:\C\system\usb\usbdrv\usbdrv.c 001270 ec5d CALL 0xeba,0x0 USBCtrlEPService(); C:\C\system\usb\usbdrv\usbdrv.c 001272 f007 C:\C\system\usb\usbdrv\usbdrv.c /* C:\C\system\usb\usbdrv\usbdrv.c * Other EP can be serviced later by responsible device class firmware. C:\C\system\usb\usbdrv\usbdrv.c * Each device driver knows when an OUT or IN transaction is ready by C:\C\system\usb\usbdrv\usbdrv.c * checking the buffer ownership bit. C:\C\system\usb\usbdrv\usbdrv.c * An OUT EP should always be owned by SIE until the data is ready. C:\C\system\usb\usbdrv\usbdrv.c * An IN EP should always be owned by CPU until the data is ready. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Because of this logic, it is not necessary to save the USTAT value C:\C\system\usb\usbdrv\usbdrv.c * of non-EP0 transactions. C:\C\system\usb\usbdrv\usbdrv.c */ C:\C\system\usb\usbdrv\usbdrv.c 001274 9668 BCF 0x68,0x3,0x0 UIRbits.TRNIF = 0; C:\C\system\usb\usbdrv\usbdrv.c }//end if(UIRbits.TRNIF && UIEbits.TRNIE) C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c 001276 0012 RETURN 0x0 }//end USBDriverService C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /****************************************************************************** C:\C\system\usb\usbdrv\usbdrv.c * Function: void USBSuspend(void) C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * PreCondition: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Input: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Output: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Side Effects: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Overview: C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Note: None C:\C\system\usb\usbdrv\usbdrv.c *****************************************************************************/ C:\C\system\usb\usbdrv\usbdrv.c void USBSuspend(void) C:\C\system\usb\usbdrv\usbdrv.c { C:\C\system\usb\usbdrv\usbdrv.c /* C:\C\system\usb\usbdrv\usbdrv.c * NOTE: Do not clear UIRbits.ACTVIF here! C:\C\system\usb\usbdrv\usbdrv.c * Reason: C:\C\system\usb\usbdrv\usbdrv.c * ACTVIF is only generated once an IDLEIF has been generated. C:\C\system\usb\usbdrv\usbdrv.c * This is a 1:1 ratio interrupt generation. C:\C\system\usb\usbdrv\usbdrv.c * For every IDLEIF, there will be only one ACTVIF regardless of C:\C\system\usb\usbdrv\usbdrv.c * the number of subsequent bus transitions. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * If the ACTIF is cleared here, a problem could occur when: C:\C\system\usb\usbdrv\usbdrv.c * [ IDLE ][bus activity -> C:\C\system\usb\usbdrv\usbdrv.c * <--- 3 ms -----> ^ C:\C\system\usb\usbdrv\usbdrv.c * ^ ACTVIF=1 C:\C\system\usb\usbdrv\usbdrv.c * IDLEIF=1 C:\C\system\usb\usbdrv\usbdrv.c * # # # # (#=Program polling flags) C:\C\system\usb\usbdrv\usbdrv.c * ^ C:\C\system\usb\usbdrv\usbdrv.c * This polling loop will see both C:\C\system\usb\usbdrv\usbdrv.c * IDLEIF=1 and ACTVIF=1. C:\C\system\usb\usbdrv\usbdrv.c * However, the program services IDLEIF first C:\C\system\usb\usbdrv\usbdrv.c * because ACTIVIE=0. C:\C\system\usb\usbdrv\usbdrv.c * If this routine clears the only ACTIVIF, C:\C\system\usb\usbdrv\usbdrv.c * then it can never get out of the suspend C:\C\system\usb\usbdrv\usbdrv.c * mode. C:\C\system\usb\usbdrv\usbdrv.c */ C:\C\system\usb\usbdrv\usbdrv.c 001278 8469 BSF 0x69,0x2,0x0 UIEbits.ACTVIE = 1; // Enable bus activity interrupt C:\C\system\usb\usbdrv\usbdrv.c 00127a 9868 BCF 0x68,0x4,0x0 UIRbits.IDLEIF = 0; C:\C\system\usb\usbdrv\usbdrv.c 00127c 826d BSF 0x6d,0x1,0x0 UCONbits.SUSPND = 1; // Put USB module in power conserve C:\C\system\usb\usbdrv\usbdrv.c // mode, SIE clock inactive C:\C\system\usb\usbdrv\usbdrv.c /* C:\C\system\usb\usbdrv\usbdrv.c * At this point the PIC can go into sleep,idle, or C:\C\system\usb\usbdrv\usbdrv.c * switch to a slower clock, etc. C:\C\system\usb\usbdrv\usbdrv.c */ C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /* Modifiable Section */ C:\C\system\usb\usbdrv\usbdrv.c 00127e 9aa1 BCF 0xa1,0x5,0x0 PIR2bits.USBIF = 0; C:\C\system\usb\usbdrv\usbdrv.c 001280 8aa0 BSF 0xa0,0x5,0x0 PIE2bits.USBIE = 1; // Set USB wakeup source C:\C\system\usb\usbdrv\usbdrv.c 001282 0003 SLEEP Sleep(); // Goto sleep C:\C\system\usb\usbdrv\usbdrv.c 001284 9aa0 BCF 0xa0,0x5,0x0 PIE2bits.USBIE = 0; C:\C\system\usb\usbdrv\usbdrv.c /* End Modifiable Section */ C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c 001286 0012 RETURN 0x0 }//end USBSuspend C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /****************************************************************************** C:\C\system\usb\usbdrv\usbdrv.c * Function: void USBWakeFromSuspend(void) C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * PreCondition: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Input: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Output: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Side Effects: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Overview: C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Note: None C:\C\system\usb\usbdrv\usbdrv.c *****************************************************************************/ C:\C\system\usb\usbdrv\usbdrv.c void USBWakeFromSuspend(void) C:\C\system\usb\usbdrv\usbdrv.c { C:\C\system\usb\usbdrv\usbdrv.c /* C:\C\system\usb\usbdrv\usbdrv.c * If using clock switching, this is the place to restore the C:\C\system\usb\usbdrv\usbdrv.c * original clock frequency. C:\C\system\usb\usbdrv\usbdrv.c */ C:\C\system\usb\usbdrv\usbdrv.c 001288 926d BCF 0x6d,0x1,0x0 UCONbits.SUSPND = 0; C:\C\system\usb\usbdrv\usbdrv.c 00128a 9469 BCF 0x69,0x2,0x0 UIEbits.ACTVIE = 0; C:\C\system\usb\usbdrv\usbdrv.c 00128c 9468 BCF 0x68,0x2,0x0 UIRbits.ACTVIF = 0; C:\C\system\usb\usbdrv\usbdrv.c 00128e 0012 RETURN 0x0 }//end USBWakeFromSuspend C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /****************************************************************************** C:\C\system\usb\usbdrv\usbdrv.c * Function: void USBRemoteWakeup(void) C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * PreCondition: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Input: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Output: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Side Effects: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Overview: This function should be called by user when the device C:\C\system\usb\usbdrv\usbdrv.c * is waken up by an external stimulus other than ACTIVIF. C:\C\system\usb\usbdrv\usbdrv.c * Please read the note below to understand the limitations. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Note: The modifiable section in this routine should be changed C:\C\system\usb\usbdrv\usbdrv.c * to meet the application needs. Current implementation C:\C\system\usb\usbdrv\usbdrv.c * temporary blocks other functions from executing for a C:\C\system\usb\usbdrv\usbdrv.c * period of 1-13 ms depending on the core frequency. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * According to USB 2.0 specification section 7.1.7.7, C:\C\system\usb\usbdrv\usbdrv.c * "The remote wakeup device must hold the resume signaling C:\C\system\usb\usbdrv\usbdrv.c * for at lest 1 ms but for no more than 15 ms." C:\C\system\usb\usbdrv\usbdrv.c * The idea here is to use a delay counter loop, using a C:\C\system\usb\usbdrv\usbdrv.c * common value that would work over a wide range of core C:\C\system\usb\usbdrv\usbdrv.c * frequencies. C:\C\system\usb\usbdrv\usbdrv.c * That value selected is 1800. See table below: C:\C\system\usb\usbdrv\usbdrv.c * ========================================================== C:\C\system\usb\usbdrv\usbdrv.c * Core Freq(MHz) MIP RESUME Signal Period (ms) C:\C\system\usb\usbdrv\usbdrv.c * ========================================================== C:\C\system\usb\usbdrv\usbdrv.c * 48 12 1.05 C:\C\system\usb\usbdrv\usbdrv.c * 4 1 12.6 C:\C\system\usb\usbdrv\usbdrv.c * ========================================================== C:\C\system\usb\usbdrv\usbdrv.c * * These timing could be incorrect when using code C:\C\system\usb\usbdrv\usbdrv.c * optimization or extended instruction mode, C:\C\system\usb\usbdrv\usbdrv.c * or when having other interrupts enabled. C:\C\system\usb\usbdrv\usbdrv.c * Make sure to verify using the MPLAB SIM's Stopwatch C:\C\system\usb\usbdrv\usbdrv.c *****************************************************************************/ C:\C\system\usb\usbdrv\usbdrv.c void USBRemoteWakeup(void) C:\C\system\usb\usbdrv\usbdrv.c { C:\C\system\usb\usbdrv\usbdrv.c static word delay_count; C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c 001290 0101 MOVLB 0x1 if(usb_stat.RemoteWakeup == 1) // Check if RemoteWakeup function C:\C\system\usb\usbdrv\usbdrv.c 001292 a113 BTFSS 0x13,0x0,0x1 001294 d00e BRA 0x12b2 { // has been enabled by the host. C:\C\system\usb\usbdrv\usbdrv.c 001296 dff8 RCALL 0x1288 USBWakeFromSuspend(); // Unsuspend USB modue C:\C\system\usb\usbdrv\usbdrv.c 001298 846d BSF 0x6d,0x2,0x0 UCONbits.RESUME = 1; // Start RESUME signaling C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /* Modifiable Section */ C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c 00129a 0101 MOVLB 0x1 delay_count = 1800U; // Set RESUME line for 1-13 ms C:\C\system\usb\usbdrv\usbdrv.c 00129c 0e08 MOVLW 0x8 00129e 6f16 MOVWF 0x16,0x1 0012a0 0e07 MOVLW 0x7 0012a2 6f17 MOVWF 0x17,0x1 do C:\C\system\usb\usbdrv\usbdrv.c { C:\C\system\usb\usbdrv\usbdrv.c 0012a4 0716 DECF 0x16,0x1,0x1 delay_count--; C:\C\system\usb\usbdrv\usbdrv.c 0012a6 0e00 MOVLW 0x0 0012a8 5b17 SUBWFB 0x17,0x1,0x1 0012aa 5116 MOVF 0x16,0x0,0x1 }while(delay_count); C:\C\system\usb\usbdrv\usbdrv.c 0012ac 1117 IORWF 0x17,0x0,0x1 0012ae e1fa BNZ 0x12a4 C:\C\system\usb\usbdrv\usbdrv.c /* End Modifiable Section */ C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c 0012b0 946d BCF 0x6d,0x2,0x0 UCONbits.RESUME = 0; C:\C\system\usb\usbdrv\usbdrv.c }//endif C:\C\system\usb\usbdrv\usbdrv.c 0012b2 0012 RETURN 0x0 }//end USBRemoteWakeup C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /****************************************************************************** C:\C\system\usb\usbdrv\usbdrv.c * Function: void USB_SOF_Handler(void) C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * PreCondition: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Input: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Output: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Side Effects: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Overview: The USB host sends out a SOF packet to full-speed devices C:\C\system\usb\usbdrv\usbdrv.c * every 1 ms. This interrupt may be useful for isochronous C:\C\system\usb\usbdrv\usbdrv.c * pipes. End designers should implement callback routine C:\C\system\usb\usbdrv\usbdrv.c * as necessary. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Note: None C:\C\system\usb\usbdrv\usbdrv.c *****************************************************************************/ C:\C\system\usb\usbdrv\usbdrv.c void USB_SOF_Handler(void) C:\C\system\usb\usbdrv\usbdrv.c { C:\C\system\usb\usbdrv\usbdrv.c /* Callback routine here */ C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c 0012b4 9c68 BCF 0x68,0x6,0x0 UIRbits.SOFIF = 0; C:\C\system\usb\usbdrv\usbdrv.c 0012b6 0012 RETURN 0x0 }//end USB_SOF_Handler C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /****************************************************************************** C:\C\system\usb\usbdrv\usbdrv.c * Function: void USBStallHandler(void) C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * PreCondition: A STALL packet is sent to the host by the SIE. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Input: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Output: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Side Effects: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Overview: The STALLIF is set anytime the SIE sends out a STALL C:\C\system\usb\usbdrv\usbdrv.c * packet regardless of which endpoint causes it. C:\C\system\usb\usbdrv\usbdrv.c * A Setup transaction overrides the STALL function. A stalled C:\C\system\usb\usbdrv\usbdrv.c * endpoint stops stalling once it receives a setup packet. C:\C\system\usb\usbdrv\usbdrv.c * In this case, the SIE will accepts the Setup packet and C:\C\system\usb\usbdrv\usbdrv.c * set the TRNIF flag to notify the firmware. STALL function C:\C\system\usb\usbdrv\usbdrv.c * for that particular endpoint pipe will be automatically C:\C\system\usb\usbdrv\usbdrv.c * disabled (direction specific). C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * There are a few reasons for an endpoint to be stalled. C:\C\system\usb\usbdrv\usbdrv.c * 1. When a non-supported USB request is received. C:\C\system\usb\usbdrv\usbdrv.c * Example: GET_DESCRIPTOR(DEVICE_QUALIFIER) C:\C\system\usb\usbdrv\usbdrv.c * 2. When an endpoint is currently halted. C:\C\system\usb\usbdrv\usbdrv.c * 3. When the device class specifies that an endpoint must C:\C\system\usb\usbdrv\usbdrv.c * stall in response to a specific event. C:\C\system\usb\usbdrv\usbdrv.c * Example: Mass Storage Device Class C:\C\system\usb\usbdrv\usbdrv.c * If the CBW is not valid, the device shall C:\C\system\usb\usbdrv\usbdrv.c * STALL the Bulk-In pipe. C:\C\system\usb\usbdrv\usbdrv.c * See USB Mass Storage Class Bulk-only Transport C:\C\system\usb\usbdrv\usbdrv.c * Specification for more details. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Note: UEPn.EPSTALL can be scanned to see which endpoint causes C:\C\system\usb\usbdrv\usbdrv.c * the stall event. C:\C\system\usb\usbdrv\usbdrv.c * If C:\C\system\usb\usbdrv\usbdrv.c *****************************************************************************/ C:\C\system\usb\usbdrv\usbdrv.c void USBStallHandler(void) C:\C\system\usb\usbdrv\usbdrv.c { C:\C\system\usb\usbdrv\usbdrv.c /* C:\C\system\usb\usbdrv\usbdrv.c * Does not really have to do anything here, C:\C\system\usb\usbdrv\usbdrv.c * even for the control endpoint. C:\C\system\usb\usbdrv\usbdrv.c * All BDs of Endpoint 0 are owned by SIE right now, C:\C\system\usb\usbdrv\usbdrv.c * but once a Setup Transaction is received, the ownership C:\C\system\usb\usbdrv\usbdrv.c * for EP0_OUT will be returned to CPU. C:\C\system\usb\usbdrv\usbdrv.c * When the Setup Transaction is serviced, the ownership C:\C\system\usb\usbdrv\usbdrv.c * for EP0_IN will then be forced back to CPU by firmware. C:\C\system\usb\usbdrv\usbdrv.c */ C:\C\system\usb\usbdrv\usbdrv.c 0012b8 a070 BTFSS 0x70,0x0,0x0 if(UEP0bits.EPSTALL == 1) C:\C\system\usb\usbdrv\usbdrv.c 0012ba d003 BRA 0x12c2 { C:\C\system\usb\usbdrv\usbdrv.c 0012bc ecd0 CALL 0x11a0,0x0 USBPrepareForNextSetupTrf(); // Firmware work-around C:\C\system\usb\usbdrv\usbdrv.c 0012be f008 0012c0 9070 BCF 0x70,0x0,0x0 UEP0bits.EPSTALL = 0; C:\C\system\usb\usbdrv\usbdrv.c } C:\C\system\usb\usbdrv\usbdrv.c 0012c2 9a68 BCF 0x68,0x5,0x0 UIRbits.STALLIF = 0; C:\C\system\usb\usbdrv\usbdrv.c 0012c4 0012 RETURN 0x0 }//end USBStallHandler C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /****************************************************************************** C:\C\system\usb\usbdrv\usbdrv.c * Function: void USBErrorHandler(void) C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * PreCondition: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Input: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Output: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Side Effects: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Overview: The purpose of this interrupt is mainly for debugging C:\C\system\usb\usbdrv\usbdrv.c * during development. Check UEIR to see which error causes C:\C\system\usb\usbdrv\usbdrv.c * the interrupt. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Note: None C:\C\system\usb\usbdrv\usbdrv.c *****************************************************************************/ C:\C\system\usb\usbdrv\usbdrv.c void USBErrorHandler(void) C:\C\system\usb\usbdrv\usbdrv.c { C:\C\system\usb\usbdrv\usbdrv.c 0012c6 9268 BCF 0x68,0x1,0x0 UIRbits.UERRIF = 0; C:\C\system\usb\usbdrv\usbdrv.c 0012c8 0012 RETURN 0x0 }//end USBErrorHandler C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /****************************************************************************** C:\C\system\usb\usbdrv\usbdrv.c * Function: void USBProtocolResetHandler(void) C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * PreCondition: A USB bus reset is received from the host. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Input: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Output: None C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Side Effects: Currently, this routine flushes any pending USB C:\C\system\usb\usbdrv\usbdrv.c * transactions. It empties out the USTAT FIFO. This action C:\C\system\usb\usbdrv\usbdrv.c * might not be desirable in some applications. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Overview: Once a USB bus reset is received from the host, this C:\C\system\usb\usbdrv\usbdrv.c * routine should be called. It resets the device address to C:\C\system\usb\usbdrv\usbdrv.c * zero, disables all non-EP0 endpoints, initializes EP0 to C:\C\system\usb\usbdrv\usbdrv.c * be ready for default communication, clears all USB C:\C\system\usb\usbdrv\usbdrv.c * interrupt flags, unmasks applicable USB interrupts, and C:\C\system\usb\usbdrv\usbdrv.c * reinitializes internal state-machine variables. C:\C\system\usb\usbdrv\usbdrv.c * C:\C\system\usb\usbdrv\usbdrv.c * Note: None C:\C\system\usb\usbdrv\usbdrv.c *****************************************************************************/ C:\C\system\usb\usbdrv\usbdrv.c void USBProtocolResetHandler(void) C:\C\system\usb\usbdrv\usbdrv.c { C:\C\system\usb\usbdrv\usbdrv.c 0012ca 6a6a CLRF 0x6a,0x0 UEIR = 0; // Clear all USB error flags C:\C\system\usb\usbdrv\usbdrv.c 0012cc 6a68 CLRF 0x68,0x0 UIR = 0; // Clears all USB interrupts C:\C\system\usb\usbdrv\usbdrv.c 0012ce 0e9f MOVLW 0x9f UEIE = 0b10011111; // Unmask all USB error interrupts C:\C\system\usb\usbdrv\usbdrv.c 0012d0 6e6b MOVWF 0x6b,0x0 0012d2 0e7b MOVLW 0x7b UIE = 0b01111011; // Enable all interrupts except ACTVIE C:\C\system\usb\usbdrv\usbdrv.c 0012d4 6e69 MOVWF 0x69,0x0 C:\C\system\usb\usbdrv\usbdrv.c 0012d6 6a6e CLRF 0x6e,0x0 UADDR = 0x00; // Reset to default address C:\C\system\usb\usbdrv\usbdrv.c 0012d8 0e0f MOVLW 0xf mDisableEP1to15(); // Reset all non-EP0 UEPn registers C:\C\system\usb\usbdrv\usbdrv.c 0012da 6ee6 MOVWF 0xe6,0x0 0012dc 0e71 MOVLW 0x71 0012de 6ee6 MOVWF 0xe6,0x0 0012e0 0e0f MOVLW 0xf 0012e2 6ee6 MOVWF 0xe6,0x0 0012e4 d814 RCALL 0x130e 0012e6 52e5 MOVF 0xe5,0x1,0x0 0012e8 52e5 MOVF 0xe5,0x1,0x0 0012ea 52e5 MOVF 0xe5,0x1,0x0 0012ec 0e16 MOVLW 0x16 UEP0 = EP_CTRL|HSHK_EN; // Init EP0 as a Ctrl EP, see usbdrv.h C:\C\system\usb\usbdrv\usbdrv.c 0012ee 6e70 MOVWF 0x70,0x0 C:\C\system\usb\usbdrv\usbdrv.c 0012f0 a668 BTFSS 0x68,0x3,0x0 while(UIRbits.TRNIF == 1) // Flush any pending transactions C:\C\system\usb\usbdrv\usbdrv.c 0012f2 d002 BRA 0x12f8 0012f6 d7fc BRA 0x12f0 0012f4 9668 BCF 0x68,0x3,0x0 UIRbits.TRNIF = 0; C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c 0012f8 986d BCF 0x6d,0x4,0x0 UCONbits.PKTDIS = 0; // Make sure packet processing is enabled C:\C\system\usb\usbdrv\usbdrv.c 0012fa ecd0 CALL 0x11a0,0x0 USBPrepareForNextSetupTrf(); // Declared in usbctrltrf.c C:\C\system\usb\usbdrv\usbdrv.c 0012fc f008 C:\C\system\usb\usbdrv\usbdrv.c 0012fe 0101 MOVLB 0x1 usb_stat.RemoteWakeup = 0; // Default status flag to disable C:\C\system\usb\usbdrv\usbdrv.c 001300 9113 BCF 0x13,0x0,0x1 001302 0101 MOVLB 0x1 usb_active_cfg = 0; // Clear active configuration C:\C\system\usb\usbdrv\usbdrv.c 001304 6b14 CLRF 0x14,0x1 001306 0101 MOVLB 0x1 usb_device_state = DEFAULT_STATE; C:\C\system\usb\usbdrv\usbdrv.c 001308 0e03 MOVLW 0x3 00130a 6f12 MOVWF 0x12,0x1 00130c 0012 RETURN 0x0 }//end USBProtocolResetHandler C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c C:\C\system\usb\usbdrv\usbdrv.c /* Auxiliary Function */ C:\C\system\usb\usbdrv\usbdrv.c 00130e cfd9 MOVFF 0xfd9,0xfe6 void ClearArray(byte* startAdr,byte count) C:\C\system\usb\usbdrv\usbdrv.c 001310 ffe6 001312 cfe1 MOVFF 0xfe1,0xfd9 001314 ffd9 { C:\C\system\usb\usbdrv\usbdrv.c 001316 0efd MOVLW 0xfd *startAdr; C:\C\system\usb\usbdrv\usbdrv.c 001318 cfdb MOVFF 0xfdb,0xfe9 00131a ffe9 00131c 0efe MOVLW 0xfe 00131e cfdb MOVFF 0xfdb,0xfea 001320 ffea 001322 0efc MOVLW 0xfc while(count) C:\C\system\usb\usbdrv\usbdrv.c 001324 50db MOVF 0xdb,0x0,0x0 001326 e004 BZ 0x1330 00132e d7f9 BRA 0x1322 { C:\C\system\usb\usbdrv\usbdrv.c _asm C:\C\system\usb\usbdrv\usbdrv.c 001328 6aee CLRF 0xee,0x0 clrf POSTINC0,0 C:\C\system\usb\usbdrv\usbdrv.c _endasm C:\C\system\usb\usbdrv\usbdrv.c 00132a 0efc MOVLW 0xfc count--; C:\C\system\usb\usbdrv\usbdrv.c 00132c 06db DECF 0xdb,0x1,0x0 }//end while C:\C\system\usb\usbdrv\usbdrv.c 001330 52e5 MOVF 0xe5,0x1,0x0 }//end ClearArray C:\C\system\usb\usbdrv\usbdrv.c 001332 cfe7 MOVFF 0xfe7,0xfd9 001334 ffd9 001336 0012 RETURN 0x0 C:\C\system\usb\usbdrv\usbdrv.c /** EOF usbdrv.c *************************************************************/ C:\C\system\usb\usbdrv\usbdrv.c /********************************************************************* C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Microchip USB C18 Firmware Version 1.0 C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c ********************************************************************* C:\C\system\usb\usb9\usb9.c * FileName: usb9.c C:\C\system\usb\usb9\usb9.c * Dependencies: See INCLUDES section below C:\C\system\usb\usb9\usb9.c * Processor: PIC18 C:\C\system\usb\usb9\usb9.c * Compiler: C18 2.30.01+ C:\C\system\usb\usb9\usb9.c * Company: Microchip Technology, Inc. C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Software License Agreement C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * The software supplied herewith by Microchip Technology Incorporated C:\C\system\usb\usb9\usb9.c * (the “Company”) for its PICmicro® Microcontroller is intended and C:\C\system\usb\usb9\usb9.c * supplied to you, the Company’s customer, for use solely and C:\C\system\usb\usb9\usb9.c * exclusively on Microchip PICmicro Microcontroller products. The C:\C\system\usb\usb9\usb9.c * software is owned by the Company and/or its supplier, and is C:\C\system\usb\usb9\usb9.c * protected under applicable copyright laws. All rights are reserved. C:\C\system\usb\usb9\usb9.c * Any use in violation of the foregoing restrictions may subject the C:\C\system\usb\usb9\usb9.c * user to criminal sanctions under applicable laws, as well as to C:\C\system\usb\usb9\usb9.c * civil liability for the breach of the terms and conditions of this C:\C\system\usb\usb9\usb9.c * license. C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, C:\C\system\usb\usb9\usb9.c * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED C:\C\system\usb\usb9\usb9.c * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A C:\C\system\usb\usb9\usb9.c * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, C:\C\system\usb\usb9\usb9.c * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR C:\C\system\usb\usb9\usb9.c * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Author Date Comment C:\C\system\usb\usb9\usb9.c *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C:\C\system\usb\usb9\usb9.c * Rawin Rojvanit 11/19/04 Original. C:\C\system\usb\usb9\usb9.c ********************************************************************/ C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c /** I N C L U D E S **********************************************************/ C:\C\system\usb\usb9\usb9.c #include C:\C\system\usb\usb9\usb9.c #include "system\typedefs.h" C:\C\system\usb\usb9\usb9.c #include "system\usb\usb.h" C:\C\system\usb\usb9\usb9.c #include "io_cfg.h" // Required for self_power status C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c /** V A R I A B L E S ********************************************************/ C:\C\system\usb\usb9\usb9.c #pragma udata C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c /** P R I V A T E P R O T O T Y P E S ***************************************/ C:\C\system\usb\usb9\usb9.c void USBStdGetDscHandler(void); C:\C\system\usb\usb9\usb9.c void USBStdSetCfgHandler(void); C:\C\system\usb\usb9\usb9.c void USBStdGetStatusHandler(void); C:\C\system\usb\usb9\usb9.c void USBStdFeatureReqHandler(void); C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c /** D E C L A R A T I O N S **************************************************/ C:\C\system\usb\usb9\usb9.c #pragma code C:\C\system\usb\usb9\usb9.c /****************************************************************************** C:\C\system\usb\usb9\usb9.c * Function: void USBCheckStdRequest(void) C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * PreCondition: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Input: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Output: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Side Effects: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Overview: This routine checks the setup data packet to see if it C:\C\system\usb\usb9\usb9.c * knows how to handle it C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Note: None C:\C\system\usb\usb9\usb9.c *****************************************************************************/ C:\C\system\usb\usb9\usb9.c void USBCheckStdRequest(void) C:\C\system\usb\usb9\usb9.c { C:\C\system\usb\usb9\usb9.c 000bb2 0104 MOVLB 0x4 if(SetupPkt.RequestType != STANDARD) return; C:\C\system\usb\usb9\usb9.c 000bb4 5120 MOVF 0x20,0x0,0x1 000bb6 0b60 ANDLW 0x60 000bb8 42e8 RRNCF 0xe8,0x1,0x0 000bba 42e8 RRNCF 0xe8,0x1,0x0 000bbc 42e8 RRNCF 0xe8,0x1,0x0 000bbe 42e8 RRNCF 0xe8,0x1,0x0 000bc0 42e8 RRNCF 0xe8,0x1,0x0 000bc2 0900 IORLW 0x0 000bc4 e001 BZ 0xbc8 000bc6 d055 BRA 0xc72 C:\C\system\usb\usb9\usb9.c 000bc8 5121 MOVF 0x21,0x0,0x1 switch(SetupPkt.bRequest) C:\C\system\usb\usb9\usb9.c 000bca 0a07 XORLW 0x7 000bcc e051 BZ 0xc70 000bce 0a0b XORLW 0xb 000bd0 e04f BZ 0xc70 000bd2 0a07 XORLW 0x7 000bd4 e040 BZ 0xc56 000bd6 0a01 XORLW 0x1 000bd8 e02c BZ 0xc32 000bda 0a0b XORLW 0xb 000bdc e028 BZ 0xc2e 000bde 0a02 XORLW 0x2 000be0 e026 BZ 0xc2e 000be2 0a03 XORLW 0x3 000be4 e022 BZ 0xc2a 000be6 0a08 XORLW 0x8 000be8 e012 BZ 0xc0e 000bea 0a01 XORLW 0x1 000bec e00e BZ 0xc0a 000bee 0a0f XORLW 0xf 000bf0 e00a BZ 0xc06 000bf2 0a03 XORLW 0x3 000bf4 e001 BZ 0xbf8 000bf6 d03c BRA 0xc70 { C:\C\system\usb\usb9\usb9.c case SET_ADR: C:\C\system\usb\usb9\usb9.c 000bf8 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_USB9; C:\C\system\usb\usb9\usb9.c 000bfa 0e01 MOVLW 0x1 000bfc 6f0b MOVWF 0xb,0x1 000bfe 0101 MOVLB 0x1 usb_device_state = ADR_PENDING_STATE; // Update state only C:\C\system\usb\usb9\usb9.c 000c00 0e04 MOVLW 0x4 000c02 6f12 MOVWF 0x12,0x1 /* See USBCtrlTrfInHandler() in usbctrltrf.c for the next step */ C:\C\system\usb\usb9\usb9.c 000c04 d036 BRA 0xc72 break; C:\C\system\usb\usb9\usb9.c case GET_DSC: C:\C\system\usb\usb9\usb9.c 000c06 d836 RCALL 0xc74 USBStdGetDscHandler(); C:\C\system\usb\usb9\usb9.c 000c08 d034 BRA 0xc72 break; C:\C\system\usb\usb9\usb9.c case SET_CFG: C:\C\system\usb\usb9\usb9.c 000c0a d890 RCALL 0xd2c USBStdSetCfgHandler(); C:\C\system\usb\usb9\usb9.c 000c0c d032 BRA 0xc72 break; C:\C\system\usb\usb9\usb9.c case GET_CFG: C:\C\system\usb\usb9\usb9.c 000c0e 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_USB9; C:\C\system\usb\usb9\usb9.c 000c10 0e01 MOVLW 0x1 000c12 6f0b MOVWF 0xb,0x1 000c14 0101 MOVLB 0x1 pSrc.bRam = (byte*)&usb_active_cfg; // Set Source C:\C\system\usb\usb9\usb9.c 000c16 0e14 MOVLW 0x14 000c18 6f0c MOVWF 0xc,0x1 000c1a 0e01 MOVLW 0x1 000c1c 6f0d MOVWF 0xd,0x1 000c1e 0101 MOVLB 0x1 usb_stat.ctrl_trf_mem = _RAM; // Set memory type C:\C\system\usb\usb9\usb9.c 000c20 9313 BCF 0x13,0x1,0x1 000c22 0101 MOVLB 0x1 LSB(wCount) = 1; // Set data count C:\C\system\usb\usb9\usb9.c 000c24 0e01 MOVLW 0x1 000c26 6f10 MOVWF 0x10,0x1 000c28 d024 BRA 0xc72 break; C:\C\system\usb\usb9\usb9.c case GET_STATUS: C:\C\system\usb\usb9\usb9.c 000c2a d8a8 RCALL 0xd7c USBStdGetStatusHandler(); C:\C\system\usb\usb9\usb9.c 000c2c d022 BRA 0xc72 break; C:\C\system\usb\usb9\usb9.c case CLR_FEATURE: C:\C\system\usb\usb9\usb9.c case SET_FEATURE: C:\C\system\usb\usb9\usb9.c 000c2e d8f4 RCALL 0xe18 USBStdFeatureReqHandler(); C:\C\system\usb\usb9\usb9.c 000c30 d020 BRA 0xc72 break; C:\C\system\usb\usb9\usb9.c case GET_INTF: C:\C\system\usb\usb9\usb9.c 000c32 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_USB9; C:\C\system\usb\usb9\usb9.c 000c34 0e01 MOVLW 0x1 000c36 6f0b MOVWF 0xb,0x1 000c38 0104 MOVLB 0x4 pSrc.bRam = (byte*)&usb_alt_intf+SetupPkt.bIntfID; // Set source C:\C\system\usb\usb9\usb9.c 000c3a 5124 MOVF 0x24,0x0,0x1 000c3c 0101 MOVLB 0x1 000c3e 6f0c MOVWF 0xc,0x1 000c40 6b0d CLRF 0xd,0x1 000c42 0e15 MOVLW 0x15 000c44 270c ADDWF 0xc,0x1,0x1 000c46 0e01 MOVLW 0x1 000c48 230d ADDWFC 0xd,0x1,0x1 000c4a 0101 MOVLB 0x1 usb_stat.ctrl_trf_mem = _RAM; // Set memory type C:\C\system\usb\usb9\usb9.c 000c4c 9313 BCF 0x13,0x1,0x1 000c4e 0101 MOVLB 0x1 LSB(wCount) = 1; // Set data count C:\C\system\usb\usb9\usb9.c 000c50 0e01 MOVLW 0x1 000c52 6f10 MOVWF 0x10,0x1 000c54 d00e BRA 0xc72 break; C:\C\system\usb\usb9\usb9.c case SET_INTF: C:\C\system\usb\usb9\usb9.c 000c56 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_USB9; C:\C\system\usb\usb9\usb9.c 000c58 0e01 MOVLW 0x1 000c5a 6f0b MOVWF 0xb,0x1 000c5c 0104 MOVLB 0x4 usb_alt_intf[SetupPkt.bIntfID] = SetupPkt.bAltID; C:\C\system\usb\usb9\usb9.c 000c5e 5124 MOVF 0x24,0x0,0x1 000c60 6aea CLRF 0xea,0x0 000c62 0f15 ADDLW 0x15 000c64 6ee9 MOVWF 0xe9,0x0 000c66 0e01 MOVLW 0x1 000c68 22ea ADDWFC 0xea,0x1,0x0 000c6a c422 MOVFF 0x422,0xfef 000c6c ffef 000c6e d001 BRA 0xc72 break; C:\C\system\usb\usb9\usb9.c case SET_DSC: C:\C\system\usb\usb9\usb9.c case SYNCH_FRAME: C:\C\system\usb\usb9\usb9.c default: C:\C\system\usb\usb9\usb9.c 000c70 d000 BRA 0xc72 break; C:\C\system\usb\usb9\usb9.c }//end switch C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c 000c72 0012 RETURN 0x0 }//end USBCheckStdRequest C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c /****************************************************************************** C:\C\system\usb\usb9\usb9.c * Function: void USBStdGetDscHandler(void) C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * PreCondition: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Input: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Output: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Side Effects: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Overview: This routine handles the standard GET_DESCRIPTOR request. C:\C\system\usb\usb9\usb9.c * It utilizes tables dynamically looks up descriptor size. C:\C\system\usb\usb9\usb9.c * This routine should never have to be modified if the tables C:\C\system\usb\usb9\usb9.c * in usbdsc.c are declared correctly. C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Note: None C:\C\system\usb\usb9\usb9.c *****************************************************************************/ C:\C\system\usb\usb9\usb9.c void USBStdGetDscHandler(void) C:\C\system\usb\usb9\usb9.c { C:\C\system\usb\usb9\usb9.c 000c74 0e80 MOVLW 0x80 if(SetupPkt.bmRequestType == 0x80) C:\C\system\usb\usb9\usb9.c 000c76 0104 MOVLB 0x4 000c78 5d20 SUBWF 0x20,0x0,0x1 000c7a e157 BNZ 0xd2a { C:\C\system\usb\usb9\usb9.c 000c7c 5123 MOVF 0x23,0x0,0x1 switch(SetupPkt.bDscType) C:\C\system\usb\usb9\usb9.c 000c7e 0a03 XORLW 0x3 000c80 e034 BZ 0xcea 000c82 0a01 XORLW 0x1 000c84 e010 BZ 0xca6 000c86 0a03 XORLW 0x3 000c88 e001 BZ 0xc8c 000c8a d04d BRA 0xd26 { C:\C\system\usb\usb9\usb9.c case DSC_DEV: C:\C\system\usb\usb9\usb9.c 000c8c 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_USB9; C:\C\system\usb\usb9\usb9.c 000c8e 0e01 MOVLW 0x1 000c90 6f0b MOVWF 0xb,0x1 000c92 0101 MOVLB 0x1 pSrc.bRom = (rom byte*)&device_dsc; C:\C\system\usb\usb9\usb9.c 000c94 0e8a MOVLW 0x8a 000c96 6f0c MOVWF 0xc,0x1 000c98 0e14 MOVLW 0x14 000c9a 6f0d MOVWF 0xd,0x1 000c9c 0e12 MOVLW 0x12 wCount._word = sizeof(device_dsc); // Set data count C:\C\system\usb\usb9\usb9.c 000c9e 0101 MOVLB 0x1 000ca0 6f10 MOVWF 0x10,0x1 000ca2 6b11 CLRF 0x11,0x1 000ca4 d040 BRA 0xd26 break; C:\C\system\usb\usb9\usb9.c case DSC_CFG: C:\C\system\usb\usb9\usb9.c 000ca6 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_USB9; C:\C\system\usb\usb9\usb9.c 000ca8 0e01 MOVLW 0x1 000caa 6f0b MOVWF 0xb,0x1 000cac 0104 MOVLB 0x4 pSrc.bRom = *(USB_CD_Ptr+SetupPkt.bDscIndex); C:\C\system\usb\usb9\usb9.c 000cae 5122 MOVF 0x22,0x0,0x1 000cb0 6ef6 MOVWF 0xf6,0x0 000cb2 6af7 CLRF 0xf7,0x0 000cb4 90d8 BCF 0xd8,0x0,0x0 000cb6 36f6 RLCF 0xf6,0x1,0x0 000cb8 36f7 RLCF 0xf7,0x1,0x0 000cba 0e3f MOVLW 0x3f 000cbc 26f6 ADDWF 0xf6,0x1,0x0 000cbe 0e15 MOVLW 0x15 000cc0 22f7 ADDWFC 0xf7,0x1,0x0 000cc2 0009 TBLRDPOSTINC 000cc4 cff5 MOVFF 0xff5,0x10c 000cc6 f10c 000cc8 000a TBLRDPOSTDEC 000cca cff5 MOVFF 0xff5,0x10d 000ccc f10d 000cce 0e02 MOVLW 0x2 wCount._word = *(pSrc.wRom+1); // Set data count C:\C\system\usb\usb9\usb9.c 000cd0 0101 MOVLB 0x1 000cd2 6af7 CLRF 0xf7,0x0 000cd4 250c ADDWF 0xc,0x0,0x1 000cd6 6ef6 MOVWF 0xf6,0x0 000cd8 510d MOVF 0xd,0x0,0x1 000cda 22f7 ADDWFC 0xf7,0x1,0x0 000cdc 0009 TBLRDPOSTINC 000cde cff5 MOVFF 0xff5,0x110 000ce0 f110 000ce2 000a TBLRDPOSTDEC 000ce4 cff5 MOVFF 0xff5,0x111 000ce6 f111 000ce8 d01e BRA 0xd26 break; C:\C\system\usb\usb9\usb9.c case DSC_STR: C:\C\system\usb\usb9\usb9.c 000cea 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_USB9; C:\C\system\usb\usb9\usb9.c 000cec 0e01 MOVLW 0x1 000cee 6f0b MOVWF 0xb,0x1 000cf0 0104 MOVLB 0x4 pSrc.bRom = *(USB_SD_Ptr+SetupPkt.bDscIndex); C:\C\system\usb\usb9\usb9.c 000cf2 5122 MOVF 0x22,0x0,0x1 000cf4 6ef6 MOVWF 0xf6,0x0 000cf6 6af7 CLRF 0xf7,0x0 000cf8 90d8 BCF 0xd8,0x0,0x0 000cfa 36f6 RLCF 0xf6,0x1,0x0 000cfc 36f7 RLCF 0xf7,0x1,0x0 000cfe 0e43 MOVLW 0x43 000d00 26f6 ADDWF 0xf6,0x1,0x0 000d02 0e15 MOVLW 0x15 000d04 22f7 ADDWFC 0xf7,0x1,0x0 000d06 0009 TBLRDPOSTINC 000d08 cff5 MOVFF 0xff5,0x10c 000d0a f10c 000d0c 000a TBLRDPOSTDEC 000d0e cff5 MOVFF 0xff5,0x10d 000d10 f10d 000d12 c10c MOVFF 0x10c,0xff6 wCount._word = *pSrc.bRom; // Set data count C:\C\system\usb\usb9\usb9.c 000d14 fff6 000d16 c10d MOVFF 0x10d,0xff7 000d18 fff7 000d1a 0008 TBLRD 000d1c 50f5 MOVF 0xf5,0x0,0x0 000d1e 0101 MOVLB 0x1 000d20 6f10 MOVWF 0x10,0x1 000d22 6b11 CLRF 0x11,0x1 000d24 d000 BRA 0xd26 break; C:\C\system\usb\usb9\usb9.c }//end switch C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c 000d26 0101 MOVLB 0x1 usb_stat.ctrl_trf_mem = _ROM; // Set memory type C:\C\system\usb\usb9\usb9.c 000d28 8313 BSF 0x13,0x1,0x1 }//end if C:\C\system\usb\usb9\usb9.c 000d2a 0012 RETURN 0x0 }//end USBStdGetDscHandler C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c /****************************************************************************** C:\C\system\usb\usb9\usb9.c * Function: void USBStdSetCfgHandler(void) C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * PreCondition: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Input: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Output: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Side Effects: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Overview: This routine first disables all endpoints by clearing C:\C\system\usb\usb9\usb9.c * UEP registers. It then configures (initializes) endpoints C:\C\system\usb\usb9\usb9.c * specified in the modifiable section. C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Note: None C:\C\system\usb\usb9\usb9.c *****************************************************************************/ C:\C\system\usb\usb9\usb9.c void USBStdSetCfgHandler(void) C:\C\system\usb\usb9\usb9.c { C:\C\system\usb\usb9\usb9.c 000d2c 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_USB9; C:\C\system\usb\usb9\usb9.c 000d2e 0e01 MOVLW 0x1 000d30 6f0b MOVWF 0xb,0x1 000d32 0e0f MOVLW 0xf mDisableEP1to15(); // See usbdrv.h C:\C\system\usb\usb9\usb9.c 000d34 6ee6 MOVWF 0xe6,0x0 000d36 0e71 MOVLW 0x71 000d38 6ee6 MOVWF 0xe6,0x0 000d3a 0e0f MOVLW 0xf 000d3c 6ee6 MOVWF 0xe6,0x0 000d3e ec87 CALL 0x130e,0x0 000d40 f009 000d42 52e5 MOVF 0xe5,0x1,0x0 000d44 52e5 MOVF 0xe5,0x1,0x0 000d46 52e5 MOVF 0xe5,0x1,0x0 000d48 0e01 MOVLW 0x1 ClearArray((byte*)&usb_alt_intf,MAX_NUM_INT); C:\C\system\usb\usb9\usb9.c 000d4a 6ee6 MOVWF 0xe6,0x0 000d4c 0e15 MOVLW 0x15 000d4e 6ee6 MOVWF 0xe6,0x0 000d50 0e01 MOVLW 0x1 000d52 6ee6 MOVWF 0xe6,0x0 000d54 ec87 CALL 0x130e,0x0 000d56 f009 000d58 52e5 MOVF 0xe5,0x1,0x0 000d5a 52e5 MOVF 0xe5,0x1,0x0 000d5c 52e5 MOVF 0xe5,0x1,0x0 000d5e c422 MOVFF 0x422,0x114 usb_active_cfg = SetupPkt.bCfgValue; C:\C\system\usb\usb9\usb9.c 000d60 f114 000d62 0104 MOVLB 0x4 if(SetupPkt.bCfgValue == 0) C:\C\system\usb\usb9\usb9.c 000d64 5122 MOVF 0x22,0x0,0x1 000d66 e104 BNZ 0xd70 000d68 0101 MOVLB 0x1 usb_device_state = ADDRESS_STATE; C:\C\system\usb\usb9\usb9.c 000d6a 0e05 MOVLW 0x5 000d6c 6f12 MOVWF 0x12,0x1 000d6e d005 BRA 0xd7a else C:\C\system\usb\usb9\usb9.c { C:\C\system\usb\usb9\usb9.c 000d70 0101 MOVLB 0x1 usb_device_state = CONFIGURED_STATE; C:\C\system\usb\usb9\usb9.c 000d72 0e06 MOVLW 0x6 000d74 6f12 MOVWF 0x12,0x1 C:\C\system\usb\usb9\usb9.c /* Modifiable Section */ C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c #if defined(USB_USE_CDC) // See autofiles\usbcfg.h C:\C\system\usb\usb9\usb9.c 000d76 ec7e CALL 0x8fc,0x0 CDCInitEP(); C:\C\system\usb\usb9\usb9.c 000d78 f004 #endif C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c /* End modifiable section */ C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c }//end if(SetupPkt.bcfgValue == 0) C:\C\system\usb\usb9\usb9.c 000d7a 0012 RETURN 0x0 }//end USBStdSetCfgHandler C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c /****************************************************************************** C:\C\system\usb\usb9\usb9.c * Function: void USBStdGetStatusHandler(void) C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * PreCondition: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Input: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Output: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Side Effects: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Overview: This routine handles the standard GET_STATUS request C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Note: None C:\C\system\usb\usb9\usb9.c *****************************************************************************/ C:\C\system\usb\usb9\usb9.c void USBStdGetStatusHandler(void) C:\C\system\usb\usb9\usb9.c { C:\C\system\usb\usb9\usb9.c 000d7c 0104 MOVLB 0x4 CtrlTrfData._byte0 = 0; // Initialize content C:\C\system\usb\usb9\usb9.c 000d7e 6b28 CLRF 0x28,0x1 000d80 6b29 CLRF 0x29,0x1 CtrlTrfData._byte1 = 0; C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c 000d82 0104 MOVLB 0x4 switch(SetupPkt.Recipient) C:\C\system\usb\usb9\usb9.c 000d84 5120 MOVF 0x20,0x0,0x1 000d86 0b1f ANDLW 0x1f 000d88 0a02 XORLW 0x2 000d8a e014 BZ 0xdb4 000d8c 0a03 XORLW 0x3 000d8e e00e BZ 0xdac 000d90 0a01 XORLW 0x1 000d92 e001 BZ 0xd96 000d94 d033 BRA 0xdfc { C:\C\system\usb\usb9\usb9.c case RCPT_DEV: C:\C\system\usb\usb9\usb9.c 000d96 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_USB9; C:\C\system\usb\usb9\usb9.c 000d98 0e01 MOVLW 0x1 000d9a 6f0b MOVWF 0xb,0x1 /* C:\C\system\usb\usb9\usb9.c * _byte0: bit0: Self-Powered Status [0] Bus-Powered [1] Self-Powered C:\C\system\usb\usb9\usb9.c * bit1: RemoteWakeup [0] Disabled [1] Enabled C:\C\system\usb\usb9\usb9.c */ C:\C\system\usb\usb9\usb9.c if(self_power == 1) // self_power defined in io_cfg.h C:\C\system\usb\usb9\usb9.c 000d9c 0104 MOVLB 0x4 CtrlTrfData._byte0|=0b000000001; // Set bit0 C:\C\system\usb\usb9\usb9.c 000d9e 8128 BSF 0x28,0x0,0x1 C:\C\system\usb\usb9\usb9.c 000da0 0101 MOVLB 0x1 if(usb_stat.RemoteWakeup == 1) // usb_stat defined in usbmmap.c C:\C\system\usb\usb9\usb9.c 000da2 a113 BTFSS 0x13,0x0,0x1 000da4 d002 BRA 0xdaa 000da6 0104 MOVLB 0x4 CtrlTrfData._byte0|=0b00000010; // Set bit1 C:\C\system\usb\usb9\usb9.c 000da8 8328 BSF 0x28,0x1,0x1 000daa d028 BRA 0xdfc break; C:\C\system\usb\usb9\usb9.c case RCPT_INTF: C:\C\system\usb\usb9\usb9.c 000dac 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_USB9; // No data to update C:\C\system\usb\usb9\usb9.c 000dae 0e01 MOVLW 0x1 000db0 6f0b MOVWF 0xb,0x1 000db2 d024 BRA 0xdfc break; C:\C\system\usb\usb9\usb9.c case RCPT_EP: C:\C\system\usb\usb9\usb9.c 000db4 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_USB9; C:\C\system\usb\usb9\usb9.c 000db6 0e01 MOVLW 0x1 000db8 6f0b MOVWF 0xb,0x1 /* C:\C\system\usb\usb9\usb9.c * _byte0: bit0: Halt Status [0] Not Halted [1] Halted C:\C\system\usb\usb9\usb9.c */ C:\C\system\usb\usb9\usb9.c 000dba 0104 MOVLB 0x4 pDst.bRam = (byte*)&ep0Bo+(SetupPkt.EPNum*8)+(SetupPkt.EPDir*4); C:\C\system\usb\usb9\usb9.c 000dbc 5124 MOVF 0x24,0x0,0x1 000dbe 0b0f ANDLW 0xf 000dc0 0d08 MULLW 0x8 000dc2 50f3 MOVF 0xf3,0x0,0x0 000dc4 6a03 CLRF 0x3,0x0 000dc6 0f00 ADDLW 0x0 000dc8 6e02 MOVWF 0x2,0x0 000dca 0e04 MOVLW 0x4 000dcc 2203 ADDWFC 0x3,0x1,0x0 000dce 5124 MOVF 0x24,0x0,0x1 000dd0 0b80 ANDLW 0x80 000dd2 e001 BZ 0xdd6 000dd4 0e01 MOVLW 0x1 000dd6 0d04 MULLW 0x4 000dd8 50f3 MOVF 0xf3,0x0,0x0 000dda 0101 MOVLB 0x1 000ddc 2402 ADDWF 0x2,0x0,0x0 000dde 6f0e MOVWF 0xe,0x1 000de0 0e00 MOVLW 0x0 000de2 2003 ADDWFC 0x3,0x0,0x0 000de4 6f0f MOVWF 0xf,0x1 000de6 c10e MOVFF 0x10e,0xfe9 if(*pDst.bRam & _BSTALL) // Use _BSTALL as a bit mask C:\C\system\usb\usb9\usb9.c 000de8 ffe9 000dea c10f MOVFF 0x10f,0xfea 000dec ffea 000dee 50ef MOVF 0xef,0x0,0x0 000df0 0b04 ANDLW 0x4 000df2 e003 BZ 0xdfa 000df4 0104 MOVLB 0x4 CtrlTrfData._byte0=0x01;// Set bit0 C:\C\system\usb\usb9\usb9.c 000df6 0e01 MOVLW 0x1 000df8 6f28 MOVWF 0x28,0x1 000dfa d000 BRA 0xdfc break; C:\C\system\usb\usb9\usb9.c }//end switch C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c 000dfc 0101 MOVLB 0x1 if(ctrl_trf_session_owner == MUID_USB9) C:\C\system\usb\usb9\usb9.c 000dfe 050b DECF 0xb,0x0,0x1 000e00 e10a BNZ 0xe16 { C:\C\system\usb\usb9\usb9.c 000e02 0101 MOVLB 0x1 pSrc.bRam = (byte*)&CtrlTrfData; // Set Source C:\C\system\usb\usb9\usb9.c 000e04 0e28 MOVLW 0x28 000e06 6f0c MOVWF 0xc,0x1 000e08 0e04 MOVLW 0x4 000e0a 6f0d MOVWF 0xd,0x1 000e0c 0101 MOVLB 0x1 usb_stat.ctrl_trf_mem = _RAM; // Set memory type C:\C\system\usb\usb9\usb9.c 000e0e 9313 BCF 0x13,0x1,0x1 000e10 0101 MOVLB 0x1 LSB(wCount) = 2; // Set data count C:\C\system\usb\usb9\usb9.c 000e12 0e02 MOVLW 0x2 000e14 6f10 MOVWF 0x10,0x1 }//end if(...) C:\C\system\usb\usb9\usb9.c 000e16 0012 RETURN 0x0 }//end USBStdGetStatusHandler C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c /****************************************************************************** C:\C\system\usb\usb9\usb9.c * Function: void USBStdFeatureReqHandler(void) C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * PreCondition: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Input: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Output: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Side Effects: None C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Overview: This routine handles the standard SET & CLEAR FEATURES C:\C\system\usb\usb9\usb9.c * requests C:\C\system\usb\usb9\usb9.c * C:\C\system\usb\usb9\usb9.c * Note: None C:\C\system\usb\usb9\usb9.c *****************************************************************************/ C:\C\system\usb\usb9\usb9.c void USBStdFeatureReqHandler(void) C:\C\system\usb\usb9\usb9.c { C:\C\system\usb\usb9\usb9.c 000e18 0104 MOVLB 0x4 if((SetupPkt.bFeature == DEVICE_REMOTE_WAKEUP)&& C:\C\system\usb\usb9\usb9.c 000e1a 0522 DECF 0x22,0x0,0x1 000e1c e110 BNZ 0xe3e (SetupPkt.Recipient == RCPT_DEV)) C:\C\system\usb\usb9\usb9.c 000e1e 5120 MOVF 0x20,0x0,0x1 000e20 0b1f ANDLW 0x1f 000e22 0900 IORLW 0x0 000e24 e10c BNZ 0xe3e { C:\C\system\usb\usb9\usb9.c 000e26 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_USB9; C:\C\system\usb\usb9\usb9.c 000e28 0e01 MOVLW 0x1 000e2a 6f0b MOVWF 0xb,0x1 000e2c 0e03 MOVLW 0x3 if(SetupPkt.bRequest == SET_FEATURE) C:\C\system\usb\usb9\usb9.c 000e2e 0104 MOVLB 0x4 000e30 5d21 SUBWF 0x21,0x0,0x1 000e32 e103 BNZ 0xe3a 000e34 0101 MOVLB 0x1 usb_stat.RemoteWakeup = 1; C:\C\system\usb\usb9\usb9.c 000e36 8113 BSF 0x13,0x0,0x1 000e38 d002 BRA 0xe3e else C:\C\system\usb\usb9\usb9.c 000e3a 0101 MOVLB 0x1 usb_stat.RemoteWakeup = 0; C:\C\system\usb\usb9\usb9.c 000e3c 9113 BCF 0x13,0x0,0x1 }//end if C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c 000e3e 0104 MOVLB 0x4 if((SetupPkt.bFeature == ENDPOINT_HALT)&& C:\C\system\usb\usb9\usb9.c 000e40 5122 MOVF 0x22,0x0,0x1 000e42 e13a BNZ 0xeb8 (SetupPkt.Recipient == RCPT_EP)&& C:\C\system\usb\usb9\usb9.c 000e44 5120 MOVF 0x20,0x0,0x1 000e46 0b1f ANDLW 0x1f 000e48 0802 SUBLW 0x2 000e4a e136 BNZ 0xeb8 000e4c 5124 MOVF 0x24,0x0,0x1 (SetupPkt.EPNum != 0)) C:\C\system\usb\usb9\usb9.c 000e4e 0b0f ANDLW 0xf 000e50 0900 IORLW 0x0 000e52 e032 BZ 0xeb8 { C:\C\system\usb\usb9\usb9.c 000e54 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_USB9; C:\C\system\usb\usb9\usb9.c 000e56 0e01 MOVLW 0x1 000e58 6f0b MOVWF 0xb,0x1 /* Must do address calculation here */ C:\C\system\usb\usb9\usb9.c 000e5a 0104 MOVLB 0x4 pDst.bRam = (byte*)&ep0Bo+(SetupPkt.EPNum*8)+(SetupPkt.EPDir*4); C:\C\system\usb\usb9\usb9.c 000e5c 5124 MOVF 0x24,0x0,0x1 000e5e 0b0f ANDLW 0xf 000e60 0d08 MULLW 0x8 000e62 50f3 MOVF 0xf3,0x0,0x0 000e64 6a03 CLRF 0x3,0x0 000e66 0f00 ADDLW 0x0 000e68 6e02 MOVWF 0x2,0x0 000e6a 0e04 MOVLW 0x4 000e6c 2203 ADDWFC 0x3,0x1,0x0 000e6e 5124 MOVF 0x24,0x0,0x1 000e70 0b80 ANDLW 0x80 000e72 e001 BZ 0xe76 000e74 0e01 MOVLW 0x1 000e76 0d04 MULLW 0x4 000e78 50f3 MOVF 0xf3,0x0,0x0 000e7a 0101 MOVLB 0x1 000e7c 2402 ADDWF 0x2,0x0,0x0 000e7e 6f0e MOVWF 0xe,0x1 000e80 0e00 MOVLW 0x0 000e82 2003 ADDWFC 0x3,0x0,0x0 000e84 6f0f MOVWF 0xf,0x1 C:\C\system\usb\usb9\usb9.c 000e86 0e03 MOVLW 0x3 if(SetupPkt.bRequest == SET_FEATURE) C:\C\system\usb\usb9\usb9.c 000e88 0104 MOVLB 0x4 000e8a 5d21 SUBWF 0x21,0x0,0x1 000e8c e107 BNZ 0xe9c 000e8e 0e84 MOVLW 0x84 *pDst.bRam = _USIE|_BSTALL; C:\C\system\usb\usb9\usb9.c 000e90 c10e MOVFF 0x10e,0xfe9 000e92 ffe9 000e94 c10f MOVFF 0x10f,0xfea 000e96 ffea 000e98 6eef MOVWF 0xef,0x0 000e9a d00e BRA 0xeb8 else C:\C\system\usb\usb9\usb9.c { C:\C\system\usb\usb9\usb9.c 000e9c af24 BTFSS 0x24,0x7,0x1 if(SetupPkt.EPDir == 1) // IN C:\C\system\usb\usb9\usb9.c 000e9e d006 BRA 0xeac 000ea0 c10e MOVFF 0x10e,0xfe9 *pDst.bRam = _UCPU; C:\C\system\usb\usb9\usb9.c 000ea2 ffe9 000ea4 c10f MOVFF 0x10f,0xfea 000ea6 ffea 000ea8 6aef CLRF 0xef,0x0 000eaa d006 BRA 0xeb8 else C:\C\system\usb\usb9\usb9.c 000eac 0e88 MOVLW 0x88 *pDst.bRam = _USIE|_DAT0|_DTSEN; C:\C\system\usb\usb9\usb9.c 000eae c10e MOVFF 0x10e,0xfe9 000eb0 ffe9 000eb2 c10f MOVFF 0x10f,0xfea 000eb4 ffea 000eb6 6eef MOVWF 0xef,0x0 }//end if C:\C\system\usb\usb9\usb9.c }//end if C:\C\system\usb\usb9\usb9.c 000eb8 0012 RETURN 0x0 }//end USBStdFeatureReqHandler C:\C\system\usb\usb9\usb9.c C:\C\system\usb\usb9\usb9.c /** EOF usb9.c ***************************************************************/ C:\C\system\usb\usb9\usb9.c /********************************************************************* C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * Microchip USB C18 Firmware Version 1.0 C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c ********************************************************************* C:\C\autofiles\usbdsc.c * FileName: usbdsc.c C:\C\autofiles\usbdsc.c * Dependencies: See INCLUDES section below C:\C\autofiles\usbdsc.c * Processor: PIC18 C:\C\autofiles\usbdsc.c * Compiler: C18 2.30.01+ C:\C\autofiles\usbdsc.c * Company: Microchip Technology, Inc. C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * Software License Agreement C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * The software supplied herewith by Microchip Technology Incorporated C:\C\autofiles\usbdsc.c * (the “Company”) for its PICmicro® Microcontroller is intended and C:\C\autofiles\usbdsc.c * supplied to you, the Company’s customer, for use solely and C:\C\autofiles\usbdsc.c * exclusively on Microchip PICmicro Microcontroller products. The C:\C\autofiles\usbdsc.c * software is owned by the Company and/or its supplier, and is C:\C\autofiles\usbdsc.c * protected under applicable copyright laws. All rights are reserved. C:\C\autofiles\usbdsc.c * Any use in violation of the foregoing restrictions may subject the C:\C\autofiles\usbdsc.c * user to criminal sanctions under applicable laws, as well as to C:\C\autofiles\usbdsc.c * civil liability for the breach of the terms and conditions of this C:\C\autofiles\usbdsc.c * license. C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, C:\C\autofiles\usbdsc.c * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED C:\C\autofiles\usbdsc.c * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A C:\C\autofiles\usbdsc.c * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, C:\C\autofiles\usbdsc.c * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR C:\C\autofiles\usbdsc.c * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c ********************************************************************/ C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c /********************************************************************* C:\C\autofiles\usbdsc.c * -usbdsc.c- C:\C\autofiles\usbdsc.c * This file contains the USB descriptor information. It is used C:\C\autofiles\usbdsc.c * in conjunction with the usbdsc.h file. When a descriptor is added C:\C\autofiles\usbdsc.c * or removed from the main configuration descriptor, i.e. CFG01, C:\C\autofiles\usbdsc.c * the user must also change the descriptor structure defined in C:\C\autofiles\usbdsc.c * the usbdsc.h file. The structure is used to calculate the C:\C\autofiles\usbdsc.c * descriptor size, i.e. sizeof(CFG01). C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * A typical configuration descriptor consists of: C:\C\autofiles\usbdsc.c * At least one configuration descriptor (USB_CFG_DSC) C:\C\autofiles\usbdsc.c * One or more interface descriptors (USB_INTF_DSC) C:\C\autofiles\usbdsc.c * One or more endpoint descriptors (USB_EP_DSC) C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * Naming Convention: C:\C\autofiles\usbdsc.c * To resolve ambiguity, the naming convention are as followed: C:\C\autofiles\usbdsc.c * - USB_CFG_DSC type should be named cdxx, where xx is the C:\C\autofiles\usbdsc.c * configuration number. This number should match the actual C:\C\autofiles\usbdsc.c * index value of this configuration. C:\C\autofiles\usbdsc.c * - USB_INTF_DSC type should be named ia, where yy is the C:\C\autofiles\usbdsc.c * interface number and zz is the alternate interface number. C:\C\autofiles\usbdsc.c * - USB_EP_DSC type should be named ep<##>_ia, where C:\C\autofiles\usbdsc.c * ## is the endpoint number and d is the direction of transfer. C:\C\autofiles\usbdsc.c * The interface name should also be listed as a suffix to identify C:\C\autofiles\usbdsc.c * which interface does the endpoint belong to. C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * Example: C:\C\autofiles\usbdsc.c * If a device has one configuration, two interfaces; interface 0 C:\C\autofiles\usbdsc.c * has two endpoints (in and out), and interface 1 has one endpoint(in). C:\C\autofiles\usbdsc.c * Then the CFG01 structure in the usbdsc.h should be: C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * #define CFG01 rom struct \ C:\C\autofiles\usbdsc.c * { USB_CFG_DSC cd01; \ C:\C\autofiles\usbdsc.c * USB_INTF_DSC i00a00; \ C:\C\autofiles\usbdsc.c * USB_EP_DSC ep01o_i00a00; \ C:\C\autofiles\usbdsc.c * USB_EP_DSC ep01i_i00a00; \ C:\C\autofiles\usbdsc.c * USB_INTF_DSC i01a00; \ C:\C\autofiles\usbdsc.c * USB_EP_DSC ep02i_i01a00; \ C:\C\autofiles\usbdsc.c * } cfg01 C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * Note the hierarchy of the descriptors above, it follows the USB C:\C\autofiles\usbdsc.c * specification requirement. All endpoints belonging to an interface C:\C\autofiles\usbdsc.c * should be listed immediately after that interface. C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * ------------------------------------------------------------------- C:\C\autofiles\usbdsc.c * Filling in the descriptor values in the usbdsc.c file: C:\C\autofiles\usbdsc.c * ------------------------------------------------------------------- C:\C\autofiles\usbdsc.c * Most items should be self-explanatory, however, a few will be C:\C\autofiles\usbdsc.c * explained for clarification. C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * [Configuration Descriptor(USB_CFG_DSC)] C:\C\autofiles\usbdsc.c * The configuration attribute must always have the _DEFAULT C:\C\autofiles\usbdsc.c * definition at the minimum. Additional options can be ORed C:\C\autofiles\usbdsc.c * to the _DEFAULT attribute. Available options are _SELF and _RWU. C:\C\autofiles\usbdsc.c * These definitions are defined in the usbdefs_std_dsc.h file. The C:\C\autofiles\usbdsc.c * _SELF tells the USB host that this device is self-powered. The C:\C\autofiles\usbdsc.c * _RWU tells the USB host that this device supports Remote Wakeup. C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * [Endpoint Descriptor(USB_EP_DSC)] C:\C\autofiles\usbdsc.c * Assume the following example: C:\C\autofiles\usbdsc.c * sizeof(USB_EP_DSC),DSC_EP,_EP01_OUT,_BULK,64,0x00 C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * The first two parameters are self-explanatory. They specify the C:\C\autofiles\usbdsc.c * length of this endpoint descriptor (7) and the descriptor type. C:\C\autofiles\usbdsc.c * The next parameter identifies the endpoint, the definitions are C:\C\autofiles\usbdsc.c * defined in usbdefs_std_dsc.h and has the following naming C:\C\autofiles\usbdsc.c * convention: C:\C\autofiles\usbdsc.c * _EP<##>_ C:\C\autofiles\usbdsc.c * where ## is the endpoint number and dir is the direction of C:\C\autofiles\usbdsc.c * transfer. The dir has the value of either 'OUT' or 'IN'. C:\C\autofiles\usbdsc.c * The next parameter identifies the type of the endpoint. Available C:\C\autofiles\usbdsc.c * options are _BULK, _INT, _ISO, and _CTRL. The _CTRL is not C:\C\autofiles\usbdsc.c * typically used because the default control transfer endpoint is C:\C\autofiles\usbdsc.c * not defined in the USB descriptors. When _ISO option is used, C:\C\autofiles\usbdsc.c * addition options can be ORed to _ISO. Example: C:\C\autofiles\usbdsc.c * _ISO|_AD|_FE C:\C\autofiles\usbdsc.c * This describes the endpoint as an isochronous pipe with adaptive C:\C\autofiles\usbdsc.c * and feedback attributes. See usbdefs_std_dsc.h and the USB C:\C\autofiles\usbdsc.c * specification for details. The next parameter defines the size of C:\C\autofiles\usbdsc.c * the endpoint. The last parameter in the polling interval. C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * ------------------------------------------------------------------- C:\C\autofiles\usbdsc.c * Adding a USB String C:\C\autofiles\usbdsc.c * ------------------------------------------------------------------- C:\C\autofiles\usbdsc.c * A string descriptor array should have the following format: C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * rom struct{byte bLength;byte bDscType;word string[size];}sdxxx={ C:\C\autofiles\usbdsc.c * sizeof(sdxxx),DSC_STR,}; C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * The above structure provides a means for the C compiler to C:\C\autofiles\usbdsc.c * calculate the length of string descriptor sdxxx, where xxx is the C:\C\autofiles\usbdsc.c * index number. The first two bytes of the descriptor are descriptor C:\C\autofiles\usbdsc.c * length and type. The rest are string texts which must be C:\C\autofiles\usbdsc.c * in the unicode format. The unicode format is achieved by declaring C:\C\autofiles\usbdsc.c * each character as a word type. The whole text string is declared C:\C\autofiles\usbdsc.c * as a word array with the number of characters equals to . C:\C\autofiles\usbdsc.c * has to be manually counted and entered into the array C:\C\autofiles\usbdsc.c * declaration. Let's study this through an example: C:\C\autofiles\usbdsc.c * if the string is "USB" , then the string descriptor should be: C:\C\autofiles\usbdsc.c * (Using index 02) C:\C\autofiles\usbdsc.c * rom struct{byte bLength;byte bDscType;word string[3];}sd002={ C:\C\autofiles\usbdsc.c * sizeof(sd002),DSC_STR,'U','S','B'}; C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * A USB project may have multiple strings and the firmware supports C:\C\autofiles\usbdsc.c * the management of multiple strings through a look-up table. C:\C\autofiles\usbdsc.c * The look-up table is defined as: C:\C\autofiles\usbdsc.c * rom const unsigned char *rom USB_SD_Ptr[]={&sd000,&sd001,&sd002}; C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * The above declaration has 3 strings, sd000, sd001, and sd002. C:\C\autofiles\usbdsc.c * Strings can be removed or added. sd000 is a specialized string C:\C\autofiles\usbdsc.c * descriptor. It defines the language code, usually this is C:\C\autofiles\usbdsc.c * US English (0x0409). The index of the string must match the index C:\C\autofiles\usbdsc.c * position of the USB_SD_Ptr array, &sd000 must be in position C:\C\autofiles\usbdsc.c * USB_SD_Ptr[0], &sd001 must be in position USB_SD_Ptr[1] and so on. C:\C\autofiles\usbdsc.c * The look-up table USB_SD_Ptr is used by the get string handler C:\C\autofiles\usbdsc.c * function in usb9.c. C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * ------------------------------------------------------------------- C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * The look-up table scheme also applies to the configuration C:\C\autofiles\usbdsc.c * descriptor. A USB device may have multiple configuration C:\C\autofiles\usbdsc.c * descriptors, i.e. CFG01, CFG02, etc. To add a configuration C:\C\autofiles\usbdsc.c * descriptor, user must implement a structure similar to CFG01. C:\C\autofiles\usbdsc.c * The next step is to add the configuration descriptor name, i.e. C:\C\autofiles\usbdsc.c * cfg01, cfg02,.., to the look-up table USB_CD_Ptr. USB_CD_Ptr[0] C:\C\autofiles\usbdsc.c * is a dummy place holder since configuration 0 is the un-configured C:\C\autofiles\usbdsc.c * state according to the definition in the USB specification. C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c ********************************************************************/ C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c /********************************************************************* C:\C\autofiles\usbdsc.c * Descriptor specific type definitions are defined in: C:\C\autofiles\usbdsc.c * system\usb\usbdefs\usbdefs_std_dsc.h C:\C\autofiles\usbdsc.c * C:\C\autofiles\usbdsc.c * Configuration information is defined in: C:\C\autofiles\usbdsc.c * autofiles\usbcfg.h C:\C\autofiles\usbdsc.c ********************************************************************/ C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c /** I N C L U D E S *************************************************/ C:\C\autofiles\usbdsc.c #include "system\typedefs.h" C:\C\autofiles\usbdsc.c #include "system\usb\usb.h" C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c /** C O N S T A N T S ************************************************/ C:\C\autofiles\usbdsc.c #pragma romdata C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c /* Device Descriptor */ C:\C\autofiles\usbdsc.c rom USB_DEV_DSC device_dsc= C:\C\autofiles\usbdsc.c { C:\C\autofiles\usbdsc.c sizeof(USB_DEV_DSC), // Size of this descriptor in bytes C:\C\autofiles\usbdsc.c DSC_DEV, // DEVICE descriptor type C:\C\autofiles\usbdsc.c 0x0200, // USB Spec Release Number in BCD format C:\C\autofiles\usbdsc.c CDC_DEVICE, // Class Code C:\C\autofiles\usbdsc.c 0x00, // Subclass code C:\C\autofiles\usbdsc.c 0x00, // Protocol code C:\C\autofiles\usbdsc.c EP0_BUFF_SIZE, // Max packet size for EP0, see usbcfg.h C:\C\autofiles\usbdsc.c 0x04D8, // Vendor ID C:\C\autofiles\usbdsc.c 0x000A, // Product ID: CDC RS-232 Emulation Demo C:\C\autofiles\usbdsc.c 0x0000, // Device release number in BCD format C:\C\autofiles\usbdsc.c 0x01, // Manufacturer string index C:\C\autofiles\usbdsc.c 0x02, // Product string index C:\C\autofiles\usbdsc.c 0x00, // Device serial number string index C:\C\autofiles\usbdsc.c 0x01 // Number of possible configurations C:\C\autofiles\usbdsc.c }; C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c /* Configuration 1 Descriptor */ C:\C\autofiles\usbdsc.c CFG01= C:\C\autofiles\usbdsc.c { C:\C\autofiles\usbdsc.c /* Configuration Descriptor */ C:\C\autofiles\usbdsc.c sizeof(USB_CFG_DSC), // Size of this descriptor in bytes C:\C\autofiles\usbdsc.c DSC_CFG, // CONFIGURATION descriptor type C:\C\autofiles\usbdsc.c sizeof(cfg01), // Total length of data for this cfg C:\C\autofiles\usbdsc.c 2, // Number of interfaces in this cfg C:\C\autofiles\usbdsc.c 1, // Index value of this configuration C:\C\autofiles\usbdsc.c 0, // Configuration string index C:\C\autofiles\usbdsc.c _DEFAULT, // Attributes, see usbdefs_std_dsc.h C:\C\autofiles\usbdsc.c 250, // Max power consumption (2X mA) C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c /* Interface Descriptor */ C:\C\autofiles\usbdsc.c sizeof(USB_INTF_DSC), // Size of this descriptor in bytes C:\C\autofiles\usbdsc.c DSC_INTF, // INTERFACE descriptor type C:\C\autofiles\usbdsc.c 0, // Interface Number C:\C\autofiles\usbdsc.c 0, // Alternate Setting Number C:\C\autofiles\usbdsc.c 1, // Number of endpoints in this intf C:\C\autofiles\usbdsc.c COMM_INTF, // Class code C:\C\autofiles\usbdsc.c ABSTRACT_CONTROL_MODEL, // Subclass code C:\C\autofiles\usbdsc.c V25TER, // Protocol code C:\C\autofiles\usbdsc.c 0, // Interface string index C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c /* CDC Class-Specific Descriptors */ C:\C\autofiles\usbdsc.c sizeof(USB_CDC_HEADER_FN_DSC),CS_INTERFACE,DSC_FN_HEADER,0x0110, C:\C\autofiles\usbdsc.c sizeof(USB_CDC_ACM_FN_DSC),CS_INTERFACE,DSC_FN_ACM,0x02, C:\C\autofiles\usbdsc.c sizeof(USB_CDC_UNION_FN_DSC),CS_INTERFACE,DSC_FN_UNION,CDC_COMM_INTF_ID,CDC_DATA_INTF_ID, C:\C\autofiles\usbdsc.c sizeof(USB_CDC_CALL_MGT_FN_DSC),CS_INTERFACE,DSC_FN_CALL_MGT,0x00,CDC_DATA_INTF_ID, C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c /* Endpoint Descriptor */ C:\C\autofiles\usbdsc.c sizeof(USB_EP_DSC),DSC_EP,_EP02_IN,_INT,CDC_INT_EP_SIZE,0x02, C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c /* Interface Descriptor */ C:\C\autofiles\usbdsc.c sizeof(USB_INTF_DSC), // Size of this descriptor in bytes C:\C\autofiles\usbdsc.c DSC_INTF, // INTERFACE descriptor type C:\C\autofiles\usbdsc.c 1, // Interface Number C:\C\autofiles\usbdsc.c 0, // Alternate Setting Number C:\C\autofiles\usbdsc.c 2, // Number of endpoints in this intf C:\C\autofiles\usbdsc.c DATA_INTF, // Class code C:\C\autofiles\usbdsc.c 0, // Subclass code C:\C\autofiles\usbdsc.c NO_PROTOCOL, // Protocol code C:\C\autofiles\usbdsc.c 0, // Interface string index C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c /* Endpoint Descriptors */ C:\C\autofiles\usbdsc.c sizeof(USB_EP_DSC),DSC_EP,_EP03_OUT,_BULK,CDC_BULK_OUT_EP_SIZE,0x00, C:\C\autofiles\usbdsc.c sizeof(USB_EP_DSC),DSC_EP,_EP03_IN,_BULK,CDC_BULK_IN_EP_SIZE,0x00 C:\C\autofiles\usbdsc.c }; C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c rom struct{byte bLength;byte bDscType;word string[1];}sd000={ C:\C\autofiles\usbdsc.c sizeof(sd000),DSC_STR,0x0409}; C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c rom struct{byte bLength;byte bDscType;word string[25];}sd001={ C:\C\autofiles\usbdsc.c sizeof(sd001),DSC_STR, C:\C\autofiles\usbdsc.c 'M','i','c','r','o','c','h','i','p',' ', C:\C\autofiles\usbdsc.c 'T','e','c','h','n','o','l','o','g','y',' ','I','n','c','.'}; C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c rom struct{byte bLength;byte bDscType;word string[19];}sd002={ C:\C\autofiles\usbdsc.c sizeof(sd002),DSC_STR, C:\C\autofiles\usbdsc.c 'U','B','W',' ','F','i','r','m','w','a', 'r', C:\C\autofiles\usbdsc.c 'e',' ','C',' ','v','0','.','1'}; C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c rom const unsigned char *rom USB_CD_Ptr[]={&cfg01,&cfg01}; C:\C\autofiles\usbdsc.c rom const unsigned char *rom USB_SD_Ptr[]={&sd000,&sd001,&sd002}; C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c rom pFunc ClassReqHandler[1]= C:\C\autofiles\usbdsc.c { C:\C\autofiles\usbdsc.c &USBCheckCDCRequest C:\C\autofiles\usbdsc.c }; C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c #pragma code C:\C\autofiles\usbdsc.c C:\C\autofiles\usbdsc.c /** EOF usbdsc.c ****************************************************/ C:\C\autofiles\usbdsc.c /********************************************************************* C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Microchip USB C18 Firmware Version 1.0 C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c ********************************************************************* C:\C\system\usb\usbctrltrf\usbctrltrf.c * FileName: usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c * Dependencies: See INCLUDES section below C:\C\system\usb\usbctrltrf\usbctrltrf.c * Processor: PIC18 C:\C\system\usb\usbctrltrf\usbctrltrf.c * Compiler: C18 2.30.01+ C:\C\system\usb\usbctrltrf\usbctrltrf.c * Company: Microchip Technology, Inc. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Software License Agreement C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * The software supplied herewith by Microchip Technology Incorporated C:\C\system\usb\usbctrltrf\usbctrltrf.c * (the “Company”) for its PICmicro® Microcontroller is intended and C:\C\system\usb\usbctrltrf\usbctrltrf.c * supplied to you, the Company’s customer, for use solely and C:\C\system\usb\usbctrltrf\usbctrltrf.c * exclusively on Microchip PICmicro Microcontroller products. The C:\C\system\usb\usbctrltrf\usbctrltrf.c * software is owned by the Company and/or its supplier, and is C:\C\system\usb\usbctrltrf\usbctrltrf.c * protected under applicable copyright laws. All rights are reserved. C:\C\system\usb\usbctrltrf\usbctrltrf.c * Any use in violation of the foregoing restrictions may subject the C:\C\system\usb\usbctrltrf\usbctrltrf.c * user to criminal sanctions under applicable laws, as well as to C:\C\system\usb\usbctrltrf\usbctrltrf.c * civil liability for the breach of the terms and conditions of this C:\C\system\usb\usbctrltrf\usbctrltrf.c * license. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, C:\C\system\usb\usbctrltrf\usbctrltrf.c * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED C:\C\system\usb\usbctrltrf\usbctrltrf.c * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A C:\C\system\usb\usbctrltrf\usbctrltrf.c * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, C:\C\system\usb\usbctrltrf\usbctrltrf.c * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR C:\C\system\usb\usbctrltrf\usbctrltrf.c * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Author Date Comment C:\C\system\usb\usbctrltrf\usbctrltrf.c *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C:\C\system\usb\usbctrltrf\usbctrltrf.c * Rawin Rojvanit 11/19/04 Original. C:\C\system\usb\usbctrltrf\usbctrltrf.c ********************************************************************/ C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c /** I N C L U D E S **********************************************************/ C:\C\system\usb\usbctrltrf\usbctrltrf.c #include C:\C\system\usb\usbctrltrf\usbctrltrf.c #include "system\typedefs.h" C:\C\system\usb\usbctrltrf\usbctrltrf.c #include "system\usb\usb.h" C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c /** V A R I A B L E S ********************************************************/ C:\C\system\usb\usbctrltrf\usbctrltrf.c #pragma udata C:\C\system\usb\usbctrltrf\usbctrltrf.c byte ctrl_trf_state; // Control Transfer State C:\C\system\usb\usbctrltrf\usbctrltrf.c byte ctrl_trf_session_owner; // Current transfer session owner C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c POINTER pSrc; // Data source pointer C:\C\system\usb\usbctrltrf\usbctrltrf.c POINTER pDst; // Data destination pointer C:\C\system\usb\usbctrltrf\usbctrltrf.c WORD wCount; // Data counter C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c /** P R I V A T E P R O T O T Y P E S ***************************************/ C:\C\system\usb\usbctrltrf\usbctrltrf.c void USBCtrlTrfSetupHandler(void); C:\C\system\usb\usbctrltrf\usbctrltrf.c void USBCtrlTrfOutHandler(void); C:\C\system\usb\usbctrltrf\usbctrltrf.c void USBCtrlTrfInHandler(void); C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c /** D E C L A R A T I O N S **************************************************/ C:\C\system\usb\usbctrltrf\usbctrltrf.c #pragma code C:\C\system\usb\usbctrltrf\usbctrltrf.c /****************************************************************************** C:\C\system\usb\usbctrltrf\usbctrltrf.c * Function: void USBCtrlEPService(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * PreCondition: USTAT is loaded with a valid endpoint address. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Input: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Output: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Side Effects: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Overview: USBCtrlEPService checks for three transaction types that C:\C\system\usb\usbctrltrf\usbctrltrf.c * it knows how to service and services them: C:\C\system\usb\usbctrltrf\usbctrltrf.c * 1. EP0 SETUP C:\C\system\usb\usbctrltrf\usbctrltrf.c * 2. EP0 OUT C:\C\system\usb\usbctrltrf\usbctrltrf.c * 3. EP0 IN C:\C\system\usb\usbctrltrf\usbctrltrf.c * It ignores all other types (i.e. EP1, EP2, etc.) C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Note: None C:\C\system\usb\usbctrltrf\usbctrltrf.c *****************************************************************************/ C:\C\system\usb\usbctrltrf\usbctrltrf.c void USBCtrlEPService(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c { C:\C\system\usb\usbctrltrf\usbctrltrf.c 000eba 506c MOVF 0x6c,0x0,0x0 if(USTAT == EP00_OUT) C:\C\system\usb\usbctrltrf\usbctrltrf.c 000ebc e002 BZ 0xec2 000ebe 0e00 MOVLW 0x0 000ec0 d001 BRA 0xec4 000ec2 0e01 MOVLW 0x1 000ec4 0900 IORLW 0x0 000ec6 e00b BZ 0xede { C:\C\system\usb\usbctrltrf\usbctrltrf.c 000ec8 0104 MOVLB 0x4 if(ep0Bo.Stat.PID == SETUP_TOKEN) // EP0 SETUP C:\C\system\usb\usbctrltrf\usbctrltrf.c 000eca 5100 MOVF 0x0,0x0,0x1 000ecc 0b3c ANDLW 0x3c 000ece 42e8 RRNCF 0xe8,0x1,0x0 000ed0 42e8 RRNCF 0xe8,0x1,0x0 000ed2 080d SUBLW 0xd 000ed4 e102 BNZ 0xeda 000ed6 d80c RCALL 0xef0 USBCtrlTrfSetupHandler(); C:\C\system\usb\usbctrltrf\usbctrltrf.c 000ed8 d001 BRA 0xedc else // EP0 OUT C:\C\system\usb\usbctrltrf\usbctrltrf.c 000eda d840 RCALL 0xf5c USBCtrlTrfOutHandler(); C:\C\system\usb\usbctrltrf\usbctrltrf.c } C:\C\system\usb\usbctrltrf\usbctrltrf.c 000edc d008 BRA 0xeee else if(USTAT == EP00_IN) // EP0 IN C:\C\system\usb\usbctrltrf\usbctrltrf.c 000ede 506c MOVF 0x6c,0x0,0x0 000ee0 e002 BZ 0xee6 000ee2 0e00 MOVLW 0x0 000ee4 d001 BRA 0xee8 000ee6 0e01 MOVLW 0x1 000ee8 0904 IORLW 0x4 000eea e001 BZ 0xeee 000eec d847 RCALL 0xf7c USBCtrlTrfInHandler(); C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c 000eee 0012 RETURN 0x0 }//end USBCtrlEPService C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c /****************************************************************************** C:\C\system\usb\usbctrltrf\usbctrltrf.c * Function: void USBCtrlTrfSetupHandler(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * PreCondition: SetupPkt buffer is loaded with valid USB Setup Data C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Input: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Output: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Side Effects: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Overview: This routine is a task dispatcher and has 3 stages. C:\C\system\usb\usbctrltrf\usbctrltrf.c * 1. It initializes the control transfer state machine. C:\C\system\usb\usbctrltrf\usbctrltrf.c * 2. It calls on each of the module that may know how to C:\C\system\usb\usbctrltrf\usbctrltrf.c * service the Setup Request from the host. C:\C\system\usb\usbctrltrf\usbctrltrf.c * Module Example: USB9, HID, CDC, MSD, ... C:\C\system\usb\usbctrltrf\usbctrltrf.c * As new classes are added, ClassReqHandler table in C:\C\system\usb\usbctrltrf\usbctrltrf.c * usbdsc.c should be updated to call all available C:\C\system\usb\usbctrltrf\usbctrltrf.c * class handlers. C:\C\system\usb\usbctrltrf\usbctrltrf.c * 3. Once each of the modules has had a chance to check if C:\C\system\usb\usbctrltrf\usbctrltrf.c * it is responsible for servicing the request, stage 3 C:\C\system\usb\usbctrltrf\usbctrltrf.c * then checks direction of the transfer to determine how C:\C\system\usb\usbctrltrf\usbctrltrf.c * to prepare EP0 for the control transfer. C:\C\system\usb\usbctrltrf\usbctrltrf.c * Refer to USBCtrlEPServiceComplete() for more details. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Note: Microchip USB Firmware has three different states for C:\C\system\usb\usbctrltrf\usbctrltrf.c * the control transfer state machine: C:\C\system\usb\usbctrltrf\usbctrltrf.c * 1. WAIT_SETUP C:\C\system\usb\usbctrltrf\usbctrltrf.c * 2. CTRL_TRF_TX C:\C\system\usb\usbctrltrf\usbctrltrf.c * 3. CTRL_TRF_RX C:\C\system\usb\usbctrltrf\usbctrltrf.c * Refer to firmware manual to find out how one state C:\C\system\usb\usbctrltrf\usbctrltrf.c * is transitioned to another. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * A Control Transfer is composed of many USB transactions. C:\C\system\usb\usbctrltrf\usbctrltrf.c * When transferring data over multiple transactions, C:\C\system\usb\usbctrltrf\usbctrltrf.c * it is important to keep track of data source, data C:\C\system\usb\usbctrltrf\usbctrltrf.c * destination, and data count. These three parameters are C:\C\system\usb\usbctrltrf\usbctrltrf.c * stored in pSrc,pDst, and wCount. A flag is used to C:\C\system\usb\usbctrltrf\usbctrltrf.c * note if the data source is from ROM or RAM. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c *****************************************************************************/ C:\C\system\usb\usbctrltrf\usbctrltrf.c 000ef0 cfd9 MOVFF 0xfd9,0xfe6 void USBCtrlTrfSetupHandler(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c 000ef2 ffe6 000ef4 cfe1 MOVFF 0xfe1,0xfd9 000ef6 ffd9 000ef8 52e6 MOVF 0xe6,0x1,0x0 { C:\C\system\usb\usbctrltrf\usbctrltrf.c byte i; C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c /* Stage 1 */ C:\C\system\usb\usbctrltrf\usbctrltrf.c 000efa 0101 MOVLB 0x1 ctrl_trf_state = WAIT_SETUP; C:\C\system\usb\usbctrltrf\usbctrltrf.c 000efc 6b0a CLRF 0xa,0x1 000efe 6b0b CLRF 0xb,0x1 ctrl_trf_session_owner = MUID_NULL; // Set owner to NULL C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f00 6b10 CLRF 0x10,0x1 wCount._word = 0; C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f02 6b11 CLRF 0x11,0x1 C:\C\system\usb\usbctrltrf\usbctrltrf.c /* Stage 2 */ C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f04 ecd9 CALL 0xbb2,0x0 USBCheckStdRequest(); // See system\usb9\usb9.c C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f06 f005 C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f08 6adf CLRF 0xdf,0x0 for(i=0;i < (sizeof(ClassReqHandler)/sizeof(pFunc));i++) C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f0a 50df MOVF 0xdf,0x0,0x0 000f0c 6e02 MOVWF 0x2,0x0 000f0e 6a03 CLRF 0x3,0x0 000f10 0e01 MOVLW 0x1 000f12 5c02 SUBWF 0x2,0x0,0x0 000f14 0e00 MOVLW 0x0 000f16 5803 SUBWFB 0x3,0x0,0x0 000f18 e21b BC 0xf50 000f4c 2adf INCF 0xdf,0x1,0x0 000f4e d7dd BRA 0xf0a { C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f1a 0101 MOVLB 0x1 if(ctrl_trf_session_owner != MUID_NULL)break; C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f1c 510b MOVF 0xb,0x0,0x1 000f1e e001 BZ 0xf22 000f20 d017 BRA 0xf50 000f22 6af7 CLRF 0xf7,0x0 ClassReqHandler[i](); // See autofiles\usbdsc.c C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f24 34df RLCF 0xdf,0x0,0x0 000f26 0bfe ANDLW 0xfe 000f28 36f7 RLCF 0xf7,0x1,0x0 000f2a 6ef6 MOVWF 0xf6,0x0 000f2c 0e49 MOVLW 0x49 000f2e 26f6 ADDWF 0xf6,0x1,0x0 000f30 0e15 MOVLW 0x15 000f32 22f7 ADDWFC 0xf7,0x1,0x0 000f34 0009 TBLRDPOSTINC 000f36 cff5 MOVFF 0xff5,0x2 000f38 f002 000f3a 0008 TBLRD 000f3c cff5 MOVFF 0xff5,0x3 000f3e f003 000f40 d004 BRA 0xf4a 000f42 c003 MOVFF 0x3,0xffa 000f44 fffa 000f46 5002 MOVF 0x2,0x0,0x0 000f48 6ef9 MOVWF 0xf9,0x0 000f4a dffb RCALL 0xf42 }//end while C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c /* Stage 3 */ C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f50 d8e1 RCALL 0x1114 USBCtrlEPServiceComplete(); C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f52 52e5 MOVF 0xe5,0x1,0x0 }//end USBCtrlTrfSetupHandler C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f54 52e5 MOVF 0xe5,0x1,0x0 000f56 cfe7 MOVFF 0xfe7,0xfd9 000f58 ffd9 000f5a 0012 RETURN 0x0 C:\C\system\usb\usbctrltrf\usbctrltrf.c /****************************************************************************** C:\C\system\usb\usbctrltrf\usbctrltrf.c * Function: void USBCtrlTrfOutHandler(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * PreCondition: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Input: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Output: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Side Effects: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Overview: This routine handles an OUT transaction according to C:\C\system\usb\usbctrltrf\usbctrltrf.c * which control transfer state is currently active. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Note: Note that if the the control transfer was from C:\C\system\usb\usbctrltrf\usbctrltrf.c * host to device, the session owner should be notified C:\C\system\usb\usbctrltrf\usbctrltrf.c * at the end of each OUT transaction to service the C:\C\system\usb\usbctrltrf\usbctrltrf.c * received data. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c *****************************************************************************/ C:\C\system\usb\usbctrltrf\usbctrltrf.c void USBCtrlTrfOutHandler(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c { C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f5c 0e02 MOVLW 0x2 if(ctrl_trf_state == CTRL_TRF_RX) C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f5e 0101 MOVLB 0x1 000f60 5d0a SUBWF 0xa,0x0,0x1 000f62 e10a BNZ 0xf78 { C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f64 d898 RCALL 0x1096 USBCtrlTrfRxService(); C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c /* C:\C\system\usb\usbctrltrf\usbctrltrf.c * Don't have to worry about overwriting _KEEP bit C:\C\system\usb\usbctrltrf\usbctrltrf.c * because if _KEEP was set, TRNIF would not have been C:\C\system\usb\usbctrltrf\usbctrltrf.c * generated in the first place. C:\C\system\usb\usbctrltrf\usbctrltrf.c */ C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f66 0104 MOVLB 0x4 if(ep0Bo.Stat.DTS == 0) C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f68 bd00 BTFSC 0x0,0x6,0x1 000f6a d003 BRA 0xf72 000f6c 0ec8 MOVLW 0xc8 ep0Bo.Stat._byte = _USIE|_DAT1|_DTSEN; C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f6e 6f00 MOVWF 0x0,0x1 000f70 d002 BRA 0xf76 else C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f72 0e88 MOVLW 0x88 ep0Bo.Stat._byte = _USIE|_DAT0|_DTSEN; C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f74 6f00 MOVWF 0x0,0x1 } C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f76 d001 BRA 0xf7a else // CTRL_TRF_TX C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f78 d913 RCALL 0x11a0 USBPrepareForNextSetupTrf(); C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f7a 0012 RETURN 0x0 }//end USBCtrlTrfOutHandler C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c /****************************************************************************** C:\C\system\usb\usbctrltrf\usbctrltrf.c * Function: void USBCtrlTrfInHandler(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * PreCondition: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Input: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Output: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Side Effects: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Overview: This routine handles an IN transaction according to C:\C\system\usb\usbctrltrf\usbctrltrf.c * which control transfer state is currently active. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Note: A Set Address Request must not change the acutal address C:\C\system\usb\usbctrltrf\usbctrltrf.c * of the device until the completion of the control C:\C\system\usb\usbctrltrf\usbctrltrf.c * transfer. The end of the control transfer for Set Address C:\C\system\usb\usbctrltrf\usbctrltrf.c * Request is an IN transaction. Therefore it is necessary C:\C\system\usb\usbctrltrf\usbctrltrf.c * to service this unique situation when the condition is C:\C\system\usb\usbctrltrf\usbctrltrf.c * right. Macro mUSBCheckAdrPendingState is defined in C:\C\system\usb\usbctrltrf\usbctrltrf.c * usb9.h and its function is to specifically service this C:\C\system\usb\usbctrltrf\usbctrltrf.c * event. C:\C\system\usb\usbctrltrf\usbctrltrf.c *****************************************************************************/ C:\C\system\usb\usbctrltrf\usbctrltrf.c void USBCtrlTrfInHandler(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c { C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f7c 0e04 MOVLW 0x4 mUSBCheckAdrPendingState(); // Must check if in ADR_PENDING_STATE C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f7e 0101 MOVLB 0x1 000f80 5d12 SUBWF 0x12,0x0,0x1 000f82 e10a BNZ 0xf98 000f84 c422 MOVFF 0x422,0xf6e 000f86 ff6e 000f88 506e MOVF 0x6e,0x0,0x0 000f8a 0800 SUBLW 0x0 000f8c e203 BC 0xf94 000f8e 0e05 MOVLW 0x5 000f90 6f12 MOVWF 0x12,0x1 000f92 d002 BRA 0xf98 000f94 0e03 MOVLW 0x3 000f96 6f12 MOVWF 0x12,0x1 C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f98 0101 MOVLB 0x1 if(ctrl_trf_state == CTRL_TRF_TX) C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f9a 050a DECF 0xa,0x0,0x1 000f9c e10a BNZ 0xfb2 { C:\C\system\usb\usbctrltrf\usbctrltrf.c 000f9e d80b RCALL 0xfb6 USBCtrlTrfTxService(); C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fa0 0104 MOVLB 0x4 if(ep0Bi.Stat.DTS == 0) C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fa2 bd04 BTFSC 0x4,0x6,0x1 000fa4 d003 BRA 0xfac 000fa6 0ec8 MOVLW 0xc8 ep0Bi.Stat._byte = _USIE|_DAT1|_DTSEN; C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fa8 6f04 MOVWF 0x4,0x1 000faa d002 BRA 0xfb0 else C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fac 0e88 MOVLW 0x88 ep0Bi.Stat._byte = _USIE|_DAT0|_DTSEN; C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fae 6f04 MOVWF 0x4,0x1 } C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fb0 d001 BRA 0xfb4 else // CTRL_TRF_RX C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fb2 d8f6 RCALL 0x11a0 USBPrepareForNextSetupTrf(); C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fb4 0012 RETURN 0x0 }//end USBCtrlTrfInHandler C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c /****************************************************************************** C:\C\system\usb\usbctrltrf\usbctrltrf.c * Function: void USBCtrlTrfTxService(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * PreCondition: pSrc, wCount, and usb_stat.ctrl_trf_mem are setup properly. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Input: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Output: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Side Effects: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Overview: This routine should be called from only two places. C:\C\system\usb\usbctrltrf\usbctrltrf.c * One from USBCtrlEPServiceComplete() and one from C:\C\system\usb\usbctrltrf\usbctrltrf.c * USBCtrlTrfInHandler(). It takes care of managing a C:\C\system\usb\usbctrltrf\usbctrltrf.c * transfer over multiple USB transactions. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Note: This routine works with isochronous endpoint larger than C:\C\system\usb\usbctrltrf\usbctrltrf.c * 256 bytes and is shown here as an example of how to deal C:\C\system\usb\usbctrltrf\usbctrltrf.c * with BC9 and BC8. In reality, a control endpoint can never C:\C\system\usb\usbctrltrf\usbctrltrf.c * be larger than 64 bytes. C:\C\system\usb\usbctrltrf\usbctrltrf.c *****************************************************************************/ C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fb6 cfd9 MOVFF 0xfd9,0xfe6 void USBCtrlTrfTxService(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fb8 ffe6 000fba cfe1 MOVFF 0xfe1,0xfd9 000fbc ffd9 000fbe 0e02 MOVLW 0x2 000fc0 26e1 ADDWF 0xe1,0x1,0x0 { C:\C\system\usb\usbctrltrf\usbctrltrf.c WORD byte_to_send; C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c /* C:\C\system\usb\usbctrltrf\usbctrltrf.c * First, have to figure out how many byte of data to send. C:\C\system\usb\usbctrltrf\usbctrltrf.c */ C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fc2 0101 MOVLB 0x1 if(wCount._word < EP0_BUFF_SIZE) C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fc4 0e08 MOVLW 0x8 000fc6 5d10 SUBWF 0x10,0x0,0x1 000fc8 0e00 MOVLW 0x0 000fca 5911 SUBWFB 0x11,0x0,0x1 000fcc e205 BC 0xfd8 000fce c110 MOVFF 0x110,0xfde byte_to_send._word = wCount._word; C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fd0 ffde 000fd2 c111 MOVFF 0x111,0xfdd 000fd4 ffdd 000fd6 d003 BRA 0xfde else C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fd8 0e08 MOVLW 0x8 byte_to_send._word = EP0_BUFF_SIZE; C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fda 6ede MOVWF 0xde,0x0 000fdc 6add CLRF 0xdd,0x0 C:\C\system\usb\usbctrltrf\usbctrltrf.c /* C:\C\system\usb\usbctrltrf\usbctrltrf.c * Next, load the number of bytes to send to BC9..0 in buffer descriptor C:\C\system\usb\usbctrltrf\usbctrltrf.c */ C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fde 0104 MOVLB 0x4 ep0Bi.Stat.BC9 = 0; C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fe0 9304 BCF 0x4,0x1,0x1 000fe2 9104 BCF 0x4,0x0,0x1 ep0Bi.Stat.BC8 = 0; C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fe4 0e01 MOVLW 0x1 ep0Bi.Stat._byte |= MSB(byte_to_send); C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fe6 50db MOVF 0xdb,0x0,0x0 000fe8 1304 IORWF 0x4,0x1,0x1 000fea cfdf MOVFF 0xfdf,0x405 ep0Bi.Cnt = LSB(byte_to_send); C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fec f405 C:\C\system\usb\usbctrltrf\usbctrltrf.c /* C:\C\system\usb\usbctrltrf\usbctrltrf.c * Subtract the number of bytes just about to be sent from the total. C:\C\system\usb\usbctrltrf\usbctrltrf.c */ C:\C\system\usb\usbctrltrf\usbctrltrf.c 000fee 0e00 MOVLW 0x0 wCount._word = wCount._word - byte_to_send._word; C:\C\system\usb\usbctrltrf\usbctrltrf.c 000ff0 50db MOVF 0xdb,0x0,0x0 000ff2 0101 MOVLB 0x1 000ff4 5f10 SUBWF 0x10,0x1,0x1 000ff6 0e01 MOVLW 0x1 000ff8 50db MOVF 0xdb,0x0,0x0 000ffa 5b11 SUBWFB 0x11,0x1,0x1 C:\C\system\usb\usbctrltrf\usbctrltrf.c 000ffc 0e28 MOVLW 0x28 pDst.bRam = (byte*)&CtrlTrfData; // Set destination pointer C:\C\system\usb\usbctrltrf\usbctrltrf.c 000ffe 6f0e MOVWF 0xe,0x1 001000 0e04 MOVLW 0x4 001002 6f0f MOVWF 0xf,0x1 C:\C\system\usb\usbctrltrf\usbctrltrf.c 001004 0101 MOVLB 0x1 if(usb_stat.ctrl_trf_mem == _ROM) // Determine type of memory source C:\C\system\usb\usbctrltrf\usbctrltrf.c 001006 a313 BTFSS 0x13,0x1,0x1 001008 d01e BRA 0x1046 { C:\C\system\usb\usbctrltrf\usbctrltrf.c 00100a cfd9 MOVFF 0xfd9,0xfe9 while(byte_to_send._word) C:\C\system\usb\usbctrltrf\usbctrltrf.c 00100c ffe9 00100e cfda MOVFF 0xfda,0xfea 001010 ffea 001012 50ee MOVF 0xee,0x0,0x0 001014 10ed IORWF 0xed,0x0,0x0 001016 e016 BZ 0x1044 001042 d7e3 BRA 0x100a { C:\C\system\usb\usbctrltrf\usbctrltrf.c 001018 c10c MOVFF 0x10c,0xff6 *pDst.bRam = *pSrc.bRom; C:\C\system\usb\usbctrltrf\usbctrltrf.c 00101a fff6 00101c c10d MOVFF 0x10d,0xff7 00101e fff7 001020 0008 TBLRD 001022 50f5 MOVF 0xf5,0x0,0x0 001024 c10e MOVFF 0x10e,0xfe9 001026 ffe9 001028 c10f MOVFF 0x10f,0xfea 00102a ffea 00102c 6eef MOVWF 0xef,0x0 00102e 0101 MOVLB 0x1 pDst.bRam++; C:\C\system\usb\usbctrltrf\usbctrltrf.c 001030 2b0e INCF 0xe,0x1,0x1 001032 0e00 MOVLW 0x0 001034 230f ADDWFC 0xf,0x1,0x1 001036 2b0c INCF 0xc,0x1,0x1 pSrc.bRom++; C:\C\system\usb\usbctrltrf\usbctrltrf.c 001038 230d ADDWFC 0xd,0x1,0x1 00103a 06df DECF 0xdf,0x1,0x0 byte_to_send._word--; C:\C\system\usb\usbctrltrf\usbctrltrf.c 00103c 0e01 MOVLW 0x1 00103e e201 BC 0x1042 001040 06db DECF 0xdb,0x1,0x0 }//end while(byte_to_send._word) C:\C\system\usb\usbctrltrf\usbctrltrf.c } C:\C\system\usb\usbctrltrf\usbctrltrf.c 001044 d01c BRA 0x107e else // RAM C:\C\system\usb\usbctrltrf\usbctrltrf.c { C:\C\system\usb\usbctrltrf\usbctrltrf.c 001046 cfd9 MOVFF 0xfd9,0xfe9 while(byte_to_send._word) C:\C\system\usb\usbctrltrf\usbctrltrf.c 001048 ffe9 00104a cfda MOVFF 0xfda,0xfea 00104c ffea 00104e 50ee MOVF 0xee,0x0,0x0 001050 10ed IORWF 0xed,0x0,0x0 001052 e015 BZ 0x107e 00107c d7e4 BRA 0x1046 { C:\C\system\usb\usbctrltrf\usbctrltrf.c 001054 c10c MOVFF 0x10c,0xfe9 *pDst.bRam = *pSrc.bRam; C:\C\system\usb\usbctrltrf\usbctrltrf.c 001056 ffe9 001058 c10d MOVFF 0x10d,0xfea 00105a ffea 00105c 50ef MOVF 0xef,0x0,0x0 00105e c10e MOVFF 0x10e,0xfe9 001060 ffe9 001062 c10f MOVFF 0x10f,0xfea 001064 ffea 001066 6eef MOVWF 0xef,0x0 001068 0101 MOVLB 0x1 pDst.bRam++; C:\C\system\usb\usbctrltrf\usbctrltrf.c 00106a 2b0e INCF 0xe,0x1,0x1 00106c 0e00 MOVLW 0x0 00106e 230f ADDWFC 0xf,0x1,0x1 001070 2b0c INCF 0xc,0x1,0x1 pSrc.bRam++; C:\C\system\usb\usbctrltrf\usbctrltrf.c 001072 230d ADDWFC 0xd,0x1,0x1 001074 06df DECF 0xdf,0x1,0x0 byte_to_send._word--; C:\C\system\usb\usbctrltrf\usbctrltrf.c 001076 0e01 MOVLW 0x1 001078 e201 BC 0x107c 00107a 06db DECF 0xdb,0x1,0x0 }//end while(byte_to_send._word) C:\C\system\usb\usbctrltrf\usbctrltrf.c }//end if(usb_stat.ctrl_trf_mem == _ROM) C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c 00107e 6ef5 MOVWF 0xf5,0x0 }//end USBCtrlTrfTxService C:\C\system\usb\usbctrltrf\usbctrltrf.c 001080 0e02 MOVLW 0x2 001082 5ce1 SUBWF 0xe1,0x0,0x0 001084 e202 BC 0x108a 001086 6ae1 CLRF 0xe1,0x0 001088 52e5 MOVF 0xe5,0x1,0x0 00108a 6ee1 MOVWF 0xe1,0x0 00108c 50f5 MOVF 0xf5,0x0,0x0 00108e 52e5 MOVF 0xe5,0x1,0x0 001090 cfe7 MOVFF 0xfe7,0xfd9 001092 ffd9 001094 0012 RETURN 0x0 C:\C\system\usb\usbctrltrf\usbctrltrf.c /****************************************************************************** C:\C\system\usb\usbctrltrf\usbctrltrf.c * Function: void USBCtrlTrfRxService(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * PreCondition: pDst and wCount are setup properly. C:\C\system\usb\usbctrltrf\usbctrltrf.c * pSrc is always &CtrlTrfData C:\C\system\usb\usbctrltrf\usbctrltrf.c * usb_stat.ctrl_trf_mem is always _RAM. C:\C\system\usb\usbctrltrf\usbctrltrf.c * wCount should be set to 0 at the start of each control C:\C\system\usb\usbctrltrf\usbctrltrf.c * transfer. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Input: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Output: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Side Effects: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Overview: *** This routine is only partially complete. Check for C:\C\system\usb\usbctrltrf\usbctrltrf.c * new version of the firmware. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Note: None C:\C\system\usb\usbctrltrf\usbctrltrf.c *****************************************************************************/ C:\C\system\usb\usbctrltrf\usbctrltrf.c 001096 cfd9 MOVFF 0xfd9,0xfe6 void USBCtrlTrfRxService(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c 001098 ffe6 00109a cfe1 MOVFF 0xfe1,0xfd9 00109c ffd9 00109e 0e02 MOVLW 0x2 0010a0 26e1 ADDWF 0xe1,0x1,0x0 { C:\C\system\usb\usbctrltrf\usbctrltrf.c WORD byte_to_read; C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010a2 0e03 MOVLW 0x3 MSB(byte_to_read) = 0x03 & ep0Bo.Stat._byte; // Filter out last 2 bits C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010a4 0104 MOVLB 0x4 0010a6 1500 ANDWF 0x0,0x0,0x1 0010a8 6ee7 MOVWF 0xe7,0x0 0010aa 0e01 MOVLW 0x1 0010ac cfe7 MOVFF 0xfe7,0xfdb 0010ae ffdb 0010b0 c401 MOVFF 0x401,0xfdf LSB(byte_to_read) = ep0Bo.Cnt; C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010b2 ffdf C:\C\system\usb\usbctrltrf\usbctrltrf.c /* C:\C\system\usb\usbctrltrf\usbctrltrf.c * Accumulate total number of bytes read C:\C\system\usb\usbctrltrf\usbctrltrf.c */ C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010b4 50de MOVF 0xde,0x0,0x0 wCount._word = wCount._word + byte_to_read._word; C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010b6 0101 MOVLB 0x1 0010b8 2710 ADDWF 0x10,0x1,0x1 0010ba 50dd MOVF 0xdd,0x0,0x0 0010bc 2311 ADDWFC 0x11,0x1,0x1 C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010be 0e28 MOVLW 0x28 pSrc.bRam = (byte*)&CtrlTrfData; C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010c0 6f0c MOVWF 0xc,0x1 0010c2 0e04 MOVLW 0x4 0010c4 6f0d MOVWF 0xd,0x1 C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010c6 cfd9 MOVFF 0xfd9,0xfe9 while(byte_to_read._word) C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010c8 ffe9 0010ca cfda MOVFF 0xfda,0xfea 0010cc ffea 0010ce 50ee MOVF 0xee,0x0,0x0 0010d0 10ed IORWF 0xed,0x0,0x0 0010d2 e014 BZ 0x10fc 0010fa d7e5 BRA 0x10c6 { C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010d4 c10c MOVFF 0x10c,0xfe9 *pDst.bRam = *pSrc.bRam; C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010d6 ffe9 0010d8 c10d MOVFF 0x10d,0xfea 0010da ffea 0010dc 50ef MOVF 0xef,0x0,0x0 0010de c10e MOVFF 0x10e,0xfe9 0010e0 ffe9 0010e2 c10f MOVFF 0x10f,0xfea 0010e4 ffea 0010e6 6eef MOVWF 0xef,0x0 0010e8 2b0e INCF 0xe,0x1,0x1 pDst.bRam++; C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010ea 0e00 MOVLW 0x0 0010ec 230f ADDWFC 0xf,0x1,0x1 0010ee 2b0c INCF 0xc,0x1,0x1 pSrc.bRam++; C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010f0 230d ADDWFC 0xd,0x1,0x1 0010f2 06df DECF 0xdf,0x1,0x0 byte_to_read._word--; C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010f4 0e01 MOVLW 0x1 0010f6 e201 BC 0x10fa 0010f8 06db DECF 0xdb,0x1,0x0 }//end while(byte_to_read._word) C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010fc 6ef5 MOVWF 0xf5,0x0 }//end USBCtrlTrfRxService C:\C\system\usb\usbctrltrf\usbctrltrf.c 0010fe 0e02 MOVLW 0x2 001100 5ce1 SUBWF 0xe1,0x0,0x0 001102 e202 BC 0x1108 001104 6ae1 CLRF 0xe1,0x0 001106 52e5 MOVF 0xe5,0x1,0x0 001108 6ee1 MOVWF 0xe1,0x0 00110a 50f5 MOVF 0xf5,0x0,0x0 00110c 52e5 MOVF 0xe5,0x1,0x0 00110e cfe7 MOVFF 0xfe7,0xfd9 001110 ffd9 001112 0012 RETURN 0x0 C:\C\system\usb\usbctrltrf\usbctrltrf.c /****************************************************************************** C:\C\system\usb\usbctrltrf\usbctrltrf.c * Function: void USBCtrlEPServiceComplete(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * PreCondition: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Input: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Output: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Side Effects: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Overview: This routine wrap up the ramaining tasks in servicing C:\C\system\usb\usbctrltrf\usbctrltrf.c * a Setup Request. Its main task is to set the endpoint C:\C\system\usb\usbctrltrf\usbctrltrf.c * controls appropriately for a given situation. See code C:\C\system\usb\usbctrltrf\usbctrltrf.c * below. C:\C\system\usb\usbctrltrf\usbctrltrf.c * There are three main scenarios: C:\C\system\usb\usbctrltrf\usbctrltrf.c * a) There was no handler for the Request, in this case C:\C\system\usb\usbctrltrf\usbctrltrf.c * a STALL should be sent out. C:\C\system\usb\usbctrltrf\usbctrltrf.c * b) The host has requested a read control transfer, C:\C\system\usb\usbctrltrf\usbctrltrf.c * endpoints are required to be setup in a specific way. C:\C\system\usb\usbctrltrf\usbctrltrf.c * c) The host has requested a write control transfer, or C:\C\system\usb\usbctrltrf\usbctrltrf.c * a control data stage is not required, endpoints are C:\C\system\usb\usbctrltrf\usbctrltrf.c * required to be setup in a specific way. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Packet processing is resumed by clearing PKTDIS bit. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Note: None C:\C\system\usb\usbctrltrf\usbctrltrf.c *****************************************************************************/ C:\C\system\usb\usbctrltrf\usbctrltrf.c void USBCtrlEPServiceComplete(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c { C:\C\system\usb\usbctrltrf\usbctrltrf.c 001114 0101 MOVLB 0x1 if(ctrl_trf_session_owner == MUID_NULL) C:\C\system\usb\usbctrltrf\usbctrltrf.c 001116 510b MOVF 0xb,0x0,0x1 001118 e10c BNZ 0x1132 { C:\C\system\usb\usbctrltrf\usbctrltrf.c /* C:\C\system\usb\usbctrltrf\usbctrltrf.c * If no one knows how to service this request then stall. C:\C\system\usb\usbctrltrf\usbctrltrf.c * Must also prepare EP0 to receive the next SETUP transaction. C:\C\system\usb\usbctrltrf\usbctrltrf.c */ C:\C\system\usb\usbctrltrf\usbctrltrf.c 00111a 0104 MOVLB 0x4 ep0Bo.Cnt = EP0_BUFF_SIZE; C:\C\system\usb\usbctrltrf\usbctrltrf.c 00111c 0e08 MOVLW 0x8 00111e 6f01 MOVWF 0x1,0x1 001120 0e20 MOVLW 0x20 ep0Bo.ADR = (byte*)&SetupPkt; C:\C\system\usb\usbctrltrf\usbctrltrf.c 001122 6f02 MOVWF 0x2,0x1 001124 0e04 MOVLW 0x4 001126 6f03 MOVWF 0x3,0x1 C:\C\system\usb\usbctrltrf\usbctrltrf.c 001128 0e84 MOVLW 0x84 ep0Bo.Stat._byte = _USIE|_BSTALL; C:\C\system\usb\usbctrltrf\usbctrltrf.c 00112a 6f00 MOVWF 0x0,0x1 00112c 0104 MOVLB 0x4 ep0Bi.Stat._byte = _USIE|_BSTALL; C:\C\system\usb\usbctrltrf\usbctrltrf.c 00112e 6f04 MOVWF 0x4,0x1 } C:\C\system\usb\usbctrltrf\usbctrltrf.c 001130 d035 BRA 0x119c else // A module has claimed ownership of the control transfer session. C:\C\system\usb\usbctrltrf\usbctrltrf.c { C:\C\system\usb\usbctrltrf\usbctrltrf.c 001132 0104 MOVLB 0x4 if(SetupPkt.DataDir == DEV_TO_HOST) C:\C\system\usb\usbctrltrf\usbctrltrf.c 001134 af20 BTFSS 0x20,0x7,0x1 001136 d022 BRA 0x117c { C:\C\system\usb\usbctrltrf\usbctrltrf.c 001138 0101 MOVLB 0x1 if(SetupPkt.wLength < wCount._word) C:\C\system\usb\usbctrltrf\usbctrltrf.c 00113a 5110 MOVF 0x10,0x0,0x1 00113c 0104 MOVLB 0x4 00113e 5d26 SUBWF 0x26,0x0,0x1 001140 0101 MOVLB 0x1 001142 5111 MOVF 0x11,0x0,0x1 001144 0104 MOVLB 0x4 001146 5927 SUBWFB 0x27,0x0,0x1 001148 e204 BC 0x1152 00114a c426 MOVFF 0x426,0x110 wCount._word = SetupPkt.wLength; C:\C\system\usb\usbctrltrf\usbctrltrf.c 00114c f110 00114e c427 MOVFF 0x427,0x111 001150 f111 001152 df31 RCALL 0xfb6 USBCtrlTrfTxService(); C:\C\system\usb\usbctrltrf\usbctrltrf.c 001154 0101 MOVLB 0x1 ctrl_trf_state = CTRL_TRF_TX; C:\C\system\usb\usbctrltrf\usbctrltrf.c 001156 0e01 MOVLW 0x1 001158 6f0a MOVWF 0xa,0x1 /* C:\C\system\usb\usbctrltrf\usbctrltrf.c * Control Read: C:\C\system\usb\usbctrltrf\usbctrltrf.c * ... | C:\C\system\usb\usbctrltrf\usbctrltrf.c * 1. Prepare OUT EP to respond to early termination C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * NOTE: C:\C\system\usb\usbctrltrf\usbctrltrf.c * If something went wrong during the control transfer, C:\C\system\usb\usbctrltrf\usbctrltrf.c * the last status stage may not be sent by the host. C:\C\system\usb\usbctrltrf\usbctrltrf.c * When this happens, two different things could happen C:\C\system\usb\usbctrltrf\usbctrltrf.c * depending on the host. C:\C\system\usb\usbctrltrf\usbctrltrf.c * a) The host could send out a RESET. C:\C\system\usb\usbctrltrf\usbctrltrf.c * b) The host could send out a new SETUP transaction C:\C\system\usb\usbctrltrf\usbctrltrf.c * without sending a RESET first. C:\C\system\usb\usbctrltrf\usbctrltrf.c * To properly handle case (b), the OUT EP must be setup C:\C\system\usb\usbctrltrf\usbctrltrf.c * to receive either a zero length OUT transaction, or a C:\C\system\usb\usbctrltrf\usbctrltrf.c * new SETUP transaction. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Since the SETUP transaction requires the DTS bit to be C:\C\system\usb\usbctrltrf\usbctrltrf.c * DAT0 while the zero length OUT status requires the DTS C:\C\system\usb\usbctrltrf\usbctrltrf.c * bit to be DAT1, the DTS bit check by the hardware should C:\C\system\usb\usbctrltrf\usbctrltrf.c * be disabled. This way the SIE could accept either of C:\C\system\usb\usbctrltrf\usbctrltrf.c * the two transactions. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Furthermore, the Cnt byte should be set to prepare for C:\C\system\usb\usbctrltrf\usbctrltrf.c * the SETUP data (8-byte or more), and the buffer address C:\C\system\usb\usbctrltrf\usbctrltrf.c * should be pointed to SetupPkt. C:\C\system\usb\usbctrltrf\usbctrltrf.c */ C:\C\system\usb\usbctrltrf\usbctrltrf.c 00115a 0104 MOVLB 0x4 ep0Bo.Cnt = EP0_BUFF_SIZE; C:\C\system\usb\usbctrltrf\usbctrltrf.c 00115c 0e08 MOVLW 0x8 00115e 6f01 MOVWF 0x1,0x1 001160 0e20 MOVLW 0x20 ep0Bo.ADR = (byte*)&SetupPkt; C:\C\system\usb\usbctrltrf\usbctrltrf.c 001162 6f02 MOVWF 0x2,0x1 001164 0e04 MOVLW 0x4 001166 6f03 MOVWF 0x3,0x1 001168 0e80 MOVLW 0x80 ep0Bo.Stat._byte = _USIE; // Note: DTSEN is 0! C:\C\system\usb\usbctrltrf\usbctrltrf.c 00116a 6f00 MOVWF 0x0,0x1 C:\C\system\usb\usbctrltrf\usbctrltrf.c /* C:\C\system\usb\usbctrltrf\usbctrltrf.c * 2. Prepare IN EP to transfer data, Cnt should have C:\C\system\usb\usbctrltrf\usbctrltrf.c * been initialized by responsible request owner. C:\C\system\usb\usbctrltrf\usbctrltrf.c */ C:\C\system\usb\usbctrltrf\usbctrltrf.c 00116c 0104 MOVLB 0x4 ep0Bi.ADR = (byte*)&CtrlTrfData; C:\C\system\usb\usbctrltrf\usbctrltrf.c 00116e 0e28 MOVLW 0x28 001170 6f06 MOVWF 0x6,0x1 001172 0e04 MOVLW 0x4 001174 6f07 MOVWF 0x7,0x1 001176 0ec8 MOVLW 0xc8 ep0Bi.Stat._byte = _USIE|_DAT1|_DTSEN; C:\C\system\usb\usbctrltrf\usbctrltrf.c 001178 6f04 MOVWF 0x4,0x1 } C:\C\system\usb\usbctrltrf\usbctrltrf.c 00117a d010 BRA 0x119c else // (SetupPkt.DataDir == HOST_TO_DEV) C:\C\system\usb\usbctrltrf\usbctrltrf.c { C:\C\system\usb\usbctrltrf\usbctrltrf.c 00117c 0101 MOVLB 0x1 ctrl_trf_state = CTRL_TRF_RX; C:\C\system\usb\usbctrltrf\usbctrltrf.c 00117e 0e02 MOVLW 0x2 001180 6f0a MOVWF 0xa,0x1 /* C:\C\system\usb\usbctrltrf\usbctrltrf.c * Control Write: C:\C\system\usb\usbctrltrf\usbctrltrf.c * ... | C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * 1. Prepare IN EP to respond to early termination C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * This is the same as a Zero Length Packet Response C:\C\system\usb\usbctrltrf\usbctrltrf.c * for control transfer without a data stage C:\C\system\usb\usbctrltrf\usbctrltrf.c */ C:\C\system\usb\usbctrltrf\usbctrltrf.c 001182 0104 MOVLB 0x4 ep0Bi.Cnt = 0; C:\C\system\usb\usbctrltrf\usbctrltrf.c 001184 6b05 CLRF 0x5,0x1 001186 0ec8 MOVLW 0xc8 ep0Bi.Stat._byte = _USIE|_DAT1|_DTSEN; C:\C\system\usb\usbctrltrf\usbctrltrf.c 001188 6f04 MOVWF 0x4,0x1 C:\C\system\usb\usbctrltrf\usbctrltrf.c /* C:\C\system\usb\usbctrltrf\usbctrltrf.c * 2. Prepare OUT EP to receive data. C:\C\system\usb\usbctrltrf\usbctrltrf.c */ C:\C\system\usb\usbctrltrf\usbctrltrf.c 00118a 0104 MOVLB 0x4 ep0Bo.Cnt = EP0_BUFF_SIZE; C:\C\system\usb\usbctrltrf\usbctrltrf.c 00118c 0e08 MOVLW 0x8 00118e 6f01 MOVWF 0x1,0x1 001190 0e28 MOVLW 0x28 ep0Bo.ADR = (byte*)&CtrlTrfData; C:\C\system\usb\usbctrltrf\usbctrltrf.c 001192 6f02 MOVWF 0x2,0x1 001194 0e04 MOVLW 0x4 001196 6f03 MOVWF 0x3,0x1 001198 0ec8 MOVLW 0xc8 ep0Bo.Stat._byte = _USIE|_DAT1|_DTSEN; C:\C\system\usb\usbctrltrf\usbctrltrf.c 00119a 6f00 MOVWF 0x0,0x1 }//end if(SetupPkt.DataDir == DEV_TO_HOST) C:\C\system\usb\usbctrltrf\usbctrltrf.c }//end if(ctrl_trf_session_owner == MUID_NULL) C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c /* C:\C\system\usb\usbctrltrf\usbctrltrf.c * PKTDIS bit is set when a Setup Transaction is received. C:\C\system\usb\usbctrltrf\usbctrltrf.c * Clear to resume packet processing. C:\C\system\usb\usbctrltrf\usbctrltrf.c */ C:\C\system\usb\usbctrltrf\usbctrltrf.c 00119c 986d BCF 0x6d,0x4,0x0 UCONbits.PKTDIS = 0; C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c 00119e 0012 RETURN 0x0 }//end USBCtrlEPServiceComplete C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c /****************************************************************************** C:\C\system\usb\usbctrltrf\usbctrltrf.c * Function: void USBPrepareForNextSetupTrf(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * PreCondition: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Input: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Output: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Side Effects: None C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Overview: The routine forces EP0 OUT to be ready for a new Setup C:\C\system\usb\usbctrltrf\usbctrltrf.c * transaction, and forces EP0 IN to be owned by CPU. C:\C\system\usb\usbctrltrf\usbctrltrf.c * C:\C\system\usb\usbctrltrf\usbctrltrf.c * Note: None C:\C\system\usb\usbctrltrf\usbctrltrf.c *****************************************************************************/ C:\C\system\usb\usbctrltrf\usbctrltrf.c void USBPrepareForNextSetupTrf(void) C:\C\system\usb\usbctrltrf\usbctrltrf.c { C:\C\system\usb\usbctrltrf\usbctrltrf.c 0011a0 0101 MOVLB 0x1 ctrl_trf_state = WAIT_SETUP; // See usbctrltrf.h C:\C\system\usb\usbctrltrf\usbctrltrf.c 0011a2 6b0a CLRF 0xa,0x1 0011a4 0104 MOVLB 0x4 ep0Bo.Cnt = EP0_BUFF_SIZE; // Defined in usbcfg.h C:\C\system\usb\usbctrltrf\usbctrltrf.c 0011a6 0e08 MOVLW 0x8 0011a8 6f01 MOVWF 0x1,0x1 0011aa 0e20 MOVLW 0x20 ep0Bo.ADR = (byte*)&SetupPkt; C:\C\system\usb\usbctrltrf\usbctrltrf.c 0011ac 6f02 MOVWF 0x2,0x1 0011ae 0e04 MOVLW 0x4 0011b0 6f03 MOVWF 0x3,0x1 0011b2 0e88 MOVLW 0x88 ep0Bo.Stat._byte = _USIE|_DAT0|_DTSEN; // EP0 buff dsc init, see usbmmap.h C:\C\system\usb\usbctrltrf\usbctrltrf.c 0011b4 6f00 MOVWF 0x0,0x1 0011b6 0104 MOVLB 0x4 ep0Bi.Stat._byte = _UCPU; // EP0 IN buffer initialization C:\C\system\usb\usbctrltrf\usbctrltrf.c 0011b8 6b04 CLRF 0x4,0x1 0011ba 0012 RETURN 0x0 }//end USBPrepareForNextSetupTrf C:\C\system\usb\usbctrltrf\usbctrltrf.c C:\C\system\usb\usbctrltrf\usbctrltrf.c /** EOF usbctrltrf.c *********************************************************/ C:\C\system\usb\usbctrltrf\usbctrltrf.c /********************************************************************* C:\C\user\user.c * C:\C\user\user.c * Microchip USB C18 Firmware Version 1.0 C:\C\user\user.c * C:\C\user\user.c ********************************************************************* C:\C\user\user.c * FileName: user.c C:\C\user\user.c * Dependencies: See INCLUDES section below C:\C\user\user.c * Processor: PIC18 C:\C\user\user.c * Compiler: C18 2.30.01+ C:\C\user\user.c * Company: Microchip Technology, Inc. C:\C\user\user.c * C:\C\user\user.c * Software License Agreement C:\C\user\user.c * C:\C\user\user.c * The software supplied herewith by Microchip Technology Incorporated C:\C\user\user.c * (the “Company”) for its PICmicro® Microcontroller is intended and C:\C\user\user.c * supplied to you, the Company’s customer, for use solely and C:\C\user\user.c * exclusively on Microchip PICmicro Microcontroller products. The C:\C\user\user.c * software is owned by the Company and/or its supplier, and is C:\C\user\user.c * protected under applicable copyright laws. All rights are reserved. C:\C\user\user.c * Any use in violation of the foregoing restrictions may subject the C:\C\user\user.c * user to criminal sanctions under applicable laws, as well as to C:\C\user\user.c * civil liability for the breach of the terms and conditions of this C:\C\user\user.c * license. C:\C\user\user.c * C:\C\user\user.c * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, C:\C\user\user.c * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED C:\C\user\user.c * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A C:\C\user\user.c * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, C:\C\user\user.c * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR C:\C\user\user.c * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. C:\C\user\user.c * C:\C\user\user.c * Author Date Comment C:\C\user\user.c *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C:\C\user\user.c * Rawin Rojvanit 11/19/04 Original. C:\C\user\user.c * Brian Schmalz 07/09/06 FW C v 1.0 now sends back PORT A C:\C\user\user.c * inputs on every USB packet reception C:\C\user\user.c ********************************************************************/ C:\C\user\user.c C:\C\user\user.c /****************************************************************************** C:\C\user\user.c * CDC RS-232 Emulation Tutorial Instructions: C:\C\user\user.c ****************************************************************************** C:\C\user\user.c * Refer to Application Note AN956 for explanation of the CDC class. C:\C\user\user.c * C:\C\user\user.c * First take a look at Exercise_Example() and study how functions are called. C:\C\user\user.c * C:\C\user\user.c * There are five exercises, each one has a solution in the CDC\user\solutions. C:\C\user\user.c * Scroll down and look for Exercise_01,_02,_03,_04, and _05. C:\C\user\user.c * Instructions on what to do is inside each function. C:\C\user\user.c * C:\C\user\user.c *****************************************************************************/ C:\C\user\user.c C:\C\user\user.c /** I N C L U D E S **********************************************************/ C:\C\user\user.c #include C:\C\user\user.c #include C:\C\user\user.c #include "system\typedefs.h" C:\C\user\user.c C:\C\user\user.c #include "system\usb\usb.h" C:\C\user\user.c C:\C\user\user.c #include "io_cfg.h" // I/O pin mapping C:\C\user\user.c #include "user\user.h" C:\C\user\user.c C:\C\user\user.c /** V A R I A B L E S ********************************************************/ C:\C\user\user.c #pragma udata C:\C\user\user.c byte old_sw; C:\C\user\user.c C:\C\user\user.c char input_buffer[64]; C:\C\user\user.c char output_buffer[64]; C:\C\user\user.c char out_ptr; C:\C\user\user.c C:\C\user\user.c /** P R I V A T E P R O T O T Y P E S ***************************************/ C:\C\user\user.c void BlinkUSBStatus(void); C:\C\user\user.c BOOL SwitchIsPressed(void); C:\C\user\user.c C:\C\user\user.c /** D E C L A R A T I O N S **************************************************/ C:\C\user\user.c #pragma code C:\C\user\user.c void UserInit(void) C:\C\user\user.c { C:\C\user\user.c 001338 0efc MOVLW 0xfc mInitAllLEDs(); C:\C\user\user.c 00133a 168b ANDWF 0x8b,0x1,0x0 00133c 1694 ANDWF 0x94,0x1,0x0 00133e 8494 BSF 0x94,0x2,0x0 mInitSwitch(); C:\C\user\user.c 001340 5082 MOVF 0x82,0x0,0x0 old_sw = sw; C:\C\user\user.c 001342 0b04 ANDLW 0x4 001344 e001 BZ 0x1348 001346 0e01 MOVLW 0x1 001348 0100 MOVLB 0x0 00134a 6f60 MOVWF 0x60,0x1 // Make all of PORTA digital inputs C:\C\user\user.c 00134c 6a89 CLRF 0x89,0x0 LATA = 0x00; C:\C\user\user.c 00134e 6892 SETF 0x92,0x0 TRISA = 0xFF; C:\C\user\user.c // Make all of PORTB an output C:\C\user\user.c 001350 688a SETF 0x8a,0x0 LATB = 0xFF; C:\C\user\user.c 001352 6a93 CLRF 0x93,0x0 TRISB = 0x00; C:\C\user\user.c 001354 0012 RETURN 0x0 }//end UserInit C:\C\user\user.c C:\C\user\user.c /****************************************************************************** C:\C\user\user.c * Function: void ProcessIO(void) C:\C\user\user.c * C:\C\user\user.c * PreCondition: None C:\C\user\user.c * C:\C\user\user.c * Input: None C:\C\user\user.c * C:\C\user\user.c * Output: None C:\C\user\user.c * C:\C\user\user.c * Side Effects: None C:\C\user\user.c * C:\C\user\user.c * Overview: This function is a place holder for other user routines. C:\C\user\user.c * It is a mixture of both USB and non-USB tasks. C:\C\user\user.c * C:\C\user\user.c * Note: None C:\C\user\user.c *****************************************************************************/ C:\C\user\user.c 001356 cfd9 MOVFF 0xfd9,0xfe6 void ProcessIO(void) C:\C\user\user.c 001358 ffe6 00135a cfe1 MOVFF 0xfe1,0xfd9 00135c ffd9 00135e 52e6 MOVF 0xe6,0x1,0x0 { C:\C\user\user.c 001360 6adf CLRF 0xdf,0x0 char bytesIn = 0; C:\C\user\user.c static char FirstTime = TRUE; C:\C\user\user.c C:\C\user\user.c 001362 d84d RCALL 0x13fe BlinkUSBStatus(); C:\C\user\user.c // User Application USB tasks C:\C\user\user.c 001364 0e06 MOVLW 0x6 if((usb_device_state < CONFIGURED_STATE)||(UCONbits.SUSPND==1)) return; C:\C\user\user.c 001366 0101 MOVLB 0x1 001368 5d12 SUBWF 0x12,0x0,0x1 00136a e303 BNC 0x1372 00136c 506d MOVF 0x6d,0x0,0x0 00136e 0b02 ANDLW 0x2 001370 e001 BZ 0x1374 001372 d040 BRA 0x13f4 C:\C\user\user.c // Pull in some new data if there is new data to pull in C:\C\user\user.c 001374 0e20 MOVLW 0x20 bytesIn = getsUSBUSART(input_buffer, 32); C:\C\user\user.c 001376 6ee6 MOVWF 0xe6,0x0 001378 0e61 MOVLW 0x61 00137a 6ee6 MOVWF 0xe6,0x0 00137c 0e00 MOVLW 0x0 00137e 6ee6 MOVWF 0xe6,0x0 001380 eca6 CALL 0x94c,0x0 001382 f004 001384 52e5 MOVF 0xe5,0x1,0x0 001386 52e5 MOVF 0xe5,0x1,0x0 001388 52e5 MOVF 0xe5,0x1,0x0 00138a 6edf MOVWF 0xdf,0x0 C:\C\user\user.c 00138c cfdf MOVFF 0xfdf,0x2 if (bytesIn > 0) C:\C\user\user.c 00138e f002 001390 0e00 MOVLW 0x0 001392 6ee7 MOVWF 0xe7,0x0 001394 1802 XORWF 0x2,0x0,0x0 001396 aee8 BTFSS 0xe8,0x7,0x0 001398 d002 BRA 0x139e 00139a 3402 RLCF 0x2,0x0,0x0 00139c d003 BRA 0x13a4 00139e 50e7 MOVF 0xe7,0x0,0x0 0013a0 80d8 BSF 0xd8,0x0,0x0 0013a2 5402 SUBFWB 0x2,0x0,0x0 0013a4 e227 BC 0x13f4 { C:\C\user\user.c // And write it out to port B C:\C\user\user.c 0013a6 c061 MOVFF 0x61,0xf8a LATB = input_buffer[0]; C:\C\user\user.c 0013a8 ff8a 0013aa 728b BTG 0x8b,0x1,0x0 mLED_2_Toggle(); C:\C\user\user.c C:\C\user\user.c // Send out hello when we first boot C:\C\user\user.c 0013ac 0100 MOVLB 0x0 if (FirstTime) C:\C\user\user.c 0013ae 51fd MOVF 0xfd,0x0,0x1 0013b0 e00e BZ 0x13ce { C:\C\user\user.c 0013b2 0100 MOVLB 0x0 if(mUSBUSARTIsTxTrfReady()) C:\C\user\user.c 0013b4 51e3 MOVF 0xe3,0x0,0x1 0013b6 e10a BNZ 0x13cc { C:\C\user\user.c 0013b8 0100 MOVLB 0x0 FirstTime = FALSE; C:\C\user\user.c 0013ba 6bfd CLRF 0xfd,0x1 0013bc 0e36 MOVLW 0x36 putrsUSBUSART("UBW Firmware C v1.0\r"); C:\C\user\user.c 0013be 6ee6 MOVWF 0xe6,0x0 0013c0 0e16 MOVLW 0x16 0013c2 6ee6 MOVWF 0xe6,0x0 0013c4 ec23 CALL 0xa46,0x0 0013c6 f005 0013c8 52e5 MOVF 0xe5,0x1,0x0 0013ca 52e5 MOVF 0xe5,0x1,0x0 } C:\C\user\user.c } C:\C\user\user.c 0013cc d013 BRA 0x13f4 else C:\C\user\user.c { C:\C\user\user.c 0013ce 0100 MOVLB 0x0 if(mUSBUSARTIsTxTrfReady()) C:\C\user\user.c 0013d0 51e3 MOVF 0xe3,0x0,0x1 0013d2 e110 BNZ 0x13f4 { C:\C\user\user.c 0013d4 cf80 MOVFF 0xf80,0xa1 output_buffer[0] = PORTA; C:\C\user\user.c 0013d6 f0a1 0013d8 0100 MOVLB 0x0 output_buffer[1] = 0x00; C:\C\user\user.c 0013da 6ba2 CLRF 0xa2,0x1 0013dc 0100 MOVLB 0x0 mUSBUSARTTxRam((byte*)output_buffer,1); C:\C\user\user.c 0013de 0ea1 MOVLW 0xa1 0013e0 6fe4 MOVWF 0xe4,0x1 0013e2 0e00 MOVLW 0x0 0013e4 6fe5 MOVWF 0xe5,0x1 0013e6 0100 MOVLB 0x0 0013e8 0e01 MOVLW 0x1 0013ea 6fe8 MOVWF 0xe8,0x1 0013ec 0100 MOVLB 0x0 0013ee 6be9 CLRF 0xe9,0x1 0013f0 0100 MOVLB 0x0 0013f2 6fe3 MOVWF 0xe3,0x1 } C:\C\user\user.c } C:\C\user\user.c } C:\C\user\user.c C:\C\user\user.c 0013f4 52e5 MOVF 0xe5,0x1,0x0 }//end ProcessIO C:\C\user\user.c 0013f6 52e5 MOVF 0xe5,0x1,0x0 0013f8 cfe7 MOVFF 0xfe7,0xfd9 0013fa ffd9 0013fc 0012 RETURN 0x0 C:\C\user\user.c /****************************************************************************** C:\C\user\user.c * Function: void BlinkUSBStatus(void) C:\C\user\user.c * C:\C\user\user.c * PreCondition: None C:\C\user\user.c * C:\C\user\user.c * Input: None C:\C\user\user.c * C:\C\user\user.c * Output: None C:\C\user\user.c * C:\C\user\user.c * Side Effects: None C:\C\user\user.c * C:\C\user\user.c * Overview: BlinkUSBStatus turns on and off LEDs corresponding to C:\C\user\user.c * the USB device state. C:\C\user\user.c * C:\C\user\user.c * Note: mLED macros can be found in io_cfg.h C:\C\user\user.c * usb_device_state is declared in usbmmap.c and is modified C:\C\user\user.c * in usbdrv.c, usbctrltrf.c, and usb9.c C:\C\user\user.c *****************************************************************************/ C:\C\user\user.c void BlinkUSBStatus(void) C:\C\user\user.c { C:\C\user\user.c static word led_count=0; C:\C\user\user.c C:\C\user\user.c 0013fe 0100 MOVLB 0x0 if(led_count == 0)led_count = 50000U; C:\C\user\user.c 001400 51fe MOVF 0xfe,0x0,0x1 001402 11ff IORWF 0xff,0x0,0x1 001404 e104 BNZ 0x140e 001406 0e50 MOVLW 0x50 001408 6ffe MOVWF 0xfe,0x1 00140a 0ec3 MOVLW 0xc3 00140c 6fff MOVWF 0xff,0x1 00140e 07fe DECF 0xfe,0x1,0x1 led_count--; C:\C\user\user.c 001410 0e00 MOVLW 0x0 001412 5bff SUBWFB 0xff,0x1,0x1 C:\C\user\user.c 001414 a26d BTFSS 0x6d,0x1,0x0 if(UCONbits.SUSPND == 1) C:\C\user\user.c 001416 d005 BRA 0x1422 { C:\C\user\user.c 001418 51fe MOVF 0xfe,0x0,0x1 if(led_count==0) C:\C\user\user.c 00141a 11ff IORWF 0xff,0x0,0x1 00141c e101 BNZ 0x1420 { C:\C\user\user.c // It would be nice if this could be a slow blink C:\C\user\user.c 00141e 908b BCF 0x8b,0x0,0x0 mLED_1_Off(); C:\C\user\user.c }//end if C:\C\user\user.c } C:\C\user\user.c 001420 d020 BRA 0x1462 else C:\C\user\user.c { C:\C\user\user.c 001422 0101 MOVLB 0x1 if(usb_device_state == DETACHED_STATE) C:\C\user\user.c 001424 5112 MOVF 0x12,0x0,0x1 001426 e102 BNZ 0x142c { C:\C\user\user.c 001428 908b BCF 0x8b,0x0,0x0 mLED_1_Off(); C:\C\user\user.c } C:\C\user\user.c 00142a d01b BRA 0x1462 else if(usb_device_state == ATTACHED_STATE) C:\C\user\user.c 00142c 0512 DECF 0x12,0x0,0x1 00142e e102 BNZ 0x1434 { C:\C\user\user.c 001430 808b BSF 0x8b,0x0,0x0 mLED_1_On(); C:\C\user\user.c } C:\C\user\user.c 001432 d017 BRA 0x1462 else if(usb_device_state == POWERED_STATE) C:\C\user\user.c 001434 0e02 MOVLW 0x2 001436 5d12 SUBWF 0x12,0x0,0x1 001438 e102 BNZ 0x143e { C:\C\user\user.c 00143a 808b BSF 0x8b,0x0,0x0 mLED_1_On(); C:\C\user\user.c } C:\C\user\user.c 00143c d012 BRA 0x1462 else if(usb_device_state == DEFAULT_STATE) C:\C\user\user.c 00143e 0e03 MOVLW 0x3 001440 5d12 SUBWF 0x12,0x0,0x1 001442 e102 BNZ 0x1448 { C:\C\user\user.c 001444 808b BSF 0x8b,0x0,0x0 mLED_1_On(); C:\C\user\user.c } C:\C\user\user.c 001446 d00d BRA 0x1462 else if(usb_device_state == ADDRESS_STATE) C:\C\user\user.c 001448 0e05 MOVLW 0x5 00144a 5d12 SUBWF 0x12,0x0,0x1 00144c e102 BNZ 0x1452 { C:\C\user\user.c 00144e 808b BSF 0x8b,0x0,0x0 mLED_1_On(); C:\C\user\user.c } C:\C\user\user.c 001450 d008 BRA 0x1462 else if(usb_device_state == CONFIGURED_STATE) C:\C\user\user.c 001452 0e06 MOVLW 0x6 001454 5d12 SUBWF 0x12,0x0,0x1 001456 e105 BNZ 0x1462 { C:\C\user\user.c 001458 0100 MOVLB 0x0 if(led_count==0) C:\C\user\user.c 00145a 51fe MOVF 0xfe,0x0,0x1 00145c 11ff IORWF 0xff,0x0,0x1 00145e e101 BNZ 0x1462 { C:\C\user\user.c 001460 708b BTG 0x8b,0x0,0x0 mLED_1_Toggle(); C:\C\user\user.c // mLED_2 = !mLED_1; // Alternate blink C:\C\user\user.c }//end if C:\C\user\user.c }//end if(...) C:\C\user\user.c }//end if(UCONbits.SUSPND...) C:\C\user\user.c C:\C\user\user.c 001462 0012 RETURN 0x0 }//end BlinkUSBStatus C:\C\user\user.c C:\C\user\user.c BOOL SwitchIsPressed(void) C:\C\user\user.c { C:\C\user\user.c 001464 5082 MOVF 0x82,0x0,0x0 if(sw != old_sw) C:\C\user\user.c 001466 0b04 ANDLW 0x4 001468 e001 BZ 0x146c 00146a 0e01 MOVLW 0x1 00146c 0100 MOVLB 0x0 00146e 5d60 SUBWF 0x60,0x0,0x1 001470 e009 BZ 0x1484 { C:\C\user\user.c 001472 5082 MOVF 0x82,0x0,0x0 old_sw = sw; // Save new value C:\C\user\user.c 001474 0b04 ANDLW 0x4 001476 e001 BZ 0x147a 001478 0e01 MOVLW 0x1 00147a 6f60 MOVWF 0x60,0x1 00147c b482 BTFSC 0x82,0x2,0x0 if(sw == 0) // If pressed C:\C\user\user.c 00147e d002 BRA 0x1484 001480 0e01 MOVLW 0x1 return TRUE; // Was pressed C:\C\user\user.c 001482 d002 BRA 0x1488 }//end if C:\C\user\user.c 001484 0e00 MOVLW 0x0 return FALSE; // Was not pressed C:\C\user\user.c 001486 d000 BRA 0x1488 001488 0012 RETURN 0x0 }//end SwitchIsPressed C:\C\user\user.c C:\C\user\user.c /** EOF user.c ***************************************************************/ C:\C\user\user.c /********************************************************************* C:\C\system\usb\class\cdc\cdc.c * C:\C\system\usb\class\cdc\cdc.c * Microchip USB C18 Firmware - CDC Version 1.0 C:\C\system\usb\class\cdc\cdc.c * C:\C\system\usb\class\cdc\cdc.c ********************************************************************* C:\C\system\usb\class\cdc\cdc.c * FileName: cdc.c C:\C\system\usb\class\cdc\cdc.c * Dependencies: See INCLUDES section below C:\C\system\usb\class\cdc\cdc.c * Processor: PIC18 C:\C\system\usb\class\cdc\cdc.c * Compiler: C18 2.30.01+ C:\C\system\usb\class\cdc\cdc.c * Company: Microchip Technology, Inc. C:\C\system\usb\class\cdc\cdc.c * C:\C\system\usb\class\cdc\cdc.c * Software License Agreement C:\C\system\usb\class\cdc\cdc.c * C:\C\system\usb\class\cdc\cdc.c * The software supplied herewith by Microchip Technology Incorporated C:\C\system\usb\class\cdc\cdc.c * (the “Company”) for its PICmicro® Microcontroller is intended and C:\C\system\usb\class\cdc\cdc.c * supplied to you, the Company’s customer, for use solely and C:\C\system\usb\class\cdc\cdc.c * exclusively on Microchip PICmicro Microcontroller products. The C:\C\system\usb\class\cdc\cdc.c * software is owned by the Company and/or its supplier, and is C:\C\system\usb\class\cdc\cdc.c * protected under applicable copyright laws. All rights are reserved. C:\C\system\usb\class\cdc\cdc.c * Any use in violation of the foregoing restrictions may subject the C:\C\system\usb\class\cdc\cdc.c * user to criminal sanctions under applicable laws, as well as to C:\C\system\usb\class\cdc\cdc.c * civil liability for the breach of the terms and conditions of this C:\C\system\usb\class\cdc\cdc.c * license. C:\C\system\usb\class\cdc\cdc.c * C:\C\system\usb\class\cdc\cdc.c * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, C:\C\system\usb\class\cdc\cdc.c * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED C:\C\system\usb\class\cdc\cdc.c * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A C:\C\system\usb\class\cdc\cdc.c * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, C:\C\system\usb\class\cdc\cdc.c * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR C:\C\system\usb\class\cdc\cdc.c * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. C:\C\system\usb\class\cdc\cdc.c * C:\C\system\usb\class\cdc\cdc.c * Author Date Comment C:\C\system\usb\class\cdc\cdc.c *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C:\C\system\usb\class\cdc\cdc.c * Rawin Rojvanit 11/19/04 Original. RS-232 Emulation Subset C:\C\system\usb\class\cdc\cdc.c ********************************************************************/ C:\C\system\usb\class\cdc\cdc.c C:\C\system\usb\class\cdc\cdc.c /** I N C L U D E S **********************************************************/ C:\C\system\usb\class\cdc\cdc.c #include C:\C\system\usb\class\cdc\cdc.c #include "system\typedefs.h" C:\C\system\usb\class\cdc\cdc.c #include "system\usb\usb.h" C:\C\system\usb\class\cdc\cdc.c C:\C\system\usb\class\cdc\cdc.c #ifdef USB_USE_CDC C:\C\system\usb\class\cdc\cdc.c C:\C\system\usb\class\cdc\cdc.c /** V A R I A B L E S ********************************************************/ C:\C\system\usb\class\cdc\cdc.c #pragma udata C:\C\system\usb\class\cdc\cdc.c byte cdc_rx_len; // total rx length C:\C\system\usb\class\cdc\cdc.c C:\C\system\usb\class\cdc\cdc.c byte cdc_trf_state; // States are defined cdc.h C:\C\system\usb\class\cdc\cdc.c POINTER pCDCSrc; // Dedicated source pointer C:\C\system\usb\class\cdc\cdc.c POINTER pCDCDst; // Dedicated destination pointer C:\C\system\usb\class\cdc\cdc.c byte cdc_tx_len; // total tx length C:\C\system\usb\class\cdc\cdc.c byte cdc_mem_type; // _ROM, _RAM C:\C\system\usb\class\cdc\cdc.c C:\C\system\usb\class\cdc\cdc.c LINE_CODING line_coding; // Buffer to store line coding information C:\C\system\usb\class\cdc\cdc.c CONTROL_SIGNAL_BITMAP control_signal_bitmap; C:\C\system\usb\class\cdc\cdc.c C:\C\system\usb\class\cdc\cdc.c /* C:\C\system\usb\class\cdc\cdc.c * SEND_ENCAPSULATED_COMMAND and GET_ENCAPSULATED_RESPONSE are required C:\C\system\usb\class\cdc\cdc.c * requests according to the CDC specification. C:\C\system\usb\class\cdc\cdc.c * However, it is not really being used here, therefore a dummy buffer is C:\C\system\usb\class\cdc\cdc.c * used for conformance. C:\C\system\usb\class\cdc\cdc.c */ C:\C\system\usb\class\cdc\cdc.c #define dummy_length 0x08 C:\C\system\usb\class\cdc\cdc.c byte dummy_encapsulated_cmd_response[dummy_length]; C:\C\system\usb\class\cdc\cdc.c C:\C\system\usb\class\cdc\cdc.c /** P R I V A T E P R O T O T Y P E S ***************************************/ C:\C\system\usb\class\cdc\cdc.c C:\C\system\usb\class\cdc\cdc.c /** D E C L A R A T I O N S **************************************************/ C:\C\system\usb\class\cdc\cdc.c #pragma code C:\C\system\usb\class\cdc\cdc.c C:\C\system\usb\class\cdc\cdc.c /** C L A S S S P E C I F I C R E Q ****************************************/ C:\C\system\usb\class\cdc\cdc.c /****************************************************************************** C:\C\system\usb\class\cdc\cdc.c * Function: void USBCheckCDCRequest(void) C:\C\system\usb\class\cdc\cdc.c * C:\C\system\usb\class\cdc\cdc.c * PreCondition: None C:\C\system\usb\class\cdc\cdc.c * C:\C\system\usb\class\cdc\cdc.c * Input: None C:\C\system\usb\class\cdc\cdc.c * C:\C\system\usb\class\cdc\cdc.c * Output: None C:\C\system\usb\class\cdc\cdc.c * C:\C\system\usb\class\cdc\cdc.c * Side Effects: None C:\C\system\usb\class\cdc\cdc.c * C:\C\system\usb\class\cdc\cdc.c * Overview: This routine checks the setup data packet to see if it C:\C\system\usb\class\cdc\cdc.c * knows how to handle it C:\C\system\usb\class\cdc\cdc.c * C:\C\system\usb\class\cdc\cdc.c * Note: None C:\C\system\usb\class\cdc\cdc.c *****************************************************************************/ C:\C\system\usb\class\cdc\cdc.c void USBCheckCDCRequest(void) C:\C\system\usb\class\cdc\cdc.c { C:\C\system\usb\class\cdc\cdc.c /* C:\C\system\usb\class\cdc\cdc.c * If request recipient is not an interface then return C:\C\system\usb\class\cdc\cdc.c */ C:\C\system\usb\class\cdc\cdc.c 000838 0104 MOVLB 0x4 if(SetupPkt.Recipient != RCPT_INTF) return; C:\C\system\usb\class\cdc\cdc.c 00083a 5120 MOVF 0x20,0x0,0x1 00083c 0b1f ANDLW 0x1f 00083e 0801 SUBLW 0x1 000840 e001 BZ 0x844 000842 d05b BRA 0x8fa C:\C\system\usb\class\cdc\cdc.c /* C:\C\system\usb\class\cdc\cdc.c * If request type is not class-specific then return C:\C\system\usb\class\cdc\cdc.c */ C:\C\system\usb\class\cdc\cdc.c 000844 5120 MOVF 0x20,0x0,0x1 if(SetupPkt.RequestType != CLASS) return; C:\C\system\usb\class\cdc\cdc.c 000846 0b60 ANDLW 0x60 000848 42e8 RRNCF 0xe8,0x1,0x0 00084a 42e8 RRNCF 0xe8,0x1,0x0 00084c 42e8 RRNCF 0xe8,0x1,0x0 00084e 42e8 RRNCF 0xe8,0x1,0x0 000850 42e8 RRNCF 0xe8,0x1,0x0 000852 0801 SUBLW 0x1 000854 e001 BZ 0x858 000856 d051 BRA 0x8fa C:\C\system\usb\class\cdc\cdc.c /* C:\C\system\usb\class\cdc\cdc.c * Interface ID must match interface numbers associated with C:\C\system\usb\class\cdc\cdc.c * CDC class, else return C:\C\system\usb\class\cdc\cdc.c */ C:\C\system\usb\class\cdc\cdc.c 000858 5124 MOVF 0x24,0x0,0x1 if((SetupPkt.bIntfID != CDC_COMM_INTF_ID)&& C:\C\system\usb\class\cdc\cdc.c 00085a e003 BZ 0x862 (SetupPkt.bIntfID != CDC_DATA_INTF_ID)) return; C:\C\system\usb\class\cdc\cdc.c 00085c 0524 DECF 0x24,0x0,0x1 00085e e001 BZ 0x862 000860 d04c BRA 0x8fa C:\C\system\usb\class\cdc\cdc.c 000862 5121 MOVF 0x21,0x0,0x1 switch(SetupPkt.bRequest) C:\C\system\usb\class\cdc\cdc.c 000864 0a23 XORLW 0x23 000866 e048 BZ 0x8f8 000868 0a01 XORLW 0x1 00086a e040 BZ 0x8ec 00086c 0a03 XORLW 0x3 00086e e030 BZ 0x8d0 000870 0a01 XORLW 0x1 000872 e025 BZ 0x8be 000874 0a24 XORLW 0x24 000876 e022 BZ 0x8bc 000878 0a07 XORLW 0x7 00087a e01f BZ 0x8ba 00087c 0a01 XORLW 0x1 00087e e01c BZ 0x8b8 000880 0a03 XORLW 0x3 000882 e011 BZ 0x8a6 000884 0a01 XORLW 0x1 000886 e001 BZ 0x88a { C:\C\system\usb\class\cdc\cdc.c case SEND_ENCAPSULATED_COMMAND: C:\C\system\usb\class\cdc\cdc.c 00088a 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_CDC; C:\C\system\usb\class\cdc\cdc.c 00088c 0e03 MOVLW 0x3 00088e 6f0b MOVWF 0xb,0x1 000890 0101 MOVLB 0x1 pSrc.bRam = (byte*)&dummy_encapsulated_cmd_response; C:\C\system\usb\class\cdc\cdc.c 000892 0ef5 MOVLW 0xf5 000894 6f0c MOVWF 0xc,0x1 000896 0e00 MOVLW 0x0 000898 6f0d MOVWF 0xd,0x1 00089a 0101 MOVLB 0x1 usb_stat.ctrl_trf_mem = _RAM; C:\C\system\usb\class\cdc\cdc.c 00089c 9313 BCF 0x13,0x1,0x1 00089e 0101 MOVLB 0x1 LSB(wCount) = dummy_length; C:\C\system\usb\class\cdc\cdc.c 0008a0 0e08 MOVLW 0x8 0008a2 6f10 MOVWF 0x10,0x1 0008a4 d02a BRA 0x8fa break; C:\C\system\usb\class\cdc\cdc.c case GET_ENCAPSULATED_RESPONSE: C:\C\system\usb\class\cdc\cdc.c 0008a6 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_CDC; C:\C\system\usb\class\cdc\cdc.c 0008a8 0e03 MOVLW 0x3 0008aa 6f0b MOVWF 0xb,0x1 // Populate dummy_encapsulated_cmd_response first. C:\C\system\usb\class\cdc\cdc.c 0008ac 0101 MOVLB 0x1 pDst.bRam = (byte*)&dummy_encapsulated_cmd_response; C:\C\system\usb\class\cdc\cdc.c 0008ae 0ef5 MOVLW 0xf5 0008b0 6f0e MOVWF 0xe,0x1 0008b2 0e00 MOVLW 0x0 0008b4 6f0f MOVWF 0xf,0x1 0008b6 d021 BRA 0x8fa break; C:\C\system\usb\class\cdc\cdc.c case SET_COMM_FEATURE: // Optional C:\C\system\usb\class\cdc\cdc.c 0008b8 d020 BRA 0x8fa break; C:\C\system\usb\class\cdc\cdc.c case GET_COMM_FEATURE: // Optional C:\C\system\usb\class\cdc\cdc.c 0008ba d01f BRA 0x8fa break; C:\C\system\usb\class\cdc\cdc.c case CLEAR_COMM_FEATURE: // Optional C:\C\system\usb\class\cdc\cdc.c 0008bc d01e BRA 0x8fa break; C:\C\system\usb\class\cdc\cdc.c case SET_LINE_CODING: C:\C\system\usb\class\cdc\cdc.c 0008be 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_CDC; C:\C\system\usb\class\cdc\cdc.c 0008c0 0e03 MOVLW 0x3 0008c2 6f0b MOVWF 0xb,0x1 0008c4 0101 MOVLB 0x1 pDst.bRam = (byte*)&line_coding; // Set destination C:\C\system\usb\class\cdc\cdc.c 0008c6 0eea MOVLW 0xea 0008c8 6f0e MOVWF 0xe,0x1 0008ca 0e00 MOVLW 0x0 0008cc 6f0f MOVWF 0xf,0x1 0008ce d015 BRA 0x8fa break; C:\C\system\usb\class\cdc\cdc.c case GET_LINE_CODING: C:\C\system\usb\class\cdc\cdc.c 0008d0 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_CDC; C:\C\system\usb\class\cdc\cdc.c 0008d2 0e03 MOVLW 0x3 0008d4 6f0b MOVWF 0xb,0x1 0008d6 0101 MOVLB 0x1 pSrc.bRam = (byte*)&line_coding; // Set source C:\C\system\usb\class\cdc\cdc.c 0008d8 0eea MOVLW 0xea 0008da 6f0c MOVWF 0xc,0x1 0008dc 0e00 MOVLW 0x0 0008de 6f0d MOVWF 0xd,0x1 0008e0 0101 MOVLB 0x1 usb_stat.ctrl_trf_mem = _RAM; // Set memory type C:\C\system\usb\class\cdc\cdc.c 0008e2 9313 BCF 0x13,0x1,0x1 0008e4 0101 MOVLB 0x1 LSB(wCount) = LINE_CODING_LENGTH; // Set data count C:\C\system\usb\class\cdc\cdc.c 0008e6 0e07 MOVLW 0x7 0008e8 6f10 MOVWF 0x10,0x1 0008ea d007 BRA 0x8fa break; C:\C\system\usb\class\cdc\cdc.c case SET_CONTROL_LINE_STATE: C:\C\system\usb\class\cdc\cdc.c 0008ec 0101 MOVLB 0x1 ctrl_trf_session_owner = MUID_CDC; C:\C\system\usb\class\cdc\cdc.c 0008ee 0e03 MOVLW 0x3 0008f0 6f0b MOVWF 0xb,0x1 0008f2 c422 MOVFF 0x422,0xf1 control_signal_bitmap._byte = LSB(SetupPkt.W_Value); C:\C\system\usb\class\cdc\cdc.c 0008f4 f0f1 0008f6 d001 BRA 0x8fa break; C:\C\system\usb\class\cdc\cdc.c case SEND_BREAK: // Optional C:\C\system\usb\class\cdc\cdc.c 0008f8 d000 BRA 0x8fa break; C:\C\system\usb\class\cdc\cdc.c default