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