Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/hic_hal/nuvoton/m48ssidae/usbd_m480.c@0:01f31e923fe2, 2020-04-07 (annotated)
- Committer:
- Pawel Zarembski
- Date:
- Tue Apr 07 12:55:42 2020 +0200
- Revision:
- 0:01f31e923fe2
hani: DAPLink with reset workaround
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pawel Zarembski |
0:01f31e923fe2 | 1 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 2 | * Copyright (c) 2004-2016 ARM Limited. All rights reserved. |
Pawel Zarembski |
0:01f31e923fe2 | 3 | * |
Pawel Zarembski |
0:01f31e923fe2 | 4 | * SPDX-License-Identifier: Apache-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 5 | * |
Pawel Zarembski |
0:01f31e923fe2 | 6 | * Licensed under the Apache License, Version 2.0 (the License); you may |
Pawel Zarembski |
0:01f31e923fe2 | 7 | * not use this file except in compliance with the License. |
Pawel Zarembski |
0:01f31e923fe2 | 8 | * You may obtain a copy of the License at |
Pawel Zarembski |
0:01f31e923fe2 | 9 | * |
Pawel Zarembski |
0:01f31e923fe2 | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 11 | * |
Pawel Zarembski |
0:01f31e923fe2 | 12 | * Unless required by applicable law or agreed to in writing, software |
Pawel Zarembski |
0:01f31e923fe2 | 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
Pawel Zarembski |
0:01f31e923fe2 | 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pawel Zarembski |
0:01f31e923fe2 | 15 | * See the License for the specific language governing permissions and |
Pawel Zarembski |
0:01f31e923fe2 | 16 | * limitations under the License. |
Pawel Zarembski |
0:01f31e923fe2 | 17 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 18 | |
Pawel Zarembski |
0:01f31e923fe2 | 19 | #include <rl_usb.h> |
Pawel Zarembski |
0:01f31e923fe2 | 20 | #include "NuMicro.h" |
Pawel Zarembski |
0:01f31e923fe2 | 21 | |
Pawel Zarembski |
0:01f31e923fe2 | 22 | #define __NO_USB_LIB_C |
Pawel Zarembski |
0:01f31e923fe2 | 23 | #include "usb_config.c" |
Pawel Zarembski |
0:01f31e923fe2 | 24 | |
Pawel Zarembski |
0:01f31e923fe2 | 25 | /* Bit definition of CEPCTL register */ |
Pawel Zarembski |
0:01f31e923fe2 | 26 | #define HSUSBD_CEPCTL_NAKCLR ((uint32_t)0x00000000UL) |
Pawel Zarembski |
0:01f31e923fe2 | 27 | #define HSUSBD_CEPCTL_STALL ((uint32_t)0x00000002UL) |
Pawel Zarembski |
0:01f31e923fe2 | 28 | #define HSUSBD_CEPCTL_ZEROLEN ((uint32_t)0x00000004UL) |
Pawel Zarembski |
0:01f31e923fe2 | 29 | #define HSUSBD_CEPCTL_FLUSH ((uint32_t)0x00000008UL) |
Pawel Zarembski |
0:01f31e923fe2 | 30 | |
Pawel Zarembski |
0:01f31e923fe2 | 31 | /* Bit definition of EPxRSPCTL register */ |
Pawel Zarembski |
0:01f31e923fe2 | 32 | #define HSUSBD_EP_RSPCTL_FLUSH ((uint32_t)0x00000001UL) |
Pawel Zarembski |
0:01f31e923fe2 | 33 | #define HSUSBD_EP_RSPCTL_MODE_AUTO ((uint32_t)0x00000000UL) |
Pawel Zarembski |
0:01f31e923fe2 | 34 | #define HSUSBD_EP_RSPCTL_MODE_MANUAL ((uint32_t)0x00000002UL) |
Pawel Zarembski |
0:01f31e923fe2 | 35 | #define HSUSBD_EP_RSPCTL_MODE_FLY ((uint32_t)0x00000004UL) |
Pawel Zarembski |
0:01f31e923fe2 | 36 | #define HSUSBD_EP_RSPCTL_MODE_MASK ((uint32_t)0x00000006UL) |
Pawel Zarembski |
0:01f31e923fe2 | 37 | #define HSUSBD_EP_RSPCTL_TOGGLE ((uint32_t)0x00000008UL) |
Pawel Zarembski |
0:01f31e923fe2 | 38 | #define HSUSBD_EP_RSPCTL_HALT ((uint32_t)0x00000010UL) |
Pawel Zarembski |
0:01f31e923fe2 | 39 | #define HSUSBD_EP_RSPCTL_ZEROLEN ((uint32_t)0x00000020UL) |
Pawel Zarembski |
0:01f31e923fe2 | 40 | #define HSUSBD_EP_RSPCTL_SHORTTXEN ((uint32_t)0x00000040UL) |
Pawel Zarembski |
0:01f31e923fe2 | 41 | #define HSUSBD_EP_RSPCTL_DISBUF ((uint32_t)0x00000080UL) |
Pawel Zarembski |
0:01f31e923fe2 | 42 | |
Pawel Zarembski |
0:01f31e923fe2 | 43 | /* Bit definition of EPxCFG register */ |
Pawel Zarembski |
0:01f31e923fe2 | 44 | #define HSUSBD_EP_CFG_VALID ((uint32_t)0x00000001UL) |
Pawel Zarembski |
0:01f31e923fe2 | 45 | #define HSUSBD_EP_CFG_TYPE_BULK ((uint32_t)0x00000002UL) |
Pawel Zarembski |
0:01f31e923fe2 | 46 | #define HSUSBD_EP_CFG_TYPE_INT ((uint32_t)0x00000004UL) |
Pawel Zarembski |
0:01f31e923fe2 | 47 | #define HSUSBD_EP_CFG_TYPE_ISO ((uint32_t)0x00000006UL) |
Pawel Zarembski |
0:01f31e923fe2 | 48 | #define HSUSBD_EP_CFG_TYPE_MASK ((uint32_t)0x00000006UL) |
Pawel Zarembski |
0:01f31e923fe2 | 49 | #define HSUSBD_EP_CFG_DIR_OUT ((uint32_t)0x00000000UL) |
Pawel Zarembski |
0:01f31e923fe2 | 50 | #define HSUSBD_EP_CFG_DIR_IN ((uint32_t)0x00000008UL) |
Pawel Zarembski |
0:01f31e923fe2 | 51 | |
Pawel Zarembski |
0:01f31e923fe2 | 52 | #define HSUSBD_ENABLE_USB() ((uint32_t)(HSUSBD->PHYCTL |= (HSUSBD_PHYCTL_PHYEN_Msk|HSUSBD_PHYCTL_DPPUEN_Msk))) |
Pawel Zarembski |
0:01f31e923fe2 | 53 | #define HSUSBD_DISABLE_USB() ((uint32_t)(HSUSBD->PHYCTL &= ~HSUSBD_PHYCTL_DPPUEN_Msk)) |
Pawel Zarembski |
0:01f31e923fe2 | 54 | #define HSUSBD_ENABLE_PHY() ((uint32_t)(HSUSBD->PHYCTL |= HSUSBD_PHYCTL_PHYEN_Msk)) |
Pawel Zarembski |
0:01f31e923fe2 | 55 | #define HSUSBD_DISABLE_PHY() ((uint32_t)(HSUSBD->PHYCTL &= ~HSUSBD_PHYCTL_PHYEN_Msk)) |
Pawel Zarembski |
0:01f31e923fe2 | 56 | #define HSUSBD_SET_SE0() ((uint32_t)(HSUSBD->PHYCTL &= ~HSUSBD_PHYCTL_DPPUEN_Msk)) |
Pawel Zarembski |
0:01f31e923fe2 | 57 | #define HSUSBD_CLR_SE0() ((uint32_t)(HSUSBD->PHYCTL |= HSUSBD_PHYCTL_DPPUEN_Msk)) |
Pawel Zarembski |
0:01f31e923fe2 | 58 | #define HSUSBD_SET_ADDR(addr) (HSUSBD->FADDR = (addr)) |
Pawel Zarembski |
0:01f31e923fe2 | 59 | #define HSUSBD_GET_ADDR() ((uint32_t)(HSUSBD->FADDR)) |
Pawel Zarembski |
0:01f31e923fe2 | 60 | #define HSUSBD_ENABLE_USB_INT(intr) (HSUSBD->GINTEN = (intr)) |
Pawel Zarembski |
0:01f31e923fe2 | 61 | #define HSUSBD_ENABLE_BUS_INT(intr) (HSUSBD->BUSINTEN = (intr)) |
Pawel Zarembski |
0:01f31e923fe2 | 62 | #define HSUSBD_GET_BUS_INT_FLAG() (HSUSBD->BUSINTSTS) |
Pawel Zarembski |
0:01f31e923fe2 | 63 | #define HSUSBD_CLR_BUS_INT_FLAG(flag) (HSUSBD->BUSINTSTS = (flag)) |
Pawel Zarembski |
0:01f31e923fe2 | 64 | #define HSUSBD_ENABLE_CEP_INT(intr) (HSUSBD->CEPINTEN = (intr)) |
Pawel Zarembski |
0:01f31e923fe2 | 65 | #define HSUSBD_CLR_CEP_INT_FLAG(flag) (HSUSBD->CEPINTSTS = (flag)) |
Pawel Zarembski |
0:01f31e923fe2 | 66 | #define HSUSBD_SET_CEP_STATE(flag) (HSUSBD->CEPCTL = (flag)) |
Pawel Zarembski |
0:01f31e923fe2 | 67 | #define HSUSBD_START_CEP_IN(size) (HSUSBD->CEPTXCNT = (size)) |
Pawel Zarembski |
0:01f31e923fe2 | 68 | #define HSUSBD_SET_MAX_PAYLOAD(ep, size) (HSUSBD->EP[(ep)].EPMPS = (size)) |
Pawel Zarembski |
0:01f31e923fe2 | 69 | #define HSUSBD_ENABLE_EP_INT(ep, intr) (HSUSBD->EP[(ep)].EPINTEN = (intr)) |
Pawel Zarembski |
0:01f31e923fe2 | 70 | #define HSUSBD_GET_EP_INT_FLAG(ep) (HSUSBD->EP[(ep)].EPINTSTS) |
Pawel Zarembski |
0:01f31e923fe2 | 71 | #define HSUSBD_CLR_EP_INT_FLAG(ep, flag) (HSUSBD->EP[(ep)].EPINTSTS = (flag)) |
Pawel Zarembski |
0:01f31e923fe2 | 72 | #define HSUSBD_SET_DMA_LEN(len) (HSUSBD->DMACNT = (len)) |
Pawel Zarembski |
0:01f31e923fe2 | 73 | #define HSUSBD_SET_DMA_ADDR(addr) (HSUSBD->DMAADDR = (addr)) |
Pawel Zarembski |
0:01f31e923fe2 | 74 | #define HSUSBD_SET_DMA_READ(epnum) (HSUSBD->DMACTL = (HSUSBD->DMACTL & ~HSUSBD_DMACTL_EPNUM_Msk) | HSUSBD_DMACTL_DMARD_Msk | (epnum) | 0x100) |
Pawel Zarembski |
0:01f31e923fe2 | 75 | #define HSUSBD_SET_DMA_WRITE(epnum) (HSUSBD->DMACTL = (HSUSBD->DMACTL & ~(HSUSBD_DMACTL_EPNUM_Msk | HSUSBD_DMACTL_DMARD_Msk | 0x100)) | (epnum)) |
Pawel Zarembski |
0:01f31e923fe2 | 76 | #define HSUSBD_ENABLE_DMA() (HSUSBD->DMACTL |= HSUSBD_DMACTL_DMAEN_Msk) |
Pawel Zarembski |
0:01f31e923fe2 | 77 | #define HSUSBD_IS_ATTACHED() ((uint32_t)(HSUSBD->PHYCTL & HSUSBD_PHYCTL_VBUSDET_Msk)) |
Pawel Zarembski |
0:01f31e923fe2 | 78 | |
Pawel Zarembski |
0:01f31e923fe2 | 79 | #define HSUSBD_MAX_EP 12UL |
Pawel Zarembski |
0:01f31e923fe2 | 80 | #define CEP 0xFFUL |
Pawel Zarembski |
0:01f31e923fe2 | 81 | #define EPA 0UL |
Pawel Zarembski |
0:01f31e923fe2 | 82 | #define EPB 1UL |
Pawel Zarembski |
0:01f31e923fe2 | 83 | #define EPC 2UL |
Pawel Zarembski |
0:01f31e923fe2 | 84 | #define EPD 3UL |
Pawel Zarembski |
0:01f31e923fe2 | 85 | #define EPE 4UL |
Pawel Zarembski |
0:01f31e923fe2 | 86 | #define EPF 5UL |
Pawel Zarembski |
0:01f31e923fe2 | 87 | #define EPG 6UL |
Pawel Zarembski |
0:01f31e923fe2 | 88 | #define EPH 7UL |
Pawel Zarembski |
0:01f31e923fe2 | 89 | #define EPI 8UL |
Pawel Zarembski |
0:01f31e923fe2 | 90 | #define EPJ 9UL |
Pawel Zarembski |
0:01f31e923fe2 | 91 | #define EPK 10UL |
Pawel Zarembski |
0:01f31e923fe2 | 92 | #define EPL 11UL |
Pawel Zarembski |
0:01f31e923fe2 | 93 | |
Pawel Zarembski |
0:01f31e923fe2 | 94 | #define USBD_EP_TO_NUM(ep) ((ep == CEP) ? (0) : (1 + (ep - EPA))) |
Pawel Zarembski |
0:01f31e923fe2 | 95 | #define USBD_NUM_TO_EP(num) ((num == 0) ? (CEP) : (EPA + (num - 1))) |
Pawel Zarembski |
0:01f31e923fe2 | 96 | |
Pawel Zarembski |
0:01f31e923fe2 | 97 | #define CEP_BUF_BASE 0 |
Pawel Zarembski |
0:01f31e923fe2 | 98 | #define CEP_BUF_LEN USBD_MAX_PACKET0 |
Pawel Zarembski |
0:01f31e923fe2 | 99 | |
Pawel Zarembski |
0:01f31e923fe2 | 100 | static uint32_t g_u32FreeBufAddr; |
Pawel Zarembski |
0:01f31e923fe2 | 101 | static uint8_t g_u8StatusIn; |
Pawel Zarembski |
0:01f31e923fe2 | 102 | |
Pawel Zarembski |
0:01f31e923fe2 | 103 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 104 | * USB Device Interrupt enable |
Pawel Zarembski |
0:01f31e923fe2 | 105 | * Called by USBD_Init to enable the USB Interrupt |
Pawel Zarembski |
0:01f31e923fe2 | 106 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 107 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 108 | |
Pawel Zarembski |
0:01f31e923fe2 | 109 | #ifdef __RTX |
Pawel Zarembski |
0:01f31e923fe2 | 110 | void __svc(1) USBD_IntrEna(void); |
Pawel Zarembski |
0:01f31e923fe2 | 111 | void __SVC_1(void) |
Pawel Zarembski |
0:01f31e923fe2 | 112 | { |
Pawel Zarembski |
0:01f31e923fe2 | 113 | #else |
Pawel Zarembski |
0:01f31e923fe2 | 114 | void USBD_IntrEna(void) |
Pawel Zarembski |
0:01f31e923fe2 | 115 | { |
Pawel Zarembski |
0:01f31e923fe2 | 116 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 117 | NVIC_EnableIRQ(USBD20_IRQn); |
Pawel Zarembski |
0:01f31e923fe2 | 118 | } |
Pawel Zarembski |
0:01f31e923fe2 | 119 | |
Pawel Zarembski |
0:01f31e923fe2 | 120 | |
Pawel Zarembski |
0:01f31e923fe2 | 121 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 122 | * USB Device Initialize Function |
Pawel Zarembski |
0:01f31e923fe2 | 123 | * Called by the User to initialize USB |
Pawel Zarembski |
0:01f31e923fe2 | 124 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 125 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 126 | |
Pawel Zarembski |
0:01f31e923fe2 | 127 | void USBD_Init(void) |
Pawel Zarembski |
0:01f31e923fe2 | 128 | { |
Pawel Zarembski |
0:01f31e923fe2 | 129 | uint32_t volatile i; |
Pawel Zarembski |
0:01f31e923fe2 | 130 | /* Initial USB engine */ |
Pawel Zarembski |
0:01f31e923fe2 | 131 | HSUSBD_ENABLE_PHY(); |
Pawel Zarembski |
0:01f31e923fe2 | 132 | |
Pawel Zarembski |
0:01f31e923fe2 | 133 | /* wait PHY clock ready */ |
Pawel Zarembski |
0:01f31e923fe2 | 134 | while (1) { |
Pawel Zarembski |
0:01f31e923fe2 | 135 | HSUSBD->EP[EPA].EPMPS = 0x20UL; |
Pawel Zarembski |
0:01f31e923fe2 | 136 | |
Pawel Zarembski |
0:01f31e923fe2 | 137 | if (HSUSBD->EP[EPA].EPMPS == 0x20UL) { |
Pawel Zarembski |
0:01f31e923fe2 | 138 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 139 | } |
Pawel Zarembski |
0:01f31e923fe2 | 140 | } |
Pawel Zarembski |
0:01f31e923fe2 | 141 | |
Pawel Zarembski |
0:01f31e923fe2 | 142 | for (i = 0; i < 0x10000; i++); |
Pawel Zarembski |
0:01f31e923fe2 | 143 | |
Pawel Zarembski |
0:01f31e923fe2 | 144 | if (HSUSBD->OPER & HSUSBD_OPER_CURSPD_Msk) { |
Pawel Zarembski |
0:01f31e923fe2 | 145 | USBD_HighSpeed = __TRUE; |
Pawel Zarembski |
0:01f31e923fe2 | 146 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 147 | USBD_HighSpeed = __FALSE; |
Pawel Zarembski |
0:01f31e923fe2 | 148 | } |
Pawel Zarembski |
0:01f31e923fe2 | 149 | |
Pawel Zarembski |
0:01f31e923fe2 | 150 | /* Enable USB BUS, CEP global interrupt */ |
Pawel Zarembski |
0:01f31e923fe2 | 151 | HSUSBD_ENABLE_USB_INT(HSUSBD_GINTEN_USBIEN_Msk | HSUSBD_GINTEN_CEPIEN_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 152 | /* Enable BUS interrupt */ |
Pawel Zarembski |
0:01f31e923fe2 | 153 | HSUSBD_ENABLE_BUS_INT(HSUSBD_BUSINTEN_RESUMEIEN_Msk | HSUSBD_BUSINTEN_RSTIEN_Msk | HSUSBD_BUSINTEN_VBUSDETIEN_Msk | HSUSBD_BUSINTEN_SOFIEN_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 154 | /* Reset Address to 0 */ |
Pawel Zarembski |
0:01f31e923fe2 | 155 | HSUSBD_SET_ADDR(0); |
Pawel Zarembski |
0:01f31e923fe2 | 156 | /* Control endpoint */ |
Pawel Zarembski |
0:01f31e923fe2 | 157 | HSUSBD->CEPBUFST = CEP_BUF_BASE; |
Pawel Zarembski |
0:01f31e923fe2 | 158 | HSUSBD->CEPBUFEND = CEP_BUF_BASE + CEP_BUF_LEN - 1UL; |
Pawel Zarembski |
0:01f31e923fe2 | 159 | HSUSBD_ENABLE_CEP_INT(HSUSBD_CEPINTEN_SETUPPKIEN_Msk | HSUSBD_CEPINTEN_STSDONEIEN_Msk | HSUSBD_CEPINTEN_RXPKIEN_Msk | HSUSBD_CEPINTEN_TXPKIEN_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 160 | USBD_IntrEna(); |
Pawel Zarembski |
0:01f31e923fe2 | 161 | } |
Pawel Zarembski |
0:01f31e923fe2 | 162 | |
Pawel Zarembski |
0:01f31e923fe2 | 163 | |
Pawel Zarembski |
0:01f31e923fe2 | 164 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 165 | * USB Device Connect Function |
Pawel Zarembski |
0:01f31e923fe2 | 166 | * Called by the User to Connect/Disconnect USB Device |
Pawel Zarembski |
0:01f31e923fe2 | 167 | * Parameters: con: Connect/Disconnect |
Pawel Zarembski |
0:01f31e923fe2 | 168 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 169 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 170 | |
Pawel Zarembski |
0:01f31e923fe2 | 171 | void USBD_Connect(BOOL con) |
Pawel Zarembski |
0:01f31e923fe2 | 172 | { |
Pawel Zarembski |
0:01f31e923fe2 | 173 | if (con) { |
Pawel Zarembski |
0:01f31e923fe2 | 174 | HSUSBD_CLR_SE0(); |
Pawel Zarembski |
0:01f31e923fe2 | 175 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 176 | HSUSBD_SET_SE0(); |
Pawel Zarembski |
0:01f31e923fe2 | 177 | } |
Pawel Zarembski |
0:01f31e923fe2 | 178 | } |
Pawel Zarembski |
0:01f31e923fe2 | 179 | |
Pawel Zarembski |
0:01f31e923fe2 | 180 | |
Pawel Zarembski |
0:01f31e923fe2 | 181 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 182 | * USB Device Reset Function |
Pawel Zarembski |
0:01f31e923fe2 | 183 | * Called automatically on USB Device Reset |
Pawel Zarembski |
0:01f31e923fe2 | 184 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 185 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 186 | |
Pawel Zarembski |
0:01f31e923fe2 | 187 | void USBD_Reset(void) |
Pawel Zarembski |
0:01f31e923fe2 | 188 | { |
Pawel Zarembski |
0:01f31e923fe2 | 189 | uint32_t i; |
Pawel Zarembski |
0:01f31e923fe2 | 190 | |
Pawel Zarembski |
0:01f31e923fe2 | 191 | for (i = 0; i < HSUSBD_MAX_EP; i++) { |
Pawel Zarembski |
0:01f31e923fe2 | 192 | HSUSBD->EP[EPA + i].EPRSPCTL = HSUSBD_EPRSPCTL_FLUSH_Msk; |
Pawel Zarembski |
0:01f31e923fe2 | 193 | } |
Pawel Zarembski |
0:01f31e923fe2 | 194 | |
Pawel Zarembski |
0:01f31e923fe2 | 195 | if (HSUSBD->OPER & HSUSBD_OPER_CURSPD_Msk) { |
Pawel Zarembski |
0:01f31e923fe2 | 196 | USBD_HighSpeed = __TRUE; |
Pawel Zarembski |
0:01f31e923fe2 | 197 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 198 | USBD_HighSpeed = __FALSE; |
Pawel Zarembski |
0:01f31e923fe2 | 199 | } |
Pawel Zarembski |
0:01f31e923fe2 | 200 | |
Pawel Zarembski |
0:01f31e923fe2 | 201 | g_u32FreeBufAddr = CEP_BUF_BASE + CEP_BUF_LEN; |
Pawel Zarembski |
0:01f31e923fe2 | 202 | g_u8StatusIn = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 203 | HSUSBD_SET_ADDR(0); |
Pawel Zarembski |
0:01f31e923fe2 | 204 | } |
Pawel Zarembski |
0:01f31e923fe2 | 205 | |
Pawel Zarembski |
0:01f31e923fe2 | 206 | |
Pawel Zarembski |
0:01f31e923fe2 | 207 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 208 | * USB Device Suspend Function |
Pawel Zarembski |
0:01f31e923fe2 | 209 | * Called automatically on USB Device Suspend |
Pawel Zarembski |
0:01f31e923fe2 | 210 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 211 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 212 | |
Pawel Zarembski |
0:01f31e923fe2 | 213 | void USBD_Suspend(void) |
Pawel Zarembski |
0:01f31e923fe2 | 214 | { |
Pawel Zarembski |
0:01f31e923fe2 | 215 | } |
Pawel Zarembski |
0:01f31e923fe2 | 216 | |
Pawel Zarembski |
0:01f31e923fe2 | 217 | |
Pawel Zarembski |
0:01f31e923fe2 | 218 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 219 | * USB Device Resume Function |
Pawel Zarembski |
0:01f31e923fe2 | 220 | * Called automatically on USB Device Resume |
Pawel Zarembski |
0:01f31e923fe2 | 221 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 222 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 223 | |
Pawel Zarembski |
0:01f31e923fe2 | 224 | void USBD_Resume(void) |
Pawel Zarembski |
0:01f31e923fe2 | 225 | { |
Pawel Zarembski |
0:01f31e923fe2 | 226 | } |
Pawel Zarembski |
0:01f31e923fe2 | 227 | |
Pawel Zarembski |
0:01f31e923fe2 | 228 | |
Pawel Zarembski |
0:01f31e923fe2 | 229 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 230 | * USB Device Remote Wakeup Function |
Pawel Zarembski |
0:01f31e923fe2 | 231 | * Called automatically on USB Device Remote Wakeup |
Pawel Zarembski |
0:01f31e923fe2 | 232 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 233 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 234 | |
Pawel Zarembski |
0:01f31e923fe2 | 235 | void USBD_WakeUp(void) |
Pawel Zarembski |
0:01f31e923fe2 | 236 | { |
Pawel Zarembski |
0:01f31e923fe2 | 237 | } |
Pawel Zarembski |
0:01f31e923fe2 | 238 | |
Pawel Zarembski |
0:01f31e923fe2 | 239 | |
Pawel Zarembski |
0:01f31e923fe2 | 240 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 241 | * USB Device Remote Wakeup Configuration Function |
Pawel Zarembski |
0:01f31e923fe2 | 242 | * Parameters: cfg: Device Enable/Disable |
Pawel Zarembski |
0:01f31e923fe2 | 243 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 244 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 245 | |
Pawel Zarembski |
0:01f31e923fe2 | 246 | void USBD_WakeUpCfg(BOOL cfg) |
Pawel Zarembski |
0:01f31e923fe2 | 247 | { |
Pawel Zarembski |
0:01f31e923fe2 | 248 | } |
Pawel Zarembski |
0:01f31e923fe2 | 249 | |
Pawel Zarembski |
0:01f31e923fe2 | 250 | |
Pawel Zarembski |
0:01f31e923fe2 | 251 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 252 | * USB Device Set Address Function |
Pawel Zarembski |
0:01f31e923fe2 | 253 | * Parameters: adr: USB Device Address |
Pawel Zarembski |
0:01f31e923fe2 | 254 | * setup: Called in setup stage (!=0), else after status stage |
Pawel Zarembski |
0:01f31e923fe2 | 255 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 256 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 257 | |
Pawel Zarembski |
0:01f31e923fe2 | 258 | void USBD_SetAddress(U32 adr, U32 setup) |
Pawel Zarembski |
0:01f31e923fe2 | 259 | { |
Pawel Zarembski |
0:01f31e923fe2 | 260 | if (setup) { |
Pawel Zarembski |
0:01f31e923fe2 | 261 | return; |
Pawel Zarembski |
0:01f31e923fe2 | 262 | } |
Pawel Zarembski |
0:01f31e923fe2 | 263 | |
Pawel Zarembski |
0:01f31e923fe2 | 264 | HSUSBD_SET_ADDR(adr); |
Pawel Zarembski |
0:01f31e923fe2 | 265 | } |
Pawel Zarembski |
0:01f31e923fe2 | 266 | |
Pawel Zarembski |
0:01f31e923fe2 | 267 | |
Pawel Zarembski |
0:01f31e923fe2 | 268 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 269 | * USB Device Configure Function |
Pawel Zarembski |
0:01f31e923fe2 | 270 | * Parameters: cfg: Device Configure/Deconfigure |
Pawel Zarembski |
0:01f31e923fe2 | 271 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 272 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 273 | |
Pawel Zarembski |
0:01f31e923fe2 | 274 | void USBD_Configure(BOOL cfg) |
Pawel Zarembski |
0:01f31e923fe2 | 275 | { |
Pawel Zarembski |
0:01f31e923fe2 | 276 | if (cfg == __FALSE) { |
Pawel Zarembski |
0:01f31e923fe2 | 277 | g_u32FreeBufAddr = CEP_BUF_BASE + CEP_BUF_LEN; |
Pawel Zarembski |
0:01f31e923fe2 | 278 | } |
Pawel Zarembski |
0:01f31e923fe2 | 279 | } |
Pawel Zarembski |
0:01f31e923fe2 | 280 | |
Pawel Zarembski |
0:01f31e923fe2 | 281 | |
Pawel Zarembski |
0:01f31e923fe2 | 282 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 283 | * Configure USB Device Endpoint according to Descriptor |
Pawel Zarembski |
0:01f31e923fe2 | 284 | * Parameters: pEPD: Pointer to Device Endpoint Descriptor |
Pawel Zarembski |
0:01f31e923fe2 | 285 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 286 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 287 | |
Pawel Zarembski |
0:01f31e923fe2 | 288 | void USBD_ConfigEP(USB_ENDPOINT_DESCRIPTOR *pEPD) |
Pawel Zarembski |
0:01f31e923fe2 | 289 | { |
Pawel Zarembski |
0:01f31e923fe2 | 290 | uint32_t u32Num, u32Ep, u32Size, u32Type, u32Dir; |
Pawel Zarembski |
0:01f31e923fe2 | 291 | u32Num = pEPD->bEndpointAddress & 0x0F; |
Pawel Zarembski |
0:01f31e923fe2 | 292 | u32Ep = USBD_NUM_TO_EP(u32Num); |
Pawel Zarembski |
0:01f31e923fe2 | 293 | u32Size = pEPD->wMaxPacketSize; |
Pawel Zarembski |
0:01f31e923fe2 | 294 | |
Pawel Zarembski |
0:01f31e923fe2 | 295 | switch (pEPD->bmAttributes & USB_ENDPOINT_TYPE_MASK) { |
Pawel Zarembski |
0:01f31e923fe2 | 296 | case USB_ENDPOINT_TYPE_ISOCHRONOUS: |
Pawel Zarembski |
0:01f31e923fe2 | 297 | u32Type = HSUSBD_EP_CFG_TYPE_ISO; |
Pawel Zarembski |
0:01f31e923fe2 | 298 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 299 | |
Pawel Zarembski |
0:01f31e923fe2 | 300 | case USB_ENDPOINT_TYPE_BULK: |
Pawel Zarembski |
0:01f31e923fe2 | 301 | u32Type = HSUSBD_EP_CFG_TYPE_BULK; |
Pawel Zarembski |
0:01f31e923fe2 | 302 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 303 | |
Pawel Zarembski |
0:01f31e923fe2 | 304 | case USB_ENDPOINT_TYPE_INTERRUPT: |
Pawel Zarembski |
0:01f31e923fe2 | 305 | u32Type = HSUSBD_EP_CFG_TYPE_INT; |
Pawel Zarembski |
0:01f31e923fe2 | 306 | break; |
Pawel Zarembski |
0:01f31e923fe2 | 307 | } |
Pawel Zarembski |
0:01f31e923fe2 | 308 | |
Pawel Zarembski |
0:01f31e923fe2 | 309 | if (pEPD->bEndpointAddress & USB_ENDPOINT_DIRECTION_MASK) { |
Pawel Zarembski |
0:01f31e923fe2 | 310 | u32Dir = HSUSBD_EP_CFG_DIR_IN; |
Pawel Zarembski |
0:01f31e923fe2 | 311 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 312 | u32Dir = HSUSBD_EP_CFG_DIR_OUT; |
Pawel Zarembski |
0:01f31e923fe2 | 313 | } |
Pawel Zarembski |
0:01f31e923fe2 | 314 | |
Pawel Zarembski |
0:01f31e923fe2 | 315 | HSUSBD->EP[u32Ep].EPBUFST = g_u32FreeBufAddr; |
Pawel Zarembski |
0:01f31e923fe2 | 316 | HSUSBD->EP[u32Ep].EPBUFEND = g_u32FreeBufAddr + u32Size - 1UL; |
Pawel Zarembski |
0:01f31e923fe2 | 317 | HSUSBD_SET_MAX_PAYLOAD(u32Ep, u32Size); |
Pawel Zarembski |
0:01f31e923fe2 | 318 | HSUSBD->EP[u32Ep].EPRSPCTL = (HSUSBD_EP_RSPCTL_FLUSH | HSUSBD_EP_RSPCTL_MODE_AUTO); |
Pawel Zarembski |
0:01f31e923fe2 | 319 | HSUSBD->EP[u32Ep].EPCFG = (u32Type | u32Dir | HSUSBD_EP_CFG_VALID | (u32Num << 4)); |
Pawel Zarembski |
0:01f31e923fe2 | 320 | g_u32FreeBufAddr += u32Size; |
Pawel Zarembski |
0:01f31e923fe2 | 321 | } |
Pawel Zarembski |
0:01f31e923fe2 | 322 | |
Pawel Zarembski |
0:01f31e923fe2 | 323 | |
Pawel Zarembski |
0:01f31e923fe2 | 324 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 325 | * Set Direction for USB Device Control Endpoint |
Pawel Zarembski |
0:01f31e923fe2 | 326 | * Parameters: dir: Out (dir == 0), In (dir <> 0) |
Pawel Zarembski |
0:01f31e923fe2 | 327 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 328 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 329 | |
Pawel Zarembski |
0:01f31e923fe2 | 330 | void USBD_DirCtrlEP(U32 dir) |
Pawel Zarembski |
0:01f31e923fe2 | 331 | { |
Pawel Zarembski |
0:01f31e923fe2 | 332 | } |
Pawel Zarembski |
0:01f31e923fe2 | 333 | |
Pawel Zarembski |
0:01f31e923fe2 | 334 | |
Pawel Zarembski |
0:01f31e923fe2 | 335 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 336 | * Enable USB Device Endpoint |
Pawel Zarembski |
0:01f31e923fe2 | 337 | * Parameters: EPNum: Device Endpoint Number |
Pawel Zarembski |
0:01f31e923fe2 | 338 | * EPNum.0..3: Address |
Pawel Zarembski |
0:01f31e923fe2 | 339 | * EPNum.7: Dir |
Pawel Zarembski |
0:01f31e923fe2 | 340 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 341 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 342 | |
Pawel Zarembski |
0:01f31e923fe2 | 343 | void USBD_EnableEP(U32 EPNum) |
Pawel Zarembski |
0:01f31e923fe2 | 344 | { |
Pawel Zarembski |
0:01f31e923fe2 | 345 | uint32_t u32Ep, u32Num, u32Intr; |
Pawel Zarembski |
0:01f31e923fe2 | 346 | u32Num = EPNum & 0x0F; |
Pawel Zarembski |
0:01f31e923fe2 | 347 | u32Ep = USBD_NUM_TO_EP(u32Num); |
Pawel Zarembski |
0:01f31e923fe2 | 348 | HSUSBD->GINTEN |= (0x1UL << (HSUSBD_GINTEN_EPAIEN_Pos + (u32Num - USBD_EP_TO_NUM(EPA)))); |
Pawel Zarembski |
0:01f31e923fe2 | 349 | |
Pawel Zarembski |
0:01f31e923fe2 | 350 | if (EPNum & 0x80) { |
Pawel Zarembski |
0:01f31e923fe2 | 351 | u32Intr = HSUSBD_EPINTEN_TXPKIEN_Msk; |
Pawel Zarembski |
0:01f31e923fe2 | 352 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 353 | u32Intr = HSUSBD_EPINTEN_RXPKIEN_Msk | HSUSBD_EPINTEN_SHORTRXIEN_Msk | HSUSBD_EPINTEN_BUFFULLIEN_Msk; |
Pawel Zarembski |
0:01f31e923fe2 | 354 | } |
Pawel Zarembski |
0:01f31e923fe2 | 355 | |
Pawel Zarembski |
0:01f31e923fe2 | 356 | HSUSBD_ENABLE_EP_INT(u32Ep, u32Intr); |
Pawel Zarembski |
0:01f31e923fe2 | 357 | } |
Pawel Zarembski |
0:01f31e923fe2 | 358 | |
Pawel Zarembski |
0:01f31e923fe2 | 359 | |
Pawel Zarembski |
0:01f31e923fe2 | 360 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 361 | * Disable USB Endpoint |
Pawel Zarembski |
0:01f31e923fe2 | 362 | * Parameters: EPNum: Endpoint Number |
Pawel Zarembski |
0:01f31e923fe2 | 363 | * EPNum.0..3: Address |
Pawel Zarembski |
0:01f31e923fe2 | 364 | * EPNum.7: Dir |
Pawel Zarembski |
0:01f31e923fe2 | 365 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 366 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 367 | |
Pawel Zarembski |
0:01f31e923fe2 | 368 | void USBD_DisableEP(U32 EPNum) |
Pawel Zarembski |
0:01f31e923fe2 | 369 | { |
Pawel Zarembski |
0:01f31e923fe2 | 370 | uint32_t u32Ep, u32Num; |
Pawel Zarembski |
0:01f31e923fe2 | 371 | u32Num = EPNum & 0x0F; |
Pawel Zarembski |
0:01f31e923fe2 | 372 | u32Ep = USBD_NUM_TO_EP(u32Num); |
Pawel Zarembski |
0:01f31e923fe2 | 373 | HSUSBD->GINTEN &= ~(0x1UL << (HSUSBD_GINTEN_EPAIEN_Pos + (u32Num - USBD_EP_TO_NUM(EPA)))); |
Pawel Zarembski |
0:01f31e923fe2 | 374 | HSUSBD_ENABLE_EP_INT(u32Ep, 0); |
Pawel Zarembski |
0:01f31e923fe2 | 375 | } |
Pawel Zarembski |
0:01f31e923fe2 | 376 | |
Pawel Zarembski |
0:01f31e923fe2 | 377 | |
Pawel Zarembski |
0:01f31e923fe2 | 378 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 379 | * Reset USB Device Endpoint |
Pawel Zarembski |
0:01f31e923fe2 | 380 | * Parameters: EPNum: Device Endpoint Number |
Pawel Zarembski |
0:01f31e923fe2 | 381 | * EPNum.0..3: Address |
Pawel Zarembski |
0:01f31e923fe2 | 382 | * EPNum.7: Dir |
Pawel Zarembski |
0:01f31e923fe2 | 383 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 384 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 385 | |
Pawel Zarembski |
0:01f31e923fe2 | 386 | void USBD_ResetEP(U32 EPNum) |
Pawel Zarembski |
0:01f31e923fe2 | 387 | { |
Pawel Zarembski |
0:01f31e923fe2 | 388 | uint32_t u32Ep, u32Num; |
Pawel Zarembski |
0:01f31e923fe2 | 389 | u32Num = EPNum & 0x0F; |
Pawel Zarembski |
0:01f31e923fe2 | 390 | u32Ep = USBD_NUM_TO_EP(u32Num); |
Pawel Zarembski |
0:01f31e923fe2 | 391 | HSUSBD->EP[u32Ep].EPRSPCTL = (HSUSBD->EP[u32Ep].EPRSPCTL & HSUSBD_EP_RSPCTL_MODE_MASK) | HSUSBD_EPRSPCTL_FLUSH_Msk; |
Pawel Zarembski |
0:01f31e923fe2 | 392 | } |
Pawel Zarembski |
0:01f31e923fe2 | 393 | |
Pawel Zarembski |
0:01f31e923fe2 | 394 | |
Pawel Zarembski |
0:01f31e923fe2 | 395 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 396 | * Set Stall for USB Device Endpoint |
Pawel Zarembski |
0:01f31e923fe2 | 397 | * Parameters: EPNum: Device Endpoint Number |
Pawel Zarembski |
0:01f31e923fe2 | 398 | * EPNum.0..3: Address |
Pawel Zarembski |
0:01f31e923fe2 | 399 | * EPNum.7: Dir |
Pawel Zarembski |
0:01f31e923fe2 | 400 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 401 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 402 | |
Pawel Zarembski |
0:01f31e923fe2 | 403 | void USBD_SetStallEP(U32 EPNum) |
Pawel Zarembski |
0:01f31e923fe2 | 404 | { |
Pawel Zarembski |
0:01f31e923fe2 | 405 | uint32_t u32Ep, u32Num; |
Pawel Zarembski |
0:01f31e923fe2 | 406 | u32Num = EPNum & 0x0F; |
Pawel Zarembski |
0:01f31e923fe2 | 407 | u32Ep = USBD_NUM_TO_EP(u32Num); |
Pawel Zarembski |
0:01f31e923fe2 | 408 | |
Pawel Zarembski |
0:01f31e923fe2 | 409 | if (u32Ep == CEP) { |
Pawel Zarembski |
0:01f31e923fe2 | 410 | HSUSBD_SET_CEP_STATE(HSUSBD_CEPCTL_STALL); |
Pawel Zarembski |
0:01f31e923fe2 | 411 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 412 | HSUSBD->EP[u32Ep].EPRSPCTL = (HSUSBD->EP[u32Ep].EPRSPCTL & 0xF7UL) | HSUSBD_EP_RSPCTL_HALT; |
Pawel Zarembski |
0:01f31e923fe2 | 413 | } |
Pawel Zarembski |
0:01f31e923fe2 | 414 | } |
Pawel Zarembski |
0:01f31e923fe2 | 415 | |
Pawel Zarembski |
0:01f31e923fe2 | 416 | |
Pawel Zarembski |
0:01f31e923fe2 | 417 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 418 | * Clear Stall for USB Device Endpoint |
Pawel Zarembski |
0:01f31e923fe2 | 419 | * Parameters: EPNum: Device Endpoint Number |
Pawel Zarembski |
0:01f31e923fe2 | 420 | * EPNum.0..3: Address |
Pawel Zarembski |
0:01f31e923fe2 | 421 | * EPNum.7: Dir |
Pawel Zarembski |
0:01f31e923fe2 | 422 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 423 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 424 | |
Pawel Zarembski |
0:01f31e923fe2 | 425 | void USBD_ClrStallEP(U32 EPNum) |
Pawel Zarembski |
0:01f31e923fe2 | 426 | { |
Pawel Zarembski |
0:01f31e923fe2 | 427 | uint32_t u32Ep, u32Num; |
Pawel Zarembski |
0:01f31e923fe2 | 428 | u32Num = EPNum & 0x0F; |
Pawel Zarembski |
0:01f31e923fe2 | 429 | u32Ep = USBD_NUM_TO_EP(u32Num); |
Pawel Zarembski |
0:01f31e923fe2 | 430 | |
Pawel Zarembski |
0:01f31e923fe2 | 431 | if (u32Ep == CEP) { |
Pawel Zarembski |
0:01f31e923fe2 | 432 | HSUSBD_SET_CEP_STATE(HSUSBD_CEPCTL_NAKCLR_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 433 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 434 | HSUSBD->EP[u32Ep].EPRSPCTL = (HSUSBD->EP[u32Ep].EPRSPCTL & HSUSBD_EP_RSPCTL_MODE_MASK) | HSUSBD_EP_RSPCTL_TOGGLE; |
Pawel Zarembski |
0:01f31e923fe2 | 435 | } |
Pawel Zarembski |
0:01f31e923fe2 | 436 | } |
Pawel Zarembski |
0:01f31e923fe2 | 437 | |
Pawel Zarembski |
0:01f31e923fe2 | 438 | |
Pawel Zarembski |
0:01f31e923fe2 | 439 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 440 | * Clear USB Device Endpoint Buffer |
Pawel Zarembski |
0:01f31e923fe2 | 441 | * Parameters: EPNum: Device Endpoint Number |
Pawel Zarembski |
0:01f31e923fe2 | 442 | * EPNum.0..3: Address |
Pawel Zarembski |
0:01f31e923fe2 | 443 | * EPNum.7: Dir |
Pawel Zarembski |
0:01f31e923fe2 | 444 | * Return Value: None |
Pawel Zarembski |
0:01f31e923fe2 | 445 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 446 | |
Pawel Zarembski |
0:01f31e923fe2 | 447 | void USBD_ClearEPBuf(U32 EPNum) |
Pawel Zarembski |
0:01f31e923fe2 | 448 | { |
Pawel Zarembski |
0:01f31e923fe2 | 449 | } |
Pawel Zarembski |
0:01f31e923fe2 | 450 | |
Pawel Zarembski |
0:01f31e923fe2 | 451 | |
Pawel Zarembski |
0:01f31e923fe2 | 452 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 453 | * Read USB Device Endpoint Data |
Pawel Zarembski |
0:01f31e923fe2 | 454 | * Parameters: EPNum: Device Endpoint Number |
Pawel Zarembski |
0:01f31e923fe2 | 455 | * EPNum.0..3: Address |
Pawel Zarembski |
0:01f31e923fe2 | 456 | * EPNum.7: Dir |
Pawel Zarembski |
0:01f31e923fe2 | 457 | * pData: Pointer to Data Buffer |
Pawel Zarembski |
0:01f31e923fe2 | 458 | * Return Value: Number of bytes read |
Pawel Zarembski |
0:01f31e923fe2 | 459 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 460 | |
Pawel Zarembski |
0:01f31e923fe2 | 461 | U32 USBD_ReadEP(U32 EPNum, U8 *pData, U32 bufsz) |
Pawel Zarembski |
0:01f31e923fe2 | 462 | { |
Pawel Zarembski |
0:01f31e923fe2 | 463 | uint32_t u32Ep, u32Num, u32Len, i; |
Pawel Zarembski |
0:01f31e923fe2 | 464 | u32Num = EPNum & 0x0F; |
Pawel Zarembski |
0:01f31e923fe2 | 465 | u32Ep = USBD_NUM_TO_EP(u32Num); |
Pawel Zarembski |
0:01f31e923fe2 | 466 | |
Pawel Zarembski |
0:01f31e923fe2 | 467 | if (u32Num == 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 468 | if (pData == (uint8_t *)&USBD_SetupPacket) { |
Pawel Zarembski |
0:01f31e923fe2 | 469 | *((uint16_t *)(pData + 0)) = (uint16_t)(HSUSBD->SETUP1_0 & 0xFFFFUL); |
Pawel Zarembski |
0:01f31e923fe2 | 470 | *((uint16_t *)(pData + 2)) = (uint16_t)(HSUSBD->SETUP3_2 & 0xFFFFUL); |
Pawel Zarembski |
0:01f31e923fe2 | 471 | *((uint16_t *)(pData + 4)) = (uint16_t)(HSUSBD->SETUP5_4 & 0xFFFFUL); |
Pawel Zarembski |
0:01f31e923fe2 | 472 | *((uint16_t *)(pData + 6)) = (uint16_t)(HSUSBD->SETUP7_6 & 0xFFFFUL); |
Pawel Zarembski |
0:01f31e923fe2 | 473 | return 8; |
Pawel Zarembski |
0:01f31e923fe2 | 474 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 475 | u32Len = HSUSBD->CEPDATCNT & 0xFFFFUL; |
Pawel Zarembski |
0:01f31e923fe2 | 476 | |
Pawel Zarembski |
0:01f31e923fe2 | 477 | if (u32Len > bufsz) { |
Pawel Zarembski |
0:01f31e923fe2 | 478 | u32Len = bufsz; |
Pawel Zarembski |
0:01f31e923fe2 | 479 | } |
Pawel Zarembski |
0:01f31e923fe2 | 480 | |
Pawel Zarembski |
0:01f31e923fe2 | 481 | for (i = 0; i < bufsz; i++) { |
Pawel Zarembski |
0:01f31e923fe2 | 482 | pData[i] = inpb(&HSUSBD->CEPDAT); |
Pawel Zarembski |
0:01f31e923fe2 | 483 | } |
Pawel Zarembski |
0:01f31e923fe2 | 484 | |
Pawel Zarembski |
0:01f31e923fe2 | 485 | return u32Len; |
Pawel Zarembski |
0:01f31e923fe2 | 486 | } |
Pawel Zarembski |
0:01f31e923fe2 | 487 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 488 | u32Len = HSUSBD->EP[u32Ep].EPDATCNT & 0xFFFFUL; |
Pawel Zarembski |
0:01f31e923fe2 | 489 | |
Pawel Zarembski |
0:01f31e923fe2 | 490 | if (u32Len > bufsz) { |
Pawel Zarembski |
0:01f31e923fe2 | 491 | u32Len = bufsz; |
Pawel Zarembski |
0:01f31e923fe2 | 492 | } |
Pawel Zarembski |
0:01f31e923fe2 | 493 | |
Pawel Zarembski |
0:01f31e923fe2 | 494 | for (i = 0; i < u32Len; i++) { |
Pawel Zarembski |
0:01f31e923fe2 | 495 | pData[i] = HSUSBD->EP[u32Ep].EPDAT_BYTE; |
Pawel Zarembski |
0:01f31e923fe2 | 496 | } |
Pawel Zarembski |
0:01f31e923fe2 | 497 | |
Pawel Zarembski |
0:01f31e923fe2 | 498 | return u32Len; |
Pawel Zarembski |
0:01f31e923fe2 | 499 | } |
Pawel Zarembski |
0:01f31e923fe2 | 500 | } |
Pawel Zarembski |
0:01f31e923fe2 | 501 | |
Pawel Zarembski |
0:01f31e923fe2 | 502 | |
Pawel Zarembski |
0:01f31e923fe2 | 503 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 504 | * Write USB Device Endpoint Data |
Pawel Zarembski |
0:01f31e923fe2 | 505 | * Parameters: EPNum: Device Endpoint Number |
Pawel Zarembski |
0:01f31e923fe2 | 506 | * EPNum.0..3: Address |
Pawel Zarembski |
0:01f31e923fe2 | 507 | * EPNum.7: Dir |
Pawel Zarembski |
0:01f31e923fe2 | 508 | * pData: Pointer to Data Buffer |
Pawel Zarembski |
0:01f31e923fe2 | 509 | * cnt: Number of bytes to write |
Pawel Zarembski |
0:01f31e923fe2 | 510 | * Return Value: Number of bytes written |
Pawel Zarembski |
0:01f31e923fe2 | 511 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 512 | |
Pawel Zarembski |
0:01f31e923fe2 | 513 | U32 USBD_WriteEP(U32 EPNum, U8 *pData, U32 cnt) |
Pawel Zarembski |
0:01f31e923fe2 | 514 | { |
Pawel Zarembski |
0:01f31e923fe2 | 515 | uint32_t u32Ep, u32Num, i; |
Pawel Zarembski |
0:01f31e923fe2 | 516 | u32Num = EPNum & 0x0F; |
Pawel Zarembski |
0:01f31e923fe2 | 517 | u32Ep = USBD_NUM_TO_EP(u32Num); |
Pawel Zarembski |
0:01f31e923fe2 | 518 | |
Pawel Zarembski |
0:01f31e923fe2 | 519 | if (u32Num == 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 520 | if (pData != NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 521 | if (cnt > 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 522 | for (i = 0; i < cnt; i++) { |
Pawel Zarembski |
0:01f31e923fe2 | 523 | HSUSBD->CEPDAT_BYTE = pData[i]; |
Pawel Zarembski |
0:01f31e923fe2 | 524 | } |
Pawel Zarembski |
0:01f31e923fe2 | 525 | |
Pawel Zarembski |
0:01f31e923fe2 | 526 | HSUSBD_START_CEP_IN(cnt); |
Pawel Zarembski |
0:01f31e923fe2 | 527 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 528 | HSUSBD_SET_CEP_STATE(HSUSBD_CEPCTL_ZEROLEN); |
Pawel Zarembski |
0:01f31e923fe2 | 529 | } |
Pawel Zarembski |
0:01f31e923fe2 | 530 | } else if (cnt == 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 531 | g_u8StatusIn = 1; |
Pawel Zarembski |
0:01f31e923fe2 | 532 | HSUSBD_CLR_CEP_INT_FLAG(HSUSBD_CEPINTSTS_STSDONEIF_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 533 | HSUSBD_SET_CEP_STATE(HSUSBD_CEPCTL_NAKCLR); |
Pawel Zarembski |
0:01f31e923fe2 | 534 | } |
Pawel Zarembski |
0:01f31e923fe2 | 535 | |
Pawel Zarembski |
0:01f31e923fe2 | 536 | return cnt; |
Pawel Zarembski |
0:01f31e923fe2 | 537 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 538 | if (cnt > 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 539 | for (i = 0; i < cnt; i++) { |
Pawel Zarembski |
0:01f31e923fe2 | 540 | HSUSBD->EP[u32Ep].EPDAT_BYTE = pData[i]; |
Pawel Zarembski |
0:01f31e923fe2 | 541 | } |
Pawel Zarembski |
0:01f31e923fe2 | 542 | |
Pawel Zarembski |
0:01f31e923fe2 | 543 | HSUSBD->EP[u32Ep].EPRSPCTL = (HSUSBD->EP[u32Ep].EPRSPCTL & HSUSBD_EP_RSPCTL_HALT) | HSUSBD_EP_RSPCTL_SHORTTXEN; |
Pawel Zarembski |
0:01f31e923fe2 | 544 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 545 | HSUSBD->EP[u32Ep].EPRSPCTL = (HSUSBD->EP[u32Ep].EPRSPCTL & HSUSBD_EP_RSPCTL_HALT) | HSUSBD_EP_RSPCTL_ZEROLEN; |
Pawel Zarembski |
0:01f31e923fe2 | 546 | } |
Pawel Zarembski |
0:01f31e923fe2 | 547 | |
Pawel Zarembski |
0:01f31e923fe2 | 548 | return cnt; |
Pawel Zarembski |
0:01f31e923fe2 | 549 | } |
Pawel Zarembski |
0:01f31e923fe2 | 550 | } |
Pawel Zarembski |
0:01f31e923fe2 | 551 | |
Pawel Zarembski |
0:01f31e923fe2 | 552 | |
Pawel Zarembski |
0:01f31e923fe2 | 553 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 554 | * Get USB Device Last Frame Number |
Pawel Zarembski |
0:01f31e923fe2 | 555 | * Parameters: None |
Pawel Zarembski |
0:01f31e923fe2 | 556 | * Return Value: Frame Number |
Pawel Zarembski |
0:01f31e923fe2 | 557 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 558 | |
Pawel Zarembski |
0:01f31e923fe2 | 559 | U32 USBD_GetFrame(void) |
Pawel Zarembski |
0:01f31e923fe2 | 560 | { |
Pawel Zarembski |
0:01f31e923fe2 | 561 | return 0; |
Pawel Zarembski |
0:01f31e923fe2 | 562 | } |
Pawel Zarembski |
0:01f31e923fe2 | 563 | |
Pawel Zarembski |
0:01f31e923fe2 | 564 | |
Pawel Zarembski |
0:01f31e923fe2 | 565 | #ifdef __RTX |
Pawel Zarembski |
0:01f31e923fe2 | 566 | U32 LastError; |
Pawel Zarembski |
0:01f31e923fe2 | 567 | |
Pawel Zarembski |
0:01f31e923fe2 | 568 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 569 | * Get USB Last Error Code |
Pawel Zarembski |
0:01f31e923fe2 | 570 | * Parameters: None |
Pawel Zarembski |
0:01f31e923fe2 | 571 | * Return Value: Error Code |
Pawel Zarembski |
0:01f31e923fe2 | 572 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 573 | |
Pawel Zarembski |
0:01f31e923fe2 | 574 | U32 USBD_GetError(void) |
Pawel Zarembski |
0:01f31e923fe2 | 575 | { |
Pawel Zarembski |
0:01f31e923fe2 | 576 | return (LastError); |
Pawel Zarembski |
0:01f31e923fe2 | 577 | } |
Pawel Zarembski |
0:01f31e923fe2 | 578 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 579 | |
Pawel Zarembski |
0:01f31e923fe2 | 580 | |
Pawel Zarembski |
0:01f31e923fe2 | 581 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 582 | * USB Device Interrupt Service Routine |
Pawel Zarembski |
0:01f31e923fe2 | 583 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 584 | |
Pawel Zarembski |
0:01f31e923fe2 | 585 | void USBD20_IRQHandler(void) |
Pawel Zarembski |
0:01f31e923fe2 | 586 | { |
Pawel Zarembski |
0:01f31e923fe2 | 587 | NVIC_DisableIRQ(USBD20_IRQn); |
Pawel Zarembski |
0:01f31e923fe2 | 588 | USBD_SignalHandler(); |
Pawel Zarembski |
0:01f31e923fe2 | 589 | } |
Pawel Zarembski |
0:01f31e923fe2 | 590 | |
Pawel Zarembski |
0:01f31e923fe2 | 591 | void USBD_Handler_Main() |
Pawel Zarembski |
0:01f31e923fe2 | 592 | { |
Pawel Zarembski |
0:01f31e923fe2 | 593 | __IO uint32_t IrqStL, IrqSt; |
Pawel Zarembski |
0:01f31e923fe2 | 594 | uint32_t u32Ep, u32Num, i; |
Pawel Zarembski |
0:01f31e923fe2 | 595 | IrqStL = HSUSBD->GINTSTS & HSUSBD->GINTEN; |
Pawel Zarembski |
0:01f31e923fe2 | 596 | |
Pawel Zarembski |
0:01f31e923fe2 | 597 | if (!IrqStL) { |
Pawel Zarembski |
0:01f31e923fe2 | 598 | return; |
Pawel Zarembski |
0:01f31e923fe2 | 599 | } |
Pawel Zarembski |
0:01f31e923fe2 | 600 | |
Pawel Zarembski |
0:01f31e923fe2 | 601 | if (IrqStL & HSUSBD_GINTSTS_USBIF_Msk) { |
Pawel Zarembski |
0:01f31e923fe2 | 602 | IrqSt = HSUSBD->BUSINTSTS & HSUSBD->BUSINTEN; |
Pawel Zarembski |
0:01f31e923fe2 | 603 | |
Pawel Zarembski |
0:01f31e923fe2 | 604 | if (IrqSt & HSUSBD_BUSINTSTS_SOFIF_Msk) { |
Pawel Zarembski |
0:01f31e923fe2 | 605 | #ifdef __RTX |
Pawel Zarembski |
0:01f31e923fe2 | 606 | |
Pawel Zarembski |
0:01f31e923fe2 | 607 | if (USBD_RTX_DevTask) { |
Pawel Zarembski |
0:01f31e923fe2 | 608 | isr_evt_set(USBD_EVT_SOF, USBD_RTX_DevTask); |
Pawel Zarembski |
0:01f31e923fe2 | 609 | } |
Pawel Zarembski |
0:01f31e923fe2 | 610 | |
Pawel Zarembski |
0:01f31e923fe2 | 611 | #else |
Pawel Zarembski |
0:01f31e923fe2 | 612 | |
Pawel Zarembski |
0:01f31e923fe2 | 613 | if (USBD_P_SOF_Event) { |
Pawel Zarembski |
0:01f31e923fe2 | 614 | USBD_P_SOF_Event(); |
Pawel Zarembski |
0:01f31e923fe2 | 615 | } |
Pawel Zarembski |
0:01f31e923fe2 | 616 | |
Pawel Zarembski |
0:01f31e923fe2 | 617 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 618 | HSUSBD_CLR_BUS_INT_FLAG(HSUSBD_BUSINTSTS_SOFIF_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 619 | } |
Pawel Zarembski |
0:01f31e923fe2 | 620 | |
Pawel Zarembski |
0:01f31e923fe2 | 621 | if (IrqSt & HSUSBD_BUSINTSTS_RSTIF_Msk) { |
Pawel Zarembski |
0:01f31e923fe2 | 622 | USBD_Reset(); |
Pawel Zarembski |
0:01f31e923fe2 | 623 | usbd_reset_core(); |
Pawel Zarembski |
0:01f31e923fe2 | 624 | #ifdef __RTX |
Pawel Zarembski |
0:01f31e923fe2 | 625 | |
Pawel Zarembski |
0:01f31e923fe2 | 626 | if (USBD_RTX_DevTask) { |
Pawel Zarembski |
0:01f31e923fe2 | 627 | isr_evt_set(USBD_EVT_RESET, USBD_RTX_DevTask); |
Pawel Zarembski |
0:01f31e923fe2 | 628 | } |
Pawel Zarembski |
0:01f31e923fe2 | 629 | |
Pawel Zarembski |
0:01f31e923fe2 | 630 | #else |
Pawel Zarembski |
0:01f31e923fe2 | 631 | |
Pawel Zarembski |
0:01f31e923fe2 | 632 | if (USBD_P_Reset_Event) { |
Pawel Zarembski |
0:01f31e923fe2 | 633 | USBD_P_Reset_Event(); |
Pawel Zarembski |
0:01f31e923fe2 | 634 | } |
Pawel Zarembski |
0:01f31e923fe2 | 635 | |
Pawel Zarembski |
0:01f31e923fe2 | 636 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 637 | HSUSBD_ENABLE_BUS_INT(HSUSBD_BUSINTEN_RSTIEN_Msk | HSUSBD_BUSINTEN_RESUMEIEN_Msk | HSUSBD_BUSINTEN_SUSPENDIEN_Msk | HSUSBD_BUSINTEN_SOFIEN_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 638 | HSUSBD_CLR_BUS_INT_FLAG(HSUSBD_BUSINTSTS_RSTIF_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 639 | HSUSBD_CLR_CEP_INT_FLAG(0x1FFC); |
Pawel Zarembski |
0:01f31e923fe2 | 640 | } |
Pawel Zarembski |
0:01f31e923fe2 | 641 | |
Pawel Zarembski |
0:01f31e923fe2 | 642 | if (IrqSt & HSUSBD_BUSINTSTS_RESUMEIF_Msk) { |
Pawel Zarembski |
0:01f31e923fe2 | 643 | USBD_WakeUp(); |
Pawel Zarembski |
0:01f31e923fe2 | 644 | #ifdef __RTX |
Pawel Zarembski |
0:01f31e923fe2 | 645 | |
Pawel Zarembski |
0:01f31e923fe2 | 646 | if (USBD_RTX_DevTask) { |
Pawel Zarembski |
0:01f31e923fe2 | 647 | isr_evt_set(USBD_EVT_RESUME, USBD_RTX_DevTask); |
Pawel Zarembski |
0:01f31e923fe2 | 648 | } |
Pawel Zarembski |
0:01f31e923fe2 | 649 | |
Pawel Zarembski |
0:01f31e923fe2 | 650 | #else |
Pawel Zarembski |
0:01f31e923fe2 | 651 | |
Pawel Zarembski |
0:01f31e923fe2 | 652 | if (USBD_P_Resume_Event) { |
Pawel Zarembski |
0:01f31e923fe2 | 653 | USBD_P_Resume_Event(); |
Pawel Zarembski |
0:01f31e923fe2 | 654 | } |
Pawel Zarembski |
0:01f31e923fe2 | 655 | |
Pawel Zarembski |
0:01f31e923fe2 | 656 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 657 | HSUSBD_ENABLE_BUS_INT(HSUSBD_BUSINTEN_RSTIEN_Msk | HSUSBD_BUSINTEN_SUSPENDIEN_Msk | HSUSBD_BUSINTEN_SOFIEN_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 658 | HSUSBD_CLR_BUS_INT_FLAG(HSUSBD_BUSINTSTS_RESUMEIF_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 659 | } |
Pawel Zarembski |
0:01f31e923fe2 | 660 | |
Pawel Zarembski |
0:01f31e923fe2 | 661 | if (IrqSt & HSUSBD_BUSINTSTS_SUSPENDIF_Msk) { |
Pawel Zarembski |
0:01f31e923fe2 | 662 | USBD_Suspend(); |
Pawel Zarembski |
0:01f31e923fe2 | 663 | #ifdef __RTX |
Pawel Zarembski |
0:01f31e923fe2 | 664 | |
Pawel Zarembski |
0:01f31e923fe2 | 665 | if (USBD_RTX_DevTask) { |
Pawel Zarembski |
0:01f31e923fe2 | 666 | isr_evt_set(USBD_EVT_SUSPEND, USBD_RTX_DevTask); |
Pawel Zarembski |
0:01f31e923fe2 | 667 | } |
Pawel Zarembski |
0:01f31e923fe2 | 668 | |
Pawel Zarembski |
0:01f31e923fe2 | 669 | #else |
Pawel Zarembski |
0:01f31e923fe2 | 670 | |
Pawel Zarembski |
0:01f31e923fe2 | 671 | if (USBD_P_Suspend_Event) { |
Pawel Zarembski |
0:01f31e923fe2 | 672 | USBD_P_Suspend_Event(); |
Pawel Zarembski |
0:01f31e923fe2 | 673 | } |
Pawel Zarembski |
0:01f31e923fe2 | 674 | |
Pawel Zarembski |
0:01f31e923fe2 | 675 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 676 | HSUSBD_ENABLE_BUS_INT(HSUSBD_BUSINTEN_RSTIEN_Msk | HSUSBD_BUSINTEN_RESUMEIEN_Msk | HSUSBD_BUSINTEN_SOFIEN_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 677 | HSUSBD_CLR_BUS_INT_FLAG(HSUSBD_BUSINTSTS_SUSPENDIF_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 678 | } |
Pawel Zarembski |
0:01f31e923fe2 | 679 | |
Pawel Zarembski |
0:01f31e923fe2 | 680 | if (IrqSt & HSUSBD_BUSINTSTS_VBUSDETIF_Msk) { |
Pawel Zarembski |
0:01f31e923fe2 | 681 | if (HSUSBD_IS_ATTACHED()) { |
Pawel Zarembski |
0:01f31e923fe2 | 682 | HSUSBD_ENABLE_USB(); |
Pawel Zarembski |
0:01f31e923fe2 | 683 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 684 | HSUSBD_DISABLE_USB(); |
Pawel Zarembski |
0:01f31e923fe2 | 685 | } |
Pawel Zarembski |
0:01f31e923fe2 | 686 | |
Pawel Zarembski |
0:01f31e923fe2 | 687 | HSUSBD_CLR_BUS_INT_FLAG(HSUSBD_BUSINTSTS_VBUSDETIF_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 688 | } |
Pawel Zarembski |
0:01f31e923fe2 | 689 | } |
Pawel Zarembski |
0:01f31e923fe2 | 690 | |
Pawel Zarembski |
0:01f31e923fe2 | 691 | if (IrqStL & HSUSBD_GINTSTS_CEPIF_Msk) { |
Pawel Zarembski |
0:01f31e923fe2 | 692 | IrqSt = HSUSBD->CEPINTSTS & HSUSBD->CEPINTEN; |
Pawel Zarembski |
0:01f31e923fe2 | 693 | |
Pawel Zarembski |
0:01f31e923fe2 | 694 | if (IrqSt & HSUSBD_CEPINTSTS_SETUPPKIF_Msk) { |
Pawel Zarembski |
0:01f31e923fe2 | 695 | #ifdef __RTX |
Pawel Zarembski |
0:01f31e923fe2 | 696 | |
Pawel Zarembski |
0:01f31e923fe2 | 697 | if (USBD_RTX_EPTask[0]) { |
Pawel Zarembski |
0:01f31e923fe2 | 698 | isr_evt_set(USBD_EVT_SETUP, USBD_RTX_EPTask[0]); |
Pawel Zarembski |
0:01f31e923fe2 | 699 | } |
Pawel Zarembski |
0:01f31e923fe2 | 700 | |
Pawel Zarembski |
0:01f31e923fe2 | 701 | #else |
Pawel Zarembski |
0:01f31e923fe2 | 702 | |
Pawel Zarembski |
0:01f31e923fe2 | 703 | if (USBD_P_EP[0]) { |
Pawel Zarembski |
0:01f31e923fe2 | 704 | USBD_P_EP[0](USBD_EVT_SETUP); |
Pawel Zarembski |
0:01f31e923fe2 | 705 | } |
Pawel Zarembski |
0:01f31e923fe2 | 706 | |
Pawel Zarembski |
0:01f31e923fe2 | 707 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 708 | HSUSBD_CLR_CEP_INT_FLAG(HSUSBD_CEPINTSTS_SETUPPKIF_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 709 | return; |
Pawel Zarembski |
0:01f31e923fe2 | 710 | } |
Pawel Zarembski |
0:01f31e923fe2 | 711 | |
Pawel Zarembski |
0:01f31e923fe2 | 712 | if (IrqSt & HSUSBD_CEPINTSTS_TXPKIF_Msk) { |
Pawel Zarembski |
0:01f31e923fe2 | 713 | HSUSBD_CLR_CEP_INT_FLAG(HSUSBD_CEPINTSTS_STSDONEIF_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 714 | HSUSBD_SET_CEP_STATE(HSUSBD_CEPCTL_NAKCLR); |
Pawel Zarembski |
0:01f31e923fe2 | 715 | #ifdef __RTX |
Pawel Zarembski |
0:01f31e923fe2 | 716 | |
Pawel Zarembski |
0:01f31e923fe2 | 717 | if (USBD_RTX_EPTask[0]) { |
Pawel Zarembski |
0:01f31e923fe2 | 718 | isr_evt_set(USBD_EVT_IN, USBD_RTX_EPTask[0]); |
Pawel Zarembski |
0:01f31e923fe2 | 719 | } |
Pawel Zarembski |
0:01f31e923fe2 | 720 | |
Pawel Zarembski |
0:01f31e923fe2 | 721 | #else |
Pawel Zarembski |
0:01f31e923fe2 | 722 | |
Pawel Zarembski |
0:01f31e923fe2 | 723 | if (USBD_P_EP[0]) { |
Pawel Zarembski |
0:01f31e923fe2 | 724 | USBD_P_EP[0](USBD_EVT_IN); |
Pawel Zarembski |
0:01f31e923fe2 | 725 | } |
Pawel Zarembski |
0:01f31e923fe2 | 726 | |
Pawel Zarembski |
0:01f31e923fe2 | 727 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 728 | HSUSBD_CLR_CEP_INT_FLAG(HSUSBD_CEPINTSTS_TXPKIF_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 729 | return; |
Pawel Zarembski |
0:01f31e923fe2 | 730 | } |
Pawel Zarembski |
0:01f31e923fe2 | 731 | |
Pawel Zarembski |
0:01f31e923fe2 | 732 | if (IrqSt & HSUSBD_CEPINTSTS_RXPKIF_Msk) { |
Pawel Zarembski |
0:01f31e923fe2 | 733 | #ifdef __RTX |
Pawel Zarembski |
0:01f31e923fe2 | 734 | |
Pawel Zarembski |
0:01f31e923fe2 | 735 | if (USBD_RTX_EPTask[0]) { |
Pawel Zarembski |
0:01f31e923fe2 | 736 | isr_evt_set(USBD_EVT_OUT, USBD_RTX_EPTask[0]); |
Pawel Zarembski |
0:01f31e923fe2 | 737 | } |
Pawel Zarembski |
0:01f31e923fe2 | 738 | |
Pawel Zarembski |
0:01f31e923fe2 | 739 | #else |
Pawel Zarembski |
0:01f31e923fe2 | 740 | |
Pawel Zarembski |
0:01f31e923fe2 | 741 | if (USBD_P_EP[0]) { |
Pawel Zarembski |
0:01f31e923fe2 | 742 | USBD_P_EP[0](USBD_EVT_OUT); |
Pawel Zarembski |
0:01f31e923fe2 | 743 | } |
Pawel Zarembski |
0:01f31e923fe2 | 744 | |
Pawel Zarembski |
0:01f31e923fe2 | 745 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 746 | HSUSBD_CLR_CEP_INT_FLAG(HSUSBD_CEPINTSTS_RXPKIF_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 747 | return; |
Pawel Zarembski |
0:01f31e923fe2 | 748 | } |
Pawel Zarembski |
0:01f31e923fe2 | 749 | |
Pawel Zarembski |
0:01f31e923fe2 | 750 | if (IrqSt & HSUSBD_CEPINTSTS_STSDONEIF_Msk) { |
Pawel Zarembski |
0:01f31e923fe2 | 751 | if (g_u8StatusIn == 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 752 | #ifdef __RTX |
Pawel Zarembski |
0:01f31e923fe2 | 753 | |
Pawel Zarembski |
0:01f31e923fe2 | 754 | if (USBD_RTX_EPTask[0]) { |
Pawel Zarembski |
0:01f31e923fe2 | 755 | isr_evt_set(USBD_EVT_OUT, USBD_RTX_EPTask[0]); |
Pawel Zarembski |
0:01f31e923fe2 | 756 | } |
Pawel Zarembski |
0:01f31e923fe2 | 757 | |
Pawel Zarembski |
0:01f31e923fe2 | 758 | #else |
Pawel Zarembski |
0:01f31e923fe2 | 759 | |
Pawel Zarembski |
0:01f31e923fe2 | 760 | if (USBD_P_EP[0]) { |
Pawel Zarembski |
0:01f31e923fe2 | 761 | USBD_P_EP[0](USBD_EVT_OUT); |
Pawel Zarembski |
0:01f31e923fe2 | 762 | } |
Pawel Zarembski |
0:01f31e923fe2 | 763 | |
Pawel Zarembski |
0:01f31e923fe2 | 764 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 765 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 766 | #ifdef __RTX |
Pawel Zarembski |
0:01f31e923fe2 | 767 | |
Pawel Zarembski |
0:01f31e923fe2 | 768 | if (USBD_RTX_EPTask[0]) { |
Pawel Zarembski |
0:01f31e923fe2 | 769 | isr_evt_set(USBD_EVT_IN, USBD_RTX_EPTask[0]); |
Pawel Zarembski |
0:01f31e923fe2 | 770 | } |
Pawel Zarembski |
0:01f31e923fe2 | 771 | |
Pawel Zarembski |
0:01f31e923fe2 | 772 | #else |
Pawel Zarembski |
0:01f31e923fe2 | 773 | |
Pawel Zarembski |
0:01f31e923fe2 | 774 | if (USBD_P_EP[0]) { |
Pawel Zarembski |
0:01f31e923fe2 | 775 | USBD_P_EP[0](USBD_EVT_IN); |
Pawel Zarembski |
0:01f31e923fe2 | 776 | } |
Pawel Zarembski |
0:01f31e923fe2 | 777 | |
Pawel Zarembski |
0:01f31e923fe2 | 778 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 779 | } |
Pawel Zarembski |
0:01f31e923fe2 | 780 | |
Pawel Zarembski |
0:01f31e923fe2 | 781 | g_u8StatusIn = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 782 | HSUSBD_CLR_CEP_INT_FLAG(HSUSBD_CEPINTSTS_STSDONEIF_Msk); |
Pawel Zarembski |
0:01f31e923fe2 | 783 | return; |
Pawel Zarembski |
0:01f31e923fe2 | 784 | } |
Pawel Zarembski |
0:01f31e923fe2 | 785 | } |
Pawel Zarembski |
0:01f31e923fe2 | 786 | |
Pawel Zarembski |
0:01f31e923fe2 | 787 | for (i = 0; i < HSUSBD_MAX_EP; i++) { |
Pawel Zarembski |
0:01f31e923fe2 | 788 | u32Ep = EPA + i; |
Pawel Zarembski |
0:01f31e923fe2 | 789 | u32Num = USBD_EP_TO_NUM(u32Ep); |
Pawel Zarembski |
0:01f31e923fe2 | 790 | |
Pawel Zarembski |
0:01f31e923fe2 | 791 | if (IrqStL & (0x1UL << (HSUSBD_GINTSTS_EPAIF_Pos + i))) { |
Pawel Zarembski |
0:01f31e923fe2 | 792 | IrqSt = HSUSBD->EP[u32Ep].EPINTSTS & HSUSBD->EP[u32Ep].EPINTEN; |
Pawel Zarembski |
0:01f31e923fe2 | 793 | |
Pawel Zarembski |
0:01f31e923fe2 | 794 | if (IrqSt & HSUSBD_EPINTSTS_TXPKIF_Msk) { |
Pawel Zarembski |
0:01f31e923fe2 | 795 | #ifdef __RTX |
Pawel Zarembski |
0:01f31e923fe2 | 796 | |
Pawel Zarembski |
0:01f31e923fe2 | 797 | if (USBD_RTX_EPTask[u32Num]) { |
Pawel Zarembski |
0:01f31e923fe2 | 798 | isr_evt_set(USBD_EVT_IN, USBD_RTX_EPTask[u32Num]); |
Pawel Zarembski |
0:01f31e923fe2 | 799 | } |
Pawel Zarembski |
0:01f31e923fe2 | 800 | |
Pawel Zarembski |
0:01f31e923fe2 | 801 | #else |
Pawel Zarembski |
0:01f31e923fe2 | 802 | |
Pawel Zarembski |
0:01f31e923fe2 | 803 | if (USBD_P_EP[u32Num]) { |
Pawel Zarembski |
0:01f31e923fe2 | 804 | USBD_P_EP[u32Num](USBD_EVT_IN); |
Pawel Zarembski |
0:01f31e923fe2 | 805 | } |
Pawel Zarembski |
0:01f31e923fe2 | 806 | |
Pawel Zarembski |
0:01f31e923fe2 | 807 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 808 | } |
Pawel Zarembski |
0:01f31e923fe2 | 809 | |
Pawel Zarembski |
0:01f31e923fe2 | 810 | if (IrqSt & (HSUSBD_EPINTSTS_RXPKIF_Msk | HSUSBD_EPINTSTS_SHORTRXIF_Msk | HSUSBD_EPINTEN_BUFFULLIEN_Msk)) { |
Pawel Zarembski |
0:01f31e923fe2 | 811 | #ifdef __RTX |
Pawel Zarembski |
0:01f31e923fe2 | 812 | |
Pawel Zarembski |
0:01f31e923fe2 | 813 | if (USBD_RTX_EPTask[u32Num]) { |
Pawel Zarembski |
0:01f31e923fe2 | 814 | isr_evt_set(USBD_EVT_OUT, USBD_RTX_EPTask[u32Num]); |
Pawel Zarembski |
0:01f31e923fe2 | 815 | } |
Pawel Zarembski |
0:01f31e923fe2 | 816 | |
Pawel Zarembski |
0:01f31e923fe2 | 817 | #else |
Pawel Zarembski |
0:01f31e923fe2 | 818 | |
Pawel Zarembski |
0:01f31e923fe2 | 819 | if (USBD_P_EP[u32Num]) { |
Pawel Zarembski |
0:01f31e923fe2 | 820 | USBD_P_EP[u32Num](USBD_EVT_OUT); |
Pawel Zarembski |
0:01f31e923fe2 | 821 | } |
Pawel Zarembski |
0:01f31e923fe2 | 822 | |
Pawel Zarembski |
0:01f31e923fe2 | 823 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 824 | } |
Pawel Zarembski |
0:01f31e923fe2 | 825 | |
Pawel Zarembski |
0:01f31e923fe2 | 826 | HSUSBD_CLR_EP_INT_FLAG(u32Ep, IrqSt); |
Pawel Zarembski |
0:01f31e923fe2 | 827 | } |
Pawel Zarembski |
0:01f31e923fe2 | 828 | } |
Pawel Zarembski |
0:01f31e923fe2 | 829 | } |
Pawel Zarembski |
0:01f31e923fe2 | 830 | |
Pawel Zarembski |
0:01f31e923fe2 | 831 | void USBD_Handler(void) |
Pawel Zarembski |
0:01f31e923fe2 | 832 | { |
Pawel Zarembski |
0:01f31e923fe2 | 833 | USBD_Handler_Main(); |
Pawel Zarembski |
0:01f31e923fe2 | 834 | NVIC_EnableIRQ(USBD20_IRQn); |
Pawel Zarembski |
0:01f31e923fe2 | 835 | } |