diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/bootVect.h | 52 | ||||
-rw-r--r-- | src/lib/usb.c | 24 | ||||
-rw-r--r-- | src/lib/usb.h | 28 |
3 files changed, 78 insertions, 26 deletions
diff --git a/src/lib/bootVect.h b/src/lib/bootVect.h new file mode 100644 index 0000000..5bcb42b --- /dev/null +++ b/src/lib/bootVect.h @@ -0,0 +1,52 @@ +/* ***************************************************************************** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * ****************************************************************************/ + +/** + * @file HardwareUsb.h + * + * @brief Defines the maple boot vector structure + */ + +#ifndef _BOOTVECT_H_ +#define _BOOTVECT_H_ + +#define BOOTLOADER_VECT_TABLE ((uint32_t*)0x20000000) + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef void (*FuncPtr)(void); + +typedef struct { + FuncPtr serial_tx_cb; + FuncPtr serial_rx_cb; + FuncPtr serial_linecoding_cb; + uint32_t* serial_count_in; + uint32_t* serial_count_out; + uint8_t* serial_buffer_out; + void* linecoding; + uint8_t major_rev; + uint8_t minor_rev; + void* usb_device_ptr; + void* usb_local_obj_ptr; +} BootVectTable; + +#ifdef __cplusplus +} +#endif + +#endif // _BOOTVECT_H_ diff --git a/src/lib/usb.c b/src/lib/usb.c index 17c8c8d..8c312f8 100644 --- a/src/lib/usb.c +++ b/src/lib/usb.c @@ -1,8 +1,6 @@ #include <inttypes.h> #include "usb.h" -BootVectTable* bootVect = ((BootVectTable*) BOOTLOADER_VECT_TABLE); - void usb_lpIRQHandler(void) { typedef void (*funcPtr)(void); @@ -60,8 +58,26 @@ void usb_serialWriteStr(const char* outStr) { } +void usb_serialWriteChar(unsigned char ch) { + BootVectTable *bootVector = ((BootVectTable*)BOOTLOADER_VECT_TABLE); + + delay(1); + + *(bootVector->serial_count_in) = 1; + usb_userToPMABufferCopy((u8*)(&ch),USB_SERIAL_ENDP_TXADDR,1); + _SetEPTxCount(USB_SERIAL_ENDP_TX,1); + _SetEPTxValid(USB_SERIAL_ENDP_TX); + +} + uint8_t usb_serialGetRecvLen() { - uint8_t count_out = _GetEPRxCount(USB_SERIAL_ENDP_RX); - _SetEPRxValid(USB_SERIAL_ENDP_RX); + uint8_t count_out =_GetEPRxCount(USB_SERIAL_ENDP_RX); return count_out; } + +void usb_copyRecvBuffer(unsigned char* dest, uint8_t len) { + ASSERT(len < USB_SERIAL_BUF_SIZE); + usb_PMAToUserBufferCopy((u8*)(dest),USB_SERIAL_ENDP_RXADDR,len); + _SetEPRxValid(USB_SERIAL_ENDP_RX); +} + diff --git a/src/lib/usb.h b/src/lib/usb.h index 3a7e92b..3b7a971 100644 --- a/src/lib/usb.h +++ b/src/lib/usb.h @@ -5,10 +5,7 @@ #include "util.h" #include "cortexm3_macro.h" #include "usb_regs.h" - -#ifdef __cplusplus -extern "C" { -#endif +#include "bootVect.h" #define USB_ISR_ADDR (0x08000090) #define USB_SERIAL_ENDP_TXADDR ((uint32_t) 0xC0) @@ -17,30 +14,17 @@ extern "C" { #define USB_SERIAL_ENDP_RX ((uint16_t) 0x3) #define USB_SERIAL_BUF_SIZE (0x40) -#define BOOTLOADER_VECT_TABLE ((uint32_t*)0x20000000) - -typedef void (*FuncPtr)(void); - -typedef struct { - FuncPtr serial_tx_cb; - FuncPtr serial_rx_cb; - FuncPtr serial_linecoding_cb; - uint32_t* serial_count_in; - uint32_t* serial_count_out; - uint8_t* serial_buffer_out; - void* linecoding; - uint8_t major_rev; - uint8_t minor_rev; - void* usb_device_ptr; -} BootVectTable; - -extern BootVectTable* bootVect; +#ifdef __cplusplus +extern "C" { +#endif void usb_lpIRQHandler(void); void usb_userToPMABufferCopy(u8 *pbUsrBuf,u16 wPMABufAddr,u16 wNBytes); void usb_PMAToUserBufferCopy(u8 *pbUsrBuf,u16 wPMABufAddr,u16 wNBytes); void usb_serialWriteStr(const char *outStr); +void usb_serialWriteChar(unsigned char ch); uint8_t usb_serialGetRecvLen(); +void usb_copyRecvBuffer(unsigned char* dest, uint8_t len); #ifdef __cplusplus } // extern "C" |