U32 USB_ReadEP (U32 EPNum, U8 *pData) { /* Double Buffering is not yet supported */ U32 num, cnt, *pv, n; num = EPNum & 0x0F; pv = (U32 *)(USB_PMA_ADDR + 2*((pBUF_DSCR + num)->ADDR_RX)); cnt = (pBUF_DSCR + num)->COUNT_RX & EP_COUNT_MASK; for (n = 0; n < (cnt + 1) / 2; n++) { *((__packed U16 *)pData) = *pv++; pData += 2; } EP_Status(EPNum, EP_RX_VALID); return (cnt); }
uint32 CmtUsbDev::USB_WriteEP8( uint8 EPNum, uint8 *pData, uint32 cnt ) { /* Double Buffering is not yet supported */ uint32 num, *pv, n; num = EPNum & 0x0F; pv = (uint32*)(USB_PMA_ADDR + 2*((pBUF_DSCR + num)->ADDR_TX)); for (n = 0; n < (cnt + 1) / 2; n++) { *pv++ = (pData[0] & 0xff) | ((pData[1] << 8) & 0xff00); pData += 2; } (pBUF_DSCR + num)->COUNT_TX = cnt; EP_Status(EPNum, EP_TX_VALID); return (cnt); }
uint32 CmtUsbDev::USB_ReadEP8 (uint8 EPNum, uint8 *pData) { /* Double Buffering is not yet supported */ uint32 num, cnt, *pv, n, v; num = EPNum & 0x0F; pv = (uint32*)(USB_PMA_ADDR + 2*((pBUF_DSCR + num)->ADDR_RX)); cnt = (pBUF_DSCR + num)->COUNT_RX & EP_COUNT_MASK; for (n = 0; n < (cnt + 1) / 2; n++) { v = *pv++; pData[0] = v; pData[1] = v >> 8; // *((__packed WORD *)pData) = *pv++; pData += 2; } EP_Status(EPNum, EP_RX_VALID); return (cnt); }
U32 USB_WriteEP (U32 EPNum, U8 *pData, U32 cnt) { /* Double Buffering is not yet supported */ U32 num, *pv, n; U16 statusEP; num = EPNum & 0x0F; pv = (U32 *)(USB_PMA_ADDR + 2*((pBUF_DSCR + num)->ADDR_TX)); for (n = 0; n < (cnt + 1) / 2; n++) { *pv++ = *((__packed U16 *)pData); pData += 2; } (pBUF_DSCR + num)->COUNT_TX = cnt; statusEP = EPxREG(num); if ((statusEP & EP_STAT_TX) != EP_TX_STALL) { EP_Status(EPNum, EP_TX_VALID); /* do not make EP valid if it is stalled previously */ } return (cnt); }
void USB_ClrStallEP (U32 EPNum) { EP_Reset(EPNum); /* reset DTog Bits */ EP_Status(EPNum, EP_TX_VALID | EP_RX_VALID); }
void USB_SetStallEP (U32 EPNum) { EP_Status(EPNum, EP_TX_STALL | EP_RX_STALL); }
void USB_DisableEP (U32 EPNum) { EP_Status(EPNum, EP_TX_DIS | EP_RX_DIS); }
void USB_EnableEP (U32 EPNum) { EP_Status(EPNum, EP_TX_NAK | EP_RX_VALID); /* EP is able to receive */ }
void CmtUsbDev::USB_EnableEP( uint8 EPNum ) { EP_Status(EPNum, EP_TX_VALID | EP_RX_VALID); }
void CmtUsbDev::USB_DisableEP( uint8 EPNum ) { EP_Status(EPNum, EP_TX_DIS | EP_RX_DIS); }
void CmtUsbDev::USB_SetStallEP( uint8 EPNum ) { EP_Status(EPNum, EP_TX_STALL | EP_RX_STALL); }
void CmtUsbDev::USB_ClrStallEP( uint8 EPNum ) { EP_Status(EPNum, EP_TX_VALID | EP_RX_VALID); }
void CmtUsbDev::USB_ResetNAK( uint8 EPNum ) { //Только для ненулевой EP if( (EPNum & 0x7f) != 0 ) EP_Status(EPNum, EP_RX_VALID); }