From 614a45197029b7f1beaf78f65e7b9467737a46b8 Mon Sep 17 00:00:00 2001 From: ccli8 Date: Tue, 3 Jan 2017 13:23:30 +0800 Subject: [PATCH] [NUC472/M453] Remove Tab in USB HAL --- .../USBDevice/USBDevice/USBEndpoints_M453.h | 24 +- .../USBDevice/USBDevice/USBEndpoints_NUC472.h | 42 +- .../USBDevice/USBDevice/USBHAL_M453.cpp | 335 ++++----- .../USBDevice/USBDevice/USBHAL_NUC472.cpp | 675 +++++++++--------- 4 files changed, 539 insertions(+), 537 deletions(-) diff --git a/features/unsupported/USBDevice/USBDevice/USBEndpoints_M453.h b/features/unsupported/USBDevice/USBDevice/USBEndpoints_M453.h index 793d2574fbf..78cc22e6718 100644 --- a/features/unsupported/USBDevice/USBDevice/USBEndpoints_M453.h +++ b/features/unsupported/USBDevice/USBDevice/USBEndpoints_M453.h @@ -16,8 +16,8 @@ #define NU_MAX_EPX_BUFSIZE 4096 #define NU_EP2EPL(ep) ((ep) >> 1) #define NU_EP2EPH(ep) (((ep) >> 1) + 1) -#define NU_EPL2EPH(ep) ((ep) + 1) -#define NU_EPH2EPL(ep) ((ep) - 1) +#define NU_EPL2EPH(ep) ((ep) + 1) +#define NU_EPH2EPL(ep) ((ep) - 1) #define NU_EP_DIR_Pos 0 #define NU_EP_DIR_Msk (1 << NU_EP_DIR_Pos) #define NU_EP_DIR_OUT 0 @@ -37,22 +37,22 @@ #define EP2IN (5) #define EP3OUT (6) #define EP3IN (7) -#define EP4OUT (8) -#define EP4IN (9) +#define EP4OUT (8) +#define EP4IN (9) #define EP5OUT (10) #define EP5IN (11) #define EP6OUT (12) #define EP6IN (13) /* Maximum Packet sizes */ -#define MAX_PACKET_SIZE_EP0 64 -#define MAX_PACKET_SIZE_EP1 64 -#define MAX_PACKET_SIZE_EP2 64 -#define MAX_PACKET_SIZE_EP3 0x60 -#define MAX_PACKET_SIZE_EP4 64 -#define MAX_PACKET_SIZE_EP5 64 -#define MAX_PACKET_SIZE_EP6 64 -#define MAX_PACKET_SIZE_EP7 64 +#define MAX_PACKET_SIZE_EP0 64 +#define MAX_PACKET_SIZE_EP1 64 +#define MAX_PACKET_SIZE_EP2 64 +#define MAX_PACKET_SIZE_EP3 0x60 +#define MAX_PACKET_SIZE_EP4 64 +#define MAX_PACKET_SIZE_EP5 64 +#define MAX_PACKET_SIZE_EP6 64 +#define MAX_PACKET_SIZE_EP7 64 /* Generic endpoints - intended to be portable accross devices */ /* and be suitable for simple USB devices. */ diff --git a/features/unsupported/USBDevice/USBDevice/USBEndpoints_NUC472.h b/features/unsupported/USBDevice/USBDevice/USBEndpoints_NUC472.h index 2041cbaf14e..0d5e97f839a 100644 --- a/features/unsupported/USBDevice/USBDevice/USBEndpoints_NUC472.h +++ b/features/unsupported/USBDevice/USBDevice/USBEndpoints_NUC472.h @@ -16,9 +16,9 @@ #define NU_MAX_EPX_BUFSIZE 4096 #define NU_EP2EPL(ep) ((ep) >> 1) #define NU_EP2EPH(ep) (((ep) >> 1) - 1) -#define NU_EPX2EP(ep) ((ep == CEP) ? EP0OUT : ((ep) - EPA + EP1OUT)) -#define NU_EPL2EPH(ep) ((ep) - 1) -#define NU_EPH2EPL(ep) ((ep) + 1) +#define NU_EPX2EP(ep) ((ep == CEP) ? EP0OUT : ((ep) - EPA + EP1OUT)) +#define NU_EPL2EPH(ep) ((ep) - 1) +#define NU_EPH2EPL(ep) ((ep) + 1) #define NU_EP_DIR_Pos 0 #define NU_EP_DIR_Msk (1 << NU_EP_DIR_Pos) #define NU_EP_DIR_OUT 0 @@ -39,26 +39,26 @@ #define EP2IN (5) #define EP3OUT (6) #define EP3IN (7) -#define EP4OUT (8) -#define EP4IN (9) +#define EP4OUT (8) +#define EP4IN (9) #define EP5OUT (10) #define EP5IN (11) #define EP6OUT (12) #define EP6IN (13) /* Maximum Packet sizes */ -#define MAX_PACKET_SIZE_EP0 64 -#define MAX_PACKET_SIZE_EP1 64 -#define MAX_PACKET_SIZE_EP2 64 -#define MAX_PACKET_SIZE_EP3 0x60 -#define MAX_PACKET_SIZE_EP4 64 -#define MAX_PACKET_SIZE_EP5 64 -#define MAX_PACKET_SIZE_EP6 64 -#define MAX_PACKET_SIZE_EP7 64 -#define MAX_PACKET_SIZE_EP8 64 -#define MAX_PACKET_SIZE_EP9 64 -#define MAX_PACKET_SIZE_EP10 64 -#define MAX_PACKET_SIZE_EP11 64 +#define MAX_PACKET_SIZE_EP0 64 +#define MAX_PACKET_SIZE_EP1 64 +#define MAX_PACKET_SIZE_EP2 64 +#define MAX_PACKET_SIZE_EP3 0x60 +#define MAX_PACKET_SIZE_EP4 64 +#define MAX_PACKET_SIZE_EP5 64 +#define MAX_PACKET_SIZE_EP6 64 +#define MAX_PACKET_SIZE_EP7 64 +#define MAX_PACKET_SIZE_EP8 64 +#define MAX_PACKET_SIZE_EP9 64 +#define MAX_PACKET_SIZE_EP10 64 +#define MAX_PACKET_SIZE_EP11 64 /* Generic endpoints - intended to be portable accross devices */ /* and be suitable for simple USB devices. */ @@ -83,7 +83,7 @@ #define MAX_PACKET_SIZE_EPINT 64 #define MAX_PACKET_SIZE_EPISO 1023 -#define USBD_GET_EP_MAX_PAYLOAD(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EPAMPS + (uint32_t)((ep)*0x28)))) -#define USBD_GET_EP_DATA_COUNT(ep) ((*((__IO uint32_t *) ((uint32_t)&USBD->EPADATCNT + (uint32_t)((ep)*0x28)))) & 0xFFFFF) -#define USBD_SET_EP_SHORT_PACKET(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EPARSPCTL + (uint32_t)((ep)*0x28))) = (*((__IO uint32_t *) ((uint32_t)&USBD->EPARSPCTL + (uint32_t)((ep)*0x28)))) & 0x10 | 0x40) -#define USBD_GET_EP_INT_EN(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EPAINTEN + (uint32_t)((ep)*0x28)))) +#define USBD_GET_EP_MAX_PAYLOAD(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EPAMPS + (uint32_t)((ep)*0x28)))) +#define USBD_GET_EP_DATA_COUNT(ep) ((*((__IO uint32_t *) ((uint32_t)&USBD->EPADATCNT + (uint32_t)((ep)*0x28)))) & 0xFFFFF) +#define USBD_SET_EP_SHORT_PACKET(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EPARSPCTL + (uint32_t)((ep)*0x28))) = (*((__IO uint32_t *) ((uint32_t)&USBD->EPARSPCTL + (uint32_t)((ep)*0x28)))) & 0x10 | 0x40) +#define USBD_GET_EP_INT_EN(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EPAINTEN + (uint32_t)((ep)*0x28)))) diff --git a/features/unsupported/USBDevice/USBDevice/USBHAL_M453.cpp b/features/unsupported/USBDevice/USBDevice/USBHAL_M453.cpp index ea79711cfe4..fb933170267 100644 --- a/features/unsupported/USBDevice/USBDevice/USBHAL_M453.cpp +++ b/features/unsupported/USBDevice/USBDevice/USBHAL_M453.cpp @@ -46,12 +46,12 @@ extern volatile uint32_t g_usbd_CtrlMaxPktSize; extern volatile uint32_t g_usbd_UsbAltInterface; volatile uint32_t g_usbd_CepTransferLen = 0; volatile uint32_t frame_cnt = 0; -USBHAL::USBHAL(void) +USBHAL::USBHAL(void) { - SYS_UnlockReg(); - + SYS_UnlockReg(); + s_ep_buf_ind = 8; - + memset(epCallback, 0x00, sizeof (epCallback)); epCallback[0] = &USBHAL::EP1_OUT_callback; epCallback[1] = &USBHAL::EP2_IN_callback; @@ -63,34 +63,34 @@ USBHAL::USBHAL(void) instance = this; /* Enable USBD module clock */ CLK_EnableModuleClock(USBD_MODULE); - + CLK_SetModuleClock(USBD_MODULE, 0, CLK_CLKDIV0_USB(3)); /* Enable USB LDO33 */ SYS->USBPHY = SYS_USBPHY_LDO33EN_Msk; - + /* Initial USB engine */ USBD->ATTR = 0x7D0; - + /* Set SE0 (disconnect) */ USBD_SET_SE0(); - + //NVIC_SetVector(OTG_FS_IRQn, (uint32_t) &_usbisr); NVIC_SetVector(USBD_IRQn, (uint32_t) &_usbisr); NVIC_EnableIRQ(USBD_IRQn); } -USBHAL::~USBHAL(void) +USBHAL::~USBHAL(void) { NVIC_DisableIRQ(USBD_IRQn); - USBD_SET_SE0(); + USBD_SET_SE0(); USBD_DISABLE_PHY(); } void USBHAL::connect(void) { - USBD->STBUFSEG = 0; - frame_cnt = 0; + USBD->STBUFSEG = 0; + frame_cnt = 0; /* EP0 ==> control IN endpoint, address 0 */ USBD_CONFIG_EP(EP0, USBD_CFG_CSTALL | USBD_CFG_EPMODE_IN | 0); /* Buffer range for EP0 */ @@ -99,11 +99,11 @@ void USBHAL::connect(void) /* EP1 ==> control OUT endpoint, address 0 */ USBD_CONFIG_EP(EP1, USBD_CFG_CSTALL | USBD_CFG_EPMODE_OUT | 0); /* Buffer range for EP1 */ - USBD_SET_EP_BUF_ADDR(EP1, s_ep_buf_ind); - + USBD_SET_EP_BUF_ADDR(EP1, s_ep_buf_ind); + s_ep_buf_ind += MAX_PACKET_SIZE_EP0; - - /* Disable software-disconnect function */ + + /* Disable software-disconnect function */ USBD_CLR_SE0(); /* Clear USB-related interrupts before enable interrupt */ @@ -127,7 +127,7 @@ void USBHAL::configureDevice(void) * 1. Allocate for CEP on connect(). * 2. Allocate for EPX in realiseEndpoint(). * 3. Deallocate all except for CEP in unconfigureDevice(). - */ + */ } void USBHAL::unconfigureDevice(void) @@ -143,30 +143,30 @@ void USBHAL::setAddress(uint8_t address) void USBHAL::remoteWakeup(void) { -#if 0 +#if 0 USBD->OPER |= USBD_OPER_RESUMEEN_Msk; -#endif +#endif } bool USBHAL::realiseEndpoint(uint8_t endpoint, uint32_t maxPacket, uint32_t options) { uint32_t ep_type = 0; uint32_t ep_hw_index = NU_EP2EPH(endpoint); - uint32_t ep_logic_index = NU_EP2EPL(endpoint); - uint32_t ep_dir = (NU_EP_DIR(endpoint) == NU_EP_DIR_IN) ? USBD_CFG_EPMODE_IN : USBD_CFG_EPMODE_OUT; - - if(ep_logic_index == 3 || ep_logic_index == 4) - ep_type = USBD_CFG_TYPE_ISO; - - USBD_CONFIG_EP(ep_hw_index, ep_dir | ep_type | ep_logic_index); + uint32_t ep_logic_index = NU_EP2EPL(endpoint); + uint32_t ep_dir = (NU_EP_DIR(endpoint) == NU_EP_DIR_IN) ? USBD_CFG_EPMODE_IN : USBD_CFG_EPMODE_OUT; + + if (ep_logic_index == 3 || ep_logic_index == 4) + ep_type = USBD_CFG_TYPE_ISO; + + USBD_CONFIG_EP(ep_hw_index, ep_dir | ep_type | ep_logic_index); /* Buffer range */ - USBD_SET_EP_BUF_ADDR(ep_hw_index, s_ep_buf_ind); - - if(ep_dir == USBD_CFG_EPMODE_OUT) - USBD_SET_PAYLOAD_LEN(ep_hw_index, maxPacket); - - s_ep_mxp[ep_logic_index] = maxPacket; - + USBD_SET_EP_BUF_ADDR(ep_hw_index, s_ep_buf_ind); + + if (ep_dir == USBD_CFG_EPMODE_OUT) + USBD_SET_PAYLOAD_LEN(ep_hw_index, maxPacket); + + s_ep_mxp[ep_logic_index] = maxPacket; + s_ep_buf_ind += maxPacket; return true; @@ -181,55 +181,55 @@ void USBHAL::EP0setup(uint8_t *buffer) void USBHAL::EP0read(void) { - + } void USBHAL::EP0readStage(void) { - // N/A + // N/A - USBD_PrepareCtrlOut(0,0); + USBD_PrepareCtrlOut(0,0); } uint32_t USBHAL::EP0getReadResult(uint8_t *buffer) -{ - uint32_t i; - uint8_t *buf = (uint8_t *)(USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP1)); +{ + uint32_t i; + uint8_t *buf = (uint8_t *)(USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP1)); uint32_t ceprxcnt = USBD_GET_PAYLOAD_LEN(EP1); - for (i = 0; i < ceprxcnt; i ++) + for (i = 0; i < ceprxcnt; i ++) buffer[i] = buf[i]; - USBD_SET_PAYLOAD_LEN(EP1, MAX_PACKET_SIZE_EP0); - return ceprxcnt; + USBD_SET_PAYLOAD_LEN(EP1, MAX_PACKET_SIZE_EP0); + return ceprxcnt; } void USBHAL::EP0write(uint8_t *buffer, uint32_t size) { - if (buffer && size) - { - if(s_ep_data_bit[0] & 1) - USBD_SET_DATA1(EP0); - else - USBD_SET_DATA0(EP0); - s_ep_data_bit[0]++; - - USBD_MemCopy((uint8_t *)USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP0), buffer, size); - USBD_SET_PAYLOAD_LEN(EP0, size); - if(size < MAX_PACKET_SIZE_EP0) - s_ep_data_bit[0] = 1; - - } - else - { - if(g_usbd_SetupPacket[0] & 0x80) //Device to Host - { - // Status stage - // USBD_PrepareCtrlOut(0,0); - }else - { + if (buffer && size) + { + if (s_ep_data_bit[0] & 1) + USBD_SET_DATA1(EP0); + else + USBD_SET_DATA0(EP0); + s_ep_data_bit[0]++; + + USBD_MemCopy((uint8_t *)USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP0), buffer, size); + USBD_SET_PAYLOAD_LEN(EP0, size); + if (size < MAX_PACKET_SIZE_EP0) + s_ep_data_bit[0] = 1; + + } + else + { + if (g_usbd_SetupPacket[0] & 0x80) //Device to Host + { + // Status stage + // USBD_PrepareCtrlOut(0,0); + } else + { USBD_SET_DATA1(EP0); - USBD_SET_PAYLOAD_LEN(EP0, 0); - } - } + USBD_SET_PAYLOAD_LEN(EP0, 0); + } + } } void USBHAL::EP0getWriteResult(void) @@ -242,33 +242,33 @@ void USBHAL::EP0stall(void) stallEndpoint(EP0OUT); } -EP_STATUS USBHAL::endpointRead(uint8_t endpoint, uint32_t maximumSize) +EP_STATUS USBHAL::endpointRead(uint8_t endpoint, uint32_t maximumSize) { return EP_PENDING; } EP_STATUS USBHAL::endpointReadResult(uint8_t endpoint, uint8_t * buffer, uint32_t *bytesRead) //spcheng { - if(endpoint == EP0OUT) - { - USBD_MemCopy(g_usbd_SetupPacket, (uint8_t *)USBD_BUF_BASE, 8); - if (buffer) { - USBD_MemCopy(buffer, g_usbd_SetupPacket, 8); - } - USBD_SET_PAYLOAD_LEN(EP1, MAX_PACKET_SIZE_EP0); - } - else - { - uint32_t i; - uint8_t *buf = (uint8_t *)(USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(NU_EP2EPH(endpoint))); - uint32_t eprxcnt = USBD_GET_PAYLOAD_LEN(NU_EP2EPH(endpoint)); - for (i = 0; i < eprxcnt; i ++) - buffer[i] = buf[i]; - - *bytesRead = eprxcnt; - - USBD_SET_PAYLOAD_LEN(NU_EP2EPH(endpoint),s_ep_mxp[NU_EPH2EPL(NU_EP2EPL(endpoint))]); - } + if (endpoint == EP0OUT) + { + USBD_MemCopy(g_usbd_SetupPacket, (uint8_t *)USBD_BUF_BASE, 8); + if (buffer) { + USBD_MemCopy(buffer, g_usbd_SetupPacket, 8); + } + USBD_SET_PAYLOAD_LEN(EP1, MAX_PACKET_SIZE_EP0); + } + else + { + uint32_t i; + uint8_t *buf = (uint8_t *)(USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(NU_EP2EPH(endpoint))); + uint32_t eprxcnt = USBD_GET_PAYLOAD_LEN(NU_EP2EPH(endpoint)); + for (i = 0; i < eprxcnt; i ++) + buffer[i] = buf[i]; + + *bytesRead = eprxcnt; + + USBD_SET_PAYLOAD_LEN(NU_EP2EPH(endpoint),s_ep_mxp[NU_EPH2EPL(NU_EP2EPL(endpoint))]); + } return EP_COMPLETED; } @@ -280,41 +280,41 @@ uint32_t USBHAL::endpointReadcore(uint8_t endpoint, uint8_t *buffer) EP_STATUS USBHAL::endpointWrite(uint8_t endpoint, uint8_t *data, uint32_t size) { - uint32_t ep_logic_index = NU_EP2EPL(endpoint); - if(ep_logic_index == 0) - return EP_INVALID; - else - { - uint8_t *buf; - uint32_t i=0; - uint32_t ep_hw_index = NU_EP2EPH(endpoint); - s_ep_compl |= (1 << ep_logic_index); - buf = (uint8_t *)(USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(ep_hw_index)); - for(i=0;i= NUMBER_OF_PHYSICAL_ENDPOINTS) + if (ep_hw_index >= NUMBER_OF_PHYSICAL_ENDPOINTS) return; - + USBD_SetStall(NU_EPH2EPL(ep_hw_index)); - + } void USBHAL::unstallEndpoint(uint8_t endpoint) @@ -322,7 +322,7 @@ void USBHAL::unstallEndpoint(uint8_t endpoint) uint32_t ep_hw_index = NU_EP2EPH(endpoint); if (ep_hw_index >= NUMBER_OF_PHYSICAL_ENDPOINTS) return; - USBD_ClearStall(NU_EPH2EPL(ep_hw_index)); + USBD_ClearStall(NU_EPH2EPL(ep_hw_index)); } bool USBHAL::getEndpointStallState(uint8_t endpoint) @@ -339,19 +339,19 @@ void USBHAL::_usbisr(void) MBED_ASSERT(instance); instance->usbisr(); } - -void USBHAL::usbisr(void) + +void USBHAL::usbisr(void) { - uint32_t u32IntSts = USBD_GET_INT_FLAG(); + uint32_t u32IntSts = USBD_GET_INT_FLAG(); uint32_t u32State = USBD_GET_BUS_STATE(); //------------------------------------------------------------------ - if(u32IntSts & USBD_INTSTS_VBDETIF_Msk) + if (u32IntSts & USBD_INTSTS_VBDETIF_Msk) { // Floating detect USBD_CLR_INT_FLAG(USBD_INTSTS_VBDETIF_Msk); - if(USBD_IS_ATTACHED()) + if (USBD_IS_ATTACHED()) { /* USB Plug In */ USBD_ENABLE_USB(); @@ -364,33 +364,33 @@ void USBHAL::usbisr(void) } //------------------------------------------------------------------ - if(u32IntSts & USBD_INTSTS_BUSIF_Msk) + if (u32IntSts & USBD_INTSTS_BUSIF_Msk) { /* Clear event flag */ USBD_CLR_INT_FLAG(USBD_INTSTS_BUSIF_Msk); - if(u32State & USBD_ATTR_USBRST_Msk) + if (u32State & USBD_ATTR_USBRST_Msk) { /* Bus reset */ USBD_ENABLE_USB(); USBD_SwReset(); } - if(u32State & USBD_ATTR_SUSPEND_Msk) + if (u32State & USBD_ATTR_SUSPEND_Msk) { /* Enable USB but disable PHY */ USBD_DISABLE_PHY(); } - if(u32State & USBD_ATTR_RESUME_Msk) + if (u32State & USBD_ATTR_RESUME_Msk) { /* Enable USB and enable PHY */ USBD_ENABLE_USB(); } } - if(u32IntSts & USBD_INTSTS_USBIF_Msk) + if (u32IntSts & USBD_INTSTS_USBIF_Msk) { // USB event - if(u32IntSts & USBD_INTSTS_SETUP_Msk) + if (u32IntSts & USBD_INTSTS_SETUP_Msk) { // Setup packet /* Clear event flag */ @@ -399,66 +399,67 @@ void USBHAL::usbisr(void) /* Clear the data IN/OUT ready flag of control end-points */ USBD_STOP_TRANSACTION(EP0); USBD_STOP_TRANSACTION(EP1); - EP0setupCallback(); + EP0setupCallback(); } // EP events - if(u32IntSts & USBD_INTSTS_EP0) + if (u32IntSts & USBD_INTSTS_EP0) { /* Clear event flag */ USBD_CLR_INT_FLAG(USBD_INTSTS_EP0); // control IN EP0in(); - - // In ACK for Set address - if((g_usbd_SetupPacket[0] == REQ_STANDARD) && (g_usbd_SetupPacket[1] == USBD_SET_ADDRESS)) - { - if((USBD_GET_ADDR() != s_usb_addr) && (USBD_GET_ADDR() == 0)) - { - USBD_SET_ADDR(s_usb_addr); - } - } + + // In ACK for Set address + if ((g_usbd_SetupPacket[0] == REQ_STANDARD) && (g_usbd_SetupPacket[1] == USBD_SET_ADDRESS)) + { + if ((USBD_GET_ADDR() != s_usb_addr) && (USBD_GET_ADDR() == 0)) + { + USBD_SET_ADDR(s_usb_addr); + } + } } - if(u32IntSts & USBD_INTSTS_EP1) + if (u32IntSts & USBD_INTSTS_EP1) { /* Clear event flag */ USBD_CLR_INT_FLAG(USBD_INTSTS_EP1); - // control OUT + // control OUT EP0out(); } - - uint32_t gintsts_epx = (u32IntSts >> 18) & 0x3F; - uint32_t ep_hw_index = 2; - while (gintsts_epx) { - if(gintsts_epx & 0x01) - { - uint32_t ep_status = (USBD_GET_EP_FLAG() >> (ep_hw_index * 3 + 8)) & 0x7; - /* Clear event flag */ - USBD_CLR_INT_FLAG(1 << (ep_hw_index + 16)); - - if(ep_status == 0x02 || ep_status == 0x06 || (ep_status == 0x07 && NU_EPH2EPL(ep_hw_index) == 3)) //RX - { - if(ep_status == 0x07) - SOF(frame_cnt++); - if ((instance->*(epCallback[ep_hw_index-2]))()) - { - - } - USBD_SET_PAYLOAD_LEN(ep_hw_index,s_ep_mxp[NU_EPH2EPL(ep_hw_index)]); - } - else if(ep_status == 0x00 || ep_status == 0x07) //TX - { - s_ep_compl &= ~(1 << (NU_EPH2EPL(ep_hw_index))); - if ((instance->*(epCallback[ep_hw_index-2]))()) - { - } - } - } - - gintsts_epx = gintsts_epx >> 1; - ep_hw_index++; - } - } + + uint32_t gintsts_epx = (u32IntSts >> 18) & 0x3F; + uint32_t ep_hw_index = 2; + while (gintsts_epx) { + if (gintsts_epx & 0x01) + { + uint32_t ep_status = (USBD_GET_EP_FLAG() >> (ep_hw_index * 3 + 8)) & 0x7; + /* Clear event flag */ + USBD_CLR_INT_FLAG(1 << (ep_hw_index + 16)); + + if (ep_status == 0x02 || ep_status == 0x06 || (ep_status == 0x07 && NU_EPH2EPL(ep_hw_index) == 3)) //RX + { + if (ep_status == 0x07) + SOF(frame_cnt++); + if ((instance->*(epCallback[ep_hw_index-2]))()) + { + + } + USBD_SET_PAYLOAD_LEN(ep_hw_index,s_ep_mxp[NU_EPH2EPL(ep_hw_index)]); + } + else if (ep_status == 0x00 || ep_status == 0x07) //TX + { + s_ep_compl &= ~(1 << (NU_EPH2EPL(ep_hw_index))); + if ((instance->*(epCallback[ep_hw_index-2]))()) + { + } + } + } + + gintsts_epx = gintsts_epx >> 1; + ep_hw_index++; + } + } } #endif + diff --git a/features/unsupported/USBDevice/USBDevice/USBHAL_NUC472.cpp b/features/unsupported/USBDevice/USBDevice/USBHAL_NUC472.cpp index 255a5959aa4..7a81554c984 100644 --- a/features/unsupported/USBDevice/USBDevice/USBHAL_NUC472.cpp +++ b/features/unsupported/USBDevice/USBDevice/USBHAL_NUC472.cpp @@ -38,22 +38,22 @@ static uint32_t g_usbd_ShortPkt = 0; static uint32_t gEpRead = 0; static uint32_t gEpReadCnt = 0; -void USBD_CtrlInput(void) +void USBD_CtrlInput(void) { int volatile i; uint32_t volatile count; // Process remained data - if(g_usbd_CtrlInSize >= g_usbd_CtrlMaxPktSize) - { + if (g_usbd_CtrlInSize >= g_usbd_CtrlMaxPktSize) + { // Data size > MXPLD for (i=0; i<(g_usbd_CtrlMaxPktSize >> 2); i++, g_usbd_CtrlInPointer+=4) USBD->CEPDAT = *(uint32_t *)g_usbd_CtrlInPointer; USBD_START_CEP_IN(g_usbd_CtrlMaxPktSize); g_usbd_CtrlInSize -= g_usbd_CtrlMaxPktSize; } - else - { + else + { // Data size <= MXPLD for (i=0; i<(g_usbd_CtrlInSize >> 2); i++, g_usbd_CtrlInPointer+=4) USBD->CEPDAT = *(uint32_t *)g_usbd_CtrlInPointer; @@ -68,12 +68,12 @@ void USBD_CtrlInput(void) } } -USBHAL::USBHAL(void) +USBHAL::USBHAL(void) { - SYS_UnlockReg(); - + SYS_UnlockReg(); + s_ep_buf_ind = 0; - + memset(epCallback, 0x00, sizeof (epCallback)); epCallback[0] = &USBHAL::EP1_OUT_callback; epCallback[1] = &USBHAL::EP2_IN_callback; @@ -89,36 +89,36 @@ USBHAL::USBHAL(void) epCallback[11] = &USBHAL::EP12_IN_callback; instance = this; - + /* Enable USBD module clock */ CLK_EnableModuleClock(USBD_MODULE); - + /* Enable USB PHY's LDO33. Run as USB device. */ SYS->USBPHY = SYS_USBPHY_USBROLE_OTG_V33_EN | SYS_USBPHY_USBROLE_STD_USBD; - + /* Enable USB PHY and wait for it ready */ USBD_ENABLE_PHY(); while (1) - { + { USBD->EPAMPS = 0x20; - if (USBD->EPAMPS == 0x20) + if (USBD->EPAMPS == 0x20) break; } - + /* Force to full-speed */ USBD->OPER = 0;//USBD_OPER_HISPDEN_Msk; - + /* Set SE0 (disconnect) */ USBD_SET_SE0(); - + NVIC_SetVector(USBD_IRQn, (uint32_t) &_usbisr); NVIC_EnableIRQ(USBD_IRQn); } -USBHAL::~USBHAL(void) +USBHAL::~USBHAL(void) { NVIC_DisableIRQ(USBD_IRQn); - USBD_SET_SE0(); + USBD_SET_SE0(); USBD_DISABLE_PHY(); } @@ -126,7 +126,7 @@ void USBHAL::connect(void) { USBD_ResetDMA(); USBD_SET_ADDR(0); - + /** * Control Transfer Packet Size Constraints * low-speed: 8 @@ -136,20 +136,20 @@ void USBHAL::connect(void) /* Control endpoint */ USBD_SetEpBufAddr(CEP, s_ep_buf_ind, MAX_PACKET_SIZE_EP0); s_ep_buf_ind = MAX_PACKET_SIZE_EP0; - + /* Enable USB/CEP interrupt */ - USBD_ENABLE_USB_INT(USBD_GINTEN_USBIE_Msk | USBD_GINTEN_CEPIE_Msk); + USBD_ENABLE_USB_INT(USBD_GINTEN_USBIE_Msk | USBD_GINTEN_CEPIE_Msk); USBD_ENABLE_CEP_INT(USBD_CEPINTEN_SETUPPKIEN_Msk|USBD_CEPINTEN_STSDONEIEN_Msk); - + /* Enable BUS interrupt */ USBD_ENABLE_BUS_INT( - USBD_BUSINTEN_DMADONEIEN_Msk | - USBD_BUSINTEN_RESUMEIEN_Msk | - USBD_BUSINTEN_RSTIEN_Msk | - USBD_BUSINTEN_VBUSDETIEN_Msk | - USBD_BUSINTEN_SOFIEN_Msk - ); - + USBD_BUSINTEN_DMADONEIEN_Msk | + USBD_BUSINTEN_RESUMEIEN_Msk | + USBD_BUSINTEN_RSTIEN_Msk | + USBD_BUSINTEN_VBUSDETIEN_Msk | + USBD_BUSINTEN_SOFIEN_Msk + ); + /* Clear SE0 (connect) */ USBD_CLR_SE0(); } @@ -168,7 +168,7 @@ void USBHAL::configureDevice(void) * 1. Allocate for CEP on connect(). * 2. Allocate for EPX in realiseEndpoint(). * 3. Deallocate all except for CEP in unconfigureDevice(). - */ + */ } void USBHAL::unconfigureDevice(void) @@ -191,37 +191,37 @@ bool USBHAL::realiseEndpoint(uint8_t endpoint, uint32_t maxPacket, uint32_t opti { uint32_t ep_type; uint32_t ep_hw_index = NU_EP2EPH(endpoint); - + USBD_SetEpBufAddr(ep_hw_index, s_ep_buf_ind, maxPacket); s_ep_buf_ind += maxPacket; USBD_SET_MAX_PAYLOAD(ep_hw_index, maxPacket); - - switch (NU_EP2EPL(endpoint)) - { - case 1:case 2: - ep_type = USB_EP_CFG_TYPE_INT; - break; - - case 3:case 4: - ep_type = USB_EP_CFG_TYPE_ISO; - break; - - default: - ep_type = USB_EP_CFG_TYPE_BULK; + + switch (NU_EP2EPL(endpoint)) + { + case 1: case 2: + ep_type = USB_EP_CFG_TYPE_INT; + break; + + case 3: case 4: + ep_type = USB_EP_CFG_TYPE_ISO; + break; + + default: + ep_type = USB_EP_CFG_TYPE_BULK; } uint32_t ep_dir = (NU_EP_DIR(endpoint) == NU_EP_DIR_IN) ? USB_EP_CFG_DIR_IN : USB_EP_CFG_DIR_OUT; USBD_ConfigEp(ep_hw_index, NU_EP2EPL(endpoint), ep_type, ep_dir); - + /* Enable USB/EPX interrupt */ // NOTE: Require USBD_GINTEN_EPAIE_Pos, USBD_GINTEN_EPBIE_Pos, ... USBD_GINTEN_EPLIE_Pos to be consecutive. USBD_ENABLE_USB_INT(USBD->GINTEN | USBD_GINTEN_USBIE_Msk | - USBD_GINTEN_CEPIE_Msk | - 1 << (ep_hw_index + USBD_GINTEN_EPAIE_Pos)); // Added USB/EPX interrupt - - if (ep_dir == 0) + USBD_GINTEN_CEPIE_Msk | + 1 << (ep_hw_index + USBD_GINTEN_EPAIE_Pos)); // Added USB/EPX interrupt + + if (ep_dir == 0) USBD_ENABLE_EP_INT(ep_hw_index, USBD_EPINTEN_RXPKIEN_Msk); - else - USBD_ENABLE_EP_INT(ep_hw_index, USBD_EPINTEN_TXPKIEN_Msk); + else + USBD_ENABLE_EP_INT(ep_hw_index, USBD_EPINTEN_TXPKIEN_Msk); return true; } @@ -233,51 +233,51 @@ void USBHAL::EP0setup(uint8_t *buffer) void USBHAL::EP0read(void) { - if (s_setup.wLength && ! (s_setup.bmRequestType & 0x80)) - { + if (s_setup.wLength && ! (s_setup.bmRequestType & 0x80)) + { // Control OUT USBD_ENABLE_CEP_INT(USBD_CEPINTEN_SETUPPKIEN_Msk | USBD_CEPINTEN_RXPKIEN_Msk); } - else - { + else + { // Status stage - USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_STSDONEIF_Msk); - USBD_SET_CEP_STATE(USB_CEPCTL_NAKCLR); - USBD_ENABLE_CEP_INT(USBD_CEPINTEN_STSDONEIEN_Msk); + USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_STSDONEIF_Msk); + USBD_SET_CEP_STATE(USB_CEPCTL_NAKCLR); + USBD_ENABLE_CEP_INT(USBD_CEPINTEN_STSDONEIEN_Msk); } } void USBHAL::EP0readStage(void) { - // N/A + // N/A } uint32_t USBHAL::EP0getReadResult(uint8_t *buffer) { uint32_t i; uint32_t ceprxcnt = USBD->CEPRXCNT; - for (i = 0; i < ceprxcnt; i ++) + for (i = 0; i < ceprxcnt; i ++) *buffer ++ = USBD->CEPDAT_BYTE; return ceprxcnt; } void USBHAL::EP0write(uint8_t *buffer, uint32_t size) { - if (buffer && size) - { - g_usbd_CtrlInPointer = buffer; - g_usbd_CtrlInSize = size; - USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_INTKIF_Msk); - USBD_ENABLE_CEP_INT(USBD_CEPINTEN_INTKIEN_Msk); + if (buffer && size) + { + g_usbd_CtrlInPointer = buffer; + g_usbd_CtrlInSize = size; + USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_INTKIF_Msk); + USBD_ENABLE_CEP_INT(USBD_CEPINTEN_INTKIEN_Msk); } - else - { - /* Status stage */ + else + { + /* Status stage */ s_ctrlin_packetsize = 0; - USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_STSDONEIF_Msk); - USBD_SET_CEP_STATE(USB_CEPCTL_NAKCLR); - USBD_ENABLE_CEP_INT(USBD_CEPINTEN_STSDONEIEN_Msk); - } + USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_STSDONEIF_Msk); + USBD_SET_CEP_STATE(USB_CEPCTL_NAKCLR); + USBD_ENABLE_CEP_INT(USBD_CEPINTEN_STSDONEIEN_Msk); + } } void USBHAL::EP0getWriteResult(void) @@ -290,64 +290,64 @@ void USBHAL::EP0stall(void) stallEndpoint(EP0OUT); } -EP_STATUS USBHAL::endpointRead(uint8_t endpoint, uint32_t maximumSize) +EP_STATUS USBHAL::endpointRead(uint8_t endpoint, uint32_t maximumSize) { return EP_PENDING; } EP_STATUS USBHAL::endpointReadResult(uint8_t endpoint, uint8_t * buffer, uint32_t *bytesRead) //spcheng { - if(endpoint == EP0OUT) - { - if (buffer) { - *((uint16_t *) (buffer + 0)) = (uint16_t) USBD->SETUP1_0; - *((uint16_t *) (buffer + 2)) = (uint16_t) USBD->SETUP3_2; - *((uint16_t *) (buffer + 4)) = (uint16_t) USBD->SETUP5_4; - *((uint16_t *) (buffer + 6)) = (uint16_t) USBD->SETUP7_6; - } - - s_setup.bmRequestType = (uint8_t) (USBD->SETUP1_0 & 0xff); - s_setup.bRequest = (int8_t) (USBD->SETUP1_0 >> 8) & 0xff; - s_setup.wValue = (uint16_t) USBD->SETUP3_2; - s_setup.wIndex = (uint16_t) USBD->SETUP5_4; - s_setup.wLength = (uint16_t) USBD->SETUP7_6; - } - else - { - if (!(s_ep_compl & (1 << NU_EP2EPL(endpoint)))) - { - while(1) - { - if (!(USBD->DMACTL & USBD_DMACTL_DMAEN_Msk)) - break; - else - if (!USBD_IS_ATTACHED()) - break; - } - gEpReadCnt = USBD_GET_EP_DATA_COUNT(NU_EP2EPH(endpoint)); - if(gEpReadCnt == 0) - { - *bytesRead = 0; - return EP_COMPLETED; - } - s_ep_compl |= (1 << NU_EP2EPL(endpoint)); - USBD_SET_DMA_LEN(gEpReadCnt); - USBD_SET_DMA_ADDR((uint32_t)buffer); - USBD_SET_DMA_WRITE(NU_EP2EPL(endpoint)); - USBD_ENABLE_DMA(); - return EP_PENDING;; - - } - else - { - if ((USBD->DMACTL & USBD_DMACTL_DMAEN_Msk)) - return EP_PENDING;; - - USBD_CLR_BUS_INT_FLAG(USBD_BUSINTSTS_DMADONEIF_Msk); - s_ep_compl &= ~(1 << NU_EP2EPL(endpoint)); - *bytesRead = gEpReadCnt; - } - } + if (endpoint == EP0OUT) + { + if (buffer) { + *((uint16_t *) (buffer + 0)) = (uint16_t) USBD->SETUP1_0; + *((uint16_t *) (buffer + 2)) = (uint16_t) USBD->SETUP3_2; + *((uint16_t *) (buffer + 4)) = (uint16_t) USBD->SETUP5_4; + *((uint16_t *) (buffer + 6)) = (uint16_t) USBD->SETUP7_6; + } + + s_setup.bmRequestType = (uint8_t) (USBD->SETUP1_0 & 0xff); + s_setup.bRequest = (int8_t) (USBD->SETUP1_0 >> 8) & 0xff; + s_setup.wValue = (uint16_t) USBD->SETUP3_2; + s_setup.wIndex = (uint16_t) USBD->SETUP5_4; + s_setup.wLength = (uint16_t) USBD->SETUP7_6; + } + else + { + if (!(s_ep_compl & (1 << NU_EP2EPL(endpoint)))) + { + while (1) + { + if (!(USBD->DMACTL & USBD_DMACTL_DMAEN_Msk)) + break; + else + if (!USBD_IS_ATTACHED()) + break; + } + gEpReadCnt = USBD_GET_EP_DATA_COUNT(NU_EP2EPH(endpoint)); + if (gEpReadCnt == 0) + { + *bytesRead = 0; + return EP_COMPLETED; + } + s_ep_compl |= (1 << NU_EP2EPL(endpoint)); + USBD_SET_DMA_LEN(gEpReadCnt); + USBD_SET_DMA_ADDR((uint32_t)buffer); + USBD_SET_DMA_WRITE(NU_EP2EPL(endpoint)); + USBD_ENABLE_DMA(); + return EP_PENDING;; + + } + else + { + if ((USBD->DMACTL & USBD_DMACTL_DMAEN_Msk)) + return EP_PENDING;; + + USBD_CLR_BUS_INT_FLAG(USBD_BUSINTSTS_DMADONEIF_Msk); + s_ep_compl &= ~(1 << NU_EP2EPL(endpoint)); + *bytesRead = gEpReadCnt; + } + } return EP_COMPLETED; } @@ -359,58 +359,58 @@ uint32_t USBHAL::endpointReadcore(uint8_t endpoint, uint8_t *buffer) EP_STATUS USBHAL::endpointWrite(uint8_t endpoint, uint8_t *data, uint32_t size) { - uint32_t ep_logic_index = NU_EP2EPL(endpoint); - if(ep_logic_index == 0) - return EP_INVALID; - else - { - uint32_t ep_hw_index = NU_EP2EPH(endpoint); - uint32_t mps = USBD_GET_EP_MAX_PAYLOAD(ep_hw_index); - if (size > mps) { - return EP_INVALID; - } - if(size < mps) - g_usbd_ShortPkt = 1; - if (!(s_ep_compl & (1 << NU_EP2EPL(endpoint)))) - { - s_ep_compl |= (1 << ep_logic_index); - - while(1) - { - if (!(USBD->DMACTL & USBD_DMACTL_DMAEN_Msk)) - break; - else - if (!USBD_IS_ATTACHED()) - break; - } - USBD_SET_DMA_LEN(size); - USBD_SET_DMA_ADDR((uint32_t)data); - USBD_SET_DMA_READ(ep_logic_index); - USBD_ENABLE_DMA(); - } - } + uint32_t ep_logic_index = NU_EP2EPL(endpoint); + if (ep_logic_index == 0) + return EP_INVALID; + else + { + uint32_t ep_hw_index = NU_EP2EPH(endpoint); + uint32_t mps = USBD_GET_EP_MAX_PAYLOAD(ep_hw_index); + if (size > mps) { + return EP_INVALID; + } + if (size < mps) + g_usbd_ShortPkt = 1; + if (!(s_ep_compl & (1 << NU_EP2EPL(endpoint)))) + { + s_ep_compl |= (1 << ep_logic_index); + + while (1) + { + if (!(USBD->DMACTL & USBD_DMACTL_DMAEN_Msk)) + break; + else + if (!USBD_IS_ATTACHED()) + break; + } + USBD_SET_DMA_LEN(size); + USBD_SET_DMA_ADDR((uint32_t)data); + USBD_SET_DMA_READ(ep_logic_index); + USBD_ENABLE_DMA(); + } + } return EP_PENDING; } EP_STATUS USBHAL::endpointWriteResult(uint8_t endpoint) { - if (!(s_ep_compl & (1 << NU_EP2EPL(endpoint)))) + if (!(s_ep_compl & (1 << NU_EP2EPL(endpoint)))) return EP_COMPLETED; - else - { - if((USBD_GET_EP_DATA_COUNT(NU_EP2EPH(endpoint))) == 0 && !(USBD->DMACTL & USBD_DMACTL_DMAEN_Msk)) - { - s_ep_compl &= ~(s_ep_compl & (1 << NU_EP2EPL(endpoint))); - return EP_COMPLETED; - } - } + else + { + if ((USBD_GET_EP_DATA_COUNT(NU_EP2EPH(endpoint))) == 0 && !(USBD->DMACTL & USBD_DMACTL_DMAEN_Msk)) + { + s_ep_compl &= ~(s_ep_compl & (1 << NU_EP2EPL(endpoint))); + return EP_COMPLETED; + } + } return EP_PENDING; } void USBHAL::stallEndpoint(uint8_t endpoint) { uint32_t ep_hw_index = NU_EP2EPH(endpoint); - if (ep_hw_index >= NUMBER_OF_PHYSICAL_ENDPOINTS) + if (ep_hw_index >= NUMBER_OF_PHYSICAL_ENDPOINTS) return; USBD_SetStall(ep_hw_index); } @@ -420,7 +420,7 @@ void USBHAL::unstallEndpoint(uint8_t endpoint) uint32_t ep_hw_index = NU_EP2EPH(endpoint); if (ep_hw_index >= NUMBER_OF_PHYSICAL_ENDPOINTS) return; - USBD_ClearStall(ep_hw_index); + USBD_ClearStall(ep_hw_index); } bool USBHAL::getEndpointStallState(uint8_t endpoint) @@ -436,187 +436,187 @@ void USBHAL::_usbisr(void) MBED_ASSERT(instance); instance->usbisr(); } - -void USBHAL::usbisr(void) + +void USBHAL::usbisr(void) { uint32_t gintsts = USBD->GINTSTS & USBD->GINTEN; if (! gintsts) return; - - if (gintsts & USBD_GINTSTS_USBIF_Msk) - { + + if (gintsts & USBD_GINTSTS_USBIF_Msk) + { uint32_t busintsts = USBD->BUSINTSTS & USBD->BUSINTEN; - + /* SOF */ if (busintsts & USBD_BUSINTSTS_SOFIF_Msk) - { - USBD_CLR_BUS_INT_FLAG(USBD_BUSINTSTS_SOFIF_Msk); + { + USBD_CLR_BUS_INT_FLAG(USBD_BUSINTSTS_SOFIF_Msk); // TODO - SOF(USBD->FRAMECNT >> 3); + SOF(USBD->FRAMECNT >> 3); } - + /* Reset */ - if (busintsts & USBD_BUSINTSTS_RSTIF_Msk) - { - connect(); + if (busintsts & USBD_BUSINTSTS_RSTIF_Msk) + { + connect(); USBD_CLR_BUS_INT_FLAG(USBD_BUSINTSTS_RSTIF_Msk); - USBD_CLR_CEP_INT_FLAG(0x1ffc); + USBD_CLR_CEP_INT_FLAG(0x1ffc); } /* Resume */ if (busintsts & USBD_BUSINTSTS_RESUMEIF_Msk) - { + { USBD_ENABLE_BUS_INT(USBD_BUSINTEN_RSTIEN_Msk|USBD_BUSINTEN_SUSPENDIEN_Msk | USBD_BUSINTEN_SOFIEN_Msk | USBD_BUSINTEN_SOFIEN_Msk); USBD_CLR_BUS_INT_FLAG(USBD_BUSINTSTS_RESUMEIF_Msk); } /* Suspend */ - if (busintsts & USBD_BUSINTSTS_SUSPENDIF_Msk) - { + if (busintsts & USBD_BUSINTSTS_SUSPENDIF_Msk) + { USBD_ENABLE_BUS_INT(USBD_BUSINTEN_RSTIEN_Msk | USBD_BUSINTEN_RESUMEIEN_Msk |USBD_BUSINTEN_SOFIEN_Msk); USBD_CLR_BUS_INT_FLAG(USBD_BUSINTSTS_SUSPENDIF_Msk); } /* High-speed */ if (busintsts & USBD_BUSINTSTS_HISPDIF_Msk) - { + { USBD_ENABLE_CEP_INT(USBD_CEPINTEN_SETUPPKIEN_Msk); USBD_CLR_BUS_INT_FLAG(USBD_BUSINTSTS_HISPDIF_Msk); } /* DMA */ - if (busintsts & USBD_BUSINTSTS_DMADONEIF_Msk) - { - if(USBD->DMACTL & 0x10) /* IN - Read */ - { - if(g_usbd_ShortPkt) - { - uint32_t ep_hw_index = NU_EPL2EPH((USBD->DMACTL & 0xF)); - USBD_SET_EP_SHORT_PACKET(ep_hw_index); - g_usbd_ShortPkt = 0; - } - } - USBD_CLR_BUS_INT_FLAG(USBD_BUSINTSTS_DMADONEIF_Msk); + if (busintsts & USBD_BUSINTSTS_DMADONEIF_Msk) + { + if (USBD->DMACTL & 0x10) /* IN - Read */ + { + if (g_usbd_ShortPkt) + { + uint32_t ep_hw_index = NU_EPL2EPH((USBD->DMACTL & 0xF)); + USBD_SET_EP_SHORT_PACKET(ep_hw_index); + g_usbd_ShortPkt = 0; + } + } + USBD_CLR_BUS_INT_FLAG(USBD_BUSINTSTS_DMADONEIF_Msk); } /* PHY clock available */ if (busintsts & USBD_BUSINTSTS_PHYCLKVLDIF_Msk) - { + { USBD_CLR_BUS_INT_FLAG(USBD_BUSINTSTS_PHYCLKVLDIF_Msk); } /* VBUS plug-in */ - if (busintsts & USBD_BUSINTSTS_VBUSDETIF_Msk) - { + if (busintsts & USBD_BUSINTSTS_VBUSDETIF_Msk) + { if (USBD_IS_ATTACHED()) - { + { // USB plug-in USBD_ENABLE_USB(); } - else - { + else + { // USB unplug-out - USBD_DISABLE_USB(); + USBD_DISABLE_USB(); } - USBD_CLR_BUS_INT_FLAG(USBD_BUSINTSTS_VBUSDETIF_Msk); + USBD_CLR_BUS_INT_FLAG(USBD_BUSINTSTS_VBUSDETIF_Msk); } } - + /* CEP interrupts */ - if (gintsts & USBD_GINTSTS_CEPIF_Msk) - { + if (gintsts & USBD_GINTSTS_CEPIF_Msk) + { uint32_t cepintsts = USBD->CEPINTSTS & USBD->CEPINTEN; - + /* SETUP token packet */ - if (cepintsts & USBD_CEPINTSTS_SETUPTKIF_Msk) - { - USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_SETUPTKIF_Msk); + if (cepintsts & USBD_CEPINTSTS_SETUPTKIF_Msk) + { + USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_SETUPTKIF_Msk); return; } /* SETUP transaction */ - if (cepintsts & USBD_CEPINTSTS_SETUPPKIF_Msk) - { - USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_SETUPPKIF_Msk); + if (cepintsts & USBD_CEPINTSTS_SETUPPKIF_Msk) + { + USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_SETUPPKIF_Msk); EP0setupCallback(); - return; + return; } /* OUT token packet */ - if (cepintsts & USBD_CEPINTSTS_OUTTKIF_Msk) - { - USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_OUTTKIF_Msk); + if (cepintsts & USBD_CEPINTSTS_OUTTKIF_Msk) + { + USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_OUTTKIF_Msk); USBD_ENABLE_CEP_INT(USBD_CEPINTEN_STSDONEIEN_Msk); - return; + return; } /* IN token packet */ - if (cepintsts & USBD_CEPINTSTS_INTKIF_Msk) - { - USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_INTKIF_Msk); - if (!(cepintsts & USBD_CEPINTSTS_STSDONEIF_Msk)) - { + if (cepintsts & USBD_CEPINTSTS_INTKIF_Msk) + { + USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_INTKIF_Msk); + if (!(cepintsts & USBD_CEPINTSTS_STSDONEIF_Msk)) + { USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_TXPKIF_Msk); USBD_ENABLE_CEP_INT(USBD_CEPINTEN_TXPKIEN_Msk); USBD_CtrlInput(); - } - else - { + } + else + { USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_TXPKIF_Msk); USBD_ENABLE_CEP_INT(USBD_CEPINTEN_TXPKIEN_Msk|USBD_CEPINTEN_STSDONEIEN_Msk); } - return; + return; } /* PING packet */ - if (cepintsts & USBD_CEPINTSTS_PINGIF_Msk) - { + if (cepintsts & USBD_CEPINTSTS_PINGIF_Msk) + { USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_PINGIF_Msk); - return; + return; } /* IN transaction */ - if (cepintsts & USBD_CEPINTSTS_TXPKIF_Msk) - { - EP0in(); - USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_TXPKIF_Msk); - return; + if (cepintsts & USBD_CEPINTSTS_TXPKIF_Msk) + { + EP0in(); + USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_TXPKIF_Msk); + return; } /* OUT transaction */ - if (cepintsts & USBD_CEPINTSTS_RXPKIF_Msk) - { + if (cepintsts & USBD_CEPINTSTS_RXPKIF_Msk) + { EP0out(); USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_RXPKIF_Msk); - return; + return; } /* NAK handshake packet */ if (cepintsts & USBD_CEPINTSTS_NAKIF_Msk) - { + { USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_NAKIF_Msk); - return; + return; } /* STALL handshake packet */ if (cepintsts & USBD_CEPINTSTS_STALLIF_Msk) - { + { USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_STALLIF_Msk); - return; + return; } /* ERR special packet */ - if (cepintsts & USBD_CEPINTSTS_ERRIF_Msk) - { + if (cepintsts & USBD_CEPINTSTS_ERRIF_Msk) + { USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_ERRIF_Msk); - return; + return; } /* Status stage transaction */ - if (cepintsts & USBD_CEPINTSTS_STSDONEIF_Msk) - { - if (s_usb_addr) - { + if (cepintsts & USBD_CEPINTSTS_STSDONEIF_Msk) + { + if (s_usb_addr) + { USBD_SET_ADDR(s_usb_addr); s_usb_addr = 0; } @@ -627,103 +627,104 @@ void USBHAL::usbisr(void) /* Buffer Full */ if (cepintsts & USBD_CEPINTSTS_BUFFULLIF_Msk) - { + { USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_BUFFULLIF_Msk); return; } /* Buffer Empty */ - if (cepintsts & USBD_CEPINTSTS_BUFEMPTYIF_Msk) - { + if (cepintsts & USBD_CEPINTSTS_BUFEMPTYIF_Msk) + { USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_BUFEMPTYIF_Msk); return; } } /* EPA, EPB, EPC, ... EPL interrupts */ uint32_t gintsts_epx = gintsts >> 2; - uint32_t ep_hw_index = 0; + uint32_t ep_hw_index = 0; while (gintsts_epx) { - if(gintsts_epx & 0x01) - { - uint32_t epxintsts = USBD_GET_EP_INT_FLAG(ep_hw_index) & USBD_GET_EP_INT_EN(ep_hw_index); - - USBD_CLR_EP_INT_FLAG(ep_hw_index, epxintsts); - - /* Buffer Full */ - if (epxintsts & USBD_EPINTSTS_BUFFULLIF_Msk) - { - } - - /* Buffer Empty */ - if (epxintsts & USBD_EPINTSTS_BUFEMPTYIF_Msk) - { - } - - /* Short Packet Transferred */ - if (epxintsts & USBD_EPINTSTS_SHORTTXIF_Msk) - { - } - - /* Data Packet Transmitted */ - if (epxintsts & USBD_EPINTSTS_TXPKIF_Msk) - { - s_ep_compl &= ~(1 << (NU_EPH2EPL(ep_hw_index))); - if ((instance->*(epCallback[ep_hw_index]))()) - { - } - } - - /* Data Packet Received */ - if (epxintsts & USBD_EPINTSTS_RXPKIF_Msk) - { - if ((instance->*(epCallback[ep_hw_index]))()) - { - - } - } - - /* OUT token packet */ - if (epxintsts & USBD_EPINTSTS_OUTTKIF_Msk) - { - } - - /* IN token packet */ - if (epxintsts & USBD_EPINTSTS_INTKIF_Msk) - { - } - - /* PING packet */ - if (epxintsts & USBD_EPINTSTS_PINGIF_Msk) - { - } - - /* NAK handshake packet sent to Host */ - if (epxintsts & USBD_EPINTSTS_NAKIF_Msk) - { - } - - /* STALL handshake packet sent to Host */ - if (epxintsts & USBD_EPINTSTS_STALLIF_Msk) - { - } - - /* NYET handshake packet sent to Host */ - if (epxintsts & USBD_EPINTSTS_NYETIF_Msk) - { - } - - /* ERR packet sent to Host */ - if (epxintsts & USBD_EPINTSTS_ERRIF_Msk) - { - } - - /* Bulk Out Short Packet Received */ - if (epxintsts & USBD_EPINTSTS_SHORTRXIF_Msk) - { - } - } - gintsts_epx = gintsts_epx >> 1; - ep_hw_index++; - } + if (gintsts_epx & 0x01) + { + uint32_t epxintsts = USBD_GET_EP_INT_FLAG(ep_hw_index) & USBD_GET_EP_INT_EN(ep_hw_index); + + USBD_CLR_EP_INT_FLAG(ep_hw_index, epxintsts); + + /* Buffer Full */ + if (epxintsts & USBD_EPINTSTS_BUFFULLIF_Msk) + { + } + + /* Buffer Empty */ + if (epxintsts & USBD_EPINTSTS_BUFEMPTYIF_Msk) + { + } + + /* Short Packet Transferred */ + if (epxintsts & USBD_EPINTSTS_SHORTTXIF_Msk) + { + } + + /* Data Packet Transmitted */ + if (epxintsts & USBD_EPINTSTS_TXPKIF_Msk) + { + s_ep_compl &= ~(1 << (NU_EPH2EPL(ep_hw_index))); + if ((instance->*(epCallback[ep_hw_index]))()) + { + } + } + + /* Data Packet Received */ + if (epxintsts & USBD_EPINTSTS_RXPKIF_Msk) + { + if ((instance->*(epCallback[ep_hw_index]))()) + { + + } + } + + /* OUT token packet */ + if (epxintsts & USBD_EPINTSTS_OUTTKIF_Msk) + { + } + + /* IN token packet */ + if (epxintsts & USBD_EPINTSTS_INTKIF_Msk) + { + } + + /* PING packet */ + if (epxintsts & USBD_EPINTSTS_PINGIF_Msk) + { + } + + /* NAK handshake packet sent to Host */ + if (epxintsts & USBD_EPINTSTS_NAKIF_Msk) + { + } + + /* STALL handshake packet sent to Host */ + if (epxintsts & USBD_EPINTSTS_STALLIF_Msk) + { + } + + /* NYET handshake packet sent to Host */ + if (epxintsts & USBD_EPINTSTS_NYETIF_Msk) + { + } + + /* ERR packet sent to Host */ + if (epxintsts & USBD_EPINTSTS_ERRIF_Msk) + { + } + + /* Bulk Out Short Packet Received */ + if (epxintsts & USBD_EPINTSTS_SHORTRXIF_Msk) + { + } + } + gintsts_epx = gintsts_epx >> 1; + ep_hw_index++; + } } #endif +