diff options
Diffstat (limited to 'src/lib/usb.c')
-rw-r--r-- | src/lib/usb.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/lib/usb.c b/src/lib/usb.c new file mode 100644 index 0000000..e0d7d42 --- /dev/null +++ b/src/lib/usb.c @@ -0,0 +1,56 @@ +#include "usb.h" +#include <inttypes.h> + +void usb_lpIRQHandler(void) +{ + typedef void (*funcPtr)(void); + + const uint32_t usbIsrAddr = *(uint32_t*)(USB_ISR_ADDR); + void (*ptrToUsbISR)(void) = (funcPtr) usbIsrAddr; + ptrToUsbISR(); +} + +void UserToPMABufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes) +{ + u32 n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */ + u32 i, temp1, temp2; + u16 *pdwVal; + pdwVal = (u16 *)(wPMABufAddr * 2 + PMAAddr); + for (i = n; i != 0; i--) + { + temp1 = (u16) * pbUsrBuf; + pbUsrBuf++; + temp2 = temp1 | (u16) * pbUsrBuf << 8; + *pdwVal++ = temp2; + pdwVal++; + pbUsrBuf++; + } +} + +void PMAToUserBufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes) +{ + u32 n = (wNBytes + 1) >> 1;/* /2*/ + u32 i; + u32 *pdwVal; + pdwVal = (u32 *)(wPMABufAddr * 2 + PMAAddr); + for (i = n; i != 0; i--) + { + *(u16*)pbUsrBuf++ = *pdwVal++; + pbUsrBuf++; + } +} + +void serialWriteStr(char* outStr) { + u8 offset=0; + while ((outStr[offset] != 0) + && (offset < USB_SERIAL_BUF_SIZE)) { + offset++; + } + + while (_GetEPTxCount(USB_SERIAL_ENDP_TX) > 0) {} + + UserToPMABufferCopy(outStr,USB_SERIAL_ENDP_TXADDR,offset); + _SetEPTxCount(USB_SERIAL_ENDP_TX,offset); + _SetEPTxValid(USB_SERIAL_ENDP_TX); +} + |