3 * Copyright (c) 2007, Benedikt Sauter <sauter@ixbat.de>
6 * Short descripton of file: at90usb1287-hcdi.c
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * * Neither the name of the FH Augsburg nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include "at90usb1287.h"
46 #include <core/core.h>
47 #include <usbspec/usb11spec.h>
49 void at90usb1287_roothub_probe();
50 void at90usb1287_roothub_check();
52 void at90usb1287_start_transfer();
54 usb_device * device_on_downstream;
57 /* cuurent transferdescriptor on port a and port b */
58 usb_transfer_descriptor * td_usba;
59 usb_transfer_descriptor * td_usbb;
61 usb_driver at90usb1287_roothub = {
62 .name = "at90usb1287_roothub",
63 .probe = at90usb1287_roothub_probe,
64 .check = at90usb1287_roothub_check,
68 usb_device * device_on_downstream;
71 * Find and initial root hub
73 void at90usb1287_roothub_probe()
75 // called on n every new enumeration and at usb_register_driver
76 // der sollte nach dem ersten aufruf igonriert werden
78 core.stdout("Probe: AT90USB1287 Root Hub\r\n");
83 * This function is called periodical, to notice
84 * port changes after an hub
86 void at90usb1287_roothub_check()
88 //USART_WriteHex(UHINT);
92 device_on_downstream=NULL;
94 core.stdout("Device: Removed!\r\n");
96 //UHINT &= ~(1<<DDISCI);
99 if(device_on_downstream!=NULL) {
100 // normal transfer check for interrupt and isochonous endpoints
101 //USART_WriteHex(0x88);
103 // check if device is connected
108 core.stdout("Device: Found new one!\r\n");
111 if((USBSTA & (1<<SPEED)) &&(USBSTA & (1<<SPEED))){
114 core.stdout("FS\r\n");
119 core.stdout("LS\r\n");
121 // mark device as low speed
124 //UHCON = (1<<SOFEN); /* host generate for FS SOF, and for LS keep-alive! */
125 //UHCON = (1<<RESET);
128 device_on_downstream = 1;
129 //device_on_downstream = usb_add_device();
130 //UHINT &= ~(1<<DCONNI);
133 // wenn geraet nicht aktiviert ist das immer aufrufen!
134 //USART_WriteHex(0x55);
140 USBCON &= ~(1<<USBE);
146 UDCON &= ~(1<<DETACH);
149 /* disable vbus hw control */
150 OTGCON |= (1<<VBUSHWC);
152 OTGCON |= (1<<VBUSREQ);
159 /* register virtual root hub driver */
160 usb_register_driver(&at90usb1287_roothub);
162 /* enable regulator */
163 UHWCON |= (1<<UVREGE);
164 /* force host mode */
165 UHWCON &= ~(1<<UIDE);
166 UHWCON &= ~(1<<UIMOD);
169 UsbSetPLL_CPU_Frequency();
174 USBCON &= ~(1<<USBE);
183 UDCON &= ~(1<<DETACH);
185 /* enable uconv pin */
186 UsbDisableUVCON_PinControl();
187 UsbEnableUID_ModeSelection();
192 /* disable vbus hw control */
193 OTGCON |= (1<<VBUSHWC);
197 OTGCON |= (1<<VBUSREQ);
199 UHIEN |= (1<<DDISCE);
200 UHIEN |= (1<<DCONNE);
207 * hcdi_enqueue takes usb_irp and split it into
208 * several usb packeges (SETUP,IN,OUT)
209 * In the usbstack they are transported with the
210 * usb_transfer_descriptor data structure.
213 u8 hcdi_enqueue(usb_transfer_descriptor *td)
217 at90usb1287_start_transfer();
223 u8 hcdi_dequeue(usb_transfer_descriptor *td)
236 void at90usb1287_start_transfer()
238 usb_transfer_descriptor * td;
239 //core.stdout("Transfer: Start!\r\n");
242 /* choose next free port */