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:
Tue Mar 31 16:15:42 2015 +0100
Revision:
29:d3b77affed28
Parent:
27:4206883f4cb7
Child:
32:140defdf151c
Synchronized with git revision 251f3f8b55a4dc98b831c80e032464ed45cce309

Full URL: https://github.com/mbedmicro/mbed/commit/251f3f8b55a4dc98b831c80e032464ed45cce309/

[RZ/A1H]Add some function(USB 2port, NVIC wrapper) and modify some settings(OS, Terminal).

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 uint32_t iso_chk_starting_frame(genelal_ed_t *p_g_ed);
mbed_official 29:d3b77affed28 203 static void iso_trans(genelal_ed_t *p_g_ed);
mbed_official 29:d3b77affed28 204 #endif
mbed_official 27:4206883f4cb7 205 static void connect_check(void);
mbed_official 27:4206883f4cb7 206
mbed_official 29:d3b77affed28 207 extern USB_HOST_CFG_PIPETBL_t usb_host_blk_ep_tbl1[];
mbed_official 29:d3b77affed28 208 extern USB_HOST_CFG_PIPETBL_t usb_host_int_ep_tbl1[];
mbed_official 29:d3b77affed28 209 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 29:d3b77affed28 210 extern USB_HOST_CFG_PIPETBL_t usb_host_iso_ep_tbl1[];
mbed_official 29:d3b77affed28 211 #endif
mbed_official 27:4206883f4cb7 212
mbed_official 27:4206883f4cb7 213 static usb_ohci_reg_t usb_reg;
mbed_official 27:4206883f4cb7 214 static usb_ohci_reg_t *p_usb_reg = &usb_reg;
mbed_official 27:4206883f4cb7 215 static usbisr_fnc_t *p_usbisr_cb = NULL;
mbed_official 27:4206883f4cb7 216 static osSemaphoreId semid_cb = NULL;
mbed_official 27:4206883f4cb7 217 static uint32_t connect_change = 0xFFFFFFFF;
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 29:d3b77affed28 286 osThreadDef(iso_ed_task_1, osPriorityNormal, 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 29:d3b77affed28 292 osThreadDef(iso_ed_task_2, osPriorityNormal, 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 27:4206883f4cb7 881
mbed_official 27:4206883f4cb7 882 if (td_info.direction == 0) {
mbed_official 27:4206883f4cb7 883 uint16_t Req = (p_td->currBufPtr[1] << 8) + p_td->currBufPtr[0];
mbed_official 27:4206883f4cb7 884 uint16_t Val = (p_td->currBufPtr[3] << 8) + p_td->currBufPtr[2];
mbed_official 27:4206883f4cb7 885 uint16_t Indx = (p_td->currBufPtr[5] << 8) + p_td->currBufPtr[4];
mbed_official 27:4206883f4cb7 886 uint16_t Len = (p_td->currBufPtr[7] << 8) + p_td->currBufPtr[6];
mbed_official 27:4206883f4cb7 887
mbed_official 29:d3b77affed28 888 g_usbx_host_data_pointer[USB_HOST_PIPE0] = p_td->bufEnd;
mbed_official 29:d3b77affed28 889 usbx_host_SetupStage(Req, Val, Indx, Len);
mbed_official 27:4206883f4cb7 890 } else if (td_info.direction == 1) {
mbed_official 29:d3b77affed28 891 usbx_host_CtrlWriteStart(td_info.count, p_td->currBufPtr);
mbed_official 27:4206883f4cb7 892 } else {
mbed_official 29:d3b77affed28 893 usbx_host_CtrlReadStart(td_info.count, p_td->currBufPtr);
mbed_official 27:4206883f4cb7 894 }
mbed_official 27:4206883f4cb7 895
mbed_official 27:4206883f4cb7 896 (void)osSemaphoreWait(p_g_ed->semid_wait, CTL_TRANS_TIMEOUT);
mbed_official 27:4206883f4cb7 897 if (p_g_ed->trans_wait == 1) {
mbed_official 27:4206883f4cb7 898 p_g_ed->trans_wait = 0;
mbed_official 27:4206883f4cb7 899 RZA_IO_RegWrite_32(&p_td->control, TD_CC_DEVICENOTRESPONDING, TD_CTL_SHFT_CC, TD_CTL_MSK_CC);
mbed_official 27:4206883f4cb7 900 }
mbed_official 27:4206883f4cb7 901
mbed_official 29:d3b77affed28 902 g_usbx_host_CmdStage &= (~USB_HOST_CMD_FIELD);
mbed_official 29:d3b77affed28 903 g_usbx_host_CmdStage |= USB_HOST_CMD_IDLE;
mbed_official 29:d3b77affed28 904 g_usbx_host_pipe_status[USB_HOST_PIPE0] = USB_HOST_PIPE_IDLE;
mbed_official 27:4206883f4cb7 905 }
mbed_official 27:4206883f4cb7 906
mbed_official 27:4206883f4cb7 907 static void bulk_trans(genelal_ed_t *p_g_ed) {
mbed_official 29:d3b77affed28 908 hctd_t *p_td = (hctd_t *)p_g_ed->p_curr_td;
mbed_official 27:4206883f4cb7 909 hced_t *p_ed = p_g_ed->p_curr_ed;
mbed_official 27:4206883f4cb7 910 tdinfo_t td_info;
mbed_official 29:d3b77affed28 911 USB_HOST_CFG_PIPETBL_t *user_table = &usb_host_blk_ep_tbl1[0];
mbed_official 27:4206883f4cb7 912 uint8_t wk_table[6];
mbed_official 27:4206883f4cb7 913
mbed_official 27:4206883f4cb7 914 get_td_info(p_g_ed, &td_info);
mbed_official 27:4206883f4cb7 915
mbed_official 27:4206883f4cb7 916 wk_table[0] = 0;
mbed_official 27:4206883f4cb7 917 wk_table[1] = USB_HOST_ENDPOINT_DESC;
mbed_official 27:4206883f4cb7 918 wk_table[2] = td_info.endpoint_no;
mbed_official 27:4206883f4cb7 919 if (td_info.direction == 2) {
mbed_official 27:4206883f4cb7 920 wk_table[2] |= USB_HOST_EP_IN;
mbed_official 27:4206883f4cb7 921 }
mbed_official 27:4206883f4cb7 922 wk_table[3] = USB_HOST_EP_BULK;
mbed_official 27:4206883f4cb7 923 wk_table[4] = (uint8_t)td_info.msp;
mbed_official 27:4206883f4cb7 924 wk_table[5] = (uint8_t)(td_info.msp >> 8);
mbed_official 27:4206883f4cb7 925 p_g_ed->pipe_no = user_table->pipe_number;
mbed_official 29:d3b77affed28 926 usbx_api_host_SetEndpointTable(td_info.devadr, user_table, wk_table);
mbed_official 27:4206883f4cb7 927
mbed_official 27:4206883f4cb7 928 set_togle(p_g_ed->pipe_no, p_td, p_ed);
mbed_official 27:4206883f4cb7 929
mbed_official 27:4206883f4cb7 930 p_g_ed->trans_wait = 1;
mbed_official 27:4206883f4cb7 931 if (td_info.direction == 1) {
mbed_official 29:d3b77affed28 932 usbx_host_start_send_transfer(p_g_ed->pipe_no, td_info.count, p_td->currBufPtr);
mbed_official 27:4206883f4cb7 933 } else {
mbed_official 29:d3b77affed28 934 usbx_host_start_receive_transfer(p_g_ed->pipe_no, td_info.count, p_td->currBufPtr);
mbed_official 27:4206883f4cb7 935 }
mbed_official 27:4206883f4cb7 936
mbed_official 27:4206883f4cb7 937 (void)osSemaphoreWait(p_g_ed->semid_wait, BLK_TRANS_TIMEOUT);
mbed_official 29:d3b77affed28 938 usbx_host_stop_transfer(p_g_ed->pipe_no);
mbed_official 27:4206883f4cb7 939 }
mbed_official 27:4206883f4cb7 940
mbed_official 27:4206883f4cb7 941 static void int_trans_setting(genelal_ed_t *p_g_ed, uint32_t index) {
mbed_official 29:d3b77affed28 942 hctd_t *p_td = (hctd_t *)p_g_ed->p_curr_td;
mbed_official 27:4206883f4cb7 943 hced_t *p_ed = p_g_ed->p_curr_ed;
mbed_official 27:4206883f4cb7 944 tdinfo_t td_info;
mbed_official 29:d3b77affed28 945 USB_HOST_CFG_PIPETBL_t *user_table = &usb_host_int_ep_tbl1[index];
mbed_official 27:4206883f4cb7 946 uint8_t wk_table[6];
mbed_official 27:4206883f4cb7 947 uint32_t cycle_time;
mbed_official 27:4206883f4cb7 948 uint16_t devadd;
mbed_official 27:4206883f4cb7 949
mbed_official 27:4206883f4cb7 950 get_td_info(p_g_ed, &td_info);
mbed_official 27:4206883f4cb7 951
mbed_official 27:4206883f4cb7 952 wk_table[0] = 0;
mbed_official 27:4206883f4cb7 953 wk_table[1] = USB_HOST_ENDPOINT_DESC;
mbed_official 27:4206883f4cb7 954 wk_table[2] = td_info.endpoint_no;
mbed_official 27:4206883f4cb7 955 if (td_info.direction == 2) {
mbed_official 27:4206883f4cb7 956 wk_table[2] |= USB_HOST_EP_IN;
mbed_official 27:4206883f4cb7 957 }
mbed_official 27:4206883f4cb7 958 wk_table[3] = USB_HOST_EP_INT;
mbed_official 27:4206883f4cb7 959 wk_table[4] = (uint8_t)td_info.msp;
mbed_official 27:4206883f4cb7 960 wk_table[5] = (uint8_t)(td_info.msp >> 8);
mbed_official 27:4206883f4cb7 961 cycle_time = chk_cycle(p_ed);
mbed_official 27:4206883f4cb7 962 p_g_ed->cycle_time = cycle_time;
mbed_official 27:4206883f4cb7 963 user_table->pipe_cycle = 0;
mbed_official 27:4206883f4cb7 964 while (cycle_time > 1) {
mbed_official 27:4206883f4cb7 965 cycle_time >>= 1;
mbed_official 27:4206883f4cb7 966 user_table->pipe_cycle++;
mbed_official 27:4206883f4cb7 967 }
mbed_official 29:d3b77affed28 968 if (g_usbx_host_UsbDeviceSpeed == USB_HOST_HIGH_SPEED) {
mbed_official 29:d3b77affed28 969 usbx_host_get_devadd(td_info.devadr, &devadd);
mbed_official 27:4206883f4cb7 970 if (RZA_IO_RegRead_16(&devadd, USB_DEVADDn_USBSPD_SHIFT, USB_DEVADDn_USBSPD) == USB_HOST_HIGH_SPEED) {
mbed_official 27:4206883f4cb7 971 user_table->pipe_cycle += 3;
mbed_official 27:4206883f4cb7 972 if (user_table->pipe_cycle > 7) {
mbed_official 27:4206883f4cb7 973 user_table->pipe_cycle = 7;
mbed_official 27:4206883f4cb7 974 }
mbed_official 27:4206883f4cb7 975 }
mbed_official 27:4206883f4cb7 976 }
mbed_official 27:4206883f4cb7 977
mbed_official 27:4206883f4cb7 978 p_g_ed->pipe_no = user_table->pipe_number;
mbed_official 29:d3b77affed28 979 usbx_api_host_SetEndpointTable(td_info.devadr, user_table, wk_table);
mbed_official 27:4206883f4cb7 980
mbed_official 27:4206883f4cb7 981 set_togle(p_g_ed->pipe_no, p_td, p_ed);
mbed_official 27:4206883f4cb7 982 }
mbed_official 27:4206883f4cb7 983
mbed_official 27:4206883f4cb7 984 static uint32_t chk_cycle(hced_t *p_ed) {
mbed_official 27:4206883f4cb7 985 uint32_t cnt;
mbed_official 27:4206883f4cb7 986 uint32_t hit_cnt = 0;
mbed_official 27:4206883f4cb7 987 uint32_t cycle_time = 1;
mbed_official 27:4206883f4cb7 988 hcca_t *p_hcca;
mbed_official 27:4206883f4cb7 989 hced_t *p_wk_ed;
mbed_official 27:4206883f4cb7 990
mbed_official 27:4206883f4cb7 991 p_hcca = (hcca_t *)p_usb_reg->HcHCCA;
mbed_official 27:4206883f4cb7 992
mbed_official 27:4206883f4cb7 993 for (cnt = 0; cnt < 32; cnt++) {
mbed_official 27:4206883f4cb7 994 p_wk_ed = (hced_t *)p_hcca->IntTable[cnt];
mbed_official 27:4206883f4cb7 995 while (p_wk_ed != NULL) {
mbed_official 27:4206883f4cb7 996 if (p_wk_ed == p_ed) {
mbed_official 27:4206883f4cb7 997 hit_cnt++;
mbed_official 27:4206883f4cb7 998 break;
mbed_official 27:4206883f4cb7 999 }
mbed_official 27:4206883f4cb7 1000 p_wk_ed = p_wk_ed->nextED;
mbed_official 27:4206883f4cb7 1001 }
mbed_official 27:4206883f4cb7 1002 }
mbed_official 27:4206883f4cb7 1003 if (hit_cnt < 2) {
mbed_official 27:4206883f4cb7 1004 cycle_time = 32;
mbed_official 27:4206883f4cb7 1005 } else if (hit_cnt < 4) {
mbed_official 27:4206883f4cb7 1006 cycle_time = 16;
mbed_official 27:4206883f4cb7 1007 } else if (hit_cnt < 8) {
mbed_official 27:4206883f4cb7 1008 cycle_time = 8;
mbed_official 27:4206883f4cb7 1009 } else if (hit_cnt < 16) {
mbed_official 27:4206883f4cb7 1010 cycle_time = 4;
mbed_official 27:4206883f4cb7 1011 } else if (hit_cnt < 32) {
mbed_official 27:4206883f4cb7 1012 cycle_time = 2;
mbed_official 27:4206883f4cb7 1013 } else{
mbed_official 27:4206883f4cb7 1014 cycle_time = 1;
mbed_official 27:4206883f4cb7 1015 }
mbed_official 27:4206883f4cb7 1016
mbed_official 27:4206883f4cb7 1017 return cycle_time;
mbed_official 27:4206883f4cb7 1018 }
mbed_official 27:4206883f4cb7 1019
mbed_official 27:4206883f4cb7 1020 static void int_trans(genelal_ed_t *p_g_ed) {
mbed_official 29:d3b77affed28 1021 hctd_t *p_td = (hctd_t *)p_g_ed->p_curr_td;
mbed_official 27:4206883f4cb7 1022 tdinfo_t td_info;
mbed_official 27:4206883f4cb7 1023
mbed_official 27:4206883f4cb7 1024 get_td_info(p_g_ed, &td_info);
mbed_official 27:4206883f4cb7 1025 p_g_ed->trans_wait = 1;
mbed_official 27:4206883f4cb7 1026 if (td_info.direction == 1) {
mbed_official 29:d3b77affed28 1027 usbx_host_start_send_transfer(p_g_ed->pipe_no, td_info.count, p_td->currBufPtr);
mbed_official 27:4206883f4cb7 1028 } else {
mbed_official 29:d3b77affed28 1029 usbx_host_start_receive_transfer(p_g_ed->pipe_no, td_info.count, p_td->currBufPtr);
mbed_official 27:4206883f4cb7 1030 }
mbed_official 27:4206883f4cb7 1031 }
mbed_official 27:4206883f4cb7 1032
mbed_official 27:4206883f4cb7 1033 static void get_td_info(genelal_ed_t *p_g_ed, tdinfo_t *p_td_info) {
mbed_official 27:4206883f4cb7 1034 hced_t *p_ed = p_g_ed->p_curr_ed;
mbed_official 27:4206883f4cb7 1035
mbed_official 27:4206883f4cb7 1036 p_td_info->endpoint_no = (uint8_t)((p_ed->control >> 7) & 0x0000000F);
mbed_official 27:4206883f4cb7 1037 p_td_info->msp = (p_ed->control >> 16) & 0x000007FF;
mbed_official 27:4206883f4cb7 1038 p_td_info->devadr = p_ed->control & 0x0000000F;
mbed_official 27:4206883f4cb7 1039 p_td_info->speed = (p_ed->control >> 13) & 0x00000001;
mbed_official 27:4206883f4cb7 1040 p_td_info->direction = (p_ed->control >> 11) & 0x00000003;
mbed_official 29:d3b77affed28 1041
mbed_official 29:d3b77affed28 1042 if ((p_ed->control & ED_FORMAT) == 0) {
mbed_official 29:d3b77affed28 1043 hctd_t *p_td = (hctd_t *)p_g_ed->p_curr_td;
mbed_official 29:d3b77affed28 1044
mbed_official 29:d3b77affed28 1045 if ((p_td_info->direction == 0) || (p_td_info->direction == 3)) {
mbed_official 29:d3b77affed28 1046 if ((p_td->control & TD_CTL_MSK_DP) == TD_SETUP) {
mbed_official 29:d3b77affed28 1047 p_td_info->direction = 0;
mbed_official 29:d3b77affed28 1048 } else if ((p_td->control & TD_CTL_MSK_DP) == TD_OUT) {
mbed_official 29:d3b77affed28 1049 p_td_info->direction = 1;
mbed_official 29:d3b77affed28 1050 } else {
mbed_official 29:d3b77affed28 1051 p_td_info->direction = 2;
mbed_official 29:d3b77affed28 1052 }
mbed_official 29:d3b77affed28 1053 }
mbed_official 29:d3b77affed28 1054 if (p_td->currBufPtr != NULL) {
mbed_official 29:d3b77affed28 1055 p_td_info->count = (uint32_t)p_td->bufEnd - (uint32_t)p_td->currBufPtr + 1;
mbed_official 27:4206883f4cb7 1056 } else {
mbed_official 29:d3b77affed28 1057 p_td_info->count = 0;
mbed_official 27:4206883f4cb7 1058 }
mbed_official 27:4206883f4cb7 1059 } else {
mbed_official 29:d3b77affed28 1060 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 29:d3b77affed28 1061 hcisotd_t *p_isotd = (hcisotd_t *)p_g_ed->p_curr_td;
mbed_official 29:d3b77affed28 1062
mbed_official 29:d3b77affed28 1063 if ((p_td_info->direction == 0) || (p_td_info->direction == 3)) {
mbed_official 29:d3b77affed28 1064 if ((p_isotd->control & TD_CTL_MSK_DP) == TD_SETUP) {
mbed_official 29:d3b77affed28 1065 p_td_info->direction = 0;
mbed_official 29:d3b77affed28 1066 } else if ((p_isotd->control & TD_CTL_MSK_DP) == TD_OUT) {
mbed_official 29:d3b77affed28 1067 p_td_info->direction = 1;
mbed_official 29:d3b77affed28 1068 } else {
mbed_official 29:d3b77affed28 1069 p_td_info->direction = 2;
mbed_official 29:d3b77affed28 1070 }
mbed_official 29:d3b77affed28 1071 }
mbed_official 29:d3b77affed28 1072 #endif
mbed_official 27:4206883f4cb7 1073 }
mbed_official 27:4206883f4cb7 1074 }
mbed_official 27:4206883f4cb7 1075
mbed_official 27:4206883f4cb7 1076 static void set_togle(uint32_t pipe, hctd_t *p_td, hced_t *p_ed) {
mbed_official 27:4206883f4cb7 1077 if ((p_td->control & TD_CTL_MSK_T) == TD_TOGGLE_0) {
mbed_official 29:d3b77affed28 1078 usbx_host_set_sqclr(pipe);
mbed_official 27:4206883f4cb7 1079 } else if ((p_td->control & TD_CTL_MSK_T) == TD_TOGGLE_1) {
mbed_official 29:d3b77affed28 1080 usbx_host_set_sqset(pipe);
mbed_official 29:d3b77affed28 1081 } else if ((p_ed->headTD & ED_TOGLE_CARRY) == 0) {
mbed_official 29:d3b77affed28 1082 usbx_host_set_sqclr(pipe);
mbed_official 27:4206883f4cb7 1083 } else {
mbed_official 29:d3b77affed28 1084 usbx_host_set_sqset(pipe);
mbed_official 29:d3b77affed28 1085 }
mbed_official 29:d3b77affed28 1086 }
mbed_official 29:d3b77affed28 1087
mbed_official 29:d3b77affed28 1088 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 29:d3b77affed28 1089 static void iso_ed_task(void const * argument) {
mbed_official 29:d3b77affed28 1090 genelal_ed_t *p_iso_ed = &iso_ed[(uint32_t)argument];
mbed_official 29:d3b77affed28 1091 uint32_t wait_cnt = 0;
mbed_official 29:d3b77affed28 1092 uint32_t wait_time = 0;
mbed_official 29:d3b77affed28 1093 hcca_t *p_hcca;
mbed_official 29:d3b77affed28 1094 hced_t *p_ed;
mbed_official 29:d3b77affed28 1095
mbed_official 29:d3b77affed28 1096 while (1) {
mbed_official 29:d3b77affed28 1097 (void)osSemaphoreWait(p_iso_ed->semid_list, osWaitForever);
mbed_official 29:d3b77affed28 1098 if (p_iso_ed->p_curr_ed == NULL) {
mbed_official 29:d3b77affed28 1099 p_hcca = (hcca_t *)p_usb_reg->HcHCCA;
mbed_official 29:d3b77affed28 1100 p_ed = (hced_t *)p_hcca->IntTable[0];
mbed_official 29:d3b77affed28 1101 while ((p_ed != NULL) && ((p_usb_reg->HcControl & OR_CONTROL_IE) != 0)
mbed_official 29:d3b77affed28 1102 && (p_iso_ed->p_curr_ed == NULL)) {
mbed_official 29:d3b77affed28 1103 if (iso_trans_doing(p_ed, (uint32_t)argument) == 0) {
mbed_official 29:d3b77affed28 1104 p_iso_ed->p_curr_ed = p_ed;
mbed_official 29:d3b77affed28 1105 if (chk_iso_ed(p_iso_ed) != 0) {
mbed_official 29:d3b77affed28 1106 iso_trans_setting(p_iso_ed, (uint32_t)argument);
mbed_official 29:d3b77affed28 1107 } else {
mbed_official 29:d3b77affed28 1108 p_iso_ed->p_curr_ed = NULL;
mbed_official 29:d3b77affed28 1109 }
mbed_official 29:d3b77affed28 1110 }
mbed_official 29:d3b77affed28 1111 p_ed = p_ed->nextED;
mbed_official 29:d3b77affed28 1112 }
mbed_official 29:d3b77affed28 1113 p_iso_ed->psw_idx = 0;
mbed_official 29:d3b77affed28 1114 }
mbed_official 29:d3b77affed28 1115 if (p_iso_ed->p_curr_ed != NULL) {
mbed_official 29:d3b77affed28 1116 while ((p_usb_reg->HcControl & OR_CONTROL_IE) != 0) {
mbed_official 29:d3b77affed28 1117 if (chk_iso_ed(p_iso_ed) != 0) {
mbed_official 29:d3b77affed28 1118 wait_time = iso_chk_starting_frame(p_iso_ed);
mbed_official 29:d3b77affed28 1119 if (wait_time != 0) {
mbed_official 29:d3b77affed28 1120 osDelay(wait_time);
mbed_official 29:d3b77affed28 1121 p_usb_reg->HcFmNumber += wait_time;
mbed_official 29:d3b77affed28 1122 p_usb_reg->HcFmNumber &= 0x0000FFFF;
mbed_official 29:d3b77affed28 1123 }
mbed_official 29:d3b77affed28 1124 p_iso_ed->psw_idx = 0;
mbed_official 29:d3b77affed28 1125 iso_trans(p_iso_ed);
mbed_official 29:d3b77affed28 1126 (void)osSemaphoreWait(p_iso_ed->semid_wait, osWaitForever);
mbed_official 29:d3b77affed28 1127 usbx_host_stop_transfer(p_iso_ed->pipe_no);
mbed_official 29:d3b77affed28 1128 wait_cnt = 1;
mbed_official 29:d3b77affed28 1129 } else {
mbed_official 29:d3b77affed28 1130 if (wait_cnt > 0) {
mbed_official 29:d3b77affed28 1131 wait_cnt--;
mbed_official 29:d3b77affed28 1132 } else {
mbed_official 29:d3b77affed28 1133 p_iso_ed->p_curr_ed = NULL;
mbed_official 29:d3b77affed28 1134 }
mbed_official 29:d3b77affed28 1135 break;
mbed_official 29:d3b77affed28 1136 }
mbed_official 29:d3b77affed28 1137 }
mbed_official 29:d3b77affed28 1138 }
mbed_official 29:d3b77affed28 1139 (void)osSemaphoreRelease(p_iso_ed->semid_list);
mbed_official 29:d3b77affed28 1140 if (p_iso_ed->p_curr_ed == NULL) {
mbed_official 29:d3b77affed28 1141 osDelay(10);
mbed_official 29:d3b77affed28 1142 } else {
mbed_official 29:d3b77affed28 1143 osDelay(1);
mbed_official 29:d3b77affed28 1144 }
mbed_official 27:4206883f4cb7 1145 }
mbed_official 27:4206883f4cb7 1146 }
mbed_official 27:4206883f4cb7 1147
mbed_official 29:d3b77affed28 1148 static int32_t iso_trans_doing(hced_t *p_ed, uint32_t index) {
mbed_official 29:d3b77affed28 1149 uint32_t cnt;
mbed_official 29:d3b77affed28 1150 int32_t ret = 0;
mbed_official 29:d3b77affed28 1151
mbed_official 29:d3b77affed28 1152 for (cnt = 0; cnt < ISO_TRANS_MAX_NUM; cnt++) {
mbed_official 29:d3b77affed28 1153 if ((index != cnt) && (iso_ed[cnt].p_curr_ed == p_ed)) {
mbed_official 29:d3b77affed28 1154 ret = 1;
mbed_official 29:d3b77affed28 1155 }
mbed_official 29:d3b77affed28 1156 }
mbed_official 29:d3b77affed28 1157
mbed_official 29:d3b77affed28 1158 return ret;
mbed_official 29:d3b77affed28 1159 }
mbed_official 29:d3b77affed28 1160
mbed_official 29:d3b77affed28 1161 static void chk_iso_td_done(genelal_ed_t *p_g_ed) {
mbed_official 29:d3b77affed28 1162 hcca_t *p_hcca;
mbed_official 29:d3b77affed28 1163 hcisotd_t *p_isotd = (hcisotd_t *)p_g_ed->p_curr_td;
mbed_official 29:d3b77affed28 1164 uint32_t ConditionCode = RZA_IO_RegRead_32(&p_isotd->control, TD_CTL_SHFT_CC, TD_CTL_MSK_CC);
mbed_official 29:d3b77affed28 1165
mbed_official 29:d3b77affed28 1166 if ((ConditionCode != TD_CC_NOT_ACCESSED_1) && (ConditionCode != TD_CC_NOT_ACCESSED_2)) {
mbed_official 29:d3b77affed28 1167 p_g_ed->p_curr_ed->headTD = ((uint32_t)p_isotd->nextTD & 0xFFFFFFF0)
mbed_official 29:d3b77affed28 1168 | (p_g_ed->p_curr_ed->headTD & 0x0000000F);
mbed_official 29:d3b77affed28 1169 p_isotd->nextTD = (hcisotd_t *)p_usb_reg->HcDoneHead;
mbed_official 29:d3b77affed28 1170 p_usb_reg->HcDoneHead = (uint32_t)p_g_ed->p_curr_td;
mbed_official 29:d3b77affed28 1171 if ((p_usb_reg->HcInterruptStatus & OR_INTR_STATUS_WDH) == 0) {
mbed_official 29:d3b77affed28 1172 p_hcca = (hcca_t *)p_usb_reg->HcHCCA;
mbed_official 29:d3b77affed28 1173 p_hcca->DoneHead = p_usb_reg->HcDoneHead;
mbed_official 29:d3b77affed28 1174 p_usb_reg->HcDoneHead = 0x00000000;
mbed_official 29:d3b77affed28 1175 p_usb_reg->HcInterruptStatus |= OR_INTR_STATUS_WDH;
mbed_official 29:d3b77affed28 1176 (void)osSemaphoreRelease(semid_cb);
mbed_official 29:d3b77affed28 1177 }
mbed_official 29:d3b77affed28 1178 }
mbed_official 29:d3b77affed28 1179 }
mbed_official 29:d3b77affed28 1180
mbed_official 29:d3b77affed28 1181 static int32_t chk_iso_ed(genelal_ed_t *p_g_ed){
mbed_official 29:d3b77affed28 1182 int32_t ret = 0;
mbed_official 29:d3b77affed28 1183 hced_t *p_ed = p_g_ed->p_curr_ed;
mbed_official 29:d3b77affed28 1184
mbed_official 29:d3b77affed28 1185 if (((p_ed->control & ED_SKIP) != 0)
mbed_official 29:d3b77affed28 1186 || ((p_ed->control & ED_FORMAT) == 0)
mbed_official 29:d3b77affed28 1187 || ((p_ed->headTD & ED_HALTED) != 0)
mbed_official 29:d3b77affed28 1188 || ((p_ed->tailTD & 0xFFFFFFF0) == (p_ed->headTD & 0xFFFFFFF0))) {
mbed_official 29:d3b77affed28 1189 /* Do Nothing */
mbed_official 29:d3b77affed28 1190 } else if ((p_ed->control & 0x0000007F) > 10) {
mbed_official 29:d3b77affed28 1191 p_ed->headTD |= ED_HALTED;
mbed_official 29:d3b77affed28 1192 } else {
mbed_official 29:d3b77affed28 1193 p_g_ed->p_curr_td = (void *)(p_ed->headTD & 0xFFFFFFF0);
mbed_official 29:d3b77affed28 1194 if (p_g_ed->p_curr_td == NULL) {
mbed_official 29:d3b77affed28 1195 p_ed->headTD |= ED_HALTED;
mbed_official 29:d3b77affed28 1196 } else {
mbed_official 29:d3b77affed28 1197 hcisotd_t *p_isotd = (hcisotd_t *)p_g_ed->p_curr_td;
mbed_official 29:d3b77affed28 1198
mbed_official 29:d3b77affed28 1199 p_g_ed->p_start_buf = p_isotd->bufferPage0;
mbed_official 29:d3b77affed28 1200 ret = 1;
mbed_official 29:d3b77affed28 1201 }
mbed_official 29:d3b77affed28 1202 }
mbed_official 29:d3b77affed28 1203
mbed_official 29:d3b77affed28 1204 return ret;
mbed_official 29:d3b77affed28 1205 }
mbed_official 29:d3b77affed28 1206
mbed_official 29:d3b77affed28 1207 static void iso_trans_setting(genelal_ed_t *p_g_ed, uint32_t index) {
mbed_official 29:d3b77affed28 1208 tdinfo_t td_info;
mbed_official 29:d3b77affed28 1209 USB_HOST_CFG_PIPETBL_t *user_table = &usb_host_iso_ep_tbl1[index];
mbed_official 29:d3b77affed28 1210 uint8_t wk_table[6];
mbed_official 29:d3b77affed28 1211 uint16_t devadd;
mbed_official 29:d3b77affed28 1212
mbed_official 29:d3b77affed28 1213 get_td_info(p_g_ed, &td_info);
mbed_official 29:d3b77affed28 1214
mbed_official 29:d3b77affed28 1215 wk_table[0] = 0;
mbed_official 29:d3b77affed28 1216 wk_table[1] = USB_HOST_ENDPOINT_DESC;
mbed_official 29:d3b77affed28 1217 wk_table[2] = td_info.endpoint_no;
mbed_official 29:d3b77affed28 1218 if (td_info.direction == 2) {
mbed_official 29:d3b77affed28 1219 wk_table[2] |= USB_HOST_EP_IN;
mbed_official 29:d3b77affed28 1220 }
mbed_official 29:d3b77affed28 1221 wk_table[3] = USB_HOST_EP_ISO;
mbed_official 29:d3b77affed28 1222 wk_table[4] = (uint8_t)td_info.msp;
mbed_official 29:d3b77affed28 1223 wk_table[5] = (uint8_t)(td_info.msp >> 8);
mbed_official 29:d3b77affed28 1224 p_g_ed->cycle_time = 1;
mbed_official 29:d3b77affed28 1225 user_table->pipe_cycle = 0;
mbed_official 29:d3b77affed28 1226 if (g_usbx_host_UsbDeviceSpeed == USB_HOST_HIGH_SPEED) {
mbed_official 29:d3b77affed28 1227 usbx_host_get_devadd(td_info.devadr, &devadd);
mbed_official 29:d3b77affed28 1228 if (RZA_IO_RegRead_16(&devadd, USB_DEVADDn_USBSPD_SHIFT, USB_DEVADDn_USBSPD) == USB_HOST_HIGH_SPEED) {
mbed_official 29:d3b77affed28 1229 user_table->pipe_cycle += 3;
mbed_official 29:d3b77affed28 1230 }
mbed_official 29:d3b77affed28 1231 }
mbed_official 29:d3b77affed28 1232
mbed_official 29:d3b77affed28 1233 p_g_ed->pipe_no = user_table->pipe_number;
mbed_official 29:d3b77affed28 1234 usbx_api_host_SetEndpointTable(td_info.devadr, user_table, wk_table);
mbed_official 29:d3b77affed28 1235 }
mbed_official 29:d3b77affed28 1236
mbed_official 29:d3b77affed28 1237 static uint32_t iso_chk_starting_frame(genelal_ed_t *p_g_ed) {
mbed_official 29:d3b77affed28 1238 hcisotd_t *p_isotd = (hcisotd_t *)p_g_ed->p_curr_td;
mbed_official 29:d3b77affed28 1239 uint32_t starting_frame = p_isotd->control & 0x0000FFFF;
mbed_official 29:d3b77affed28 1240 uint32_t wait_time = 0;
mbed_official 29:d3b77affed28 1241
mbed_official 29:d3b77affed28 1242 if ((p_g_ed->psw_idx == 0) && (starting_frame > p_usb_reg->HcFmNumber)) {
mbed_official 29:d3b77affed28 1243 wait_time = starting_frame - p_usb_reg->HcFmNumber;
mbed_official 29:d3b77affed28 1244 }
mbed_official 29:d3b77affed28 1245
mbed_official 29:d3b77affed28 1246 return wait_time;
mbed_official 29:d3b77affed28 1247 }
mbed_official 29:d3b77affed28 1248
mbed_official 29:d3b77affed28 1249 static void iso_trans(genelal_ed_t *p_g_ed) {
mbed_official 29:d3b77affed28 1250 hcisotd_t *p_isotd = (hcisotd_t *)p_g_ed->p_curr_td;
mbed_official 29:d3b77affed28 1251 tdinfo_t td_info;
mbed_official 29:d3b77affed28 1252 uint32_t buff_addr;
mbed_official 29:d3b77affed28 1253 uint32_t data_size;
mbed_official 29:d3b77affed28 1254
mbed_official 29:d3b77affed28 1255 if (((uint32_t)p_isotd->offsetPSW[p_g_ed->psw_idx] & 0x00001000) == 0) {
mbed_official 29:d3b77affed28 1256 buff_addr = (uint32_t)p_isotd->bufferPage0 & 0xFFFFF000;
mbed_official 29:d3b77affed28 1257 } else {
mbed_official 29:d3b77affed28 1258 buff_addr = (uint32_t)p_isotd->bufEnd & 0xFFFFF000;
mbed_official 29:d3b77affed28 1259 }
mbed_official 29:d3b77affed28 1260 buff_addr |= (uint32_t)p_isotd->offsetPSW[p_g_ed->psw_idx] & 0x00000FFF;
mbed_official 29:d3b77affed28 1261
mbed_official 29:d3b77affed28 1262 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 1263 data_size = p_isotd->offsetPSW[p_g_ed->psw_idx + 1] - p_isotd->offsetPSW[p_g_ed->psw_idx];
mbed_official 29:d3b77affed28 1264 } else {
mbed_official 29:d3b77affed28 1265 data_size = (uint32_t)p_isotd->bufEnd - buff_addr + 1;
mbed_official 29:d3b77affed28 1266 }
mbed_official 29:d3b77affed28 1267 p_isotd->offsetPSW[p_g_ed->psw_idx] = (uint16_t)data_size;
mbed_official 29:d3b77affed28 1268
mbed_official 29:d3b77affed28 1269 get_td_info(p_g_ed, &td_info);
mbed_official 29:d3b77affed28 1270 p_g_ed->trans_wait = 1;
mbed_official 29:d3b77affed28 1271 if (td_info.direction == 1) {
mbed_official 29:d3b77affed28 1272 usbx_host_start_send_transfer(p_g_ed->pipe_no, data_size, (uint8_t *)buff_addr);
mbed_official 29:d3b77affed28 1273 } else {
mbed_official 29:d3b77affed28 1274 usbx_host_start_receive_transfer(p_g_ed->pipe_no, data_size, (uint8_t *)buff_addr);
mbed_official 29:d3b77affed28 1275 }
mbed_official 29:d3b77affed28 1276 }
mbed_official 29:d3b77affed28 1277 #endif
mbed_official 29:d3b77affed28 1278
mbed_official 27:4206883f4cb7 1279 static void connect_check(void) {
mbed_official 27:4206883f4cb7 1280 uint32_t type = 0;
mbed_official 27:4206883f4cb7 1281 uint16_t stat;
mbed_official 27:4206883f4cb7 1282 uint16_t devadd = 0;
mbed_official 27:4206883f4cb7 1283 uint32_t wk_HcRhPortStatus1 = p_usb_reg->HcRhPortStatus1;
mbed_official 27:4206883f4cb7 1284
mbed_official 29:d3b77affed28 1285 if (usbx_host_CheckAttach() == USB_HOST_ATTACH) {
mbed_official 27:4206883f4cb7 1286 type = 1;
mbed_official 27:4206883f4cb7 1287 }
mbed_official 27:4206883f4cb7 1288
mbed_official 27:4206883f4cb7 1289 if ((((wk_HcRhPortStatus1 & OR_RH_PORT_CCS) == 0) && (type == 0))
mbed_official 27:4206883f4cb7 1290 || (((wk_HcRhPortStatus1 & OR_RH_PORT_CCS) != 0) && (type != 0))) {
mbed_official 27:4206883f4cb7 1291 return;
mbed_official 27:4206883f4cb7 1292 }
mbed_official 27:4206883f4cb7 1293
mbed_official 27:4206883f4cb7 1294 if (type == 0) {
mbed_official 29:d3b77affed28 1295 usbx_host_UsbDetach();
mbed_official 27:4206883f4cb7 1296 wk_HcRhPortStatus1 &= ~OR_RH_PORT_CCS;
mbed_official 27:4206883f4cb7 1297 } else {
mbed_official 29:d3b77affed28 1298 usbx_host_UsbAttach();
mbed_official 29:d3b77affed28 1299 stat = usbx_host_UsbBusReset();
mbed_official 27:4206883f4cb7 1300 RZA_IO_RegWrite_16(&devadd, 0, USB_DEVADDn_UPPHUB_SHIFT, USB_DEVADDn_UPPHUB);
mbed_official 27:4206883f4cb7 1301 RZA_IO_RegWrite_16(&devadd, 0, USB_DEVADDn_HUBPORT_SHIFT, USB_DEVADDn_HUBPORT);
mbed_official 27:4206883f4cb7 1302 if (stat == USB_HOST_HSMODE) {
mbed_official 27:4206883f4cb7 1303 wk_HcRhPortStatus1 &= ~OR_RH_PORT_LSDA;
mbed_official 29:d3b77affed28 1304 RZA_IO_RegWrite_16(&USB20X.SOFCFG, 0, USB_SOFCFG_TRNENSEL_SHIFT, USB_SOFCFG_TRNENSEL);
mbed_official 29:d3b77affed28 1305 g_usbx_host_UsbDeviceSpeed = USB_HOST_HIGH_SPEED;
mbed_official 27:4206883f4cb7 1306 } else if (stat == USB_HOST_FSMODE) {
mbed_official 27:4206883f4cb7 1307 wk_HcRhPortStatus1 &= ~OR_RH_PORT_LSDA;
mbed_official 29:d3b77affed28 1308 RZA_IO_RegWrite_16(&USB20X.SOFCFG, 0, USB_SOFCFG_TRNENSEL_SHIFT, USB_SOFCFG_TRNENSEL);
mbed_official 29:d3b77affed28 1309 g_usbx_host_UsbDeviceSpeed = USB_HOST_FULL_SPEED;
mbed_official 27:4206883f4cb7 1310 } else {
mbed_official 27:4206883f4cb7 1311 wk_HcRhPortStatus1 |= OR_RH_PORT_LSDA;
mbed_official 29:d3b77affed28 1312 RZA_IO_RegWrite_16(&USB20X.SOFCFG, 1, USB_SOFCFG_TRNENSEL_SHIFT, USB_SOFCFG_TRNENSEL);
mbed_official 29:d3b77affed28 1313 g_usbx_host_UsbDeviceSpeed = USB_HOST_LOW_SPEED;
mbed_official 27:4206883f4cb7 1314 }
mbed_official 29:d3b77affed28 1315 RZA_IO_RegWrite_16(&devadd, g_usbx_host_UsbDeviceSpeed, USB_DEVADDn_USBSPD_SHIFT, USB_DEVADDn_USBSPD);
mbed_official 29:d3b77affed28 1316 usbx_host_init_pipe_status();
mbed_official 29:d3b77affed28 1317 usbx_host_set_devadd(USB_HOST_DEVICE_0, &devadd);
mbed_official 27:4206883f4cb7 1318 wk_HcRhPortStatus1 |= OR_RH_PORT_CCS;
mbed_official 27:4206883f4cb7 1319 }
mbed_official 27:4206883f4cb7 1320 wk_HcRhPortStatus1 |= OR_RH_PORT_CSC;
mbed_official 27:4206883f4cb7 1321 p_usb_reg->HcRhPortStatus1 = wk_HcRhPortStatus1;
mbed_official 27:4206883f4cb7 1322 p_usb_reg->HcInterruptStatus |= OR_INTR_STATUS_RHSC;
mbed_official 27:4206883f4cb7 1323 (void)memset(&split_ctl, 0, sizeof(split_ctl));
mbed_official 29:d3b77affed28 1324 }
mbed_official 27:4206883f4cb7 1325
mbed_official 29:d3b77affed28 1326 void ohciwrapp_loc_Connect(uint32_t type) {
mbed_official 29:d3b77affed28 1327 uint32_t cnt;
mbed_official 29:d3b77affed28 1328
mbed_official 29:d3b77affed28 1329 connect_change = type;
mbed_official 27:4206883f4cb7 1330 if (type == 0) {
mbed_official 27:4206883f4cb7 1331 if (ctl_ed.trans_wait == 1) {
mbed_official 27:4206883f4cb7 1332 ohciwrapp_loc_TransEnd(ctl_ed.pipe_no, TD_CC_DEVICENOTRESPONDING);
mbed_official 27:4206883f4cb7 1333 }
mbed_official 27:4206883f4cb7 1334 if (blk_ed.trans_wait == 1) {
mbed_official 27:4206883f4cb7 1335 ohciwrapp_loc_TransEnd(blk_ed.pipe_no, TD_CC_DEVICENOTRESPONDING);
mbed_official 27:4206883f4cb7 1336 }
mbed_official 27:4206883f4cb7 1337 for (cnt = 0; cnt< INT_TRANS_MAX_NUM; cnt++) {
mbed_official 27:4206883f4cb7 1338 if (int_ed[cnt].trans_wait == 1) {
mbed_official 27:4206883f4cb7 1339 ohciwrapp_loc_TransEnd(int_ed[cnt].pipe_no, TD_CC_DEVICENOTRESPONDING);
mbed_official 27:4206883f4cb7 1340 }
mbed_official 27:4206883f4cb7 1341 }
mbed_official 29:d3b77affed28 1342 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 29:d3b77affed28 1343 for (cnt = 0; cnt< ISO_TRANS_MAX_NUM; cnt++) {
mbed_official 29:d3b77affed28 1344 if (iso_ed[cnt].trans_wait == 1) {
mbed_official 29:d3b77affed28 1345 hced_t *p_ed = iso_ed[cnt].p_curr_ed;
mbed_official 27:4206883f4cb7 1346
mbed_official 29:d3b77affed28 1347 p_ed->headTD |= ED_HALTED;
mbed_official 29:d3b77affed28 1348 ohciwrapp_loc_TransEnd(iso_ed[cnt].pipe_no, TD_CC_DEVICENOTRESPONDING);
mbed_official 29:d3b77affed28 1349 }
mbed_official 29:d3b77affed28 1350 }
mbed_official 29:d3b77affed28 1351 #endif
mbed_official 29:d3b77affed28 1352 }
mbed_official 27:4206883f4cb7 1353 (void)osSemaphoreRelease(semid_cb);
mbed_official 27:4206883f4cb7 1354 }
mbed_official 27:4206883f4cb7 1355
mbed_official 27:4206883f4cb7 1356 void ohciwrapp_loc_TransEnd(uint32_t pipe, uint32_t ConditionCode) {
mbed_official 29:d3b77affed28 1357 uint32_t periodic = 0;
mbed_official 27:4206883f4cb7 1358 uint32_t cnt;
mbed_official 27:4206883f4cb7 1359 uint32_t sqmon;
mbed_official 27:4206883f4cb7 1360 hced_t *p_ed;
mbed_official 27:4206883f4cb7 1361 genelal_ed_t *p_wait_ed = NULL;
mbed_official 27:4206883f4cb7 1362
mbed_official 27:4206883f4cb7 1363 if (ctl_ed.pipe_no == pipe) {
mbed_official 27:4206883f4cb7 1364 p_wait_ed = &ctl_ed;
mbed_official 27:4206883f4cb7 1365 } else if (blk_ed.pipe_no == pipe) {
mbed_official 27:4206883f4cb7 1366 p_wait_ed = &blk_ed;
mbed_official 27:4206883f4cb7 1367 } else {
mbed_official 29:d3b77affed28 1368 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 29:d3b77affed28 1369 if (p_wait_ed == NULL) {
mbed_official 29:d3b77affed28 1370 for (cnt = 0; cnt< ISO_TRANS_MAX_NUM; cnt++) {
mbed_official 29:d3b77affed28 1371 if (iso_ed[cnt].pipe_no == pipe) {
mbed_official 29:d3b77affed28 1372 p_wait_ed = &iso_ed[cnt];
mbed_official 29:d3b77affed28 1373 break;
mbed_official 29:d3b77affed28 1374 }
mbed_official 29:d3b77affed28 1375 }
mbed_official 29:d3b77affed28 1376 }
mbed_official 29:d3b77affed28 1377 #endif
mbed_official 29:d3b77affed28 1378 if (p_wait_ed == NULL) {
mbed_official 29:d3b77affed28 1379 for (cnt = 0; cnt< INT_TRANS_MAX_NUM; cnt++) {
mbed_official 29:d3b77affed28 1380 if (int_ed[cnt].pipe_no == pipe) {
mbed_official 29:d3b77affed28 1381 p_wait_ed = &int_ed[cnt];
mbed_official 29:d3b77affed28 1382 periodic = 1;
mbed_official 29:d3b77affed28 1383 break;
mbed_official 29:d3b77affed28 1384 }
mbed_official 27:4206883f4cb7 1385 }
mbed_official 27:4206883f4cb7 1386 }
mbed_official 27:4206883f4cb7 1387 }
mbed_official 29:d3b77affed28 1388
mbed_official 27:4206883f4cb7 1389 if (p_wait_ed == NULL) {
mbed_official 27:4206883f4cb7 1390 return;
mbed_official 27:4206883f4cb7 1391 }
mbed_official 27:4206883f4cb7 1392 p_ed = p_wait_ed->p_curr_ed;
mbed_official 29:d3b77affed28 1393 if (p_ed == NULL) {
mbed_official 27:4206883f4cb7 1394 return;
mbed_official 27:4206883f4cb7 1395 }
mbed_official 27:4206883f4cb7 1396
mbed_official 29:d3b77affed28 1397 if ((p_ed->control & ED_FORMAT) == 0) {
mbed_official 29:d3b77affed28 1398 hctd_t *p_td = (hctd_t *)p_wait_ed->p_curr_td;
mbed_official 29:d3b77affed28 1399
mbed_official 29:d3b77affed28 1400 if (p_td != NULL) {
mbed_official 29:d3b77affed28 1401 if (ConditionCode == TD_CC_NOERROR) {
mbed_official 29:d3b77affed28 1402 /* ErrorCount */
mbed_official 29:d3b77affed28 1403 RZA_IO_RegWrite_32(&p_td->control, 0, TD_CTL_SHFT_EC, TD_CTL_MSK_EC);
mbed_official 29:d3b77affed28 1404
mbed_official 29:d3b77affed28 1405 /* CurrentBufferPointer */
mbed_official 29:d3b77affed28 1406 p_td->currBufPtr += ((uint32_t)p_td->bufEnd - (uint32_t)p_td->currBufPtr + 1) - g_usbx_host_data_count[pipe];
mbed_official 29:d3b77affed28 1407 } else {
mbed_official 29:d3b77affed28 1408 /* ErrorCount */
mbed_official 29:d3b77affed28 1409 RZA_IO_RegWrite_32(&p_td->control, 3, TD_CTL_SHFT_EC, TD_CTL_MSK_EC);
mbed_official 29:d3b77affed28 1410 }
mbed_official 29:d3b77affed28 1411
mbed_official 29:d3b77affed28 1412 /* DataToggle */
mbed_official 29:d3b77affed28 1413 sqmon = usbx_host_get_sqmon(pipe);
mbed_official 29:d3b77affed28 1414 RZA_IO_RegWrite_32(&p_td->control, sqmon, TD_CTL_SHFT_T, TD_CTL_MSK_T);
mbed_official 29:d3b77affed28 1415 if (sqmon == 0) {
mbed_official 29:d3b77affed28 1416 p_ed->headTD &= ~ED_TOGLE_CARRY;
mbed_official 29:d3b77affed28 1417 } else {
mbed_official 29:d3b77affed28 1418 p_ed->headTD |= ED_TOGLE_CARRY;
mbed_official 29:d3b77affed28 1419 }
mbed_official 29:d3b77affed28 1420
mbed_official 29:d3b77affed28 1421 /* ConditionCode */
mbed_official 29:d3b77affed28 1422 RZA_IO_RegWrite_32(&p_td->control, ConditionCode, TD_CTL_SHFT_CC, TD_CTL_MSK_CC);
mbed_official 29:d3b77affed28 1423
mbed_official 29:d3b77affed28 1424 if (p_wait_ed == &ctl_ed) {
mbed_official 29:d3b77affed28 1425 chk_split_trans_setting(&ctl_ed);
mbed_official 29:d3b77affed28 1426 }
mbed_official 29:d3b77affed28 1427 chk_genelal_td_done(p_wait_ed);
mbed_official 27:4206883f4cb7 1428
mbed_official 29:d3b77affed28 1429 if (periodic != 0) {
mbed_official 29:d3b77affed28 1430 if (chk_genelal_ed(p_wait_ed) != 0) {
mbed_official 29:d3b77affed28 1431 int_trans(p_wait_ed);
mbed_official 29:d3b77affed28 1432 } else {
mbed_official 29:d3b77affed28 1433 p_wait_ed->trans_wait = 0;
mbed_official 29:d3b77affed28 1434 (void)osSemaphoreRelease(p_wait_ed->semid_wait);
mbed_official 29:d3b77affed28 1435 }
mbed_official 29:d3b77affed28 1436 } else {
mbed_official 29:d3b77affed28 1437 p_wait_ed->trans_wait = 0;
mbed_official 29:d3b77affed28 1438 (void)osSemaphoreRelease(p_wait_ed->semid_wait);
mbed_official 29:d3b77affed28 1439 }
mbed_official 29:d3b77affed28 1440 }
mbed_official 27:4206883f4cb7 1441 } else {
mbed_official 29:d3b77affed28 1442 #if (ISO_TRANS_MAX_NUM > 0)
mbed_official 29:d3b77affed28 1443 hcisotd_t *p_isotd = (hcisotd_t *)p_wait_ed->p_curr_td;
mbed_official 29:d3b77affed28 1444 uint32_t next_trans = 0;
mbed_official 29:d3b77affed28 1445
mbed_official 29:d3b77affed28 1446 if (p_isotd != NULL) {
mbed_official 29:d3b77affed28 1447 usbx_host_stop_transfer(pipe);
mbed_official 29:d3b77affed28 1448 if (p_usb_reg->HcFmNumber < 0x0000FFFF) {
mbed_official 29:d3b77affed28 1449 p_usb_reg->HcFmNumber++;
mbed_official 29:d3b77affed28 1450 } else {
mbed_official 29:d3b77affed28 1451 p_usb_reg->HcFmNumber = 0;
mbed_official 29:d3b77affed28 1452 }
mbed_official 29:d3b77affed28 1453
mbed_official 29:d3b77affed28 1454 /* Size of packet */
mbed_official 29:d3b77affed28 1455 p_isotd->offsetPSW[p_wait_ed->psw_idx] -= g_usbx_host_data_count[pipe];
mbed_official 29:d3b77affed28 1456
mbed_official 29:d3b77affed28 1457 /* ConditionCode */
mbed_official 29:d3b77affed28 1458 RZA_IO_RegWrite_32(&p_isotd->control, ConditionCode, TD_CTL_SHFT_CC, TD_CTL_MSK_CC);
mbed_official 29:d3b77affed28 1459 RZA_IO_RegWrite_16(&p_isotd->offsetPSW[p_wait_ed->psw_idx],
mbed_official 29:d3b77affed28 1460 (uint16_t)ConditionCode, TD_PSW_SHFT_CC, TD_PSW_MSK_CC);
mbed_official 29:d3b77affed28 1461
mbed_official 29:d3b77affed28 1462 if (usbx_host_CheckAttach() != USB_HOST_ATTACH) {
mbed_official 29:d3b77affed28 1463 p_ed->headTD |= ED_HALTED;
mbed_official 29:d3b77affed28 1464 }
mbed_official 29:d3b77affed28 1465 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 1466 p_wait_ed->psw_idx = 0;
mbed_official 29:d3b77affed28 1467 chk_iso_td_done(p_wait_ed);
mbed_official 29:d3b77affed28 1468 } else {
mbed_official 29:d3b77affed28 1469 p_wait_ed->psw_idx++;
mbed_official 29:d3b77affed28 1470 }
mbed_official 29:d3b77affed28 1471 if (chk_iso_ed(p_wait_ed) != 0) {
mbed_official 29:d3b77affed28 1472 if (iso_chk_starting_frame(p_wait_ed) == 0) {
mbed_official 29:d3b77affed28 1473 iso_trans(p_wait_ed);
mbed_official 29:d3b77affed28 1474 next_trans = 1;
mbed_official 29:d3b77affed28 1475 }
mbed_official 29:d3b77affed28 1476 }
mbed_official 29:d3b77affed28 1477 if (next_trans == 0) {
mbed_official 29:d3b77affed28 1478 p_wait_ed->trans_wait = 0;
mbed_official 29:d3b77affed28 1479 (void)osSemaphoreRelease(p_wait_ed->semid_wait);
mbed_official 29:d3b77affed28 1480 }
mbed_official 29:d3b77affed28 1481 }
mbed_official 29:d3b77affed28 1482 #endif
mbed_official 27:4206883f4cb7 1483 }
mbed_official 27:4206883f4cb7 1484
mbed_official 27:4206883f4cb7 1485 }
mbed_official 27:4206883f4cb7 1486