several changes..
1 /*********************************************************************
3 * Microchip USB C18 Firmware Version 1.0
5 *********************************************************************
7 * Dependencies: See INCLUDES section below
9 * Compiler: C18 2.30.01+
10 * Company: Microchip Technology, Inc.
12 * Software License Agreement
14 * The software supplied herewith by Microchip Technology Incorporated
15 * (the “Company”) for its PICmicro® Microcontroller is intended and
16 * supplied to you, the Company’s customer, for use solely and
17 * exclusively on Microchip PICmicro Microcontroller products. The
18 * software is owned by the Company and/or its supplier, and is
19 * protected under applicable copyright laws. All rights are reserved.
20 * Any use in violation of the foregoing restrictions may subject the
21 * user to criminal sanctions under applicable laws, as well as to
22 * civil liability for the breach of the terms and conditions of this
25 * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
26 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
27 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
28 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
29 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
30 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
33 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34 * Rawin Rojvanit 11/19/04 Original.
35 ********************************************************************/
37 /** I N C L U D E S **********************************************************/
41 #include "io_cfg.h" // Required for self_power status
43 /** V A R I A B L E S ********************************************************/
46 /** P R I V A T E P R O T O T Y P E S ***************************************/
47 void USBStdGetDscHandler(void);
48 void USBStdSetCfgHandler(void);
49 void USBStdGetStatusHandler(void);
50 void USBStdFeatureReqHandler(void);
52 /** D E C L A R A T I O N S **************************************************/
54 /******************************************************************************
55 * Function: void USBCheckStdRequest(void)
65 * Overview: This routine checks the setup data packet to see if it
66 * knows how to handle it
69 *****************************************************************************/
70 void USBCheckStdRequest(void)
72 if(SetupPkt.RequestType != STANDARD) return;
74 switch(SetupPkt.bRequest)
77 ctrl_trf_session_owner = MUID_USB9;
78 usb_device_state = ADR_PENDING_STATE; // Update state only
79 /* See USBCtrlTrfInHandler() in usbctrltrf.c for the next step */
82 USBStdGetDscHandler();
85 USBStdSetCfgHandler();
88 ctrl_trf_session_owner = MUID_USB9;
89 pSrc.bRam = (byte*)&usb_active_cfg; // Set Source
90 usb_stat.ctrl_trf_mem = _RAM; // Set memory type
91 LSB(wCount) = 1; // Set data count
94 USBStdGetStatusHandler();
98 USBStdFeatureReqHandler();
101 ctrl_trf_session_owner = MUID_USB9;
102 pSrc.bRam = (byte*)&usb_alt_intf+SetupPkt.bIntfID; // Set source
103 usb_stat.ctrl_trf_mem = _RAM; // Set memory type
104 LSB(wCount) = 1; // Set data count
107 ctrl_trf_session_owner = MUID_USB9;
108 usb_alt_intf[SetupPkt.bIntfID] = SetupPkt.bAltID;
116 }//end USBCheckStdRequest
118 /******************************************************************************
119 * Function: void USBStdGetDscHandler(void)
129 * Overview: This routine handles the standard GET_DESCRIPTOR request.
130 * It utilizes tables dynamically looks up descriptor size.
131 * This routine should never have to be modified if the tables
132 * in usbdsc.c are declared correctly.
135 *****************************************************************************/
136 void USBStdGetDscHandler(void)
138 if(SetupPkt.bmRequestType == 0x80)
140 switch(SetupPkt.bDscType)
143 ctrl_trf_session_owner = MUID_USB9;
144 pSrc.bRom = (rom byte*)&device_dsc;
145 wCount._word = sizeof(device_dsc); // Set data count
148 ctrl_trf_session_owner = MUID_USB9;
149 pSrc.bRom = *(USB_CD_Ptr+SetupPkt.bDscIndex);
150 wCount._word = *(pSrc.wRom+1); // Set data count
153 ctrl_trf_session_owner = MUID_USB9;
154 pSrc.bRom = *(USB_SD_Ptr+SetupPkt.bDscIndex);
155 wCount._word = *pSrc.bRom; // Set data count
159 usb_stat.ctrl_trf_mem = _ROM; // Set memory type
161 }//end USBStdGetDscHandler
163 /******************************************************************************
164 * Function: void USBStdSetCfgHandler(void)
174 * Overview: This routine first disables all endpoints by clearing
175 * UEP registers. It then configures (initializes) endpoints
176 * specified in the modifiable section.
179 *****************************************************************************/
180 void USBStdSetCfgHandler(void)
182 ctrl_trf_session_owner = MUID_USB9;
183 mDisableEP1to15(); // See usbdrv.h
184 ClearArray((byte*)&usb_alt_intf,MAX_NUM_INT);
185 usb_active_cfg = SetupPkt.bCfgValue;
186 if(SetupPkt.bCfgValue == 0)
187 usb_device_state = ADDRESS_STATE;
190 usb_device_state = CONFIGURED_STATE;
192 /* Modifiable Section */
194 #if defined(USB_USE_CDC) // See autofiles\usbcfg.h
198 /* End modifiable section */
200 }//end if(SetupPkt.bcfgValue == 0)
201 }//end USBStdSetCfgHandler
203 /******************************************************************************
204 * Function: void USBStdGetStatusHandler(void)
214 * Overview: This routine handles the standard GET_STATUS request
217 *****************************************************************************/
218 void USBStdGetStatusHandler(void)
220 CtrlTrfData._byte0 = 0; // Initialize content
221 CtrlTrfData._byte1 = 0;
223 switch(SetupPkt.Recipient)
226 ctrl_trf_session_owner = MUID_USB9;
228 * _byte0: bit0: Self-Powered Status [0] Bus-Powered [1] Self-Powered
229 * bit1: RemoteWakeup [0] Disabled [1] Enabled
231 if(self_power == 1) // self_power defined in io_cfg.h
232 CtrlTrfData._byte0|=0b000000001; // Set bit0
234 if(usb_stat.RemoteWakeup == 1) // usb_stat defined in usbmmap.c
235 CtrlTrfData._byte0|=0b00000010; // Set bit1
238 ctrl_trf_session_owner = MUID_USB9; // No data to update
241 ctrl_trf_session_owner = MUID_USB9;
243 * _byte0: bit0: Halt Status [0] Not Halted [1] Halted
245 pDst.bRam = (byte*)&ep0Bo+(SetupPkt.EPNum*8)+(SetupPkt.EPDir*4);
246 if(*pDst.bRam & _BSTALL) // Use _BSTALL as a bit mask
247 CtrlTrfData._byte0=0x01;// Set bit0
251 if(ctrl_trf_session_owner == MUID_USB9)
253 pSrc.bRam = (byte*)&CtrlTrfData; // Set Source
254 usb_stat.ctrl_trf_mem = _RAM; // Set memory type
255 LSB(wCount) = 2; // Set data count
257 }//end USBStdGetStatusHandler
259 /******************************************************************************
260 * Function: void USBStdFeatureReqHandler(void)
270 * Overview: This routine handles the standard SET & CLEAR FEATURES
274 *****************************************************************************/
275 void USBStdFeatureReqHandler(void)
277 if((SetupPkt.bFeature == DEVICE_REMOTE_WAKEUP)&&
278 (SetupPkt.Recipient == RCPT_DEV))
280 ctrl_trf_session_owner = MUID_USB9;
281 if(SetupPkt.bRequest == SET_FEATURE)
282 usb_stat.RemoteWakeup = 1;
284 usb_stat.RemoteWakeup = 0;
287 if((SetupPkt.bFeature == ENDPOINT_HALT)&&
288 (SetupPkt.Recipient == RCPT_EP)&&
289 (SetupPkt.EPNum != 0))
291 ctrl_trf_session_owner = MUID_USB9;
292 /* Must do address calculation here */
293 pDst.bRam = (byte*)&ep0Bo+(SetupPkt.EPNum*8)+(SetupPkt.EPDir*4);
295 if(SetupPkt.bRequest == SET_FEATURE)
296 *pDst.bRam = _USIE|_BSTALL;
299 if(SetupPkt.EPDir == 1) // IN
302 *pDst.bRam = _USIE|_DAT0|_DTSEN;
305 }//end USBStdFeatureReqHandler
307 /** EOF usb9.c ***************************************************************/