Support Isochronous transfer additionally

Dependents:   USBHostC270_example_GR-PEACH USBHostDac_example USBHostDac_Audio_in_out

Fork of USBHost_custom by Renesas

Committer:
mbed_official
Date:
Fri Apr 29 01:16:38 2016 +0100
Revision:
35:f72ccc6892ee
Synchronized with git revision fe9720f24b1adc71ab6962506ec51290f6afd270

Full URL: https://github.com/mbedmicro/mbed/commit/fe9720f24b1adc71ab6962506ec51290f6afd270/

[Renesas RZ/A1H] Enable asynchronous communications

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 35:f72ccc6892ee 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
mbed_official 35:f72ccc6892ee 2 *
mbed_official 35:f72ccc6892ee 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
mbed_official 35:f72ccc6892ee 4 * and associated documentation files (the "Software"), to deal in the Software without
mbed_official 35:f72ccc6892ee 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
mbed_official 35:f72ccc6892ee 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
mbed_official 35:f72ccc6892ee 7 * Software is furnished to do so, subject to the following conditions:
mbed_official 35:f72ccc6892ee 8 *
mbed_official 35:f72ccc6892ee 9 * The above copyright notice and this permission notice shall be included in all copies or
mbed_official 35:f72ccc6892ee 10 * substantial portions of the Software.
mbed_official 35:f72ccc6892ee 11 *
mbed_official 35:f72ccc6892ee 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
mbed_official 35:f72ccc6892ee 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
mbed_official 35:f72ccc6892ee 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
mbed_official 35:f72ccc6892ee 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbed_official 35:f72ccc6892ee 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
mbed_official 35:f72ccc6892ee 17 */
mbed_official 35:f72ccc6892ee 18
mbed_official 35:f72ccc6892ee 19 #include <string.h>
mbed_official 35:f72ccc6892ee 20 #include "cmsis.h"
mbed_official 35:f72ccc6892ee 21 #include "cmsis_os.h"
mbed_official 35:f72ccc6892ee 22 #include "ohci_wrapp_RZ_A1.h"
mbed_official 35:f72ccc6892ee 23 #include "ohci_wrapp_RZ_A1_local.h"
mbed_official 35:f72ccc6892ee 24 #include "rza_io_regrw.h"
mbed_official 35:f72ccc6892ee 25 #include "usb_host_setting.h"
mbed_official 35:f72ccc6892ee 26
mbed_official 35:f72ccc6892ee 27 /* ------------------ HcControl Register --------------------- */
mbed_official 35:f72ccc6892ee 28 #define OR_CONTROL_PLE (0x00000004)
mbed_official 35:f72ccc6892ee 29 #define OR_CONTROL_IE (0x00000008)
mbed_official 35:f72ccc6892ee 30 #define OR_CONTROL_CLE (0x00000010)
mbed_official 35:f72ccc6892ee 31 #define OR_CONTROL_BLE (0x00000020)
mbed_official 35:f72ccc6892ee 32 /* ----------------- HcCommandStatus Register ----------------- */
mbed_official 35:f72ccc6892ee 33 #define OR_CMD_STATUS_HCR (0x00000001)
mbed_official 35:f72ccc6892ee 34 #define OR_CMD_STATUS_CLF (0x00000002)
mbed_official 35:f72ccc6892ee 35 #define OR_CMD_STATUS_BLF (0x00000004)
mbed_official 35:f72ccc6892ee 36 #define OR_CMD_STATUS_OCR (0x00000008)
mbed_official 35:f72ccc6892ee 37 /* --------------- HcInterruptStatus Register ----------------- */
mbed_official 35:f72ccc6892ee 38 #define OR_INTR_STATUS_WDH (0x00000002)
mbed_official 35:f72ccc6892ee 39 #define OR_INTR_STATUS_RHSC (0x00000040)
mbed_official 35:f72ccc6892ee 40 /* --------------- HcInterruptEnable Register ----------------- */
mbed_official 35:f72ccc6892ee 41 #define OR_INTR_ENABLE_WDH (0x00000002)
mbed_official 35:f72ccc6892ee 42 #define OR_INTR_ENABLE_RHSC (0x00000040)
mbed_official 35:f72ccc6892ee 43 /* -------------- HcRhPortStatus[1:NDP] Register -------------- */
mbed_official 35:f72ccc6892ee 44 #define OR_RH_PORT_CSC (0x00010000)
mbed_official 35:f72ccc6892ee 45 #define OR_RH_PORT_LSDA (0x00000200)
mbed_official 35:f72ccc6892ee 46 #define OR_RH_PORT_PRS (0x00000010)
mbed_official 35:f72ccc6892ee 47 #define OR_RH_PORT_POCI (0x00000008)
mbed_official 35:f72ccc6892ee 48 #define OR_RH_PORT_CCS (0x00000001)
mbed_official 35:f72ccc6892ee 49
mbed_official 35:f72ccc6892ee 50 #define ED_FORMAT (0x00008000) /* Format */
mbed_official 35:f72ccc6892ee 51 #define ED_SKIP (0x00004000) /* Skip this ep in queue */
mbed_official 35:f72ccc6892ee 52 #define ED_TOGLE_CARRY (0x00000002)
mbed_official 35:f72ccc6892ee 53 #define ED_HALTED (0x00000001)
mbed_official 35:f72ccc6892ee 54
mbed_official 35:f72ccc6892ee 55 #define TD_SETUP (0x00000000) /* Direction of Setup Packet */
mbed_official 35:f72ccc6892ee 56 #define TD_OUT (0x00080000) /* Direction Out */
mbed_official 35:f72ccc6892ee 57 #define TD_TOGGLE_0 (0x02000000) /* Toggle 0 */
mbed_official 35:f72ccc6892ee 58 #define TD_TOGGLE_1 (0x03000000) /* Toggle 1 */
mbed_official 35:f72ccc6892ee 59
mbed_official 35:f72ccc6892ee 60 /* -------------- USB Standard Requests -------------- */
mbed_official 35:f72ccc6892ee 61 #define GET_STATUS (0x00)
mbed_official 35:f72ccc6892ee 62 #define SET_FEATURE (0x03)
mbed_official 35:f72ccc6892ee 63 #define SET_ADDRESS (0x05)
mbed_official 35:f72ccc6892ee 64
mbed_official 35:f72ccc6892ee 65 #define TD_CTL_MSK_DP (0x00180000)
mbed_official 35:f72ccc6892ee 66 #define TD_CTL_MSK_T (0x03000000)
mbed_official 35:f72ccc6892ee 67 #define TD_CTL_MSK_CC (0xF0000000)
mbed_official 35:f72ccc6892ee 68 #define TD_CTL_MSK_EC (0x0C000000)
mbed_official 35:f72ccc6892ee 69 #define TD_CTL_SHFT_CC (28)
mbed_official 35:f72ccc6892ee 70 #define TD_CTL_SHFT_EC (26)
mbed_official 35:f72ccc6892ee 71 #define TD_CTL_SHFT_T (24)
mbed_official 35:f72ccc6892ee 72 #define ED_SHFT_TOGLE_CARRY (1)
mbed_official 35:f72ccc6892ee 73 #define SIG_GEN_LIST_REQ (1)
mbed_official 35:f72ccc6892ee 74 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 35:f72ccc6892ee 75 #define TD_PSW_MSK_CC (0xF000)
mbed_official 35:f72ccc6892ee 76 #define TD_PSW_SHFT_CC (12)
mbed_official 35:f72ccc6892ee 77 #define TD_CTL_MSK_FC (0x07000000)
mbed_official 35:f72ccc6892ee 78 #define TD_CTL_SHFT_FC (24)
mbed_official 35:f72ccc6892ee 79 #endif
mbed_official 35:f72ccc6892ee 80
mbed_official 35:f72ccc6892ee 81 #define CTL_TRANS_TIMEOUT (1000)
mbed_official 35:f72ccc6892ee 82 #define BLK_TRANS_TIMEOUT (5)
mbed_official 35:f72ccc6892ee 83 #define TOTAL_SEM_NUM (5 + (2 * INT_TRANS_MAX_NUM) + (2 * ISO_TRANS_MAX_NUM))
mbed_official 35:f72ccc6892ee 84
mbed_official 35:f72ccc6892ee 85 #define PORT_LOW_SPEED (0x00000200)
mbed_official 35:f72ccc6892ee 86 #define PORT_HIGH_SPEED (0x00000400)
mbed_official 35:f72ccc6892ee 87 #define PORT_NUM (16 + 1) /* num + root(1) */
mbed_official 35:f72ccc6892ee 88
mbed_official 35:f72ccc6892ee 89 typedef struct tag_hctd {
mbed_official 35:f72ccc6892ee 90 uint32_t control; /* Transfer descriptor control */
mbed_official 35:f72ccc6892ee 91 uint8_t *currBufPtr; /* Physical address of current buffer pointer */
mbed_official 35:f72ccc6892ee 92 struct tag_hctd *nextTD; /* Physical pointer to next Transfer Descriptor */
mbed_official 35:f72ccc6892ee 93 uint8_t *bufEnd; /* Physical address of end of buffer */
mbed_official 35:f72ccc6892ee 94 } hctd_t;
mbed_official 35:f72ccc6892ee 95
mbed_official 35:f72ccc6892ee 96 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 35:f72ccc6892ee 97 #define PSW_NUM (8)
mbed_official 35:f72ccc6892ee 98 typedef struct tag_hcisotd {
mbed_official 35:f72ccc6892ee 99 uint32_t control; /* Transfer descriptor control */
mbed_official 35:f72ccc6892ee 100 uint8_t *bufferPage0; /* Buffer Page 0 */
mbed_official 35:f72ccc6892ee 101 struct tag_hcisotd *nextTD; /* Physical pointer to next Transfer Descriptor */
mbed_official 35:f72ccc6892ee 102 uint8_t *bufEnd; /* Physical address of end of buffer */
mbed_official 35:f72ccc6892ee 103 uint16_t offsetPSW[PSW_NUM]; /* Offset/PSW */
mbed_official 35:f72ccc6892ee 104 } hcisotd_t;
mbed_official 35:f72ccc6892ee 105 #endif
mbed_official 35:f72ccc6892ee 106
mbed_official 35:f72ccc6892ee 107 typedef struct tag_hced {
mbed_official 35:f72ccc6892ee 108 uint32_t control; /* Endpoint descriptor control */
mbed_official 35:f72ccc6892ee 109 uint32_t tailTD; /* Physical address of tail in Transfer descriptor list */
mbed_official 35:f72ccc6892ee 110 uint32_t headTD; /* Physcial address of head in Transfer descriptor list */
mbed_official 35:f72ccc6892ee 111 struct tag_hced *nextED; /* Physical address of next Endpoint descriptor */
mbed_official 35:f72ccc6892ee 112 } hced_t;
mbed_official 35:f72ccc6892ee 113
mbed_official 35:f72ccc6892ee 114 typedef struct tag_hcca {
mbed_official 35:f72ccc6892ee 115 uint32_t IntTable[32]; /* Interrupt Table */
mbed_official 35:f72ccc6892ee 116 uint32_t FrameNumber; /* Frame Number */
mbed_official 35:f72ccc6892ee 117 uint32_t DoneHead; /* Done Head */
mbed_official 35:f72ccc6892ee 118 volatile uint8_t Reserved[116]; /* Reserved for future use */
mbed_official 35:f72ccc6892ee 119 volatile uint8_t Unknown[4]; /* Unused */
mbed_official 35:f72ccc6892ee 120 } hcca_t;
mbed_official 35:f72ccc6892ee 121
mbed_official 35:f72ccc6892ee 122 typedef struct tag_usb_ohci_reg {
mbed_official 35:f72ccc6892ee 123 volatile uint32_t HcRevision;
mbed_official 35:f72ccc6892ee 124 volatile uint32_t HcControl;
mbed_official 35:f72ccc6892ee 125 volatile uint32_t HcCommandStatus;
mbed_official 35:f72ccc6892ee 126 volatile uint32_t HcInterruptStatus;
mbed_official 35:f72ccc6892ee 127 volatile uint32_t HcInterruptEnable;
mbed_official 35:f72ccc6892ee 128 volatile uint32_t HcInterruptDisable;
mbed_official 35:f72ccc6892ee 129 volatile uint32_t HcHCCA;
mbed_official 35:f72ccc6892ee 130 volatile uint32_t HcPeriodCurrentED;
mbed_official 35:f72ccc6892ee 131 volatile uint32_t HcControlHeadED;
mbed_official 35:f72ccc6892ee 132 volatile uint32_t HcControlCurrentED;
mbed_official 35:f72ccc6892ee 133 volatile uint32_t HcBulkHeadED;
mbed_official 35:f72ccc6892ee 134 volatile uint32_t HcBulkCurrentED;
mbed_official 35:f72ccc6892ee 135 volatile uint32_t HcDoneHead;
mbed_official 35:f72ccc6892ee 136 volatile uint32_t HcFmInterval;
mbed_official 35:f72ccc6892ee 137 volatile uint32_t HcFmRemaining;
mbed_official 35:f72ccc6892ee 138 volatile uint32_t HcFmNumber;
mbed_official 35:f72ccc6892ee 139 volatile uint32_t HcPeriodicStart;
mbed_official 35:f72ccc6892ee 140 volatile uint32_t HcLSThreshold;
mbed_official 35:f72ccc6892ee 141 volatile uint32_t HcRhDescriptorA;
mbed_official 35:f72ccc6892ee 142 volatile uint32_t HcRhDescriptorB;
mbed_official 35:f72ccc6892ee 143 volatile uint32_t HcRhStatus;
mbed_official 35:f72ccc6892ee 144 volatile uint32_t HcRhPortStatus1;
mbed_official 35:f72ccc6892ee 145 } usb_ohci_reg_t;
mbed_official 35:f72ccc6892ee 146
mbed_official 35:f72ccc6892ee 147 typedef struct tag_genelal_ed {
mbed_official 35:f72ccc6892ee 148 osThreadId tskid;
mbed_official 35:f72ccc6892ee 149 osSemaphoreId semid_wait;
mbed_official 35:f72ccc6892ee 150 osSemaphoreId semid_list;
mbed_official 35:f72ccc6892ee 151 void *p_curr_td; /* pointer of hctd_t or hcisotd_t */
mbed_official 35:f72ccc6892ee 152 hced_t *p_curr_ed;
mbed_official 35:f72ccc6892ee 153 uint32_t pipe_no;
mbed_official 35:f72ccc6892ee 154 uint32_t trans_wait;
mbed_official 35:f72ccc6892ee 155 uint32_t cycle_time;
mbed_official 35:f72ccc6892ee 156 uint8_t *p_start_buf;
mbed_official 35:f72ccc6892ee 157 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 35:f72ccc6892ee 158 uint32_t psw_idx;
mbed_official 35:f72ccc6892ee 159 #endif
mbed_official 35:f72ccc6892ee 160 } genelal_ed_t;
mbed_official 35:f72ccc6892ee 161
mbed_official 35:f72ccc6892ee 162 typedef struct tag_tdinfo {
mbed_official 35:f72ccc6892ee 163 uint32_t count;
mbed_official 35:f72ccc6892ee 164 uint32_t direction;
mbed_official 35:f72ccc6892ee 165 uint32_t msp;
mbed_official 35:f72ccc6892ee 166 uint16_t devadr;
mbed_official 35:f72ccc6892ee 167 uint16_t speed; /* 1:Speed = Low */
mbed_official 35:f72ccc6892ee 168 uint8_t endpoint_no;
mbed_official 35:f72ccc6892ee 169 } tdinfo_t;
mbed_official 35:f72ccc6892ee 170
mbed_official 35:f72ccc6892ee 171 typedef struct tag_split_trans {
mbed_official 35:f72ccc6892ee 172 uint16_t root_devadr;
mbed_official 35:f72ccc6892ee 173 uint16_t get_port;
mbed_official 35:f72ccc6892ee 174 uint16_t port_speed;
mbed_official 35:f72ccc6892ee 175 uint16_t reset_port;
mbed_official 35:f72ccc6892ee 176 uint32_t seq_cnt;
mbed_official 35:f72ccc6892ee 177 uint32_t port_sts_bits[PORT_NUM];
mbed_official 35:f72ccc6892ee 178 } split_trans_t;
mbed_official 35:f72ccc6892ee 179
mbed_official 35:f72ccc6892ee 180 static void callback_task(void const * argument);
mbed_official 35:f72ccc6892ee 181 static void control_ed_task(void const * argument);
mbed_official 35:f72ccc6892ee 182 static void bulk_ed_task(void const * argument);
mbed_official 35:f72ccc6892ee 183 static void int_ed_task(void const * argument);
mbed_official 35:f72ccc6892ee 184 static int32_t int_trans_doing(hced_t *p_ed, uint32_t index);
mbed_official 35:f72ccc6892ee 185 static int32_t chk_genelal_ed(genelal_ed_t *p_g_ed);
mbed_official 35:f72ccc6892ee 186 static void chk_genelal_td_done(genelal_ed_t *p_g_ed);
mbed_official 35:f72ccc6892ee 187 static void chk_split_trans_setting(genelal_ed_t *p_g_ed);
mbed_official 35:f72ccc6892ee 188 static void set_split_trans_setting(void);
mbed_official 35:f72ccc6892ee 189 static void control_trans(genelal_ed_t *p_g_ed);
mbed_official 35:f72ccc6892ee 190 static void bulk_trans(genelal_ed_t *p_g_ed);
mbed_official 35:f72ccc6892ee 191 static void int_trans_setting(genelal_ed_t *p_g_ed, uint32_t index);
mbed_official 35:f72ccc6892ee 192 static uint32_t chk_cycle(hced_t *p_ed);
mbed_official 35:f72ccc6892ee 193 static void int_trans(genelal_ed_t *p_g_ed);
mbed_official 35:f72ccc6892ee 194 static void get_td_info(genelal_ed_t *p_g_ed, tdinfo_t *p_td_info);
mbed_official 35:f72ccc6892ee 195 static void set_togle(uint32_t pipe, hctd_t *p_td, hced_t *p_ed);
mbed_official 35:f72ccc6892ee 196 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 35:f72ccc6892ee 197 static void iso_ed_task(void const * argument);
mbed_official 35:f72ccc6892ee 198 static int32_t iso_trans_doing(hced_t *p_ed, uint32_t index);
mbed_official 35:f72ccc6892ee 199 static void chk_iso_td_done(genelal_ed_t *p_g_ed);
mbed_official 35:f72ccc6892ee 200 static int32_t chk_iso_ed(genelal_ed_t *p_g_ed);
mbed_official 35:f72ccc6892ee 201 static void iso_trans_setting(genelal_ed_t *p_g_ed, uint32_t index);
mbed_official 35:f72ccc6892ee 202 static void iso_trans(genelal_ed_t *p_g_ed);
mbed_official 35:f72ccc6892ee 203 #endif
mbed_official 35:f72ccc6892ee 204 static void connect_check(void);
mbed_official 35:f72ccc6892ee 205
mbed_official 35:f72ccc6892ee 206 extern USB_HOST_CFG_PIPETBL_t usb_host_blk_ep_tbl1[];
mbed_official 35:f72ccc6892ee 207 extern USB_HOST_CFG_PIPETBL_t usb_host_int_ep_tbl1[];
mbed_official 35:f72ccc6892ee 208 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 35:f72ccc6892ee 209 extern USB_HOST_CFG_PIPETBL_t usb_host_iso_ep_tbl1[];
mbed_official 35:f72ccc6892ee 210 #endif
mbed_official 35:f72ccc6892ee 211
mbed_official 35:f72ccc6892ee 212 static usb_ohci_reg_t usb_reg;
mbed_official 35:f72ccc6892ee 213 static usb_ohci_reg_t *p_usb_reg = &usb_reg;
mbed_official 35:f72ccc6892ee 214 static usbisr_fnc_t *p_usbisr_cb = NULL;
mbed_official 35:f72ccc6892ee 215 static osSemaphoreId semid_cb = NULL;
mbed_official 35:f72ccc6892ee 216 static uint32_t connect_change = 0xFFFFFFFF;
mbed_official 35:f72ccc6892ee 217 static uint32_t connect_status = 0;
mbed_official 35:f72ccc6892ee 218 static uint32_t init_end = 0;
mbed_official 35:f72ccc6892ee 219 static genelal_ed_t ctl_ed;
mbed_official 35:f72ccc6892ee 220 static genelal_ed_t blk_ed;
mbed_official 35:f72ccc6892ee 221 static genelal_ed_t int_ed[INT_TRANS_MAX_NUM];
mbed_official 35:f72ccc6892ee 222 static split_trans_t split_ctl;
mbed_official 35:f72ccc6892ee 223
mbed_official 35:f72ccc6892ee 224 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 35:f72ccc6892ee 225 static genelal_ed_t iso_ed[ISO_TRANS_MAX_NUM];
mbed_official 35:f72ccc6892ee 226 #endif
mbed_official 35:f72ccc6892ee 227
mbed_official 35:f72ccc6892ee 228 osSemaphoreDef(ohciwrapp_sem_01);
mbed_official 35:f72ccc6892ee 229 osSemaphoreDef(ohciwrapp_sem_02);
mbed_official 35:f72ccc6892ee 230 osSemaphoreDef(ohciwrapp_sem_03);
mbed_official 35:f72ccc6892ee 231 osSemaphoreDef(ohciwrapp_sem_04);
mbed_official 35:f72ccc6892ee 232 osSemaphoreDef(ohciwrapp_sem_05);
mbed_official 35:f72ccc6892ee 233 osSemaphoreDef(ohciwrapp_sem_06);
mbed_official 35:f72ccc6892ee 234 osSemaphoreDef(ohciwrapp_sem_07);
mbed_official 35:f72ccc6892ee 235 #if (INT_TRANS_MAX_NUM >= 2)
mbed_official 35:f72ccc6892ee 236 osSemaphoreDef(ohciwrapp_sem_08);
mbed_official 35:f72ccc6892ee 237 osSemaphoreDef(ohciwrapp_sem_09);
mbed_official 35:f72ccc6892ee 238 #endif
mbed_official 35:f72ccc6892ee 239 #if (INT_TRANS_MAX_NUM >= 3)
mbed_official 35:f72ccc6892ee 240 osSemaphoreDef(ohciwrapp_sem_10);
mbed_official 35:f72ccc6892ee 241 osSemaphoreDef(ohciwrapp_sem_11);
mbed_official 35:f72ccc6892ee 242 #endif
mbed_official 35:f72ccc6892ee 243 #if (INT_TRANS_MAX_NUM >= 4)
mbed_official 35:f72ccc6892ee 244 osSemaphoreDef(ohciwrapp_sem_12);
mbed_official 35:f72ccc6892ee 245 osSemaphoreDef(ohciwrapp_sem_13);
mbed_official 35:f72ccc6892ee 246 #endif
mbed_official 35:f72ccc6892ee 247 #if (ISO_TRANS_MAX_NUM >= 1)
mbed_official 35:f72ccc6892ee 248 osSemaphoreDef(ohciwrapp_sem_14);
mbed_official 35:f72ccc6892ee 249 osSemaphoreDef(ohciwrapp_sem_15);
mbed_official 35:f72ccc6892ee 250 #endif
mbed_official 35:f72ccc6892ee 251 #if (ISO_TRANS_MAX_NUM >= 2)
mbed_official 35:f72ccc6892ee 252 osSemaphoreDef(ohciwrapp_sem_16);
mbed_official 35:f72ccc6892ee 253 osSemaphoreDef(ohciwrapp_sem_17);
mbed_official 35:f72ccc6892ee 254 #endif
mbed_official 35:f72ccc6892ee 255
mbed_official 35:f72ccc6892ee 256 osThreadDef(callback_task, osPriorityHigh, 512);
mbed_official 35:f72ccc6892ee 257 osThreadDef(control_ed_task, osPriorityNormal, 512);
mbed_official 35:f72ccc6892ee 258 osThreadDef(bulk_ed_task, osPriorityNormal, 512);
mbed_official 35:f72ccc6892ee 259 static void int_ed_task_1(void const * argument) {
mbed_official 35:f72ccc6892ee 260 int_ed_task(argument);
mbed_official 35:f72ccc6892ee 261 }
mbed_official 35:f72ccc6892ee 262 osThreadDef(int_ed_task_1, osPriorityNormal, 512);
mbed_official 35:f72ccc6892ee 263 #if (INT_TRANS_MAX_NUM >= 2)
mbed_official 35:f72ccc6892ee 264 static void int_ed_task_2(void const * argument) {
mbed_official 35:f72ccc6892ee 265 int_ed_task(argument);
mbed_official 35:f72ccc6892ee 266 }
mbed_official 35:f72ccc6892ee 267 osThreadDef(int_ed_task_2, osPriorityNormal, 512);
mbed_official 35:f72ccc6892ee 268 #endif
mbed_official 35:f72ccc6892ee 269 #if (INT_TRANS_MAX_NUM >= 3)
mbed_official 35:f72ccc6892ee 270 static void int_ed_task_3(void const * argument) {
mbed_official 35:f72ccc6892ee 271 int_ed_task(argument);
mbed_official 35:f72ccc6892ee 272 }
mbed_official 35:f72ccc6892ee 273 osThreadDef(int_ed_task_3, osPriorityNormal, 512);
mbed_official 35:f72ccc6892ee 274 #endif
mbed_official 35:f72ccc6892ee 275 #if (INT_TRANS_MAX_NUM >= 4)
mbed_official 35:f72ccc6892ee 276 static void int_ed_task_4(void const * argument) {
mbed_official 35:f72ccc6892ee 277 int_ed_task(argument);
mbed_official 35:f72ccc6892ee 278 }
mbed_official 35:f72ccc6892ee 279 osThreadDef(int_ed_task_4, osPriorityNormal, 512);
mbed_official 35:f72ccc6892ee 280 #endif
mbed_official 35:f72ccc6892ee 281
mbed_official 35:f72ccc6892ee 282 #if (ISO_TRANS_MAX_NUM >= 1)
mbed_official 35:f72ccc6892ee 283 static void iso_ed_task_1(void const * argument) {
mbed_official 35:f72ccc6892ee 284 iso_ed_task(argument);
mbed_official 35:f72ccc6892ee 285 }
mbed_official 35:f72ccc6892ee 286 osThreadDef(iso_ed_task_1, osPriorityAboveNormal, 512);
mbed_official 35:f72ccc6892ee 287 #endif
mbed_official 35:f72ccc6892ee 288 #if (ISO_TRANS_MAX_NUM >= 2)
mbed_official 35:f72ccc6892ee 289 static void iso_ed_task_2(void const * argument) {
mbed_official 35:f72ccc6892ee 290 iso_ed_task(argument);
mbed_official 35:f72ccc6892ee 291 }
mbed_official 35:f72ccc6892ee 292 osThreadDef(iso_ed_task_2, osPriorityAboveNormal, 512);
mbed_official 35:f72ccc6892ee 293 #endif
mbed_official 35:f72ccc6892ee 294
mbed_official 35:f72ccc6892ee 295 void ohciwrapp_init(usbisr_fnc_t *p_usbisr_fnc) {
mbed_official 35:f72ccc6892ee 296 static const osSemaphoreDef_t * const sem_def_tbl[TOTAL_SEM_NUM] = {
mbed_official 35:f72ccc6892ee 297 osSemaphore(ohciwrapp_sem_01), osSemaphore(ohciwrapp_sem_02), osSemaphore(ohciwrapp_sem_03)
mbed_official 35:f72ccc6892ee 298 , osSemaphore(ohciwrapp_sem_04), osSemaphore(ohciwrapp_sem_05), osSemaphore(ohciwrapp_sem_06)
mbed_official 35:f72ccc6892ee 299 , osSemaphore(ohciwrapp_sem_07)
mbed_official 35:f72ccc6892ee 300 #if (INT_TRANS_MAX_NUM >= 2)
mbed_official 35:f72ccc6892ee 301 , osSemaphore(ohciwrapp_sem_08), osSemaphore(ohciwrapp_sem_09)
mbed_official 35:f72ccc6892ee 302 #endif
mbed_official 35:f72ccc6892ee 303 #if (INT_TRANS_MAX_NUM >= 3)
mbed_official 35:f72ccc6892ee 304 , osSemaphore(ohciwrapp_sem_10), osSemaphore(ohciwrapp_sem_11)
mbed_official 35:f72ccc6892ee 305 #endif
mbed_official 35:f72ccc6892ee 306 #if (INT_TRANS_MAX_NUM >= 4)
mbed_official 35:f72ccc6892ee 307 , osSemaphore(ohciwrapp_sem_12), osSemaphore(ohciwrapp_sem_13)
mbed_official 35:f72ccc6892ee 308 #endif
mbed_official 35:f72ccc6892ee 309 #if (ISO_TRANS_MAX_NUM >= 1)
mbed_official 35:f72ccc6892ee 310 , osSemaphore(ohciwrapp_sem_14), osSemaphore(ohciwrapp_sem_15)
mbed_official 35:f72ccc6892ee 311 #endif
mbed_official 35:f72ccc6892ee 312 #if (ISO_TRANS_MAX_NUM >= 2)
mbed_official 35:f72ccc6892ee 313 , osSemaphore(ohciwrapp_sem_16), osSemaphore(ohciwrapp_sem_17)
mbed_official 35:f72ccc6892ee 314 #endif
mbed_official 35:f72ccc6892ee 315 };
mbed_official 35:f72ccc6892ee 316 static const osThreadDef_t * const int_tsk_def_tbl[INT_TRANS_MAX_NUM] = {
mbed_official 35:f72ccc6892ee 317 osThread(int_ed_task_1)
mbed_official 35:f72ccc6892ee 318 #if (INT_TRANS_MAX_NUM >= 2)
mbed_official 35:f72ccc6892ee 319 , osThread(int_ed_task_2)
mbed_official 35:f72ccc6892ee 320 #endif
mbed_official 35:f72ccc6892ee 321 #if (INT_TRANS_MAX_NUM >= 3)
mbed_official 35:f72ccc6892ee 322 , osThread(int_ed_task_3)
mbed_official 35:f72ccc6892ee 323 #endif
mbed_official 35:f72ccc6892ee 324 #if (INT_TRANS_MAX_NUM >= 4)
mbed_official 35:f72ccc6892ee 325 , osThread(int_ed_task_4)
mbed_official 35:f72ccc6892ee 326 #endif
mbed_official 35:f72ccc6892ee 327 };
mbed_official 35:f72ccc6892ee 328 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 35:f72ccc6892ee 329 static const osThreadDef_t * const iso_tsk_def_tbl[ISO_TRANS_MAX_NUM] = {
mbed_official 35:f72ccc6892ee 330 osThread(iso_ed_task_1)
mbed_official 35:f72ccc6892ee 331 #if (ISO_TRANS_MAX_NUM >= 2)
mbed_official 35:f72ccc6892ee 332 , osThread(iso_ed_task_2)
mbed_official 35:f72ccc6892ee 333 #endif
mbed_official 35:f72ccc6892ee 334 };
mbed_official 35:f72ccc6892ee 335 #endif
mbed_official 35:f72ccc6892ee 336
mbed_official 35:f72ccc6892ee 337 uint32_t cnt;
mbed_official 35:f72ccc6892ee 338 uint32_t index = 0;
mbed_official 35:f72ccc6892ee 339
mbed_official 35:f72ccc6892ee 340 /* Disables interrupt for usb */
mbed_official 35:f72ccc6892ee 341 GIC_DisableIRQ(USBIXUSBIX);
mbed_official 35:f72ccc6892ee 342
mbed_official 35:f72ccc6892ee 343 #if (USB_HOST_CH == 0)
mbed_official 35:f72ccc6892ee 344 /* P4_1(USB0_EN) */
mbed_official 35:f72ccc6892ee 345 GPIOP4 &= ~0x0002; /* Outputs low level */
mbed_official 35:f72ccc6892ee 346 GPIOPMC4 &= ~0x0002; /* Port mode */
mbed_official 35:f72ccc6892ee 347 GPIOPM4 &= ~0x0002; /* Output mode */
mbed_official 35:f72ccc6892ee 348 #endif
mbed_official 35:f72ccc6892ee 349
mbed_official 35:f72ccc6892ee 350 p_usbisr_cb = p_usbisr_fnc;
mbed_official 35:f72ccc6892ee 351 #if (USB_HOST_HISPEED == 0)
mbed_official 35:f72ccc6892ee 352 g_usbx_host_SupportUsbDeviceSpeed = USB_HOST_FULL_SPEED;
mbed_official 35:f72ccc6892ee 353 #else
mbed_official 35:f72ccc6892ee 354 g_usbx_host_SupportUsbDeviceSpeed = USB_HOST_HIGH_SPEED;
mbed_official 35:f72ccc6892ee 355 #endif
mbed_official 35:f72ccc6892ee 356 p_usb_reg->HcRevision = 0x00000010;
mbed_official 35:f72ccc6892ee 357 p_usb_reg->HcControl = 0x00000000;
mbed_official 35:f72ccc6892ee 358 p_usb_reg->HcCommandStatus = 0x00000000;
mbed_official 35:f72ccc6892ee 359 p_usb_reg->HcInterruptStatus = 0x00000000;
mbed_official 35:f72ccc6892ee 360 p_usb_reg->HcInterruptEnable = 0x00000000;
mbed_official 35:f72ccc6892ee 361 p_usb_reg->HcInterruptDisable = 0x00000000;
mbed_official 35:f72ccc6892ee 362 p_usb_reg->HcHCCA = 0x00000000;
mbed_official 35:f72ccc6892ee 363 p_usb_reg->HcPeriodCurrentED = 0x00000000;
mbed_official 35:f72ccc6892ee 364 p_usb_reg->HcControlHeadED = 0x00000000;
mbed_official 35:f72ccc6892ee 365 p_usb_reg->HcControlCurrentED = 0x00000000;
mbed_official 35:f72ccc6892ee 366 p_usb_reg->HcBulkHeadED = 0x00000000;
mbed_official 35:f72ccc6892ee 367 p_usb_reg->HcBulkCurrentED = 0x00000000;
mbed_official 35:f72ccc6892ee 368 p_usb_reg->HcDoneHead = 0x00000000;
mbed_official 35:f72ccc6892ee 369 p_usb_reg->HcFmInterval = 0x00002EDF;
mbed_official 35:f72ccc6892ee 370 p_usb_reg->HcFmRemaining = 0x00002EDF;
mbed_official 35:f72ccc6892ee 371 p_usb_reg->HcFmNumber = 0x00000000;
mbed_official 35:f72ccc6892ee 372 p_usb_reg->HcPeriodicStart = 0x00000000;
mbed_official 35:f72ccc6892ee 373 p_usb_reg->HcLSThreshold = 0x00000628;
mbed_official 35:f72ccc6892ee 374 p_usb_reg->HcRhDescriptorA = 0xFF000901;
mbed_official 35:f72ccc6892ee 375 p_usb_reg->HcRhDescriptorB = 0x00020000;
mbed_official 35:f72ccc6892ee 376 p_usb_reg->HcRhStatus = 0x00000000;
mbed_official 35:f72ccc6892ee 377 p_usb_reg->HcRhPortStatus1 = 0x00000000;
mbed_official 35:f72ccc6892ee 378
mbed_official 35:f72ccc6892ee 379 #if (USB_HOST_CH == 0)
mbed_official 35:f72ccc6892ee 380 GPIOP4 |= 0x0002; /* P4_1 Outputs high level */
mbed_official 35:f72ccc6892ee 381 osDelay(5);
mbed_official 35:f72ccc6892ee 382 GPIOP4 &= ~0x0002; /* P4_1 Outputs low level */
mbed_official 35:f72ccc6892ee 383 osDelay(10);
mbed_official 35:f72ccc6892ee 384 #else
mbed_official 35:f72ccc6892ee 385 osDelay(15);
mbed_official 35:f72ccc6892ee 386 #endif
mbed_official 35:f72ccc6892ee 387
mbed_official 35:f72ccc6892ee 388 if (init_end == 0) {
mbed_official 35:f72ccc6892ee 389 (void)memset(&ctl_ed, 0, sizeof(ctl_ed));
mbed_official 35:f72ccc6892ee 390 (void)memset(&blk_ed, 0, sizeof(blk_ed));
mbed_official 35:f72ccc6892ee 391 (void)memset(&int_ed[0], 0, sizeof(int_ed));
mbed_official 35:f72ccc6892ee 392 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 35:f72ccc6892ee 393 (void)memset(&iso_ed[0], 0, sizeof(iso_ed));
mbed_official 35:f72ccc6892ee 394 #endif
mbed_official 35:f72ccc6892ee 395
mbed_official 35:f72ccc6892ee 396 /* callback */
mbed_official 35:f72ccc6892ee 397 semid_cb = osSemaphoreCreate(sem_def_tbl[index], 0);
mbed_official 35:f72ccc6892ee 398 index++;
mbed_official 35:f72ccc6892ee 399 (void)osThreadCreate(osThread(callback_task), 0);
mbed_official 35:f72ccc6892ee 400
mbed_official 35:f72ccc6892ee 401 /* control transfer */
mbed_official 35:f72ccc6892ee 402 ctl_ed.semid_wait = osSemaphoreCreate(sem_def_tbl[index], 0);
mbed_official 35:f72ccc6892ee 403 index++;
mbed_official 35:f72ccc6892ee 404 ctl_ed.semid_list = osSemaphoreCreate(sem_def_tbl[index], 0);
mbed_official 35:f72ccc6892ee 405 index++;
mbed_official 35:f72ccc6892ee 406 ctl_ed.tskid = osThreadCreate(osThread(control_ed_task), 0);
mbed_official 35:f72ccc6892ee 407
mbed_official 35:f72ccc6892ee 408 /* bulk transfer */
mbed_official 35:f72ccc6892ee 409 blk_ed.semid_wait = osSemaphoreCreate(sem_def_tbl[index], 0);
mbed_official 35:f72ccc6892ee 410 index++;
mbed_official 35:f72ccc6892ee 411 blk_ed.semid_list = osSemaphoreCreate(sem_def_tbl[index], 0);
mbed_official 35:f72ccc6892ee 412 index++;
mbed_official 35:f72ccc6892ee 413 blk_ed.tskid = osThreadCreate(osThread(bulk_ed_task), 0);
mbed_official 35:f72ccc6892ee 414
mbed_official 35:f72ccc6892ee 415 /* interrupt transfer */
mbed_official 35:f72ccc6892ee 416 for (cnt = 0; cnt < INT_TRANS_MAX_NUM; cnt++) {
mbed_official 35:f72ccc6892ee 417 int_ed[cnt].semid_wait = osSemaphoreCreate(sem_def_tbl[index], 0);
mbed_official 35:f72ccc6892ee 418 index++;
mbed_official 35:f72ccc6892ee 419 int_ed[cnt].semid_list = osSemaphoreCreate(sem_def_tbl[index], 0);
mbed_official 35:f72ccc6892ee 420 index++;
mbed_official 35:f72ccc6892ee 421 int_ed[cnt].tskid = osThreadCreate(int_tsk_def_tbl[cnt], (void *)cnt);
mbed_official 35:f72ccc6892ee 422 }
mbed_official 35:f72ccc6892ee 423
mbed_official 35:f72ccc6892ee 424 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 35:f72ccc6892ee 425 /* isochronous transfer */
mbed_official 35:f72ccc6892ee 426 for (cnt = 0; cnt < ISO_TRANS_MAX_NUM; cnt++) {
mbed_official 35:f72ccc6892ee 427 iso_ed[cnt].semid_wait = osSemaphoreCreate(sem_def_tbl[index], 0);
mbed_official 35:f72ccc6892ee 428 index++;
mbed_official 35:f72ccc6892ee 429 iso_ed[cnt].semid_list = osSemaphoreCreate(sem_def_tbl[index], 0);
mbed_official 35:f72ccc6892ee 430 index++;
mbed_official 35:f72ccc6892ee 431 iso_ed[cnt].tskid = osThreadCreate(iso_tsk_def_tbl[cnt], (void *)cnt);
mbed_official 35:f72ccc6892ee 432 }
mbed_official 35:f72ccc6892ee 433 #endif
mbed_official 35:f72ccc6892ee 434 init_end = 1;
mbed_official 35:f72ccc6892ee 435 }
mbed_official 35:f72ccc6892ee 436 }
mbed_official 35:f72ccc6892ee 437
mbed_official 35:f72ccc6892ee 438 uint32_t ohciwrapp_reg_r(uint32_t reg_ofs) {
mbed_official 35:f72ccc6892ee 439 if (init_end == 0) {
mbed_official 35:f72ccc6892ee 440 return 0;
mbed_official 35:f72ccc6892ee 441 }
mbed_official 35:f72ccc6892ee 442
mbed_official 35:f72ccc6892ee 443 return *(uint32_t *)((uint8_t *)p_usb_reg + reg_ofs);
mbed_official 35:f72ccc6892ee 444 }
mbed_official 35:f72ccc6892ee 445
mbed_official 35:f72ccc6892ee 446 void ohciwrapp_reg_w(uint32_t reg_ofs, uint32_t set_data) {
mbed_official 35:f72ccc6892ee 447 uint32_t cnt;
mbed_official 35:f72ccc6892ee 448 uint32_t last_data;
mbed_official 35:f72ccc6892ee 449 hcca_t *p_hcca;
mbed_official 35:f72ccc6892ee 450
mbed_official 35:f72ccc6892ee 451 if (init_end == 0) {
mbed_official 35:f72ccc6892ee 452 return;
mbed_official 35:f72ccc6892ee 453 }
mbed_official 35:f72ccc6892ee 454
mbed_official 35:f72ccc6892ee 455 switch (reg_ofs) {
mbed_official 35:f72ccc6892ee 456 case OHCI_REG_CONTROL:
mbed_official 35:f72ccc6892ee 457 last_data = p_usb_reg->HcControl;
mbed_official 35:f72ccc6892ee 458 p_usb_reg->HcControl = (set_data & 0x000007FF);
mbed_official 35:f72ccc6892ee 459 if ((last_data & OR_CONTROL_CLE) != (set_data & OR_CONTROL_CLE)) {
mbed_official 35:f72ccc6892ee 460 /* change CLE */
mbed_official 35:f72ccc6892ee 461 if ((set_data & OR_CONTROL_CLE) != 0) {
mbed_official 35:f72ccc6892ee 462 (void)osSemaphoreRelease(ctl_ed.semid_list);
mbed_official 35:f72ccc6892ee 463 } else {
mbed_official 35:f72ccc6892ee 464 if (ctl_ed.trans_wait == 1) {
mbed_official 35:f72ccc6892ee 465 ctl_ed.trans_wait = 0;
mbed_official 35:f72ccc6892ee 466 (void)osSemaphoreRelease(ctl_ed.semid_wait);
mbed_official 35:f72ccc6892ee 467 }
mbed_official 35:f72ccc6892ee 468 (void)osSemaphoreWait(ctl_ed.semid_list, osWaitForever);
mbed_official 35:f72ccc6892ee 469 }
mbed_official 35:f72ccc6892ee 470 }
mbed_official 35:f72ccc6892ee 471 if ((last_data & OR_CONTROL_BLE) != (set_data & OR_CONTROL_BLE)) {
mbed_official 35:f72ccc6892ee 472 /* change BLE */
mbed_official 35:f72ccc6892ee 473 if ((set_data & OR_CONTROL_BLE) != 0) {
mbed_official 35:f72ccc6892ee 474 (void)osSemaphoreRelease(blk_ed.semid_list);
mbed_official 35:f72ccc6892ee 475 } else {
mbed_official 35:f72ccc6892ee 476 if (blk_ed.trans_wait == 1) {
mbed_official 35:f72ccc6892ee 477 blk_ed.trans_wait = 0;
mbed_official 35:f72ccc6892ee 478 (void)osSemaphoreRelease(blk_ed.semid_wait);
mbed_official 35:f72ccc6892ee 479 }
mbed_official 35:f72ccc6892ee 480 (void)osSemaphoreWait(blk_ed.semid_list, osWaitForever);
mbed_official 35:f72ccc6892ee 481 }
mbed_official 35:f72ccc6892ee 482 }
mbed_official 35:f72ccc6892ee 483 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 35:f72ccc6892ee 484 if ((last_data & OR_CONTROL_IE) != (set_data & OR_CONTROL_IE)) {
mbed_official 35:f72ccc6892ee 485 /* change IE */
mbed_official 35:f72ccc6892ee 486 for (cnt = 0; cnt < ISO_TRANS_MAX_NUM; cnt++) {
mbed_official 35:f72ccc6892ee 487 if ((set_data & OR_CONTROL_IE) != 0) {
mbed_official 35:f72ccc6892ee 488 (void)osSemaphoreRelease(iso_ed[cnt].semid_list);
mbed_official 35:f72ccc6892ee 489 } else {
mbed_official 35:f72ccc6892ee 490 if (iso_ed[cnt].trans_wait == 1) {
mbed_official 35:f72ccc6892ee 491 iso_ed[cnt].trans_wait = 0;
mbed_official 35:f72ccc6892ee 492 (void)osSemaphoreRelease(iso_ed[cnt].semid_wait);
mbed_official 35:f72ccc6892ee 493 }
mbed_official 35:f72ccc6892ee 494 (void)osSemaphoreWait(iso_ed[cnt].semid_list, osWaitForever);
mbed_official 35:f72ccc6892ee 495 }
mbed_official 35:f72ccc6892ee 496 }
mbed_official 35:f72ccc6892ee 497 }
mbed_official 35:f72ccc6892ee 498 #endif
mbed_official 35:f72ccc6892ee 499 if ((last_data & OR_CONTROL_PLE) != (set_data & OR_CONTROL_PLE)) {
mbed_official 35:f72ccc6892ee 500 /* change PLE */
mbed_official 35:f72ccc6892ee 501 for (cnt = 0; cnt < INT_TRANS_MAX_NUM; cnt++) {
mbed_official 35:f72ccc6892ee 502 if ((set_data & OR_CONTROL_PLE) != 0) {
mbed_official 35:f72ccc6892ee 503 (void)osSemaphoreRelease(int_ed[cnt].semid_list);
mbed_official 35:f72ccc6892ee 504 } else {
mbed_official 35:f72ccc6892ee 505 if (int_ed[cnt].trans_wait == 1) {
mbed_official 35:f72ccc6892ee 506 int_ed[cnt].trans_wait = 0;
mbed_official 35:f72ccc6892ee 507 (void)osSemaphoreRelease(int_ed[cnt].semid_wait);
mbed_official 35:f72ccc6892ee 508 }
mbed_official 35:f72ccc6892ee 509 (void)osSemaphoreWait(int_ed[cnt].semid_list, osWaitForever);
mbed_official 35:f72ccc6892ee 510 }
mbed_official 35:f72ccc6892ee 511 }
mbed_official 35:f72ccc6892ee 512 }
mbed_official 35:f72ccc6892ee 513 break;
mbed_official 35:f72ccc6892ee 514 case OHCI_REG_COMMANDSTATUS:
mbed_official 35:f72ccc6892ee 515 if ((set_data & OR_CMD_STATUS_HCR) != 0) { /* HostController Reset */
mbed_official 35:f72ccc6892ee 516 p_usb_reg->HcCommandStatus |= OR_CMD_STATUS_HCR;
mbed_official 35:f72ccc6892ee 517 if (usbx_api_host_init(16, g_usbx_host_SupportUsbDeviceSpeed, USBHCLOCK_X1_48MHZ) == USB_HOST_ATTACH) {
mbed_official 35:f72ccc6892ee 518 ohciwrapp_loc_Connect(1);
mbed_official 35:f72ccc6892ee 519 }
mbed_official 35:f72ccc6892ee 520 p_usb_reg->HcCommandStatus &= ~OR_CMD_STATUS_HCR;
mbed_official 35:f72ccc6892ee 521 }
mbed_official 35:f72ccc6892ee 522 if ((set_data & OR_CMD_STATUS_CLF) != 0) {
mbed_official 35:f72ccc6892ee 523 p_usb_reg->HcCommandStatus |= OR_CMD_STATUS_CLF;
mbed_official 35:f72ccc6892ee 524 osSignalSet(ctl_ed.tskid, SIG_GEN_LIST_REQ);
mbed_official 35:f72ccc6892ee 525 }
mbed_official 35:f72ccc6892ee 526 if ((set_data & OR_CMD_STATUS_BLF) != 0) {
mbed_official 35:f72ccc6892ee 527 p_usb_reg->HcCommandStatus |= OR_CMD_STATUS_BLF;
mbed_official 35:f72ccc6892ee 528 osSignalSet(blk_ed.tskid, SIG_GEN_LIST_REQ);
mbed_official 35:f72ccc6892ee 529 }
mbed_official 35:f72ccc6892ee 530 if ((set_data & OR_CMD_STATUS_OCR) != 0) {
mbed_official 35:f72ccc6892ee 531 p_usb_reg->HcCommandStatus |= OR_CMD_STATUS_OCR;
mbed_official 35:f72ccc6892ee 532 } else {
mbed_official 35:f72ccc6892ee 533 p_usb_reg->HcCommandStatus &= ~OR_CMD_STATUS_OCR;
mbed_official 35:f72ccc6892ee 534 }
mbed_official 35:f72ccc6892ee 535 break;
mbed_official 35:f72ccc6892ee 536 case OHCI_REG_INTERRUPTSTATUS:
mbed_official 35:f72ccc6892ee 537 if (((p_usb_reg->HcInterruptStatus & OR_INTR_STATUS_WDH) != 0)
mbed_official 35:f72ccc6892ee 538 && ((set_data & OR_INTR_STATUS_WDH) != 0)) {
mbed_official 35:f72ccc6892ee 539 if (p_usb_reg->HcDoneHead != 0x00000000) {
mbed_official 35:f72ccc6892ee 540 p_hcca = (hcca_t *)p_usb_reg->HcHCCA;
mbed_official 35:f72ccc6892ee 541 p_hcca->DoneHead = p_usb_reg->HcDoneHead;
mbed_official 35:f72ccc6892ee 542 p_usb_reg->HcDoneHead = 0x00000000;
mbed_official 35:f72ccc6892ee 543 p_usb_reg->HcInterruptStatus |= OR_INTR_STATUS_WDH;
mbed_official 35:f72ccc6892ee 544 (void)osSemaphoreRelease(semid_cb);
mbed_official 35:f72ccc6892ee 545 } else {
mbed_official 35:f72ccc6892ee 546 p_usb_reg->HcInterruptStatus &= ~OR_INTR_STATUS_WDH;
mbed_official 35:f72ccc6892ee 547 }
mbed_official 35:f72ccc6892ee 548 }
mbed_official 35:f72ccc6892ee 549 if ((set_data & OR_INTR_STATUS_RHSC) != 0) {
mbed_official 35:f72ccc6892ee 550 p_usb_reg->HcInterruptStatus &= ~OR_INTR_STATUS_RHSC;
mbed_official 35:f72ccc6892ee 551 }
mbed_official 35:f72ccc6892ee 552 break;
mbed_official 35:f72ccc6892ee 553 case OHCI_REG_INTERRUPTENABLE:
mbed_official 35:f72ccc6892ee 554 case OHCI_REG_INTERRUPTDISABLE:
mbed_official 35:f72ccc6892ee 555 case OHCI_REG_HCCA:
mbed_official 35:f72ccc6892ee 556 case OHCI_REG_CONTROLHEADED:
mbed_official 35:f72ccc6892ee 557 case OHCI_REG_CONTROLCURRENTED:
mbed_official 35:f72ccc6892ee 558 case OHCI_REG_BULKHEADED:
mbed_official 35:f72ccc6892ee 559 case OHCI_REG_BULKCURRENTED:
mbed_official 35:f72ccc6892ee 560 case OHCI_REG_FMINTERVAL:
mbed_official 35:f72ccc6892ee 561 case OHCI_REG_FMREMAINING:
mbed_official 35:f72ccc6892ee 562 case OHCI_REG_PERIODICSTART:
mbed_official 35:f72ccc6892ee 563 case OHCI_REG_LSTHRESHOLD:
mbed_official 35:f72ccc6892ee 564 case OHCI_REG_RHDESCRIPTORA:
mbed_official 35:f72ccc6892ee 565 case OHCI_REG_RHDESCRIPTORB:
mbed_official 35:f72ccc6892ee 566 case OHCI_REG_RHSTATUS:
mbed_official 35:f72ccc6892ee 567 *(uint32_t *)((uint8_t *)p_usb_reg + reg_ofs) = set_data;
mbed_official 35:f72ccc6892ee 568 break;
mbed_official 35:f72ccc6892ee 569 case OHCI_REG_RHPORTSTATUS1:
mbed_official 35:f72ccc6892ee 570 p_usb_reg->HcRhPortStatus1 &= ~(set_data & 0xFFFF0000);
mbed_official 35:f72ccc6892ee 571 if ((set_data & OR_RH_PORT_PRS) != 0) { /* Set Port Reset */
mbed_official 35:f72ccc6892ee 572 p_usb_reg->HcRhPortStatus1 |= OR_RH_PORT_PRS;
mbed_official 35:f72ccc6892ee 573 usbx_host_UsbBusReset();
mbed_official 35:f72ccc6892ee 574 p_usb_reg->HcRhPortStatus1 &= ~OR_RH_PORT_PRS;
mbed_official 35:f72ccc6892ee 575 }
mbed_official 35:f72ccc6892ee 576 break;
mbed_official 35:f72ccc6892ee 577 case OHCI_REG_REVISION:
mbed_official 35:f72ccc6892ee 578 case OHCI_REG_PERIODCURRENTED:
mbed_official 35:f72ccc6892ee 579 case OHCI_REG_DONEHEADED:
mbed_official 35:f72ccc6892ee 580 case OHCI_REG_FMNUMBER:
mbed_official 35:f72ccc6892ee 581 default:
mbed_official 35:f72ccc6892ee 582 /* Do Nothing */
mbed_official 35:f72ccc6892ee 583 break;
mbed_official 35:f72ccc6892ee 584 }
mbed_official 35:f72ccc6892ee 585 }
mbed_official 35:f72ccc6892ee 586
mbed_official 35:f72ccc6892ee 587 static void callback_task(void const * argument) {
mbed_official 35:f72ccc6892ee 588 usbisr_fnc_t *p_wk_cb = p_usbisr_cb;
mbed_official 35:f72ccc6892ee 589
mbed_official 35:f72ccc6892ee 590 if (p_wk_cb == NULL) {
mbed_official 35:f72ccc6892ee 591 return;
mbed_official 35:f72ccc6892ee 592 }
mbed_official 35:f72ccc6892ee 593
mbed_official 35:f72ccc6892ee 594 while (1) {
mbed_official 35:f72ccc6892ee 595 osSemaphoreWait(semid_cb, osWaitForever);
mbed_official 35:f72ccc6892ee 596 if (connect_change != 0xFFFFFFFF) {
mbed_official 35:f72ccc6892ee 597 connect_change = 0xFFFFFFFF;
mbed_official 35:f72ccc6892ee 598 connect_check();
mbed_official 35:f72ccc6892ee 599 }
mbed_official 35:f72ccc6892ee 600 p_wk_cb();
mbed_official 35:f72ccc6892ee 601 }
mbed_official 35:f72ccc6892ee 602 }
mbed_official 35:f72ccc6892ee 603
mbed_official 35:f72ccc6892ee 604 static void control_ed_task(void const * argument) {
mbed_official 35:f72ccc6892ee 605 while (1) {
mbed_official 35:f72ccc6892ee 606 osSignalWait(SIG_GEN_LIST_REQ, osWaitForever);
mbed_official 35:f72ccc6892ee 607 (void)osSemaphoreWait(ctl_ed.semid_list, osWaitForever);
mbed_official 35:f72ccc6892ee 608 while ((p_usb_reg->HcControl & OR_CONTROL_CLE) != 0) {
mbed_official 35:f72ccc6892ee 609 if ((p_usb_reg->HcControlCurrentED == 0)
mbed_official 35:f72ccc6892ee 610 && ((p_usb_reg->HcCommandStatus & OR_CMD_STATUS_CLF) != 0)) {
mbed_official 35:f72ccc6892ee 611 p_usb_reg->HcControlCurrentED = p_usb_reg->HcControlHeadED;
mbed_official 35:f72ccc6892ee 612 p_usb_reg->HcCommandStatus &= ~OR_CMD_STATUS_CLF;
mbed_official 35:f72ccc6892ee 613 }
mbed_official 35:f72ccc6892ee 614 if (p_usb_reg->HcControlCurrentED != 0) {
mbed_official 35:f72ccc6892ee 615 ctl_ed.p_curr_ed = (hced_t *)p_usb_reg->HcControlCurrentED;
mbed_official 35:f72ccc6892ee 616 if (chk_genelal_ed(&ctl_ed) != 0) {
mbed_official 35:f72ccc6892ee 617 control_trans(&ctl_ed);
mbed_official 35:f72ccc6892ee 618 p_usb_reg->HcCommandStatus |= OR_CMD_STATUS_CLF;
mbed_official 35:f72ccc6892ee 619 }
mbed_official 35:f72ccc6892ee 620 p_usb_reg->HcControlCurrentED = (uint32_t)ctl_ed.p_curr_ed->nextED;
mbed_official 35:f72ccc6892ee 621 } else {
mbed_official 35:f72ccc6892ee 622 break;
mbed_official 35:f72ccc6892ee 623 }
mbed_official 35:f72ccc6892ee 624 }
mbed_official 35:f72ccc6892ee 625 if ((p_usb_reg->HcCommandStatus & OR_CMD_STATUS_CLF) != 0) {
mbed_official 35:f72ccc6892ee 626 osSignalSet(ctl_ed.tskid, SIG_GEN_LIST_REQ);
mbed_official 35:f72ccc6892ee 627 }
mbed_official 35:f72ccc6892ee 628 (void)osSemaphoreRelease(ctl_ed.semid_list);
mbed_official 35:f72ccc6892ee 629 }
mbed_official 35:f72ccc6892ee 630 }
mbed_official 35:f72ccc6892ee 631
mbed_official 35:f72ccc6892ee 632 static void bulk_ed_task(void const * argument) {
mbed_official 35:f72ccc6892ee 633 while (1) {
mbed_official 35:f72ccc6892ee 634 osSignalWait(SIG_GEN_LIST_REQ, osWaitForever);
mbed_official 35:f72ccc6892ee 635 (void)osSemaphoreWait(blk_ed.semid_list, osWaitForever);
mbed_official 35:f72ccc6892ee 636 while ((p_usb_reg->HcControl & OR_CONTROL_BLE) != 0) {
mbed_official 35:f72ccc6892ee 637 if ((p_usb_reg->HcBulkCurrentED == 0)
mbed_official 35:f72ccc6892ee 638 && ((p_usb_reg->HcCommandStatus & OR_CMD_STATUS_BLF) != 0)) {
mbed_official 35:f72ccc6892ee 639 p_usb_reg->HcBulkCurrentED = p_usb_reg->HcBulkHeadED;
mbed_official 35:f72ccc6892ee 640 p_usb_reg->HcCommandStatus &= ~OR_CMD_STATUS_BLF;
mbed_official 35:f72ccc6892ee 641 }
mbed_official 35:f72ccc6892ee 642 if (p_usb_reg->HcBulkCurrentED != 0) {
mbed_official 35:f72ccc6892ee 643 blk_ed.p_curr_ed = (hced_t *)p_usb_reg->HcBulkCurrentED;
mbed_official 35:f72ccc6892ee 644 if (chk_genelal_ed(&blk_ed) != 0) {
mbed_official 35:f72ccc6892ee 645 bulk_trans(&blk_ed);
mbed_official 35:f72ccc6892ee 646 p_usb_reg->HcCommandStatus |= OR_CMD_STATUS_BLF;
mbed_official 35:f72ccc6892ee 647 }
mbed_official 35:f72ccc6892ee 648 p_usb_reg->HcBulkCurrentED = (uint32_t)blk_ed.p_curr_ed->nextED;
mbed_official 35:f72ccc6892ee 649 } else {
mbed_official 35:f72ccc6892ee 650 break;
mbed_official 35:f72ccc6892ee 651 }
mbed_official 35:f72ccc6892ee 652 }
mbed_official 35:f72ccc6892ee 653 if ((p_usb_reg->HcCommandStatus & OR_CMD_STATUS_BLF) != 0) {
mbed_official 35:f72ccc6892ee 654 osSignalSet(blk_ed.tskid, SIG_GEN_LIST_REQ);
mbed_official 35:f72ccc6892ee 655 }
mbed_official 35:f72ccc6892ee 656 (void)osSemaphoreRelease(blk_ed.semid_list);
mbed_official 35:f72ccc6892ee 657 }
mbed_official 35:f72ccc6892ee 658 }
mbed_official 35:f72ccc6892ee 659
mbed_official 35:f72ccc6892ee 660 static void int_ed_task(void const * argument) {
mbed_official 35:f72ccc6892ee 661 genelal_ed_t *p_int_ed = &int_ed[(uint32_t)argument];
mbed_official 35:f72ccc6892ee 662 uint32_t cnt;
mbed_official 35:f72ccc6892ee 663 uint32_t wait_cnt = 0;
mbed_official 35:f72ccc6892ee 664 hcca_t *p_hcca;
mbed_official 35:f72ccc6892ee 665 hced_t *p_ed;
mbed_official 35:f72ccc6892ee 666
mbed_official 35:f72ccc6892ee 667 while (1) {
mbed_official 35:f72ccc6892ee 668 (void)osSemaphoreWait(p_int_ed->semid_list, osWaitForever);
mbed_official 35:f72ccc6892ee 669 if (p_int_ed->p_curr_ed == NULL) {
mbed_official 35:f72ccc6892ee 670 for (cnt = 0; (cnt < 32) && ((p_usb_reg->HcControl & OR_CONTROL_PLE) != 0)
mbed_official 35:f72ccc6892ee 671 && (p_int_ed->p_curr_ed == NULL); cnt++) {
mbed_official 35:f72ccc6892ee 672 p_hcca = (hcca_t *)p_usb_reg->HcHCCA;
mbed_official 35:f72ccc6892ee 673 p_ed = (hced_t *)p_hcca->IntTable[cnt];
mbed_official 35:f72ccc6892ee 674 while ((p_ed != NULL) && ((p_usb_reg->HcControl & OR_CONTROL_PLE) != 0)
mbed_official 35:f72ccc6892ee 675 && (p_int_ed->p_curr_ed == NULL)) {
mbed_official 35:f72ccc6892ee 676 if (int_trans_doing(p_ed, (uint32_t)argument) == 0) {
mbed_official 35:f72ccc6892ee 677 p_int_ed->p_curr_ed = p_ed;
mbed_official 35:f72ccc6892ee 678 if (chk_genelal_ed(p_int_ed) != 0) {
mbed_official 35:f72ccc6892ee 679 int_trans_setting(p_int_ed, (uint32_t)argument);
mbed_official 35:f72ccc6892ee 680 } else {
mbed_official 35:f72ccc6892ee 681 p_int_ed->p_curr_ed = NULL;
mbed_official 35:f72ccc6892ee 682 }
mbed_official 35:f72ccc6892ee 683 }
mbed_official 35:f72ccc6892ee 684 p_ed = p_ed->nextED;
mbed_official 35:f72ccc6892ee 685 }
mbed_official 35:f72ccc6892ee 686 }
mbed_official 35:f72ccc6892ee 687 }
mbed_official 35:f72ccc6892ee 688 if (p_int_ed->p_curr_ed != NULL) {
mbed_official 35:f72ccc6892ee 689 while ((p_usb_reg->HcControl & OR_CONTROL_PLE) != 0) {
mbed_official 35:f72ccc6892ee 690 if (chk_genelal_ed(p_int_ed) != 0) {
mbed_official 35:f72ccc6892ee 691 int_trans(p_int_ed);
mbed_official 35:f72ccc6892ee 692 (void)osSemaphoreWait(p_int_ed->semid_wait, osWaitForever);
mbed_official 35:f72ccc6892ee 693 usbx_host_stop_transfer(p_int_ed->pipe_no);
mbed_official 35:f72ccc6892ee 694 wait_cnt = p_int_ed->cycle_time;
mbed_official 35:f72ccc6892ee 695 } else {
mbed_official 35:f72ccc6892ee 696 if (wait_cnt > 0) {
mbed_official 35:f72ccc6892ee 697 wait_cnt--;
mbed_official 35:f72ccc6892ee 698 } else {
mbed_official 35:f72ccc6892ee 699 p_int_ed->p_curr_ed = NULL;
mbed_official 35:f72ccc6892ee 700 }
mbed_official 35:f72ccc6892ee 701 break;
mbed_official 35:f72ccc6892ee 702 }
mbed_official 35:f72ccc6892ee 703 }
mbed_official 35:f72ccc6892ee 704 }
mbed_official 35:f72ccc6892ee 705 (void)osSemaphoreRelease(p_int_ed->semid_list);
mbed_official 35:f72ccc6892ee 706 if (p_int_ed->p_curr_ed == NULL) {
mbed_official 35:f72ccc6892ee 707 osDelay(10);
mbed_official 35:f72ccc6892ee 708 } else {
mbed_official 35:f72ccc6892ee 709 osDelay(1);
mbed_official 35:f72ccc6892ee 710 }
mbed_official 35:f72ccc6892ee 711 }
mbed_official 35:f72ccc6892ee 712 }
mbed_official 35:f72ccc6892ee 713
mbed_official 35:f72ccc6892ee 714 static int32_t int_trans_doing(hced_t *p_ed, uint32_t index) {
mbed_official 35:f72ccc6892ee 715 uint32_t cnt;
mbed_official 35:f72ccc6892ee 716 int32_t ret = 0;
mbed_official 35:f72ccc6892ee 717
mbed_official 35:f72ccc6892ee 718 for (cnt = 0; cnt < INT_TRANS_MAX_NUM; cnt++) {
mbed_official 35:f72ccc6892ee 719 if ((index != cnt) && (int_ed[cnt].p_curr_ed == p_ed)) {
mbed_official 35:f72ccc6892ee 720 ret = 1;
mbed_official 35:f72ccc6892ee 721 }
mbed_official 35:f72ccc6892ee 722 }
mbed_official 35:f72ccc6892ee 723
mbed_official 35:f72ccc6892ee 724 return ret;
mbed_official 35:f72ccc6892ee 725 }
mbed_official 35:f72ccc6892ee 726
mbed_official 35:f72ccc6892ee 727 static int32_t chk_genelal_ed(genelal_ed_t *p_g_ed){
mbed_official 35:f72ccc6892ee 728 int32_t ret = 0;
mbed_official 35:f72ccc6892ee 729 hced_t *p_ed = p_g_ed->p_curr_ed;
mbed_official 35:f72ccc6892ee 730
mbed_official 35:f72ccc6892ee 731 if (((p_ed->control & ED_SKIP) != 0)
mbed_official 35:f72ccc6892ee 732 || ((p_ed->control & ED_FORMAT) != 0)
mbed_official 35:f72ccc6892ee 733 || ((p_ed->headTD & ED_HALTED) != 0)
mbed_official 35:f72ccc6892ee 734 || ((p_ed->tailTD & 0xFFFFFFF0) == (p_ed->headTD & 0xFFFFFFF0))) {
mbed_official 35:f72ccc6892ee 735 /* Do Nothing */
mbed_official 35:f72ccc6892ee 736 } else if ((p_ed->control & 0x0000007F) > 10) {
mbed_official 35:f72ccc6892ee 737 p_ed->headTD |= ED_HALTED;
mbed_official 35:f72ccc6892ee 738 } else {
mbed_official 35:f72ccc6892ee 739 p_g_ed->p_curr_td = (void *)(p_ed->headTD & 0xFFFFFFF0);
mbed_official 35:f72ccc6892ee 740 if (p_g_ed->p_curr_td == NULL) {
mbed_official 35:f72ccc6892ee 741 p_ed->headTD |= ED_HALTED;
mbed_official 35:f72ccc6892ee 742 } else {
mbed_official 35:f72ccc6892ee 743 hctd_t *p_td = (hctd_t *)p_g_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 744
mbed_official 35:f72ccc6892ee 745 p_g_ed->p_start_buf = p_td->currBufPtr;
mbed_official 35:f72ccc6892ee 746 ret = 1;
mbed_official 35:f72ccc6892ee 747 }
mbed_official 35:f72ccc6892ee 748 }
mbed_official 35:f72ccc6892ee 749
mbed_official 35:f72ccc6892ee 750 return ret;
mbed_official 35:f72ccc6892ee 751 }
mbed_official 35:f72ccc6892ee 752
mbed_official 35:f72ccc6892ee 753 static void chk_genelal_td_done(genelal_ed_t *p_g_ed) {
mbed_official 35:f72ccc6892ee 754 hcca_t *p_hcca;
mbed_official 35:f72ccc6892ee 755 hctd_t *p_td = (hctd_t *)p_g_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 756 uint32_t ConditionCode = RZA_IO_RegRead_32(&p_td->control, TD_CTL_SHFT_CC, TD_CTL_MSK_CC);
mbed_official 35:f72ccc6892ee 757
mbed_official 35:f72ccc6892ee 758 if ((ConditionCode != TD_CC_NOT_ACCESSED_1) && (ConditionCode != TD_CC_NOT_ACCESSED_2)) {
mbed_official 35:f72ccc6892ee 759 p_g_ed->p_curr_ed->headTD = ((uint32_t)p_td->nextTD & 0xFFFFFFF0)
mbed_official 35:f72ccc6892ee 760 | (p_g_ed->p_curr_ed->headTD & 0x0000000F);
mbed_official 35:f72ccc6892ee 761 p_td->nextTD = (hctd_t *)p_usb_reg->HcDoneHead;
mbed_official 35:f72ccc6892ee 762 p_usb_reg->HcDoneHead = (uint32_t)p_g_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 763 if ((p_usb_reg->HcInterruptStatus & OR_INTR_STATUS_WDH) == 0) {
mbed_official 35:f72ccc6892ee 764 p_hcca = (hcca_t *)p_usb_reg->HcHCCA;
mbed_official 35:f72ccc6892ee 765 p_hcca->DoneHead = p_usb_reg->HcDoneHead;
mbed_official 35:f72ccc6892ee 766 p_usb_reg->HcDoneHead = 0x00000000;
mbed_official 35:f72ccc6892ee 767 p_usb_reg->HcInterruptStatus |= OR_INTR_STATUS_WDH;
mbed_official 35:f72ccc6892ee 768 (void)osSemaphoreRelease(semid_cb);
mbed_official 35:f72ccc6892ee 769 }
mbed_official 35:f72ccc6892ee 770 }
mbed_official 35:f72ccc6892ee 771 }
mbed_official 35:f72ccc6892ee 772
mbed_official 35:f72ccc6892ee 773 static void chk_split_trans_setting(genelal_ed_t *p_g_ed) {
mbed_official 35:f72ccc6892ee 774 uint8_t *p_buf;
mbed_official 35:f72ccc6892ee 775 tdinfo_t td_info;
mbed_official 35:f72ccc6892ee 776 hctd_t *p_td = (hctd_t *)p_g_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 777
mbed_official 35:f72ccc6892ee 778 /* Hi-Speed mode only */
mbed_official 35:f72ccc6892ee 779 if (g_usbx_host_UsbDeviceSpeed != USB_HOST_HIGH_SPEED) {
mbed_official 35:f72ccc6892ee 780 return;
mbed_official 35:f72ccc6892ee 781 }
mbed_official 35:f72ccc6892ee 782
mbed_official 35:f72ccc6892ee 783 if (RZA_IO_RegRead_32(&p_td->control, TD_CTL_SHFT_CC, TD_CTL_MSK_CC) != TD_CC_NOERROR) {
mbed_official 35:f72ccc6892ee 784 return;
mbed_official 35:f72ccc6892ee 785 }
mbed_official 35:f72ccc6892ee 786
mbed_official 35:f72ccc6892ee 787 get_td_info(p_g_ed, &td_info);
mbed_official 35:f72ccc6892ee 788 p_buf = p_g_ed->p_start_buf;
mbed_official 35:f72ccc6892ee 789
mbed_official 35:f72ccc6892ee 790 if (td_info.direction == 0) {
mbed_official 35:f72ccc6892ee 791 uint8_t bRequest = p_buf[1];
mbed_official 35:f72ccc6892ee 792 uint16_t wValue = (p_buf[3] << 8) + p_buf[2];
mbed_official 35:f72ccc6892ee 793 uint16_t wIndx = (p_buf[5] << 8) + p_buf[4];
mbed_official 35:f72ccc6892ee 794 uint16_t devadd;
mbed_official 35:f72ccc6892ee 795
mbed_official 35:f72ccc6892ee 796 if ((td_info.devadr == 0) && (bRequest == SET_ADDRESS)) {
mbed_official 35:f72ccc6892ee 797 /* SET_ADDRESS */
mbed_official 35:f72ccc6892ee 798 usbx_host_get_devadd(USB_HOST_DEVICE_0, &devadd);
mbed_official 35:f72ccc6892ee 799 usbx_host_set_devadd(wValue, &devadd);
mbed_official 35:f72ccc6892ee 800 if (split_ctl.root_devadr == 0) {
mbed_official 35:f72ccc6892ee 801 split_ctl.root_devadr = wValue; /* New Address */
mbed_official 35:f72ccc6892ee 802 }
mbed_official 35:f72ccc6892ee 803 } else if ((td_info.devadr == split_ctl.root_devadr) && (bRequest == SET_FEATURE)
mbed_official 35:f72ccc6892ee 804 && (wValue == 0x0004) && (split_ctl.root_devadr != 0)) {
mbed_official 35:f72ccc6892ee 805 /* SET_FEATURE PORT_RESET */
mbed_official 35:f72ccc6892ee 806 split_ctl.reset_port = (wIndx & 0x00FF);
mbed_official 35:f72ccc6892ee 807 } else if ((td_info.devadr == split_ctl.root_devadr) && (bRequest == GET_STATUS)) {
mbed_official 35:f72ccc6892ee 808 /* GET_STATUS */
mbed_official 35:f72ccc6892ee 809 split_ctl.get_port = wIndx;
mbed_official 35:f72ccc6892ee 810 split_ctl.seq_cnt = 1;
mbed_official 35:f72ccc6892ee 811 } else {
mbed_official 35:f72ccc6892ee 812 /* Do Nothing */
mbed_official 35:f72ccc6892ee 813 }
mbed_official 35:f72ccc6892ee 814 } else if (td_info.direction == 2) {
mbed_official 35:f72ccc6892ee 815 if ((td_info.devadr == split_ctl.root_devadr) && (split_ctl.seq_cnt == 1)) {
mbed_official 35:f72ccc6892ee 816 if (split_ctl.get_port < PORT_NUM) {
mbed_official 35:f72ccc6892ee 817 split_ctl.port_sts_bits[split_ctl.get_port] = (p_buf[1] << 8) + p_buf[0];
mbed_official 35:f72ccc6892ee 818 }
mbed_official 35:f72ccc6892ee 819 split_ctl.seq_cnt = 0;
mbed_official 35:f72ccc6892ee 820 }
mbed_official 35:f72ccc6892ee 821 } else {
mbed_official 35:f72ccc6892ee 822 /* Do Nothing */
mbed_official 35:f72ccc6892ee 823 }
mbed_official 35:f72ccc6892ee 824 }
mbed_official 35:f72ccc6892ee 825
mbed_official 35:f72ccc6892ee 826 static void set_split_trans_setting(void) {
mbed_official 35:f72ccc6892ee 827 uint16_t port_speed;
mbed_official 35:f72ccc6892ee 828 uint16_t devadd;
mbed_official 35:f72ccc6892ee 829
mbed_official 35:f72ccc6892ee 830 if ((split_ctl.root_devadr != 0) && (split_ctl.reset_port != 0) && (split_ctl.reset_port < PORT_NUM)) {
mbed_official 35:f72ccc6892ee 831 usbx_host_get_devadd(USB_HOST_DEVICE_0, &devadd);
mbed_official 35:f72ccc6892ee 832 RZA_IO_RegWrite_16(&devadd, split_ctl.root_devadr, USB_DEVADDn_UPPHUB_SHIFT, USB_DEVADDn_UPPHUB);
mbed_official 35:f72ccc6892ee 833 RZA_IO_RegWrite_16(&devadd, split_ctl.reset_port, USB_DEVADDn_HUBPORT_SHIFT, USB_DEVADDn_HUBPORT);
mbed_official 35:f72ccc6892ee 834 if ((split_ctl.port_sts_bits[split_ctl.reset_port] & PORT_HIGH_SPEED) != 0) {
mbed_official 35:f72ccc6892ee 835 port_speed = USB_HOST_HIGH_SPEED;
mbed_official 35:f72ccc6892ee 836 } else if ((split_ctl.port_sts_bits[split_ctl.reset_port] & PORT_LOW_SPEED) != 0) {
mbed_official 35:f72ccc6892ee 837 port_speed = USB_HOST_LOW_SPEED;
mbed_official 35:f72ccc6892ee 838 } else {
mbed_official 35:f72ccc6892ee 839 port_speed = USB_HOST_FULL_SPEED;
mbed_official 35:f72ccc6892ee 840 }
mbed_official 35:f72ccc6892ee 841 RZA_IO_RegWrite_16(&devadd, port_speed, USB_DEVADDn_USBSPD_SHIFT, USB_DEVADDn_USBSPD);
mbed_official 35:f72ccc6892ee 842 usbx_host_set_devadd(USB_HOST_DEVICE_0, &devadd);
mbed_official 35:f72ccc6892ee 843 split_ctl.reset_port = 0;
mbed_official 35:f72ccc6892ee 844 }
mbed_official 35:f72ccc6892ee 845 }
mbed_official 35:f72ccc6892ee 846
mbed_official 35:f72ccc6892ee 847 static void control_trans(genelal_ed_t *p_g_ed) {
mbed_official 35:f72ccc6892ee 848 hctd_t *p_td = (hctd_t *)p_g_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 849 tdinfo_t td_info;
mbed_official 35:f72ccc6892ee 850 uint16_t devadd;
mbed_official 35:f72ccc6892ee 851
mbed_official 35:f72ccc6892ee 852 get_td_info(p_g_ed, &td_info);
mbed_official 35:f72ccc6892ee 853
mbed_official 35:f72ccc6892ee 854 if (g_usbx_host_UsbDeviceSpeed == USB_HOST_HIGH_SPEED) {
mbed_official 35:f72ccc6892ee 855 if (td_info.devadr == 0) {
mbed_official 35:f72ccc6892ee 856 set_split_trans_setting();
mbed_official 35:f72ccc6892ee 857 }
mbed_official 35:f72ccc6892ee 858 } else {
mbed_official 35:f72ccc6892ee 859 /* When a non-Hi-Speed, the communication speed is determined from the TD. */
mbed_official 35:f72ccc6892ee 860 usbx_host_get_devadd(USB_HOST_DEVICE_0, &devadd);
mbed_official 35:f72ccc6892ee 861 if (td_info.speed == 1) {
mbed_official 35:f72ccc6892ee 862 RZA_IO_RegWrite_16(&devadd, USB_HOST_LOW_SPEED, USB_DEVADDn_USBSPD_SHIFT, USB_DEVADDn_USBSPD);
mbed_official 35:f72ccc6892ee 863 } else {
mbed_official 35:f72ccc6892ee 864 RZA_IO_RegWrite_16(&devadd, USB_HOST_FULL_SPEED, USB_DEVADDn_USBSPD_SHIFT, USB_DEVADDn_USBSPD);
mbed_official 35:f72ccc6892ee 865 }
mbed_official 35:f72ccc6892ee 866 usbx_host_set_devadd(td_info.devadr, &devadd);
mbed_official 35:f72ccc6892ee 867 }
mbed_official 35:f72ccc6892ee 868
mbed_official 35:f72ccc6892ee 869 USB20X.DCPMAXP = (td_info.devadr << 12) + td_info.msp;
mbed_official 35:f72ccc6892ee 870 if (td_info.direction == 0) {
mbed_official 35:f72ccc6892ee 871 g_usbx_host_CmdStage = (USB_HOST_STAGE_SETUP | USB_HOST_CMD_IDLE);
mbed_official 35:f72ccc6892ee 872 } else if (td_info.count != 0) {
mbed_official 35:f72ccc6892ee 873 g_usbx_host_CmdStage = (USB_HOST_STAGE_DATA | USB_HOST_CMD_IDLE);
mbed_official 35:f72ccc6892ee 874 } else {
mbed_official 35:f72ccc6892ee 875 g_usbx_host_CmdStage = (USB_HOST_STAGE_STATUS | USB_HOST_CMD_IDLE);
mbed_official 35:f72ccc6892ee 876 }
mbed_official 35:f72ccc6892ee 877 g_usbx_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_WAIT;
mbed_official 35:f72ccc6892ee 878 p_g_ed->pipe_no = USB_HOST_PIPE0;
mbed_official 35:f72ccc6892ee 879
mbed_official 35:f72ccc6892ee 880 p_g_ed->trans_wait = 1;
mbed_official 35:f72ccc6892ee 881 if (connect_status == 0) {
mbed_official 35:f72ccc6892ee 882 ohciwrapp_loc_TransEnd(p_g_ed->pipe_no, TD_CC_DEVICENOTRESPONDING);
mbed_official 35:f72ccc6892ee 883 } else {
mbed_official 35:f72ccc6892ee 884 if (td_info.direction == 0) {
mbed_official 35:f72ccc6892ee 885 uint16_t Req = (p_td->currBufPtr[1] << 8) + p_td->currBufPtr[0];
mbed_official 35:f72ccc6892ee 886 uint16_t Val = (p_td->currBufPtr[3] << 8) + p_td->currBufPtr[2];
mbed_official 35:f72ccc6892ee 887 uint16_t Indx = (p_td->currBufPtr[5] << 8) + p_td->currBufPtr[4];
mbed_official 35:f72ccc6892ee 888 uint16_t Len = (p_td->currBufPtr[7] << 8) + p_td->currBufPtr[6];
mbed_official 35:f72ccc6892ee 889
mbed_official 35:f72ccc6892ee 890 g_usbx_host_data_pointer[USB_HOST_PIPE0] = p_td->bufEnd;
mbed_official 35:f72ccc6892ee 891 usbx_host_SetupStage(Req, Val, Indx, Len);
mbed_official 35:f72ccc6892ee 892 } else if (td_info.direction == 1) {
mbed_official 35:f72ccc6892ee 893 usbx_host_CtrlWriteStart(td_info.count, p_td->currBufPtr);
mbed_official 35:f72ccc6892ee 894 } else {
mbed_official 35:f72ccc6892ee 895 usbx_host_CtrlReadStart(td_info.count, p_td->currBufPtr);
mbed_official 35:f72ccc6892ee 896 }
mbed_official 35:f72ccc6892ee 897
mbed_official 35:f72ccc6892ee 898 (void)osSemaphoreWait(p_g_ed->semid_wait, CTL_TRANS_TIMEOUT);
mbed_official 35:f72ccc6892ee 899 if (p_g_ed->trans_wait == 1) {
mbed_official 35:f72ccc6892ee 900 p_g_ed->trans_wait = 0;
mbed_official 35:f72ccc6892ee 901 RZA_IO_RegWrite_32(&p_td->control, TD_CC_DEVICENOTRESPONDING, TD_CTL_SHFT_CC, TD_CTL_MSK_CC);
mbed_official 35:f72ccc6892ee 902 }
mbed_official 35:f72ccc6892ee 903 }
mbed_official 35:f72ccc6892ee 904
mbed_official 35:f72ccc6892ee 905 g_usbx_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 35:f72ccc6892ee 906 g_usbx_host_CmdStage |= USB_HOST_CMD_IDLE;
mbed_official 35:f72ccc6892ee 907 g_usbx_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_IDLE;
mbed_official 35:f72ccc6892ee 908 }
mbed_official 35:f72ccc6892ee 909
mbed_official 35:f72ccc6892ee 910 static void bulk_trans(genelal_ed_t *p_g_ed) {
mbed_official 35:f72ccc6892ee 911 hctd_t *p_td = (hctd_t *)p_g_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 912 hced_t *p_ed = p_g_ed->p_curr_ed;
mbed_official 35:f72ccc6892ee 913 tdinfo_t td_info;
mbed_official 35:f72ccc6892ee 914 USB_HOST_CFG_PIPETBL_t *user_table = &usb_host_blk_ep_tbl1[0];
mbed_official 35:f72ccc6892ee 915 uint8_t wk_table[6];
mbed_official 35:f72ccc6892ee 916
mbed_official 35:f72ccc6892ee 917 get_td_info(p_g_ed, &td_info);
mbed_official 35:f72ccc6892ee 918
mbed_official 35:f72ccc6892ee 919 wk_table[0] = 0;
mbed_official 35:f72ccc6892ee 920 wk_table[1] = USB_HOST_ENDPOINT_DESC;
mbed_official 35:f72ccc6892ee 921 wk_table[2] = td_info.endpoint_no;
mbed_official 35:f72ccc6892ee 922 if (td_info.direction == 2) {
mbed_official 35:f72ccc6892ee 923 wk_table[2] |= USB_HOST_EP_IN;
mbed_official 35:f72ccc6892ee 924 }
mbed_official 35:f72ccc6892ee 925 wk_table[3] = USB_HOST_EP_BULK;
mbed_official 35:f72ccc6892ee 926 wk_table[4] = (uint8_t)td_info.msp;
mbed_official 35:f72ccc6892ee 927 wk_table[5] = (uint8_t)(td_info.msp >> 8);
mbed_official 35:f72ccc6892ee 928 p_g_ed->pipe_no = user_table->pipe_number;
mbed_official 35:f72ccc6892ee 929 usbx_api_host_SetEndpointTable(td_info.devadr, user_table, wk_table);
mbed_official 35:f72ccc6892ee 930
mbed_official 35:f72ccc6892ee 931 set_togle(p_g_ed->pipe_no, p_td, p_ed);
mbed_official 35:f72ccc6892ee 932
mbed_official 35:f72ccc6892ee 933 p_g_ed->trans_wait = 1;
mbed_official 35:f72ccc6892ee 934 if (connect_status == 0) {
mbed_official 35:f72ccc6892ee 935 ohciwrapp_loc_TransEnd(p_g_ed->pipe_no, TD_CC_DEVICENOTRESPONDING);
mbed_official 35:f72ccc6892ee 936 } else {
mbed_official 35:f72ccc6892ee 937 if (td_info.direction == 1) {
mbed_official 35:f72ccc6892ee 938 usbx_host_start_send_transfer(p_g_ed->pipe_no, td_info.count, p_td->currBufPtr);
mbed_official 35:f72ccc6892ee 939 } else {
mbed_official 35:f72ccc6892ee 940 usbx_host_start_receive_transfer(p_g_ed->pipe_no, td_info.count, p_td->currBufPtr);
mbed_official 35:f72ccc6892ee 941 }
mbed_official 35:f72ccc6892ee 942
mbed_official 35:f72ccc6892ee 943 (void)osSemaphoreWait(p_g_ed->semid_wait, BLK_TRANS_TIMEOUT);
mbed_official 35:f72ccc6892ee 944 usbx_host_stop_transfer(p_g_ed->pipe_no);
mbed_official 35:f72ccc6892ee 945 }
mbed_official 35:f72ccc6892ee 946 }
mbed_official 35:f72ccc6892ee 947
mbed_official 35:f72ccc6892ee 948 static void int_trans_setting(genelal_ed_t *p_g_ed, uint32_t index) {
mbed_official 35:f72ccc6892ee 949 hctd_t *p_td = (hctd_t *)p_g_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 950 hced_t *p_ed = p_g_ed->p_curr_ed;
mbed_official 35:f72ccc6892ee 951 tdinfo_t td_info;
mbed_official 35:f72ccc6892ee 952 USB_HOST_CFG_PIPETBL_t *user_table = &usb_host_int_ep_tbl1[index];
mbed_official 35:f72ccc6892ee 953 uint8_t wk_table[6];
mbed_official 35:f72ccc6892ee 954 uint32_t cycle_time;
mbed_official 35:f72ccc6892ee 955 uint16_t devadd;
mbed_official 35:f72ccc6892ee 956
mbed_official 35:f72ccc6892ee 957 get_td_info(p_g_ed, &td_info);
mbed_official 35:f72ccc6892ee 958
mbed_official 35:f72ccc6892ee 959 wk_table[0] = 0;
mbed_official 35:f72ccc6892ee 960 wk_table[1] = USB_HOST_ENDPOINT_DESC;
mbed_official 35:f72ccc6892ee 961 wk_table[2] = td_info.endpoint_no;
mbed_official 35:f72ccc6892ee 962 if (td_info.direction == 2) {
mbed_official 35:f72ccc6892ee 963 wk_table[2] |= USB_HOST_EP_IN;
mbed_official 35:f72ccc6892ee 964 }
mbed_official 35:f72ccc6892ee 965 wk_table[3] = USB_HOST_EP_INT;
mbed_official 35:f72ccc6892ee 966 wk_table[4] = (uint8_t)td_info.msp;
mbed_official 35:f72ccc6892ee 967 wk_table[5] = (uint8_t)(td_info.msp >> 8);
mbed_official 35:f72ccc6892ee 968 cycle_time = chk_cycle(p_ed);
mbed_official 35:f72ccc6892ee 969 p_g_ed->cycle_time = cycle_time;
mbed_official 35:f72ccc6892ee 970 user_table->pipe_cycle = 0;
mbed_official 35:f72ccc6892ee 971 while (cycle_time > 1) {
mbed_official 35:f72ccc6892ee 972 cycle_time >>= 1;
mbed_official 35:f72ccc6892ee 973 user_table->pipe_cycle++;
mbed_official 35:f72ccc6892ee 974 }
mbed_official 35:f72ccc6892ee 975 if (g_usbx_host_UsbDeviceSpeed == USB_HOST_HIGH_SPEED) {
mbed_official 35:f72ccc6892ee 976 usbx_host_get_devadd(td_info.devadr, &devadd);
mbed_official 35:f72ccc6892ee 977 if (RZA_IO_RegRead_16(&devadd, USB_DEVADDn_USBSPD_SHIFT, USB_DEVADDn_USBSPD) == USB_HOST_HIGH_SPEED) {
mbed_official 35:f72ccc6892ee 978 user_table->pipe_cycle += 3;
mbed_official 35:f72ccc6892ee 979 if (user_table->pipe_cycle > 7) {
mbed_official 35:f72ccc6892ee 980 user_table->pipe_cycle = 7;
mbed_official 35:f72ccc6892ee 981 }
mbed_official 35:f72ccc6892ee 982 }
mbed_official 35:f72ccc6892ee 983 }
mbed_official 35:f72ccc6892ee 984
mbed_official 35:f72ccc6892ee 985 p_g_ed->pipe_no = user_table->pipe_number;
mbed_official 35:f72ccc6892ee 986 usbx_api_host_SetEndpointTable(td_info.devadr, user_table, wk_table);
mbed_official 35:f72ccc6892ee 987
mbed_official 35:f72ccc6892ee 988 set_togle(p_g_ed->pipe_no, p_td, p_ed);
mbed_official 35:f72ccc6892ee 989 }
mbed_official 35:f72ccc6892ee 990
mbed_official 35:f72ccc6892ee 991 static uint32_t chk_cycle(hced_t *p_ed) {
mbed_official 35:f72ccc6892ee 992 uint32_t cnt;
mbed_official 35:f72ccc6892ee 993 uint32_t hit_cnt = 0;
mbed_official 35:f72ccc6892ee 994 uint32_t cycle_time = 1;
mbed_official 35:f72ccc6892ee 995 hcca_t *p_hcca;
mbed_official 35:f72ccc6892ee 996 hced_t *p_wk_ed;
mbed_official 35:f72ccc6892ee 997
mbed_official 35:f72ccc6892ee 998 p_hcca = (hcca_t *)p_usb_reg->HcHCCA;
mbed_official 35:f72ccc6892ee 999
mbed_official 35:f72ccc6892ee 1000 for (cnt = 0; cnt < 32; cnt++) {
mbed_official 35:f72ccc6892ee 1001 p_wk_ed = (hced_t *)p_hcca->IntTable[cnt];
mbed_official 35:f72ccc6892ee 1002 while (p_wk_ed != NULL) {
mbed_official 35:f72ccc6892ee 1003 if (p_wk_ed == p_ed) {
mbed_official 35:f72ccc6892ee 1004 hit_cnt++;
mbed_official 35:f72ccc6892ee 1005 break;
mbed_official 35:f72ccc6892ee 1006 }
mbed_official 35:f72ccc6892ee 1007 p_wk_ed = p_wk_ed->nextED;
mbed_official 35:f72ccc6892ee 1008 }
mbed_official 35:f72ccc6892ee 1009 }
mbed_official 35:f72ccc6892ee 1010 if (hit_cnt < 2) {
mbed_official 35:f72ccc6892ee 1011 cycle_time = 32;
mbed_official 35:f72ccc6892ee 1012 } else if (hit_cnt < 4) {
mbed_official 35:f72ccc6892ee 1013 cycle_time = 16;
mbed_official 35:f72ccc6892ee 1014 } else if (hit_cnt < 8) {
mbed_official 35:f72ccc6892ee 1015 cycle_time = 8;
mbed_official 35:f72ccc6892ee 1016 } else if (hit_cnt < 16) {
mbed_official 35:f72ccc6892ee 1017 cycle_time = 4;
mbed_official 35:f72ccc6892ee 1018 } else if (hit_cnt < 32) {
mbed_official 35:f72ccc6892ee 1019 cycle_time = 2;
mbed_official 35:f72ccc6892ee 1020 } else{
mbed_official 35:f72ccc6892ee 1021 cycle_time = 1;
mbed_official 35:f72ccc6892ee 1022 }
mbed_official 35:f72ccc6892ee 1023
mbed_official 35:f72ccc6892ee 1024 return cycle_time;
mbed_official 35:f72ccc6892ee 1025 }
mbed_official 35:f72ccc6892ee 1026
mbed_official 35:f72ccc6892ee 1027 static void int_trans(genelal_ed_t *p_g_ed) {
mbed_official 35:f72ccc6892ee 1028 hctd_t *p_td = (hctd_t *)p_g_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 1029 tdinfo_t td_info;
mbed_official 35:f72ccc6892ee 1030
mbed_official 35:f72ccc6892ee 1031 get_td_info(p_g_ed, &td_info);
mbed_official 35:f72ccc6892ee 1032 p_g_ed->trans_wait = 1;
mbed_official 35:f72ccc6892ee 1033 if (connect_status == 0) {
mbed_official 35:f72ccc6892ee 1034 ohciwrapp_loc_TransEnd(p_g_ed->pipe_no, TD_CC_DEVICENOTRESPONDING);
mbed_official 35:f72ccc6892ee 1035 } else {
mbed_official 35:f72ccc6892ee 1036 if (td_info.direction == 1) {
mbed_official 35:f72ccc6892ee 1037 usbx_host_start_send_transfer(p_g_ed->pipe_no, td_info.count, p_td->currBufPtr);
mbed_official 35:f72ccc6892ee 1038 } else {
mbed_official 35:f72ccc6892ee 1039 usbx_host_start_receive_transfer(p_g_ed->pipe_no, td_info.count, p_td->currBufPtr);
mbed_official 35:f72ccc6892ee 1040 }
mbed_official 35:f72ccc6892ee 1041 }
mbed_official 35:f72ccc6892ee 1042 }
mbed_official 35:f72ccc6892ee 1043
mbed_official 35:f72ccc6892ee 1044 static void get_td_info(genelal_ed_t *p_g_ed, tdinfo_t *p_td_info) {
mbed_official 35:f72ccc6892ee 1045 hced_t *p_ed = p_g_ed->p_curr_ed;
mbed_official 35:f72ccc6892ee 1046
mbed_official 35:f72ccc6892ee 1047 p_td_info->endpoint_no = (uint8_t)((p_ed->control >> 7) & 0x0000000F);
mbed_official 35:f72ccc6892ee 1048 p_td_info->msp = (p_ed->control >> 16) & 0x000007FF;
mbed_official 35:f72ccc6892ee 1049 p_td_info->devadr = p_ed->control & 0x0000000F;
mbed_official 35:f72ccc6892ee 1050 p_td_info->speed = (p_ed->control >> 13) & 0x00000001;
mbed_official 35:f72ccc6892ee 1051 p_td_info->direction = (p_ed->control >> 11) & 0x00000003;
mbed_official 35:f72ccc6892ee 1052
mbed_official 35:f72ccc6892ee 1053 if ((p_ed->control & ED_FORMAT) == 0) {
mbed_official 35:f72ccc6892ee 1054 hctd_t *p_td = (hctd_t *)p_g_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 1055
mbed_official 35:f72ccc6892ee 1056 if ((p_td_info->direction == 0) || (p_td_info->direction == 3)) {
mbed_official 35:f72ccc6892ee 1057 if ((p_td->control & TD_CTL_MSK_DP) == TD_SETUP) {
mbed_official 35:f72ccc6892ee 1058 p_td_info->direction = 0;
mbed_official 35:f72ccc6892ee 1059 } else if ((p_td->control & TD_CTL_MSK_DP) == TD_OUT) {
mbed_official 35:f72ccc6892ee 1060 p_td_info->direction = 1;
mbed_official 35:f72ccc6892ee 1061 } else {
mbed_official 35:f72ccc6892ee 1062 p_td_info->direction = 2;
mbed_official 35:f72ccc6892ee 1063 }
mbed_official 35:f72ccc6892ee 1064 }
mbed_official 35:f72ccc6892ee 1065 if (p_td->currBufPtr != NULL) {
mbed_official 35:f72ccc6892ee 1066 p_td_info->count = (uint32_t)p_td->bufEnd - (uint32_t)p_td->currBufPtr + 1;
mbed_official 35:f72ccc6892ee 1067 } else {
mbed_official 35:f72ccc6892ee 1068 p_td_info->count = 0;
mbed_official 35:f72ccc6892ee 1069 }
mbed_official 35:f72ccc6892ee 1070 } else {
mbed_official 35:f72ccc6892ee 1071 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 35:f72ccc6892ee 1072 hcisotd_t *p_isotd = (hcisotd_t *)p_g_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 1073
mbed_official 35:f72ccc6892ee 1074 if ((p_td_info->direction == 0) || (p_td_info->direction == 3)) {
mbed_official 35:f72ccc6892ee 1075 if ((p_isotd->control & TD_CTL_MSK_DP) == TD_SETUP) {
mbed_official 35:f72ccc6892ee 1076 p_td_info->direction = 0;
mbed_official 35:f72ccc6892ee 1077 } else if ((p_isotd->control & TD_CTL_MSK_DP) == TD_OUT) {
mbed_official 35:f72ccc6892ee 1078 p_td_info->direction = 1;
mbed_official 35:f72ccc6892ee 1079 } else {
mbed_official 35:f72ccc6892ee 1080 p_td_info->direction = 2;
mbed_official 35:f72ccc6892ee 1081 }
mbed_official 35:f72ccc6892ee 1082 }
mbed_official 35:f72ccc6892ee 1083 #endif
mbed_official 35:f72ccc6892ee 1084 }
mbed_official 35:f72ccc6892ee 1085 }
mbed_official 35:f72ccc6892ee 1086
mbed_official 35:f72ccc6892ee 1087 static void set_togle(uint32_t pipe, hctd_t *p_td, hced_t *p_ed) {
mbed_official 35:f72ccc6892ee 1088 if ((p_td->control & TD_CTL_MSK_T) == TD_TOGGLE_0) {
mbed_official 35:f72ccc6892ee 1089 usbx_host_set_sqclr(pipe);
mbed_official 35:f72ccc6892ee 1090 } else if ((p_td->control & TD_CTL_MSK_T) == TD_TOGGLE_1) {
mbed_official 35:f72ccc6892ee 1091 usbx_host_set_sqset(pipe);
mbed_official 35:f72ccc6892ee 1092 } else if ((p_ed->headTD & ED_TOGLE_CARRY) == 0) {
mbed_official 35:f72ccc6892ee 1093 usbx_host_set_sqclr(pipe);
mbed_official 35:f72ccc6892ee 1094 } else {
mbed_official 35:f72ccc6892ee 1095 usbx_host_set_sqset(pipe);
mbed_official 35:f72ccc6892ee 1096 }
mbed_official 35:f72ccc6892ee 1097 }
mbed_official 35:f72ccc6892ee 1098
mbed_official 35:f72ccc6892ee 1099 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 35:f72ccc6892ee 1100 static void iso_ed_task(void const * argument) {
mbed_official 35:f72ccc6892ee 1101 genelal_ed_t *p_iso_ed = &iso_ed[(uint32_t)argument];
mbed_official 35:f72ccc6892ee 1102 uint32_t wait_cnt = 0;
mbed_official 35:f72ccc6892ee 1103 hcca_t *p_hcca;
mbed_official 35:f72ccc6892ee 1104 hced_t *p_ed;
mbed_official 35:f72ccc6892ee 1105
mbed_official 35:f72ccc6892ee 1106 while (1) {
mbed_official 35:f72ccc6892ee 1107 (void)osSemaphoreWait(p_iso_ed->semid_list, osWaitForever);
mbed_official 35:f72ccc6892ee 1108 if (p_iso_ed->p_curr_ed == NULL) {
mbed_official 35:f72ccc6892ee 1109 p_hcca = (hcca_t *)p_usb_reg->HcHCCA;
mbed_official 35:f72ccc6892ee 1110 p_ed = (hced_t *)p_hcca->IntTable[0];
mbed_official 35:f72ccc6892ee 1111 while ((p_ed != NULL) && ((p_usb_reg->HcControl & OR_CONTROL_IE) != 0)
mbed_official 35:f72ccc6892ee 1112 && (p_iso_ed->p_curr_ed == NULL)) {
mbed_official 35:f72ccc6892ee 1113 if (iso_trans_doing(p_ed, (uint32_t)argument) == 0) {
mbed_official 35:f72ccc6892ee 1114 p_iso_ed->p_curr_ed = p_ed;
mbed_official 35:f72ccc6892ee 1115 if (chk_iso_ed(p_iso_ed) != 0) {
mbed_official 35:f72ccc6892ee 1116 iso_trans_setting(p_iso_ed, (uint32_t)argument);
mbed_official 35:f72ccc6892ee 1117 } else {
mbed_official 35:f72ccc6892ee 1118 p_iso_ed->p_curr_ed = NULL;
mbed_official 35:f72ccc6892ee 1119 }
mbed_official 35:f72ccc6892ee 1120 }
mbed_official 35:f72ccc6892ee 1121 p_ed = p_ed->nextED;
mbed_official 35:f72ccc6892ee 1122 }
mbed_official 35:f72ccc6892ee 1123 p_iso_ed->psw_idx = 0;
mbed_official 35:f72ccc6892ee 1124 }
mbed_official 35:f72ccc6892ee 1125 if (p_iso_ed->p_curr_ed != NULL) {
mbed_official 35:f72ccc6892ee 1126 while ((p_usb_reg->HcControl & OR_CONTROL_IE) != 0) {
mbed_official 35:f72ccc6892ee 1127 if (chk_iso_ed(p_iso_ed) != 0) {
mbed_official 35:f72ccc6892ee 1128 hcisotd_t *p_isotd = (hcisotd_t *)p_iso_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 1129 uint32_t starting_frame = p_isotd->control & 0x0000FFFF;
mbed_official 35:f72ccc6892ee 1130 uint32_t wait_time = 0;
mbed_official 35:f72ccc6892ee 1131 uint32_t wk_HcFmNumber = p_usb_reg->HcFmNumber;
mbed_official 35:f72ccc6892ee 1132
mbed_official 35:f72ccc6892ee 1133 if (starting_frame > wk_HcFmNumber) {
mbed_official 35:f72ccc6892ee 1134 wait_time = starting_frame - wk_HcFmNumber;
mbed_official 35:f72ccc6892ee 1135 } else {
mbed_official 35:f72ccc6892ee 1136 wait_time = (0xFFFF - wk_HcFmNumber) + starting_frame;
mbed_official 35:f72ccc6892ee 1137 }
mbed_official 35:f72ccc6892ee 1138 if ((wait_time >= 2) && (wait_time <= 1000)) {
mbed_official 35:f72ccc6892ee 1139 for (int cnt = 0; cnt < (wait_time - 1); cnt++) {
mbed_official 35:f72ccc6892ee 1140 osDelay(1);
mbed_official 35:f72ccc6892ee 1141 p_usb_reg->HcFmNumber = (wk_HcFmNumber + cnt) & 0x0000FFFF;
mbed_official 35:f72ccc6892ee 1142 }
mbed_official 35:f72ccc6892ee 1143 }
mbed_official 35:f72ccc6892ee 1144 p_iso_ed->psw_idx = 0;
mbed_official 35:f72ccc6892ee 1145 iso_trans(p_iso_ed);
mbed_official 35:f72ccc6892ee 1146 (void)osSemaphoreWait(p_iso_ed->semid_wait, osWaitForever);
mbed_official 35:f72ccc6892ee 1147 wait_cnt = 8;
mbed_official 35:f72ccc6892ee 1148 } else {
mbed_official 35:f72ccc6892ee 1149 if (wait_cnt > 0) {
mbed_official 35:f72ccc6892ee 1150 wait_cnt--;
mbed_official 35:f72ccc6892ee 1151 } else {
mbed_official 35:f72ccc6892ee 1152 p_iso_ed->p_curr_ed = NULL;
mbed_official 35:f72ccc6892ee 1153 }
mbed_official 35:f72ccc6892ee 1154 break;
mbed_official 35:f72ccc6892ee 1155 }
mbed_official 35:f72ccc6892ee 1156 }
mbed_official 35:f72ccc6892ee 1157 }
mbed_official 35:f72ccc6892ee 1158 (void)osSemaphoreRelease(p_iso_ed->semid_list);
mbed_official 35:f72ccc6892ee 1159 if (p_iso_ed->p_curr_ed == NULL) {
mbed_official 35:f72ccc6892ee 1160 osDelay(10);
mbed_official 35:f72ccc6892ee 1161 } else {
mbed_official 35:f72ccc6892ee 1162 osDelay(1);
mbed_official 35:f72ccc6892ee 1163 }
mbed_official 35:f72ccc6892ee 1164 }
mbed_official 35:f72ccc6892ee 1165 }
mbed_official 35:f72ccc6892ee 1166
mbed_official 35:f72ccc6892ee 1167 static int32_t iso_trans_doing(hced_t *p_ed, uint32_t index) {
mbed_official 35:f72ccc6892ee 1168 uint32_t cnt;
mbed_official 35:f72ccc6892ee 1169 int32_t ret = 0;
mbed_official 35:f72ccc6892ee 1170
mbed_official 35:f72ccc6892ee 1171 for (cnt = 0; cnt < ISO_TRANS_MAX_NUM; cnt++) {
mbed_official 35:f72ccc6892ee 1172 if ((index != cnt) && (iso_ed[cnt].p_curr_ed == p_ed)) {
mbed_official 35:f72ccc6892ee 1173 ret = 1;
mbed_official 35:f72ccc6892ee 1174 }
mbed_official 35:f72ccc6892ee 1175 }
mbed_official 35:f72ccc6892ee 1176
mbed_official 35:f72ccc6892ee 1177 return ret;
mbed_official 35:f72ccc6892ee 1178 }
mbed_official 35:f72ccc6892ee 1179
mbed_official 35:f72ccc6892ee 1180 static void chk_iso_td_done(genelal_ed_t *p_g_ed) {
mbed_official 35:f72ccc6892ee 1181 hcca_t *p_hcca;
mbed_official 35:f72ccc6892ee 1182 hcisotd_t *p_isotd = (hcisotd_t *)p_g_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 1183 uint32_t ConditionCode = RZA_IO_RegRead_32(&p_isotd->control, TD_CTL_SHFT_CC, TD_CTL_MSK_CC);
mbed_official 35:f72ccc6892ee 1184
mbed_official 35:f72ccc6892ee 1185 if ((ConditionCode != TD_CC_NOT_ACCESSED_1) && (ConditionCode != TD_CC_NOT_ACCESSED_2)) {
mbed_official 35:f72ccc6892ee 1186 p_g_ed->p_curr_ed->headTD = ((uint32_t)p_isotd->nextTD & 0xFFFFFFF0)
mbed_official 35:f72ccc6892ee 1187 | (p_g_ed->p_curr_ed->headTD & 0x0000000F);
mbed_official 35:f72ccc6892ee 1188 p_isotd->nextTD = (hcisotd_t *)p_usb_reg->HcDoneHead;
mbed_official 35:f72ccc6892ee 1189 p_usb_reg->HcDoneHead = (uint32_t)p_g_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 1190 if ((p_usb_reg->HcInterruptStatus & OR_INTR_STATUS_WDH) == 0) {
mbed_official 35:f72ccc6892ee 1191 p_hcca = (hcca_t *)p_usb_reg->HcHCCA;
mbed_official 35:f72ccc6892ee 1192 p_hcca->DoneHead = p_usb_reg->HcDoneHead;
mbed_official 35:f72ccc6892ee 1193 p_usb_reg->HcDoneHead = 0x00000000;
mbed_official 35:f72ccc6892ee 1194 p_usb_reg->HcInterruptStatus |= OR_INTR_STATUS_WDH;
mbed_official 35:f72ccc6892ee 1195 (void)osSemaphoreRelease(semid_cb);
mbed_official 35:f72ccc6892ee 1196 }
mbed_official 35:f72ccc6892ee 1197 }
mbed_official 35:f72ccc6892ee 1198 }
mbed_official 35:f72ccc6892ee 1199
mbed_official 35:f72ccc6892ee 1200 static int32_t chk_iso_ed(genelal_ed_t *p_g_ed){
mbed_official 35:f72ccc6892ee 1201 int32_t ret = 0;
mbed_official 35:f72ccc6892ee 1202 hced_t *p_ed = p_g_ed->p_curr_ed;
mbed_official 35:f72ccc6892ee 1203
mbed_official 35:f72ccc6892ee 1204 if (((p_ed->control & ED_SKIP) != 0)
mbed_official 35:f72ccc6892ee 1205 || ((p_ed->control & ED_FORMAT) == 0)
mbed_official 35:f72ccc6892ee 1206 || ((p_ed->headTD & ED_HALTED) != 0)
mbed_official 35:f72ccc6892ee 1207 || ((p_ed->tailTD & 0xFFFFFFF0) == (p_ed->headTD & 0xFFFFFFF0))) {
mbed_official 35:f72ccc6892ee 1208 /* Do Nothing */
mbed_official 35:f72ccc6892ee 1209 } else if ((p_ed->control & 0x0000007F) > 10) {
mbed_official 35:f72ccc6892ee 1210 p_ed->headTD |= ED_HALTED;
mbed_official 35:f72ccc6892ee 1211 } else {
mbed_official 35:f72ccc6892ee 1212 p_g_ed->p_curr_td = (void *)(p_ed->headTD & 0xFFFFFFF0);
mbed_official 35:f72ccc6892ee 1213 if (p_g_ed->p_curr_td == NULL) {
mbed_official 35:f72ccc6892ee 1214 p_ed->headTD |= ED_HALTED;
mbed_official 35:f72ccc6892ee 1215 } else {
mbed_official 35:f72ccc6892ee 1216 hcisotd_t *p_isotd = (hcisotd_t *)p_g_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 1217
mbed_official 35:f72ccc6892ee 1218 p_g_ed->p_start_buf = p_isotd->bufferPage0;
mbed_official 35:f72ccc6892ee 1219 ret = 1;
mbed_official 35:f72ccc6892ee 1220 }
mbed_official 35:f72ccc6892ee 1221 }
mbed_official 35:f72ccc6892ee 1222
mbed_official 35:f72ccc6892ee 1223 return ret;
mbed_official 35:f72ccc6892ee 1224 }
mbed_official 35:f72ccc6892ee 1225
mbed_official 35:f72ccc6892ee 1226 static void iso_trans_setting(genelal_ed_t *p_g_ed, uint32_t index) {
mbed_official 35:f72ccc6892ee 1227 tdinfo_t td_info;
mbed_official 35:f72ccc6892ee 1228 USB_HOST_CFG_PIPETBL_t *user_table = &usb_host_iso_ep_tbl1[index];
mbed_official 35:f72ccc6892ee 1229 uint8_t wk_table[6];
mbed_official 35:f72ccc6892ee 1230 uint16_t devadd;
mbed_official 35:f72ccc6892ee 1231
mbed_official 35:f72ccc6892ee 1232 get_td_info(p_g_ed, &td_info);
mbed_official 35:f72ccc6892ee 1233
mbed_official 35:f72ccc6892ee 1234 wk_table[0] = 0;
mbed_official 35:f72ccc6892ee 1235 wk_table[1] = USB_HOST_ENDPOINT_DESC;
mbed_official 35:f72ccc6892ee 1236 wk_table[2] = td_info.endpoint_no;
mbed_official 35:f72ccc6892ee 1237 if (td_info.direction == 2) {
mbed_official 35:f72ccc6892ee 1238 wk_table[2] |= USB_HOST_EP_IN;
mbed_official 35:f72ccc6892ee 1239 }
mbed_official 35:f72ccc6892ee 1240 wk_table[3] = USB_HOST_EP_ISO;
mbed_official 35:f72ccc6892ee 1241 wk_table[4] = (uint8_t)td_info.msp;
mbed_official 35:f72ccc6892ee 1242 wk_table[5] = (uint8_t)(td_info.msp >> 8);
mbed_official 35:f72ccc6892ee 1243 p_g_ed->cycle_time = 1;
mbed_official 35:f72ccc6892ee 1244 user_table->pipe_cycle = 0;
mbed_official 35:f72ccc6892ee 1245 if (g_usbx_host_UsbDeviceSpeed == USB_HOST_HIGH_SPEED) {
mbed_official 35:f72ccc6892ee 1246 usbx_host_get_devadd(td_info.devadr, &devadd);
mbed_official 35:f72ccc6892ee 1247 if (RZA_IO_RegRead_16(&devadd, USB_DEVADDn_USBSPD_SHIFT, USB_DEVADDn_USBSPD) == USB_HOST_HIGH_SPEED) {
mbed_official 35:f72ccc6892ee 1248 user_table->pipe_cycle += 3;
mbed_official 35:f72ccc6892ee 1249 }
mbed_official 35:f72ccc6892ee 1250 }
mbed_official 35:f72ccc6892ee 1251
mbed_official 35:f72ccc6892ee 1252 p_g_ed->pipe_no = user_table->pipe_number;
mbed_official 35:f72ccc6892ee 1253 usbx_api_host_SetEndpointTable(td_info.devadr, user_table, wk_table);
mbed_official 35:f72ccc6892ee 1254 }
mbed_official 35:f72ccc6892ee 1255
mbed_official 35:f72ccc6892ee 1256 static void iso_trans(genelal_ed_t *p_g_ed) {
mbed_official 35:f72ccc6892ee 1257 hcisotd_t *p_isotd = (hcisotd_t *)p_g_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 1258 tdinfo_t td_info;
mbed_official 35:f72ccc6892ee 1259 uint32_t buff_addr;
mbed_official 35:f72ccc6892ee 1260 uint32_t data_size;
mbed_official 35:f72ccc6892ee 1261
mbed_official 35:f72ccc6892ee 1262 if (((uint32_t)p_isotd->offsetPSW[p_g_ed->psw_idx] & 0x00001000) == 0) {
mbed_official 35:f72ccc6892ee 1263 buff_addr = (uint32_t)p_isotd->bufferPage0 & 0xFFFFF000;
mbed_official 35:f72ccc6892ee 1264 } else {
mbed_official 35:f72ccc6892ee 1265 buff_addr = (uint32_t)p_isotd->bufEnd & 0xFFFFF000;
mbed_official 35:f72ccc6892ee 1266 }
mbed_official 35:f72ccc6892ee 1267 buff_addr |= (uint32_t)p_isotd->offsetPSW[p_g_ed->psw_idx] & 0x00000FFF;
mbed_official 35:f72ccc6892ee 1268
mbed_official 35:f72ccc6892ee 1269 if (p_g_ed->psw_idx < RZA_IO_RegRead_32(&p_isotd->control, TD_CTL_SHFT_FC, TD_CTL_MSK_FC)) {
mbed_official 35:f72ccc6892ee 1270 data_size = p_isotd->offsetPSW[p_g_ed->psw_idx + 1] - p_isotd->offsetPSW[p_g_ed->psw_idx];
mbed_official 35:f72ccc6892ee 1271 } else {
mbed_official 35:f72ccc6892ee 1272 data_size = (uint32_t)p_isotd->bufEnd - buff_addr + 1;
mbed_official 35:f72ccc6892ee 1273 }
mbed_official 35:f72ccc6892ee 1274 p_isotd->offsetPSW[p_g_ed->psw_idx] = (uint16_t)data_size;
mbed_official 35:f72ccc6892ee 1275
mbed_official 35:f72ccc6892ee 1276 get_td_info(p_g_ed, &td_info);
mbed_official 35:f72ccc6892ee 1277 p_g_ed->trans_wait = 1;
mbed_official 35:f72ccc6892ee 1278 if (connect_status == 0) {
mbed_official 35:f72ccc6892ee 1279 ohciwrapp_loc_TransEnd(p_g_ed->pipe_no, TD_CC_DEVICENOTRESPONDING);
mbed_official 35:f72ccc6892ee 1280 } else {
mbed_official 35:f72ccc6892ee 1281 if (td_info.direction == 1) {
mbed_official 35:f72ccc6892ee 1282 usbx_host_start_send_transfer(p_g_ed->pipe_no, data_size, (uint8_t *)buff_addr);
mbed_official 35:f72ccc6892ee 1283 } else {
mbed_official 35:f72ccc6892ee 1284 usbx_host_start_receive_transfer(p_g_ed->pipe_no, data_size, (uint8_t *)buff_addr);
mbed_official 35:f72ccc6892ee 1285 }
mbed_official 35:f72ccc6892ee 1286 }
mbed_official 35:f72ccc6892ee 1287 }
mbed_official 35:f72ccc6892ee 1288 #endif
mbed_official 35:f72ccc6892ee 1289
mbed_official 35:f72ccc6892ee 1290 static void connect_check(void) {
mbed_official 35:f72ccc6892ee 1291 uint32_t type = 0;
mbed_official 35:f72ccc6892ee 1292 uint16_t stat;
mbed_official 35:f72ccc6892ee 1293 uint16_t devadd = 0;
mbed_official 35:f72ccc6892ee 1294 uint32_t wk_HcRhPortStatus1 = p_usb_reg->HcRhPortStatus1;
mbed_official 35:f72ccc6892ee 1295
mbed_official 35:f72ccc6892ee 1296 if (usbx_host_CheckAttach() == USB_HOST_ATTACH) {
mbed_official 35:f72ccc6892ee 1297 type = 1;
mbed_official 35:f72ccc6892ee 1298 }
mbed_official 35:f72ccc6892ee 1299
mbed_official 35:f72ccc6892ee 1300 if ((((wk_HcRhPortStatus1 & OR_RH_PORT_CCS) == 0) && (type == 0))
mbed_official 35:f72ccc6892ee 1301 || (((wk_HcRhPortStatus1 & OR_RH_PORT_CCS) != 0) && (type != 0))) {
mbed_official 35:f72ccc6892ee 1302 return;
mbed_official 35:f72ccc6892ee 1303 }
mbed_official 35:f72ccc6892ee 1304
mbed_official 35:f72ccc6892ee 1305 if (type == 0) {
mbed_official 35:f72ccc6892ee 1306 usbx_host_UsbDetach();
mbed_official 35:f72ccc6892ee 1307 wk_HcRhPortStatus1 &= ~OR_RH_PORT_CCS;
mbed_official 35:f72ccc6892ee 1308 } else {
mbed_official 35:f72ccc6892ee 1309 usbx_host_UsbAttach();
mbed_official 35:f72ccc6892ee 1310 stat = usbx_host_UsbBusReset();
mbed_official 35:f72ccc6892ee 1311 RZA_IO_RegWrite_16(&devadd, 0, USB_DEVADDn_UPPHUB_SHIFT, USB_DEVADDn_UPPHUB);
mbed_official 35:f72ccc6892ee 1312 RZA_IO_RegWrite_16(&devadd, 0, USB_DEVADDn_HUBPORT_SHIFT, USB_DEVADDn_HUBPORT);
mbed_official 35:f72ccc6892ee 1313 if (stat == USB_HOST_HSMODE) {
mbed_official 35:f72ccc6892ee 1314 wk_HcRhPortStatus1 &= ~OR_RH_PORT_LSDA;
mbed_official 35:f72ccc6892ee 1315 RZA_IO_RegWrite_16(&USB20X.SOFCFG, 0, USB_SOFCFG_TRNENSEL_SHIFT, USB_SOFCFG_TRNENSEL);
mbed_official 35:f72ccc6892ee 1316 g_usbx_host_UsbDeviceSpeed = USB_HOST_HIGH_SPEED;
mbed_official 35:f72ccc6892ee 1317 } else if (stat == USB_HOST_FSMODE) {
mbed_official 35:f72ccc6892ee 1318 wk_HcRhPortStatus1 &= ~OR_RH_PORT_LSDA;
mbed_official 35:f72ccc6892ee 1319 RZA_IO_RegWrite_16(&USB20X.SOFCFG, 0, USB_SOFCFG_TRNENSEL_SHIFT, USB_SOFCFG_TRNENSEL);
mbed_official 35:f72ccc6892ee 1320 g_usbx_host_UsbDeviceSpeed = USB_HOST_FULL_SPEED;
mbed_official 35:f72ccc6892ee 1321 } else {
mbed_official 35:f72ccc6892ee 1322 wk_HcRhPortStatus1 |= OR_RH_PORT_LSDA;
mbed_official 35:f72ccc6892ee 1323 RZA_IO_RegWrite_16(&USB20X.SOFCFG, 1, USB_SOFCFG_TRNENSEL_SHIFT, USB_SOFCFG_TRNENSEL);
mbed_official 35:f72ccc6892ee 1324 g_usbx_host_UsbDeviceSpeed = USB_HOST_LOW_SPEED;
mbed_official 35:f72ccc6892ee 1325 }
mbed_official 35:f72ccc6892ee 1326 RZA_IO_RegWrite_16(&devadd, g_usbx_host_UsbDeviceSpeed, USB_DEVADDn_USBSPD_SHIFT, USB_DEVADDn_USBSPD);
mbed_official 35:f72ccc6892ee 1327 usbx_host_init_pipe_status();
mbed_official 35:f72ccc6892ee 1328 usbx_host_set_devadd(USB_HOST_DEVICE_0, &devadd);
mbed_official 35:f72ccc6892ee 1329 wk_HcRhPortStatus1 |= OR_RH_PORT_CCS;
mbed_official 35:f72ccc6892ee 1330 }
mbed_official 35:f72ccc6892ee 1331 wk_HcRhPortStatus1 |= OR_RH_PORT_CSC;
mbed_official 35:f72ccc6892ee 1332 p_usb_reg->HcRhPortStatus1 = wk_HcRhPortStatus1;
mbed_official 35:f72ccc6892ee 1333 p_usb_reg->HcInterruptStatus |= OR_INTR_STATUS_RHSC;
mbed_official 35:f72ccc6892ee 1334 (void)memset(&split_ctl, 0, sizeof(split_ctl));
mbed_official 35:f72ccc6892ee 1335 }
mbed_official 35:f72ccc6892ee 1336
mbed_official 35:f72ccc6892ee 1337 void ohciwrapp_loc_Connect(uint32_t type) {
mbed_official 35:f72ccc6892ee 1338 uint32_t cnt;
mbed_official 35:f72ccc6892ee 1339
mbed_official 35:f72ccc6892ee 1340 connect_status = type;
mbed_official 35:f72ccc6892ee 1341 connect_change = type;
mbed_official 35:f72ccc6892ee 1342 if (type == 0) {
mbed_official 35:f72ccc6892ee 1343 if (ctl_ed.trans_wait == 1) {
mbed_official 35:f72ccc6892ee 1344 ohciwrapp_loc_TransEnd(ctl_ed.pipe_no, TD_CC_DEVICENOTRESPONDING);
mbed_official 35:f72ccc6892ee 1345 }
mbed_official 35:f72ccc6892ee 1346 if (blk_ed.trans_wait == 1) {
mbed_official 35:f72ccc6892ee 1347 ohciwrapp_loc_TransEnd(blk_ed.pipe_no, TD_CC_DEVICENOTRESPONDING);
mbed_official 35:f72ccc6892ee 1348 }
mbed_official 35:f72ccc6892ee 1349 for (cnt = 0; cnt< INT_TRANS_MAX_NUM; cnt++) {
mbed_official 35:f72ccc6892ee 1350 if (int_ed[cnt].trans_wait == 1) {
mbed_official 35:f72ccc6892ee 1351 ohciwrapp_loc_TransEnd(int_ed[cnt].pipe_no, TD_CC_DEVICENOTRESPONDING);
mbed_official 35:f72ccc6892ee 1352 }
mbed_official 35:f72ccc6892ee 1353 }
mbed_official 35:f72ccc6892ee 1354 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 35:f72ccc6892ee 1355 for (cnt = 0; cnt< ISO_TRANS_MAX_NUM; cnt++) {
mbed_official 35:f72ccc6892ee 1356 if (iso_ed[cnt].trans_wait == 1) {
mbed_official 35:f72ccc6892ee 1357 hced_t *p_ed = iso_ed[cnt].p_curr_ed;
mbed_official 35:f72ccc6892ee 1358
mbed_official 35:f72ccc6892ee 1359 p_ed->headTD |= ED_HALTED;
mbed_official 35:f72ccc6892ee 1360 ohciwrapp_loc_TransEnd(iso_ed[cnt].pipe_no, TD_CC_DEVICENOTRESPONDING);
mbed_official 35:f72ccc6892ee 1361 }
mbed_official 35:f72ccc6892ee 1362 }
mbed_official 35:f72ccc6892ee 1363 #endif
mbed_official 35:f72ccc6892ee 1364 }
mbed_official 35:f72ccc6892ee 1365 (void)osSemaphoreRelease(semid_cb);
mbed_official 35:f72ccc6892ee 1366 }
mbed_official 35:f72ccc6892ee 1367
mbed_official 35:f72ccc6892ee 1368 void ohciwrapp_loc_TransEnd(uint32_t pipe, uint32_t ConditionCode) {
mbed_official 35:f72ccc6892ee 1369 uint32_t periodic = 0;
mbed_official 35:f72ccc6892ee 1370 uint32_t cnt;
mbed_official 35:f72ccc6892ee 1371 uint32_t sqmon;
mbed_official 35:f72ccc6892ee 1372 hced_t *p_ed;
mbed_official 35:f72ccc6892ee 1373 genelal_ed_t *p_wait_ed = NULL;
mbed_official 35:f72ccc6892ee 1374
mbed_official 35:f72ccc6892ee 1375 if (ctl_ed.pipe_no == pipe) {
mbed_official 35:f72ccc6892ee 1376 p_wait_ed = &ctl_ed;
mbed_official 35:f72ccc6892ee 1377 } else if (blk_ed.pipe_no == pipe) {
mbed_official 35:f72ccc6892ee 1378 p_wait_ed = &blk_ed;
mbed_official 35:f72ccc6892ee 1379 } else {
mbed_official 35:f72ccc6892ee 1380 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 35:f72ccc6892ee 1381 if (p_wait_ed == NULL) {
mbed_official 35:f72ccc6892ee 1382 for (cnt = 0; cnt< ISO_TRANS_MAX_NUM; cnt++) {
mbed_official 35:f72ccc6892ee 1383 if (iso_ed[cnt].pipe_no == pipe) {
mbed_official 35:f72ccc6892ee 1384 p_wait_ed = &iso_ed[cnt];
mbed_official 35:f72ccc6892ee 1385 break;
mbed_official 35:f72ccc6892ee 1386 }
mbed_official 35:f72ccc6892ee 1387 }
mbed_official 35:f72ccc6892ee 1388 }
mbed_official 35:f72ccc6892ee 1389 #endif
mbed_official 35:f72ccc6892ee 1390 if (p_wait_ed == NULL) {
mbed_official 35:f72ccc6892ee 1391 for (cnt = 0; cnt< INT_TRANS_MAX_NUM; cnt++) {
mbed_official 35:f72ccc6892ee 1392 if (int_ed[cnt].pipe_no == pipe) {
mbed_official 35:f72ccc6892ee 1393 p_wait_ed = &int_ed[cnt];
mbed_official 35:f72ccc6892ee 1394 periodic = 1;
mbed_official 35:f72ccc6892ee 1395 break;
mbed_official 35:f72ccc6892ee 1396 }
mbed_official 35:f72ccc6892ee 1397 }
mbed_official 35:f72ccc6892ee 1398 }
mbed_official 35:f72ccc6892ee 1399 }
mbed_official 35:f72ccc6892ee 1400
mbed_official 35:f72ccc6892ee 1401 if (p_wait_ed == NULL) {
mbed_official 35:f72ccc6892ee 1402 return;
mbed_official 35:f72ccc6892ee 1403 }
mbed_official 35:f72ccc6892ee 1404 p_ed = p_wait_ed->p_curr_ed;
mbed_official 35:f72ccc6892ee 1405 if (p_ed == NULL) {
mbed_official 35:f72ccc6892ee 1406 return;
mbed_official 35:f72ccc6892ee 1407 }
mbed_official 35:f72ccc6892ee 1408
mbed_official 35:f72ccc6892ee 1409 if ((p_ed->control & ED_FORMAT) == 0) {
mbed_official 35:f72ccc6892ee 1410 hctd_t *p_td = (hctd_t *)p_wait_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 1411
mbed_official 35:f72ccc6892ee 1412 if (p_td != NULL) {
mbed_official 35:f72ccc6892ee 1413 if (ConditionCode == TD_CC_NOERROR) {
mbed_official 35:f72ccc6892ee 1414 /* ErrorCount */
mbed_official 35:f72ccc6892ee 1415 RZA_IO_RegWrite_32(&p_td->control, 0, TD_CTL_SHFT_EC, TD_CTL_MSK_EC);
mbed_official 35:f72ccc6892ee 1416
mbed_official 35:f72ccc6892ee 1417 /* CurrentBufferPointer */
mbed_official 35:f72ccc6892ee 1418 p_td->currBufPtr += ((uint32_t)p_td->bufEnd - (uint32_t)p_td->currBufPtr + 1) - g_usbx_host_data_count[pipe];
mbed_official 35:f72ccc6892ee 1419 } else {
mbed_official 35:f72ccc6892ee 1420 /* ErrorCount */
mbed_official 35:f72ccc6892ee 1421 RZA_IO_RegWrite_32(&p_td->control, 3, TD_CTL_SHFT_EC, TD_CTL_MSK_EC);
mbed_official 35:f72ccc6892ee 1422 }
mbed_official 35:f72ccc6892ee 1423
mbed_official 35:f72ccc6892ee 1424 /* DataToggle */
mbed_official 35:f72ccc6892ee 1425 sqmon = usbx_host_get_sqmon(pipe);
mbed_official 35:f72ccc6892ee 1426 RZA_IO_RegWrite_32(&p_td->control, sqmon, TD_CTL_SHFT_T, TD_CTL_MSK_T);
mbed_official 35:f72ccc6892ee 1427 if (sqmon == 0) {
mbed_official 35:f72ccc6892ee 1428 p_ed->headTD &= ~ED_TOGLE_CARRY;
mbed_official 35:f72ccc6892ee 1429 } else {
mbed_official 35:f72ccc6892ee 1430 p_ed->headTD |= ED_TOGLE_CARRY;
mbed_official 35:f72ccc6892ee 1431 }
mbed_official 35:f72ccc6892ee 1432
mbed_official 35:f72ccc6892ee 1433 /* ConditionCode */
mbed_official 35:f72ccc6892ee 1434 RZA_IO_RegWrite_32(&p_td->control, ConditionCode, TD_CTL_SHFT_CC, TD_CTL_MSK_CC);
mbed_official 35:f72ccc6892ee 1435
mbed_official 35:f72ccc6892ee 1436 if (p_wait_ed == &ctl_ed) {
mbed_official 35:f72ccc6892ee 1437 chk_split_trans_setting(&ctl_ed);
mbed_official 35:f72ccc6892ee 1438 }
mbed_official 35:f72ccc6892ee 1439 chk_genelal_td_done(p_wait_ed);
mbed_official 35:f72ccc6892ee 1440
mbed_official 35:f72ccc6892ee 1441 if (periodic != 0) {
mbed_official 35:f72ccc6892ee 1442 if (chk_genelal_ed(p_wait_ed) != 0) {
mbed_official 35:f72ccc6892ee 1443 int_trans(p_wait_ed);
mbed_official 35:f72ccc6892ee 1444 } else {
mbed_official 35:f72ccc6892ee 1445 p_wait_ed->trans_wait = 0;
mbed_official 35:f72ccc6892ee 1446 (void)osSemaphoreRelease(p_wait_ed->semid_wait);
mbed_official 35:f72ccc6892ee 1447 }
mbed_official 35:f72ccc6892ee 1448 } else {
mbed_official 35:f72ccc6892ee 1449 p_wait_ed->trans_wait = 0;
mbed_official 35:f72ccc6892ee 1450 (void)osSemaphoreRelease(p_wait_ed->semid_wait);
mbed_official 35:f72ccc6892ee 1451 }
mbed_official 35:f72ccc6892ee 1452 }
mbed_official 35:f72ccc6892ee 1453 } else {
mbed_official 35:f72ccc6892ee 1454 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 35:f72ccc6892ee 1455 hcisotd_t *p_isotd = (hcisotd_t *)p_wait_ed->p_curr_td;
mbed_official 35:f72ccc6892ee 1456 uint32_t next_trans = 0;
mbed_official 35:f72ccc6892ee 1457
mbed_official 35:f72ccc6892ee 1458 if (p_isotd != NULL) {
mbed_official 35:f72ccc6892ee 1459 usbx_host_stop_transfer(pipe);
mbed_official 35:f72ccc6892ee 1460 p_usb_reg->HcFmNumber = ((p_isotd->control & 0x0000FFFF) + p_wait_ed->psw_idx) & 0x0000FFFF;
mbed_official 35:f72ccc6892ee 1461
mbed_official 35:f72ccc6892ee 1462 /* Size of packet */
mbed_official 35:f72ccc6892ee 1463 p_isotd->offsetPSW[p_wait_ed->psw_idx] -= g_usbx_host_data_count[pipe];
mbed_official 35:f72ccc6892ee 1464
mbed_official 35:f72ccc6892ee 1465 /* ConditionCode */
mbed_official 35:f72ccc6892ee 1466 RZA_IO_RegWrite_32(&p_isotd->control, ConditionCode, TD_CTL_SHFT_CC, TD_CTL_MSK_CC);
mbed_official 35:f72ccc6892ee 1467 RZA_IO_RegWrite_16(&p_isotd->offsetPSW[p_wait_ed->psw_idx],
mbed_official 35:f72ccc6892ee 1468 (uint16_t)ConditionCode, TD_PSW_SHFT_CC, TD_PSW_MSK_CC);
mbed_official 35:f72ccc6892ee 1469
mbed_official 35:f72ccc6892ee 1470 if (usbx_host_CheckAttach() != USB_HOST_ATTACH) {
mbed_official 35:f72ccc6892ee 1471 p_ed->headTD |= ED_HALTED;
mbed_official 35:f72ccc6892ee 1472 }
mbed_official 35:f72ccc6892ee 1473 if (p_wait_ed->psw_idx >= RZA_IO_RegRead_32(&p_isotd->control, TD_CTL_SHFT_FC, TD_CTL_MSK_FC)) {
mbed_official 35:f72ccc6892ee 1474 p_wait_ed->psw_idx = 0;
mbed_official 35:f72ccc6892ee 1475 chk_iso_td_done(p_wait_ed);
mbed_official 35:f72ccc6892ee 1476 } else {
mbed_official 35:f72ccc6892ee 1477 p_wait_ed->psw_idx++;
mbed_official 35:f72ccc6892ee 1478 }
mbed_official 35:f72ccc6892ee 1479 if (chk_iso_ed(p_wait_ed) != 0) {
mbed_official 35:f72ccc6892ee 1480 iso_trans(p_wait_ed);
mbed_official 35:f72ccc6892ee 1481 next_trans = 1;
mbed_official 35:f72ccc6892ee 1482 }
mbed_official 35:f72ccc6892ee 1483 if (next_trans == 0) {
mbed_official 35:f72ccc6892ee 1484 p_wait_ed->trans_wait = 0;
mbed_official 35:f72ccc6892ee 1485 (void)osSemaphoreRelease(p_wait_ed->semid_wait);
mbed_official 35:f72ccc6892ee 1486 }
mbed_official 35:f72ccc6892ee 1487 }
mbed_official 35:f72ccc6892ee 1488 #endif
mbed_official 35:f72ccc6892ee 1489 }
mbed_official 35:f72ccc6892ee 1490
mbed_official 35:f72ccc6892ee 1491 }
mbed_official 35:f72ccc6892ee 1492