From 7021adc50a041bfb69bc4432b712aa07ef710ca3 Mon Sep 17 00:00:00 2001 From: "ajmeyer@mit.edu" Date: Sat, 19 Dec 2009 08:03:54 +0000 Subject: added USB support (TX over virtual com port), the linker modifications to work with the bootloader, a modified libcs-lanchon-stm32.a, and the arduino-required main.cxx and WProgram.h git-svn-id: https://leaflabs.googlecode.com/svn/trunk/library@72 749a229e-a60e-11de-b98f-4500b42dc123 --- src/lib/usb.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/lib/usb.c (limited to 'src/lib/usb.c') 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 + +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); +} + -- cgit v1.2.3