USBHost library. NOTE: This library is only officially supported on the LPC1768 platform. For more information, please see the handbook page.

Dependencies:   FATFileSystem mbed-rtos

Dependents:   BTstack WallbotWii SD to Flash Data Transfer USBHost-MSD_HelloWorld ... more

Legacy Warning

This is an mbed 2 library. To learn more about mbed OS 5, visit the docs.

Pull requests against this repository are no longer supported. Please raise against mbed OS 5 as documented above.

Committer:
mbed_official
Date:
Fri Oct 16 07:46:31 2015 +0100
Revision:
32:140defdf151c
Parent:
29:d3b77affed28
Synchronized with git revision 856efdc67db6f7de450e78624ace39a2917f2f33

Full URL: https://github.com/mbedmicro/mbed/commit/856efdc67db6f7de450e78624ace39a2917f2f33/

NUCLEO_F303K8 - Dev nucleo f303k8

Who changed what in which revision?

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