diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | libmaple/usb.c | 109 | ||||
-rw-r--r-- | libmaple/usb.h | 50 | ||||
-rw-r--r-- | libmaple/usb/README | 37 | ||||
-rw-r--r-- | libmaple/usb_regs.h | 554 |
5 files changed, 4 insertions, 750 deletions
@@ -129,6 +129,10 @@ info: all: info +tags: + etags `find . -name "*.c" -o -name "*.cpp" -o -name "*.h"` + @echo "Made TAGS file for EMACS code browsing" + $(BUILD_PATH): mkdir -p build diff --git a/libmaple/usb.c b/libmaple/usb.c deleted file mode 100644 index eff0317..0000000 --- a/libmaple/usb.c +++ /dev/null @@ -1,109 +0,0 @@ -/* ***************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Andrew Meyer. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * ****************************************************************************/ - -#include "libmaple.h" -#include "usb.h" -#include "usb_regs.h" -#include "bootVect.h" - -void usb_lpIRQHandler(void) -{ - typedef void (*funcPtr)(void); - - const uint32 usbIsrAddr = *(uint32*)(USB_ISR_ADDR); - void (*ptrToUsbISR)(void) = (funcPtr) usbIsrAddr; - ptrToUsbISR(); -} - -void usb_userToPMABufferCopy(uint8 *pbUsrBuf, uint16 wPMABufAddr, uint16 wNBytes) -{ - uint32 n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */ - uint32 i, temp1, temp2; - uint16 *pdwVal; - pdwVal = (uint16 *)(wPMABufAddr * 2 + PMAAddr); - for (i = n; i != 0; i--) - { - temp1 = (uint16) * pbUsrBuf; - pbUsrBuf++; - temp2 = temp1 | (uint16) * pbUsrBuf << 8; - *pdwVal++ = temp2; - pdwVal++; - pbUsrBuf++; - } -} - -void usb_PMAToUserBufferCopy(uint8 *pbUsrBuf, uint16 wPMABufAddr, uint16 wNBytes) -{ - uint32 n = (wNBytes + 1) >> 1;/* /2*/ - uint32 i; - uint32 *pdwVal; - pdwVal = (uint32 *)(wPMABufAddr * 2 + PMAAddr); - for (i = n; i != 0; i--) - { - *(uint16*)pbUsrBuf++ = *pdwVal++; - pbUsrBuf++; - } -} - -void usb_serialWriteStr(const char* outStr) { - uint8 offset=0; - BootVectTable *bootVector = ((BootVectTable*)BOOTLOADER_VECT_TABLE); - - while ((outStr[offset] != '\0') - && (offset < USB_SERIAL_BUF_SIZE)) { - offset++; - } - - delay(offset*1); - - bootVector->serial_count_in = (uint32*) &offset; - usb_userToPMABufferCopy((uint8*)outStr,USB_SERIAL_ENDP_TXADDR,offset); - _SetEPTxCount(USB_SERIAL_ENDP_TX,offset); - _SetEPTxValid(USB_SERIAL_ENDP_TX); - -} - -void usb_serialWriteChar(unsigned char ch) { - BootVectTable *bootVector = ((BootVectTable*)BOOTLOADER_VECT_TABLE); - - delay(1); - - *(bootVector->serial_count_in) = 1; - usb_userToPMABufferCopy((uint8*)(&ch),USB_SERIAL_ENDP_TXADDR,1); - _SetEPTxCount(USB_SERIAL_ENDP_TX,1); - _SetEPTxValid(USB_SERIAL_ENDP_TX); - -} - -uint8 usb_serialGetRecvLen() { - uint8 count_out =_GetEPRxCount(USB_SERIAL_ENDP_RX); - return count_out; -} - -void usb_copyRecvBuffer(unsigned char* dest, uint8 len) { - ASSERT(len < USB_SERIAL_BUF_SIZE); - usb_PMAToUserBufferCopy((uint8*)(dest),USB_SERIAL_ENDP_RXADDR,len); - _SetEPRxValid(USB_SERIAL_ENDP_RX); -} - diff --git a/libmaple/usb.h b/libmaple/usb.h deleted file mode 100644 index 7d233ef..0000000 --- a/libmaple/usb.h +++ /dev/null @@ -1,50 +0,0 @@ -/* ***************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Andrew Meyer. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * ****************************************************************************/ - -#ifndef _USB_H_ -#define _USB_H_ - -#define USB_ISR_ADDR (0x08000090) -#define USB_SERIAL_ENDP_TXADDR ((uint32) 0xC0) -#define USB_SERIAL_ENDP_RXADDR ((uint32) 0x110) -#define USB_SERIAL_ENDP_TX ((uint16) 0x1) -#define USB_SERIAL_ENDP_RX ((uint16) 0x3) -#define USB_SERIAL_BUF_SIZE (0x40) - -#ifdef __cplusplus -extern "C" { -#endif - -void usb_lpIRQHandler(void); -void usb_userToPMABufferCopy(uint8 *pbUsrBuf,uint16 wPMABufAddr,uint16 wNBytes); -void usb_PMAToUserBufferCopy(uint8 *pbUsrBuf,uint16 wPMABufAddr,uint16 wNBytes); -void usb_serialWriteStr(const char *outStr); -void usb_serialWriteChar(unsigned char ch); -uint8 usb_serialGetRecvLen(); -void usb_copyRecvBuffer(unsigned char* dest, uint8 len); - -#ifdef __cplusplus -} // extern "C" -#endif -#endif //_USB_H diff --git a/libmaple/usb/README b/libmaple/usb/README deleted file mode 100644 index 035b566..0000000 --- a/libmaple/usb/README +++ /dev/null @@ -1,37 +0,0 @@ -The USB submodule of libmaple is responsible for: - initilizing the usb peripheral, scaling the peripheral clocks appropriately, - enabling the interrupt channels to usb, defining the usb isr, resetting the usb - disc pin (used to tell the host were alive). Additionally, the usb submodule defines - the virtual com port usb applications that is available to all user sketches via Usb.print() - and others. - - Currently, the USB submodule relies on the low level core library provided by ST to access the - usb peripheral registers and implement the usb transfer protocol for control endpoint transfers. - The high level virtual com port application is unfortunately hard to untangle from this low level - dependence, and when a new USB core library is written (to nix ST dependence) changes will likely - have to be made to virtual com application code. Ideally, the new core library should mimick the - form of MyUSB (LUFA), since this library (USB for AVR) is growing in popularity and in example - applications. - - The virtual com port serves two important purposes. 1) is allows serial data transfers between - user sketches an a host computer. 2) is allows the host machine to issue a system reset by - asserting the DTR signal. After reset, Maple will run the DFU bootloader for a few seconds, - during which the user can begin a DFU download operation ('downloads' application binary into - RAM/FLASH). This without this virtual com port, it would be necessary to find an alternative means - to reset the chip in order to enable the bootloader. - - If you would like to develop your own USB application for whatever reason (uses faster isochronous - enpoints for streaming audio, or implements the USB HID or Mass Storage specs for examples) then - ensure that you leave some hook for resetting Maple remotely in order to spin up the DFU bootloader. - Please make sure to give yourself a unique vendor/product ID pair in your application, as some - operating systems will assign a host-side driver based on these tags. - - It would be possible to build a compound usb device, that implements endpoints for both the virtual - COM port as well as some other components (mass sotrage etc.) however this turns out to be a burden - from the host driver side, as windows and *nix handle compound usb devices quite differently. - - Be mindful that running the usb application isnt "free." The device must respond to periodic bus - activity (every few milliseconds) by servicing an ISR. Therefore the usb application should be disabled - inside of timing critical applications. In order to disconnect the device from the host, the USB_DISC - pin can be asserted (on Maple v1,2,3 this is GPIOC,12). Alternatively, the NVIC can be directly configured - to disable the USB LP/HP IRQ's
\ No newline at end of file diff --git a/libmaple/usb_regs.h b/libmaple/usb_regs.h deleted file mode 100644 index bf5e10c..0000000 --- a/libmaple/usb_regs.h +++ /dev/null @@ -1,554 +0,0 @@ -/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
-* File Name : usb_regs.h
-* Author : MCD Application Team
-* Version : V2.2.1
-* Date : 09/22/2008
-* Description : Interface prototype functions to USB cell registers
-********************************************************************************
-* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
-* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
-* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
-* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
-* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
-* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
-*******************************************************************************/
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_REGS_H
-#define __USB_REGS_H
-
-/* Includes ------------------------------------------------------------------*/
-/* Exported types ------------------------------------------------------------*/
-
-typedef enum _EP_DBUF_DIR
-{
- /* double buffered endpoint direction */
- EP_DBUF_ERR,
- EP_DBUF_OUT,
- EP_DBUF_IN
-}EP_DBUF_DIR;
-
-/* endpoint buffer number */
-enum EP_BUF_NUM
-{
- EP_NOBUF,
- EP_BUF0,
- EP_BUF1
-};
-
-/* Exported constants --------------------------------------------------------*/
-#define RegBase (0x40005C00L) /* USB_IP Peripheral Registers base address */
-#define PMAAddr (0x40006000L) /* USB_IP Packet Memory Area base address */
-
-/******************************************************************************/
-/* General registers */
-/******************************************************************************/
-
-/* Control register */
-#define CNTR ((volatile unsigned *)(RegBase + 0x40))
-/* Interrupt status register */
-#define ISTR ((volatile unsigned *)(RegBase + 0x44))
-/* Frame number register */
-#define FNR ((volatile unsigned *)(RegBase + 0x48))
-/* Device address register */
-#define DADDR ((volatile unsigned *)(RegBase + 0x4C))
-/* Buffer Table address register */
-#define BTABLE ((volatile unsigned *)(RegBase + 0x50))
-/******************************************************************************/
-/* Endpoint registers */
-/******************************************************************************/
-#define EP0REG ((volatile unsigned *)(RegBase)) /* endpoint 0 register address */
-
-/* endpoints enumeration */
-#define ENDP0 ((uint8)0)
-#define ENDP1 ((uint8)1)
-#define ENDP2 ((uint8)2)
-#define ENDP3 ((uint8)3)
-#define ENDP4 ((uint8)4)
-#define ENDP5 ((uint8)5)
-#define ENDP6 ((uint8)6)
-#define ENDP7 ((uint8)7)
-/******************************************************************************/
-/* ISTR interrupt events */
-/******************************************************************************/
-#define ISTR_CTR (0x8000) /* Correct TRansfer (clear-only bit) */
-#define ISTR_DOVR (0x4000) /* DMA OVeR/underrun (clear-only bit) */
-#define ISTR_ERR (0x2000) /* ERRor (clear-only bit) */
-#define ISTR_WKUP (0x1000) /* WaKe UP (clear-only bit) */
-#define ISTR_SUSP (0x0800) /* SUSPend (clear-only bit) */
-#define ISTR_RESET (0x0400) /* RESET (clear-only bit) */
-#define ISTR_SOF (0x0200) /* Start Of Frame (clear-only bit) */
-#define ISTR_ESOF (0x0100) /* Expected Start Of Frame (clear-only bit) */
-
-
-#define ISTR_DIR (0x0010) /* DIRection of transaction (read-only bit) */
-#define ISTR_EP_ID (0x000F) /* EndPoint IDentifier (read-only bit) */
-
-#define CLR_CTR (~ISTR_CTR) /* clear Correct TRansfer bit */
-#define CLR_DOVR (~ISTR_DOVR) /* clear DMA OVeR/underrun bit*/
-#define CLR_ERR (~ISTR_ERR) /* clear ERRor bit */
-#define CLR_WKUP (~ISTR_WKUP) /* clear WaKe UP bit */
-#define CLR_SUSP (~ISTR_SUSP) /* clear SUSPend bit */
-#define CLR_RESET (~ISTR_RESET) /* clear RESET bit */
-#define CLR_SOF (~ISTR_SOF) /* clear Start Of Frame bit */
-#define CLR_ESOF (~ISTR_ESOF) /* clear Expected Start Of Frame bit */
-
-/******************************************************************************/
-/* CNTR control register bits definitions */
-/******************************************************************************/
-#define CNTR_CTRM (0x8000) /* Correct TRansfer Mask */
-#define CNTR_DOVRM (0x4000) /* DMA OVeR/underrun Mask */
-#define CNTR_ERRM (0x2000) /* ERRor Mask */
-#define CNTR_WKUPM (0x1000) /* WaKe UP Mask */
-#define CNTR_SUSPM (0x0800) /* SUSPend Mask */
-#define CNTR_RESETM (0x0400) /* RESET Mask */
-#define CNTR_SOFM (0x0200) /* Start Of Frame Mask */
-#define CNTR_ESOFM (0x0100) /* Expected Start Of Frame Mask */
-
-
-#define CNTR_RESUME (0x0010) /* RESUME request */
-#define CNTR_FSUSP (0x0008) /* Force SUSPend */
-#define CNTR_LPMODE (0x0004) /* Low-power MODE */
-#define CNTR_PDWN (0x0002) /* Power DoWN */
-#define CNTR_FRES (0x0001) /* Force USB RESet */
-
-/******************************************************************************/
-/* FNR Frame Number Register bit definitions */
-/******************************************************************************/
-#define FNR_RXDP (0x8000) /* status of D+ data line */
-#define FNR_RXDM (0x4000) /* status of D- data line */
-#define FNR_LCK (0x2000) /* LoCKed */
-#define FNR_LSOF (0x1800) /* Lost SOF */
-#define FNR_FN (0x07FF) /* Frame Number */
-/******************************************************************************/
-/* DADDR Device ADDRess bit definitions */
-/******************************************************************************/
-#define DADDR_EF (0x80)
-#define DADDR_ADD (0x7F)
-/******************************************************************************/
-/* Endpoint register */
-/******************************************************************************/
-/* bit positions */
-#define EP_CTR_RX (0x8000) /* EndPoint Correct TRansfer RX */
-#define EP_DTOG_RX (0x4000) /* EndPoint Data TOGGLE RX */
-#define EPRX_STAT (0x3000) /* EndPoint RX STATus bit field */
-#define EP_SETUP (0x0800) /* EndPoint SETUP */
-#define EP_T_FIELD (0x0600) /* EndPoint TYPE */
-#define EP_KIND (0x0100) /* EndPoint KIND */
-#define EP_CTR_TX (0x0080) /* EndPoint Correct TRansfer TX */
-#define EP_DTOG_TX (0x0040) /* EndPoint Data TOGGLE TX */
-#define EPTX_STAT (0x0030) /* EndPoint TX STATus bit field */
-#define EPADDR_FIELD (0x000F) /* EndPoint ADDRess FIELD */
-
-/* EndPoint REGister MASK (no toggle fields) */
-#define EPREG_MASK (EP_CTR_RX|EP_SETUP|EP_T_FIELD|EP_KIND|EP_CTR_TX|EPADDR_FIELD)
-
-/* EP_TYPE[1:0] EndPoint TYPE */
-#define EP_TYPE_MASK (0x0600) /* EndPoint TYPE Mask */
-#define EP_BULK (0x0000) /* EndPoint BULK */
-#define EP_CONTROL (0x0200) /* EndPoint CONTROL */
-#define EP_ISOCHRONOUS (0x0400) /* EndPoint ISOCHRONOUS */
-#define EP_INTERRUPT (0x0600) /* EndPoint INTERRUPT */
-#define EP_T_MASK (~EP_T_FIELD & EPREG_MASK)
-
-
-/* EP_KIND EndPoint KIND */
-#define EPKIND_MASK (~EP_KIND & EPREG_MASK)
-
-/* STAT_TX[1:0] STATus for TX transfer */
-#define EP_TX_DIS (0x0000) /* EndPoint TX DISabled */
-#define EP_TX_STALL (0x0010) /* EndPoint TX STALLed */
-#define EP_TX_NAK (0x0020) /* EndPoint TX NAKed */
-#define EP_TX_VALID (0x0030) /* EndPoint TX VALID */
-#define EPTX_DTOG1 (0x0010) /* EndPoint TX Data TOGgle bit1 */
-#define EPTX_DTOG2 (0x0020) /* EndPoint TX Data TOGgle bit2 */
-#define EPTX_DTOGMASK (EPTX_STAT|EPREG_MASK)
-
-/* STAT_RX[1:0] STATus for RX transfer */
-#define EP_RX_DIS (0x0000) /* EndPoint RX DISabled */
-#define EP_RX_STALL (0x1000) /* EndPoint RX STALLed */
-#define EP_RX_NAK (0x2000) /* EndPoint RX NAKed */
-#define EP_RX_VALID (0x3000) /* EndPoint RX VALID */
-#define EPRX_DTOG1 (0x1000) /* EndPoint RX Data TOGgle bit1 */
-#define EPRX_DTOG2 (0x2000) /* EndPoint RX Data TOGgle bit1 */
-#define EPRX_DTOGMASK (EPRX_STAT|EPREG_MASK)
-/* Exported macro ------------------------------------------------------------*/
-/* SetCNTR */
-#define _SetCNTR(wRegValue) (*CNTR = (uint16)wRegValue)
-
-/* SetISTR */
-#define _SetISTR(wRegValue) (*ISTR = (uint16)wRegValue)
-
-/* SetDADDR */
-#define _SetDADDR(wRegValue) (*DADDR = (uint16)wRegValue)
-
-/* SetBTABLE */
-#define _SetBTABLE(wRegValue)(*BTABLE = (uint16)(wRegValue & 0xFFF8))
-
-/* GetCNTR */
-#define _GetCNTR() ((uint16) *CNTR)
-
-/* GetISTR */
-#define _GetISTR() ((uint16) *ISTR)
-
-/* GetFNR */
-#define _GetFNR() ((uint16) *FNR)
-
-/* GetDADDR */
-#define _GetDADDR() ((uint16) *DADDR)
-
-/* GetBTABLE */
-#define _GetBTABLE() ((uint16) *BTABLE)
-
-/* SetENDPOINT */
-#define _SetENDPOINT(bEpNum,wRegValue) (*(EP0REG + bEpNum)= \
- (uint16)wRegValue)
-
-/* GetENDPOINT */
-#define _GetENDPOINT(bEpNum) ((uint16)(*(EP0REG + bEpNum)))
-
-/*******************************************************************************
-* Macro Name : SetEPType
-* Description : sets the type in the endpoint register(bits EP_TYPE[1:0])
-* Input : bEpNum: Endpoint Number.
-* wType
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPType(bEpNum,wType) (_SetENDPOINT(bEpNum,\
- ((_GetENDPOINT(bEpNum) & EP_T_MASK) | wType)))
-
-/*******************************************************************************
-* Macro Name : GetEPType
-* Description : gets the type in the endpoint register(bits EP_TYPE[1:0])
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : Endpoint Type
-*******************************************************************************/
-#define _GetEPType(bEpNum) (_GetENDPOINT(bEpNum) & EP_T_FIELD)
-
-/*******************************************************************************
-* Macro Name : SetEPTxStatus
-* Description : sets the status for tx transfer (bits STAT_TX[1:0]).
-* Input : bEpNum: Endpoint Number.
-* wState: new state
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPTxStatus(bEpNum,wState) {\
- register uint16 _wRegVal; \
- _wRegVal = _GetENDPOINT(bEpNum) & EPTX_DTOGMASK;\
- /* toggle first bit ? */ \
- if((EPTX_DTOG1 & wState)!= 0) \
- _wRegVal ^= EPTX_DTOG1; \
- /* toggle second bit ? */ \
- if((EPTX_DTOG2 & wState)!= 0) \
- _wRegVal ^= EPTX_DTOG2; \
- _SetENDPOINT(bEpNum, _wRegVal); \
- } /* _SetEPTxStatus */
-
-/*******************************************************************************
-* Macro Name : SetEPRxStatus
-* Description : sets the status for rx transfer (bits STAT_TX[1:0])
-* Input : bEpNum: Endpoint Number.
-* wState: new state.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPRxStatus(bEpNum,wState) {\
- register uint16 _wRegVal; \
- \
- _wRegVal = _GetENDPOINT(bEpNum) & EPRX_DTOGMASK;\
- /* toggle first bit ? */ \
- if((EPRX_DTOG1 & wState)!= 0) \
- _wRegVal ^= EPRX_DTOG1; \
- /* toggle second bit ? */ \
- if((EPRX_DTOG2 & wState)!= 0) \
- _wRegVal ^= EPRX_DTOG2; \
- _SetENDPOINT(bEpNum, _wRegVal); \
- } /* _SetEPRxStatus */
-/*******************************************************************************
-* Macro Name : GetEPTxStatus / GetEPRxStatus
-* Description : gets the status for tx/rx transfer (bits STAT_TX[1:0]
-* /STAT_RX[1:0])
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : status .
-*******************************************************************************/
-#define _GetEPTxStatus(bEpNum) ((uint16)_GetENDPOINT(bEpNum) & EPTX_STAT)
-
-#define _GetEPRxStatus(bEpNum) ((uint16)_GetENDPOINT(bEpNum) & EPRX_STAT)
-
-/*******************************************************************************
-* Macro Name : SetEPTxValid / SetEPRxValid
-* Description : sets directly the VALID tx/rx-status into the enpoint register
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPTxValid(bEpNum) (_SetEPTxStatus(bEpNum, EP_TX_VALID))
-
-#define _SetEPRxValid(bEpNum) (_SetEPRxStatus(bEpNum, EP_RX_VALID))
-
-/*******************************************************************************
-* Macro Name : GetTxStallStatus / GetRxStallStatus.
-* Description : checks stall condition in an endpoint.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : TRUE = endpoint in stall condition.
-*******************************************************************************/
-#define _GetTxStallStatus(bEpNum) (_GetEPTxStatus(bEpNum) \
- == EP_TX_STALL)
-#define _GetRxStallStatus(bEpNum) (_GetEPRxStatus(bEpNum) \
- == EP_RX_STALL)
-
-/*******************************************************************************
-* Macro Name : SetEP_KIND / ClearEP_KIND.
-* Description : set & clear EP_KIND bit.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
- (_GetENDPOINT(bEpNum) | EP_KIND) & EPREG_MASK))
-#define _ClearEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
- (_GetENDPOINT(bEpNum) & EPKIND_MASK)))
-
-/*******************************************************************************
-* Macro Name : Set_Status_Out / Clear_Status_Out.
-* Description : Sets/clears directly STATUS_OUT bit in the endpoint register.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _Set_Status_Out(bEpNum) _SetEP_KIND(bEpNum)
-#define _Clear_Status_Out(bEpNum) _ClearEP_KIND(bEpNum)
-
-/*******************************************************************************
-* Macro Name : SetEPDoubleBuff / ClearEPDoubleBuff.
-* Description : Sets/clears directly EP_KIND bit in the endpoint register.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPDoubleBuff(bEpNum) _SetEP_KIND(bEpNum)
-#define _ClearEPDoubleBuff(bEpNum) _ClearEP_KIND(bEpNum)
-
-/*******************************************************************************
-* Macro Name : ClearEP_CTR_RX / ClearEP_CTR_TX.
-* Description : Clears bit CTR_RX / CTR_TX in the endpoint register.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _ClearEP_CTR_RX(bEpNum) (_SetENDPOINT(bEpNum,\
- _GetENDPOINT(bEpNum) & 0x7FFF & EPREG_MASK))
-#define _ClearEP_CTR_TX(bEpNum) (_SetENDPOINT(bEpNum,\
- _GetENDPOINT(bEpNum) & 0xFF7F & EPREG_MASK))
-
-/*******************************************************************************
-* Macro Name : ToggleDTOG_RX / ToggleDTOG_TX .
-* Description : Toggles DTOG_RX / DTOG_TX bit in the endpoint register.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _ToggleDTOG_RX(bEpNum) (_SetENDPOINT(bEpNum, \
- EP_DTOG_RX | _GetENDPOINT(bEpNum) & EPREG_MASK))
-#define _ToggleDTOG_TX(bEpNum) (_SetENDPOINT(bEpNum, \
- EP_DTOG_TX | _GetENDPOINT(bEpNum) & EPREG_MASK))
-
-/*******************************************************************************
-* Macro Name : ClearDTOG_RX / ClearDTOG_TX.
-* Description : Clears DTOG_RX / DTOG_TX bit in the endpoint register.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _ClearDTOG_RX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_RX) != 0)\
- _ToggleDTOG_RX(bEpNum)
-#define _ClearDTOG_TX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_TX) != 0)\
- _ToggleDTOG_TX(bEpNum)
-/*******************************************************************************
-* Macro Name : SetEPAddress.
-* Description : Sets address in an endpoint register.
-* Input : bEpNum: Endpoint Number.
-* bAddr: Address.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPAddress(bEpNum,bAddr) _SetENDPOINT(bEpNum,\
- _GetENDPOINT(bEpNum) & EPREG_MASK | bAddr)
-
-/*******************************************************************************
-* Macro Name : GetEPAddress.
-* Description : Gets address in an endpoint register.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _GetEPAddress(bEpNum) ((uint8)(_GetENDPOINT(bEpNum) & EPADDR_FIELD))
-
-#define _pEPTxAddr(bEpNum) ((uint32 *)((_GetBTABLE()+bEpNum*8 )*2 + PMAAddr))
-#define _pEPTxCount(bEpNum) ((uint32 *)((_GetBTABLE()+bEpNum*8+2)*2 + PMAAddr))
-#define _pEPRxAddr(bEpNum) ((uint32 *)((_GetBTABLE()+bEpNum*8+4)*2 + PMAAddr))
-#define _pEPRxCount(bEpNum) ((uint32 *)((_GetBTABLE()+bEpNum*8+6)*2 + PMAAddr))
-
-/*******************************************************************************
-* Macro Name : SetEPTxAddr / SetEPRxAddr.
-* Description : sets address of the tx/rx buffer.
-* Input : bEpNum: Endpoint Number.
-* wAddr: address to be set (must be word aligned).
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPTxAddr(bEpNum,wAddr) (*_pEPTxAddr(bEpNum) = ((wAddr >> 1) << 1))
-#define _SetEPRxAddr(bEpNum,wAddr) (*_pEPRxAddr(bEpNum) = ((wAddr >> 1) << 1))
-
-/*******************************************************************************
-* Macro Name : GetEPTxAddr / GetEPRxAddr.
-* Description : Gets address of the tx/rx buffer.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : address of the buffer.
-*******************************************************************************/
-#define _GetEPTxAddr(bEpNum) ((uint16)*_pEPTxAddr(bEpNum))
-#define _GetEPRxAddr(bEpNum) ((uint16)*_pEPRxAddr(bEpNum))
-
-/*******************************************************************************
-* Macro Name : SetEPCountRxReg.
-* Description : Sets counter of rx buffer with no. of blocks.
-* Input : pdwReg: pointer to counter.
-* wCount: Counter.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _BlocksOf32(dwReg,wCount,wNBlocks) {\
- wNBlocks = wCount >> 5;\
- if((wCount & 0x1f) == 0)\
- wNBlocks--;\
- *pdwReg = (uint32)((wNBlocks << 10) | 0x8000);\
- }/* _BlocksOf32 */
-
-#define _BlocksOf2(dwReg,wCount,wNBlocks) {\
- wNBlocks = wCount >> 1;\
- if((wCount & 0x1) != 0)\
- wNBlocks++;\
- *pdwReg = (uint32)(wNBlocks << 10);\
- }/* _BlocksOf2 */
-
-#define _SetEPCountRxReg(dwReg,wCount) {\
- uint16 wNBlocks;\
- if(wCount > 62){_BlocksOf32(dwReg,wCount,wNBlocks);}\
- else {_BlocksOf2(dwReg,wCount,wNBlocks);}\
- }/* _SetEPCountRxReg */
-
-
-
-#define _SetEPRxDblBuf0Count(bEpNum,wCount) {\
- uint32 *pdwReg = _pEPTxCount(bEpNum); \
- _SetEPCountRxReg(pdwReg, wCount);\
- }
-/*******************************************************************************
-* Macro Name : SetEPTxCount / SetEPRxCount.
-* Description : sets counter for the tx/rx buffer.
-* Input : bEpNum: endpoint number.
-* wCount: Counter value.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPTxCount(bEpNum,wCount) (*_pEPTxCount(bEpNum) = wCount)
-#define _SetEPRxCount(bEpNum,wCount) {\
- uint32 *pdwReg = _pEPRxCount(bEpNum); \
- _SetEPCountRxReg(pdwReg, wCount);\
- }
-/*******************************************************************************
-* Macro Name : GetEPTxCount / GetEPRxCount.
-* Description : gets counter of the tx buffer.
-* Input : bEpNum: endpoint number.
-* Output : None.
-* Return : Counter value.
-*******************************************************************************/
-#define _GetEPTxCount(bEpNum)((uint16)(*_pEPTxCount(bEpNum)) & 0x3ff)
-#define _GetEPRxCount(bEpNum)((uint16)(*_pEPRxCount(bEpNum)) & 0x3ff)
-
-/*******************************************************************************
-* Macro Name : SetEPDblBuf0Addr / SetEPDblBuf1Addr.
-* Description : Sets buffer 0/1 address in a double buffer endpoint.
-* Input : bEpNum: endpoint number.
-* : wBuf0Addr: buffer 0 address.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPDblBuf0Addr(bEpNum,wBuf0Addr) {_SetEPTxAddr(bEpNum, wBuf0Addr);}
-#define _SetEPDblBuf1Addr(bEpNum,wBuf1Addr) {_SetEPRxAddr(bEpNum, wBuf1Addr);}
-
-/*******************************************************************************
-* Macro Name : SetEPDblBuffAddr.
-* Description : Sets addresses in a double buffer endpoint.
-* Input : bEpNum: endpoint number.
-* : wBuf0Addr: buffer 0 address.
-* : wBuf1Addr = buffer 1 address.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPDblBuffAddr(bEpNum,wBuf0Addr,wBuf1Addr) { \
- _SetEPDblBuf0Addr(bEpNum, wBuf0Addr);\
- _SetEPDblBuf1Addr(bEpNum, wBuf1Addr);\
- } /* _SetEPDblBuffAddr */
-
-/*******************************************************************************
-* Macro Name : GetEPDblBuf0Addr / GetEPDblBuf1Addr.
-* Description : Gets buffer 0/1 address of a double buffer endpoint.
-* Input : bEpNum: endpoint number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _GetEPDblBuf0Addr(bEpNum) (_GetEPTxAddr(bEpNum))
-#define _GetEPDblBuf1Addr(bEpNum) (_GetEPRxAddr(bEpNum))
-
-/*******************************************************************************
-* Macro Name : SetEPDblBuffCount / SetEPDblBuf0Count / SetEPDblBuf1Count.
-* Description : Gets buffer 0/1 address of a double buffer endpoint.
-* Input : bEpNum: endpoint number.
-* : bDir: endpoint dir EP_DBUF_OUT = OUT
-* EP_DBUF_IN = IN
-* : wCount: Counter value
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPDblBuf0Count(bEpNum, bDir, wCount) { \
- if(bDir == EP_DBUF_OUT)\
- /* OUT endpoint */ \
- {_SetEPRxDblBuf0Count(bEpNum,wCount);} \
- else if(bDir == EP_DBUF_IN)\
- /* IN endpoint */ \
- *_pEPTxCount(bEpNum) = (uint32)wCount; \
- } /* SetEPDblBuf0Count*/
-
-#define _SetEPDblBuf1Count(bEpNum, bDir, wCount) { \
- if(bDir == EP_DBUF_OUT)\
- /* OUT endpoint */ \
- {_SetEPRxCount(bEpNum,wCount);}\
- else if(bDir == EP_DBUF_IN)\
- /* IN endpoint */\
- *_pEPRxCount(bEpNum) = (uint32)wCount; \
- } /* SetEPDblBuf1Count */
-
-#define _SetEPDblBuffCount(bEpNum, bDir, wCount) {\
- _SetEPDblBuf0Count(bEpNum, bDir, wCount); \
- _SetEPDblBuf1Count(bEpNum, bDir, wCount); \
- } /* _SetEPDblBuffCount */
-
-/*******************************************************************************
-* Macro Name : GetEPDblBuf0Count / GetEPDblBuf1Count.
-* Description : Gets buffer 0/1 rx/tx counter for double buffering.
-* Input : bEpNum: endpoint number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _GetEPDblBuf0Count(bEpNum) (_GetEPTxCount(bEpNum))
-#define _GetEPDblBuf1Count(bEpNum) (_GetEPRxCount(bEpNum))
-
-#endif
-/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
|