USBHost library. NOTE: This library is only officially supported on the LPC1768 platform. For more information, please see the handbook page.
Dependencies: FATFileSystem mbed-rtos
Dependents: BTstack WallbotWii SD to Flash Data Transfer USBHost-MSD_HelloWorld ... more
Legacy Warning
This is an mbed 2 library. To learn more about mbed OS 5, visit the docs.
Pull requests against this repository are no longer supported. Please raise against mbed OS 5 as documented above.
targets/TARGET_RENESAS/USBHALHost_RZ_A1.cpp@39:d96aa62afc5b, 2017-07-27 (annotated)
- Committer:
- Kojto
- Date:
- Thu Jul 27 12:24:30 2017 +0100
- Revision:
- 39:d96aa62afc5b
Update USBHost - add targets directory
This corresponds to mbed-os/master commit 9207365
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 39:d96aa62afc5b | 1 | /* mbed USBHost Library |
Kojto | 39:d96aa62afc5b | 2 | * Copyright (c) 2006-2013 ARM Limited |
Kojto | 39:d96aa62afc5b | 3 | * |
Kojto | 39:d96aa62afc5b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Kojto | 39:d96aa62afc5b | 5 | * you may not use this file except in compliance with the License. |
Kojto | 39:d96aa62afc5b | 6 | * You may obtain a copy of the License at |
Kojto | 39:d96aa62afc5b | 7 | * |
Kojto | 39:d96aa62afc5b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Kojto | 39:d96aa62afc5b | 9 | * |
Kojto | 39:d96aa62afc5b | 10 | * Unless required by applicable law or agreed to in writing, software |
Kojto | 39:d96aa62afc5b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Kojto | 39:d96aa62afc5b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Kojto | 39:d96aa62afc5b | 13 | * See the License for the specific language governing permissions and |
Kojto | 39:d96aa62afc5b | 14 | * limitations under the License. |
Kojto | 39:d96aa62afc5b | 15 | */ |
Kojto | 39:d96aa62afc5b | 16 | |
Kojto | 39:d96aa62afc5b | 17 | #if defined(TARGET_RZ_A1H) || defined(TARGET_VK_RZ_A1H) |
Kojto | 39:d96aa62afc5b | 18 | |
Kojto | 39:d96aa62afc5b | 19 | #include "mbed.h" |
Kojto | 39:d96aa62afc5b | 20 | #include "USBHALHost.h" |
Kojto | 39:d96aa62afc5b | 21 | #include "dbg.h" |
Kojto | 39:d96aa62afc5b | 22 | |
Kojto | 39:d96aa62afc5b | 23 | #include "ohci_wrapp_RZ_A1.h" |
Kojto | 39:d96aa62afc5b | 24 | |
Kojto | 39:d96aa62afc5b | 25 | |
Kojto | 39:d96aa62afc5b | 26 | #define HCCA_SIZE sizeof(HCCA) |
Kojto | 39:d96aa62afc5b | 27 | #define ED_SIZE sizeof(HCED) |
Kojto | 39:d96aa62afc5b | 28 | #define TD_SIZE sizeof(HCTD) |
Kojto | 39:d96aa62afc5b | 29 | |
Kojto | 39:d96aa62afc5b | 30 | #define TOTAL_SIZE (HCCA_SIZE + (MAX_ENDPOINT*ED_SIZE) + (MAX_TD*TD_SIZE)) |
Kojto | 39:d96aa62afc5b | 31 | #define ALIGNE_MSK (0x0000000F) |
Kojto | 39:d96aa62afc5b | 32 | |
Kojto | 39:d96aa62afc5b | 33 | static volatile uint8_t usb_buf[TOTAL_SIZE + ALIGNE_MSK]; //16 bytes aligned! |
Kojto | 39:d96aa62afc5b | 34 | |
Kojto | 39:d96aa62afc5b | 35 | USBHALHost * USBHALHost::instHost; |
Kojto | 39:d96aa62afc5b | 36 | |
Kojto | 39:d96aa62afc5b | 37 | USBHALHost::USBHALHost() { |
Kojto | 39:d96aa62afc5b | 38 | instHost = this; |
Kojto | 39:d96aa62afc5b | 39 | memInit(); |
Kojto | 39:d96aa62afc5b | 40 | memset((void*)usb_hcca, 0, HCCA_SIZE); |
Kojto | 39:d96aa62afc5b | 41 | for (int i = 0; i < MAX_ENDPOINT; i++) { |
Kojto | 39:d96aa62afc5b | 42 | edBufAlloc[i] = false; |
Kojto | 39:d96aa62afc5b | 43 | } |
Kojto | 39:d96aa62afc5b | 44 | for (int i = 0; i < MAX_TD; i++) { |
Kojto | 39:d96aa62afc5b | 45 | tdBufAlloc[i] = false; |
Kojto | 39:d96aa62afc5b | 46 | } |
Kojto | 39:d96aa62afc5b | 47 | } |
Kojto | 39:d96aa62afc5b | 48 | |
Kojto | 39:d96aa62afc5b | 49 | void USBHALHost::init() { |
Kojto | 39:d96aa62afc5b | 50 | ohciwrapp_init(&_usbisr); |
Kojto | 39:d96aa62afc5b | 51 | |
Kojto | 39:d96aa62afc5b | 52 | ohciwrapp_reg_w(OHCI_REG_CONTROL, 1); // HARDWARE RESET |
Kojto | 39:d96aa62afc5b | 53 | ohciwrapp_reg_w(OHCI_REG_CONTROLHEADED, 0); // Initialize Control list head to Zero |
Kojto | 39:d96aa62afc5b | 54 | ohciwrapp_reg_w(OHCI_REG_BULKHEADED, 0); // Initialize Bulk list head to Zero |
Kojto | 39:d96aa62afc5b | 55 | |
Kojto | 39:d96aa62afc5b | 56 | // Wait 100 ms before apply reset |
Kojto | 39:d96aa62afc5b | 57 | wait_ms(100); |
Kojto | 39:d96aa62afc5b | 58 | |
Kojto | 39:d96aa62afc5b | 59 | // software reset |
Kojto | 39:d96aa62afc5b | 60 | ohciwrapp_reg_w(OHCI_REG_COMMANDSTATUS, OR_CMD_STATUS_HCR); |
Kojto | 39:d96aa62afc5b | 61 | |
Kojto | 39:d96aa62afc5b | 62 | // Write Fm Interval and Largest Data Packet Counter |
Kojto | 39:d96aa62afc5b | 63 | ohciwrapp_reg_w(OHCI_REG_FMINTERVAL, DEFAULT_FMINTERVAL); |
Kojto | 39:d96aa62afc5b | 64 | ohciwrapp_reg_w(OHCI_REG_PERIODICSTART, FI * 90 / 100); |
Kojto | 39:d96aa62afc5b | 65 | |
Kojto | 39:d96aa62afc5b | 66 | // Put HC in operational state |
Kojto | 39:d96aa62afc5b | 67 | ohciwrapp_reg_w(OHCI_REG_CONTROL, (ohciwrapp_reg_r(OHCI_REG_CONTROL) & (~OR_CONTROL_HCFS)) | OR_CONTROL_HC_OPER); |
Kojto | 39:d96aa62afc5b | 68 | // Set Global Power |
Kojto | 39:d96aa62afc5b | 69 | ohciwrapp_reg_w(OHCI_REG_RHSTATUS, OR_RH_STATUS_LPSC); |
Kojto | 39:d96aa62afc5b | 70 | |
Kojto | 39:d96aa62afc5b | 71 | ohciwrapp_reg_w(OHCI_REG_HCCA, (uint32_t)(usb_hcca)); |
Kojto | 39:d96aa62afc5b | 72 | |
Kojto | 39:d96aa62afc5b | 73 | // Clear Interrrupt Status |
Kojto | 39:d96aa62afc5b | 74 | ohciwrapp_reg_w(OHCI_REG_INTERRUPTSTATUS, ohciwrapp_reg_r(OHCI_REG_INTERRUPTSTATUS)); |
Kojto | 39:d96aa62afc5b | 75 | |
Kojto | 39:d96aa62afc5b | 76 | ohciwrapp_reg_w(OHCI_REG_INTERRUPTENABLE, OR_INTR_ENABLE_MIE | OR_INTR_ENABLE_WDH | OR_INTR_ENABLE_RHSC); |
Kojto | 39:d96aa62afc5b | 77 | |
Kojto | 39:d96aa62afc5b | 78 | // Enable the USB Interrupt |
Kojto | 39:d96aa62afc5b | 79 | ohciwrapp_reg_w(OHCI_REG_RHPORTSTATUS1, OR_RH_PORT_CSC); |
Kojto | 39:d96aa62afc5b | 80 | ohciwrapp_reg_w(OHCI_REG_RHPORTSTATUS1, OR_RH_PORT_PRSC); |
Kojto | 39:d96aa62afc5b | 81 | |
Kojto | 39:d96aa62afc5b | 82 | // Check for any connected devices |
Kojto | 39:d96aa62afc5b | 83 | if (ohciwrapp_reg_r(OHCI_REG_RHPORTSTATUS1) & OR_RH_PORT_CCS) { |
Kojto | 39:d96aa62afc5b | 84 | //Device connected |
Kojto | 39:d96aa62afc5b | 85 | wait_ms(150); |
Kojto | 39:d96aa62afc5b | 86 | USB_DBG("Device connected (%08x)\n\r", ohciwrapp_reg_r(OHCI_REG_RHPORTSTATUS1)); |
Kojto | 39:d96aa62afc5b | 87 | deviceConnected(0, 1, ohciwrapp_reg_r(OHCI_REG_RHPORTSTATUS1) & OR_RH_PORT_LSDA); |
Kojto | 39:d96aa62afc5b | 88 | } |
Kojto | 39:d96aa62afc5b | 89 | } |
Kojto | 39:d96aa62afc5b | 90 | |
Kojto | 39:d96aa62afc5b | 91 | uint32_t USBHALHost::controlHeadED() { |
Kojto | 39:d96aa62afc5b | 92 | return ohciwrapp_reg_r(OHCI_REG_CONTROLHEADED); |
Kojto | 39:d96aa62afc5b | 93 | } |
Kojto | 39:d96aa62afc5b | 94 | |
Kojto | 39:d96aa62afc5b | 95 | uint32_t USBHALHost::bulkHeadED() { |
Kojto | 39:d96aa62afc5b | 96 | return ohciwrapp_reg_r(OHCI_REG_BULKHEADED); |
Kojto | 39:d96aa62afc5b | 97 | } |
Kojto | 39:d96aa62afc5b | 98 | |
Kojto | 39:d96aa62afc5b | 99 | uint32_t USBHALHost::interruptHeadED() { |
Kojto | 39:d96aa62afc5b | 100 | return usb_hcca->IntTable[0]; |
Kojto | 39:d96aa62afc5b | 101 | } |
Kojto | 39:d96aa62afc5b | 102 | |
Kojto | 39:d96aa62afc5b | 103 | void USBHALHost::updateBulkHeadED(uint32_t addr) { |
Kojto | 39:d96aa62afc5b | 104 | ohciwrapp_reg_w(OHCI_REG_BULKHEADED, addr); |
Kojto | 39:d96aa62afc5b | 105 | } |
Kojto | 39:d96aa62afc5b | 106 | |
Kojto | 39:d96aa62afc5b | 107 | |
Kojto | 39:d96aa62afc5b | 108 | void USBHALHost::updateControlHeadED(uint32_t addr) { |
Kojto | 39:d96aa62afc5b | 109 | ohciwrapp_reg_w(OHCI_REG_CONTROLHEADED, addr); |
Kojto | 39:d96aa62afc5b | 110 | } |
Kojto | 39:d96aa62afc5b | 111 | |
Kojto | 39:d96aa62afc5b | 112 | void USBHALHost::updateInterruptHeadED(uint32_t addr) { |
Kojto | 39:d96aa62afc5b | 113 | usb_hcca->IntTable[0] = addr; |
Kojto | 39:d96aa62afc5b | 114 | } |
Kojto | 39:d96aa62afc5b | 115 | |
Kojto | 39:d96aa62afc5b | 116 | |
Kojto | 39:d96aa62afc5b | 117 | void USBHALHost::enableList(ENDPOINT_TYPE type) { |
Kojto | 39:d96aa62afc5b | 118 | uint32_t wk_data; |
Kojto | 39:d96aa62afc5b | 119 | |
Kojto | 39:d96aa62afc5b | 120 | switch(type) { |
Kojto | 39:d96aa62afc5b | 121 | case CONTROL_ENDPOINT: |
Kojto | 39:d96aa62afc5b | 122 | ohciwrapp_reg_w(OHCI_REG_COMMANDSTATUS, OR_CMD_STATUS_CLF); |
Kojto | 39:d96aa62afc5b | 123 | wk_data = (ohciwrapp_reg_r(OHCI_REG_CONTROL) | OR_CONTROL_CLE); |
Kojto | 39:d96aa62afc5b | 124 | ohciwrapp_reg_w(OHCI_REG_CONTROL, wk_data); |
Kojto | 39:d96aa62afc5b | 125 | break; |
Kojto | 39:d96aa62afc5b | 126 | case ISOCHRONOUS_ENDPOINT: |
Kojto | 39:d96aa62afc5b | 127 | break; |
Kojto | 39:d96aa62afc5b | 128 | case BULK_ENDPOINT: |
Kojto | 39:d96aa62afc5b | 129 | ohciwrapp_reg_w(OHCI_REG_COMMANDSTATUS, OR_CMD_STATUS_BLF); |
Kojto | 39:d96aa62afc5b | 130 | wk_data = (ohciwrapp_reg_r(OHCI_REG_CONTROL) | OR_CONTROL_BLE); |
Kojto | 39:d96aa62afc5b | 131 | ohciwrapp_reg_w(OHCI_REG_CONTROL, wk_data); |
Kojto | 39:d96aa62afc5b | 132 | break; |
Kojto | 39:d96aa62afc5b | 133 | case INTERRUPT_ENDPOINT: |
Kojto | 39:d96aa62afc5b | 134 | wk_data = (ohciwrapp_reg_r(OHCI_REG_CONTROL) | OR_CONTROL_PLE); |
Kojto | 39:d96aa62afc5b | 135 | ohciwrapp_reg_w(OHCI_REG_CONTROL, wk_data); |
Kojto | 39:d96aa62afc5b | 136 | break; |
Kojto | 39:d96aa62afc5b | 137 | } |
Kojto | 39:d96aa62afc5b | 138 | } |
Kojto | 39:d96aa62afc5b | 139 | |
Kojto | 39:d96aa62afc5b | 140 | |
Kojto | 39:d96aa62afc5b | 141 | bool USBHALHost::disableList(ENDPOINT_TYPE type) { |
Kojto | 39:d96aa62afc5b | 142 | uint32_t wk_data; |
Kojto | 39:d96aa62afc5b | 143 | |
Kojto | 39:d96aa62afc5b | 144 | switch(type) { |
Kojto | 39:d96aa62afc5b | 145 | case CONTROL_ENDPOINT: |
Kojto | 39:d96aa62afc5b | 146 | wk_data = ohciwrapp_reg_r(OHCI_REG_CONTROL); |
Kojto | 39:d96aa62afc5b | 147 | if(wk_data & OR_CONTROL_CLE) { |
Kojto | 39:d96aa62afc5b | 148 | wk_data &= ~OR_CONTROL_CLE; |
Kojto | 39:d96aa62afc5b | 149 | ohciwrapp_reg_w(OHCI_REG_CONTROL, wk_data); |
Kojto | 39:d96aa62afc5b | 150 | return true; |
Kojto | 39:d96aa62afc5b | 151 | } |
Kojto | 39:d96aa62afc5b | 152 | return false; |
Kojto | 39:d96aa62afc5b | 153 | case ISOCHRONOUS_ENDPOINT: |
Kojto | 39:d96aa62afc5b | 154 | return false; |
Kojto | 39:d96aa62afc5b | 155 | case BULK_ENDPOINT: |
Kojto | 39:d96aa62afc5b | 156 | wk_data = ohciwrapp_reg_r(OHCI_REG_CONTROL); |
Kojto | 39:d96aa62afc5b | 157 | if(wk_data & OR_CONTROL_BLE) { |
Kojto | 39:d96aa62afc5b | 158 | wk_data &= ~OR_CONTROL_BLE; |
Kojto | 39:d96aa62afc5b | 159 | ohciwrapp_reg_w(OHCI_REG_CONTROL, wk_data); |
Kojto | 39:d96aa62afc5b | 160 | return true; |
Kojto | 39:d96aa62afc5b | 161 | } |
Kojto | 39:d96aa62afc5b | 162 | return false; |
Kojto | 39:d96aa62afc5b | 163 | case INTERRUPT_ENDPOINT: |
Kojto | 39:d96aa62afc5b | 164 | wk_data = ohciwrapp_reg_r(OHCI_REG_CONTROL); |
Kojto | 39:d96aa62afc5b | 165 | if(wk_data & OR_CONTROL_PLE) { |
Kojto | 39:d96aa62afc5b | 166 | wk_data &= ~OR_CONTROL_PLE; |
Kojto | 39:d96aa62afc5b | 167 | ohciwrapp_reg_w(OHCI_REG_CONTROL, wk_data); |
Kojto | 39:d96aa62afc5b | 168 | return true; |
Kojto | 39:d96aa62afc5b | 169 | } |
Kojto | 39:d96aa62afc5b | 170 | return false; |
Kojto | 39:d96aa62afc5b | 171 | } |
Kojto | 39:d96aa62afc5b | 172 | return false; |
Kojto | 39:d96aa62afc5b | 173 | } |
Kojto | 39:d96aa62afc5b | 174 | |
Kojto | 39:d96aa62afc5b | 175 | |
Kojto | 39:d96aa62afc5b | 176 | void USBHALHost::memInit() { |
Kojto | 39:d96aa62afc5b | 177 | volatile uint8_t *p_wk_buf = (uint8_t *)(((uint32_t)usb_buf + ALIGNE_MSK) & ~ALIGNE_MSK); |
Kojto | 39:d96aa62afc5b | 178 | |
Kojto | 39:d96aa62afc5b | 179 | usb_hcca = (volatile HCCA *)p_wk_buf; |
Kojto | 39:d96aa62afc5b | 180 | usb_edBuf = (volatile uint8_t *)(p_wk_buf + HCCA_SIZE); |
Kojto | 39:d96aa62afc5b | 181 | usb_tdBuf = (volatile uint8_t *)(p_wk_buf + HCCA_SIZE + (MAX_ENDPOINT*ED_SIZE)); |
Kojto | 39:d96aa62afc5b | 182 | } |
Kojto | 39:d96aa62afc5b | 183 | |
Kojto | 39:d96aa62afc5b | 184 | volatile uint8_t * USBHALHost::getED() { |
Kojto | 39:d96aa62afc5b | 185 | for (int i = 0; i < MAX_ENDPOINT; i++) { |
Kojto | 39:d96aa62afc5b | 186 | if ( !edBufAlloc[i] ) { |
Kojto | 39:d96aa62afc5b | 187 | edBufAlloc[i] = true; |
Kojto | 39:d96aa62afc5b | 188 | return (volatile uint8_t *)(usb_edBuf + i*ED_SIZE); |
Kojto | 39:d96aa62afc5b | 189 | } |
Kojto | 39:d96aa62afc5b | 190 | } |
Kojto | 39:d96aa62afc5b | 191 | perror("Could not allocate ED\r\n"); |
Kojto | 39:d96aa62afc5b | 192 | return NULL; //Could not alloc ED |
Kojto | 39:d96aa62afc5b | 193 | } |
Kojto | 39:d96aa62afc5b | 194 | |
Kojto | 39:d96aa62afc5b | 195 | volatile uint8_t * USBHALHost::getTD() { |
Kojto | 39:d96aa62afc5b | 196 | int i; |
Kojto | 39:d96aa62afc5b | 197 | for (i = 0; i < MAX_TD; i++) { |
Kojto | 39:d96aa62afc5b | 198 | if ( !tdBufAlloc[i] ) { |
Kojto | 39:d96aa62afc5b | 199 | tdBufAlloc[i] = true; |
Kojto | 39:d96aa62afc5b | 200 | return (volatile uint8_t *)(usb_tdBuf + i*TD_SIZE); |
Kojto | 39:d96aa62afc5b | 201 | } |
Kojto | 39:d96aa62afc5b | 202 | } |
Kojto | 39:d96aa62afc5b | 203 | perror("Could not allocate TD\r\n"); |
Kojto | 39:d96aa62afc5b | 204 | return NULL; //Could not alloc TD |
Kojto | 39:d96aa62afc5b | 205 | } |
Kojto | 39:d96aa62afc5b | 206 | |
Kojto | 39:d96aa62afc5b | 207 | |
Kojto | 39:d96aa62afc5b | 208 | void USBHALHost::freeED(volatile uint8_t * ed) { |
Kojto | 39:d96aa62afc5b | 209 | int i; |
Kojto | 39:d96aa62afc5b | 210 | i = (ed - usb_edBuf) / ED_SIZE; |
Kojto | 39:d96aa62afc5b | 211 | edBufAlloc[i] = false; |
Kojto | 39:d96aa62afc5b | 212 | } |
Kojto | 39:d96aa62afc5b | 213 | |
Kojto | 39:d96aa62afc5b | 214 | void USBHALHost::freeTD(volatile uint8_t * td) { |
Kojto | 39:d96aa62afc5b | 215 | int i; |
Kojto | 39:d96aa62afc5b | 216 | i = (td - usb_tdBuf) / TD_SIZE; |
Kojto | 39:d96aa62afc5b | 217 | tdBufAlloc[i] = false; |
Kojto | 39:d96aa62afc5b | 218 | } |
Kojto | 39:d96aa62afc5b | 219 | |
Kojto | 39:d96aa62afc5b | 220 | |
Kojto | 39:d96aa62afc5b | 221 | void USBHALHost::resetRootHub() { |
Kojto | 39:d96aa62afc5b | 222 | // Initiate port reset |
Kojto | 39:d96aa62afc5b | 223 | ohciwrapp_reg_w(OHCI_REG_RHPORTSTATUS1, OR_RH_PORT_PRS); |
Kojto | 39:d96aa62afc5b | 224 | |
Kojto | 39:d96aa62afc5b | 225 | while (ohciwrapp_reg_r(OHCI_REG_RHPORTSTATUS1) & OR_RH_PORT_PRS); |
Kojto | 39:d96aa62afc5b | 226 | |
Kojto | 39:d96aa62afc5b | 227 | // ...and clear port reset signal |
Kojto | 39:d96aa62afc5b | 228 | ohciwrapp_reg_w(OHCI_REG_RHPORTSTATUS1, OR_RH_PORT_PRSC); |
Kojto | 39:d96aa62afc5b | 229 | } |
Kojto | 39:d96aa62afc5b | 230 | |
Kojto | 39:d96aa62afc5b | 231 | |
Kojto | 39:d96aa62afc5b | 232 | void USBHALHost::_usbisr(void) { |
Kojto | 39:d96aa62afc5b | 233 | if (instHost) { |
Kojto | 39:d96aa62afc5b | 234 | instHost->UsbIrqhandler(); |
Kojto | 39:d96aa62afc5b | 235 | } |
Kojto | 39:d96aa62afc5b | 236 | } |
Kojto | 39:d96aa62afc5b | 237 | |
Kojto | 39:d96aa62afc5b | 238 | void USBHALHost::UsbIrqhandler() { |
Kojto | 39:d96aa62afc5b | 239 | uint32_t int_status = ohciwrapp_reg_r(OHCI_REG_INTERRUPTSTATUS) & ohciwrapp_reg_r(OHCI_REG_INTERRUPTENABLE); |
Kojto | 39:d96aa62afc5b | 240 | uint32_t data; |
Kojto | 39:d96aa62afc5b | 241 | |
Kojto | 39:d96aa62afc5b | 242 | if (int_status != 0) { //Is there something to actually process? |
Kojto | 39:d96aa62afc5b | 243 | // Root hub status change interrupt |
Kojto | 39:d96aa62afc5b | 244 | if (int_status & OR_INTR_STATUS_RHSC) { |
Kojto | 39:d96aa62afc5b | 245 | if (ohciwrapp_reg_r(OHCI_REG_RHPORTSTATUS1) & OR_RH_PORT_CSC) { |
Kojto | 39:d96aa62afc5b | 246 | if (ohciwrapp_reg_r(OHCI_REG_RHSTATUS) & OR_RH_STATUS_DRWE) { |
Kojto | 39:d96aa62afc5b | 247 | // When DRWE is on, Connect Status Change |
Kojto | 39:d96aa62afc5b | 248 | // means a remote wakeup event. |
Kojto | 39:d96aa62afc5b | 249 | } else { |
Kojto | 39:d96aa62afc5b | 250 | |
Kojto | 39:d96aa62afc5b | 251 | //Root device connected |
Kojto | 39:d96aa62afc5b | 252 | if (ohciwrapp_reg_r(OHCI_REG_RHPORTSTATUS1) & OR_RH_PORT_CCS) { |
Kojto | 39:d96aa62afc5b | 253 | |
Kojto | 39:d96aa62afc5b | 254 | // wait 150ms to avoid bounce |
Kojto | 39:d96aa62afc5b | 255 | wait_ms(150); |
Kojto | 39:d96aa62afc5b | 256 | |
Kojto | 39:d96aa62afc5b | 257 | //Hub 0 (root hub), Port 1 (count starts at 1), Low or High speed |
Kojto | 39:d96aa62afc5b | 258 | data = ohciwrapp_reg_r(OHCI_REG_RHPORTSTATUS1) & OR_RH_PORT_LSDA; |
Kojto | 39:d96aa62afc5b | 259 | deviceConnected(0, 1, data); |
Kojto | 39:d96aa62afc5b | 260 | } |
Kojto | 39:d96aa62afc5b | 261 | |
Kojto | 39:d96aa62afc5b | 262 | //Root device disconnected |
Kojto | 39:d96aa62afc5b | 263 | else { |
Kojto | 39:d96aa62afc5b | 264 | deviceDisconnected(0, 1, NULL, usb_hcca->DoneHead & 0xFFFFFFFE); |
Kojto | 39:d96aa62afc5b | 265 | } |
Kojto | 39:d96aa62afc5b | 266 | } |
Kojto | 39:d96aa62afc5b | 267 | ohciwrapp_reg_w(OHCI_REG_RHPORTSTATUS1, OR_RH_PORT_CSC); |
Kojto | 39:d96aa62afc5b | 268 | } |
Kojto | 39:d96aa62afc5b | 269 | if (ohciwrapp_reg_r(OHCI_REG_RHPORTSTATUS1) & OR_RH_PORT_PRSC) { |
Kojto | 39:d96aa62afc5b | 270 | ohciwrapp_reg_w(OHCI_REG_RHPORTSTATUS1, OR_RH_PORT_PRSC); |
Kojto | 39:d96aa62afc5b | 271 | } |
Kojto | 39:d96aa62afc5b | 272 | ohciwrapp_reg_w(OHCI_REG_INTERRUPTSTATUS, OR_INTR_STATUS_RHSC); |
Kojto | 39:d96aa62afc5b | 273 | } |
Kojto | 39:d96aa62afc5b | 274 | |
Kojto | 39:d96aa62afc5b | 275 | // Writeback Done Head interrupt |
Kojto | 39:d96aa62afc5b | 276 | if (int_status & OR_INTR_STATUS_WDH) { |
Kojto | 39:d96aa62afc5b | 277 | transferCompleted(usb_hcca->DoneHead & 0xFFFFFFFE); |
Kojto | 39:d96aa62afc5b | 278 | ohciwrapp_reg_w(OHCI_REG_INTERRUPTSTATUS, OR_INTR_STATUS_WDH); |
Kojto | 39:d96aa62afc5b | 279 | } |
Kojto | 39:d96aa62afc5b | 280 | } |
Kojto | 39:d96aa62afc5b | 281 | } |
Kojto | 39:d96aa62afc5b | 282 | #endif |