?? stm32f_usb.c
字號:
/*************************************************************************
*
* Used with ICCARM and AARM.
*
* (c) Copyright IAR Systems 2006
*
* File name : STM32F_usb.c
* Description : usb module (HAL)
*
* History :
* 1. Date : July 28, 2006
* Author : Stanimir Bonev
* Description : Create
* 2. Date : November 20, 2006
* Author : Stanimir Bonev
* Description : Modify
* Fix problems with double buffered EPs
* 3. Date : APril 30, 2007
* Author : Stanimir Bonev
* Description : Modify
* Adapt for STM32F
*
* $Revision: 1.2.2.4 $
**************************************************************************/
#define HAL_USB_GLOBAL
#include "STM32F_usb.h"
#pragma segment="USB_PACKET_MEMORY"
#pragma location="USB_PACKET_MEMORY"
__root __no_init Int32U USB_PacketMemory[256];
pPacketMemUse_t pPacketMemUse;
PacketMemUse_t PacketMemBuff[EP_MAX_SLOTS*2];
EpInfo_t EpInfo[ENP_MAX_NUMB];
Int32U DlyCnt;
UserFunc_t UsbUserFun [UsbLastEvent] =
{
// Ep 0 Out
NULL,
// Ep 0 In
NULL,
// Ep 1 Out
NULL,
// Ep 1 In
NULL,
// Ep 2 Out
NULL,
// Ep 2 Int
NULL,
// Ep 3 Out
NULL,
// Ep 3 In
NULL,
// Ep 4 Out
NULL,
// Ep 4 In
NULL,
// Ep 5 Out
NULL,
// Ep 5 In
NULL,
// Ep 6 Out
NULL,
// Ep 6 In
NULL,
// Ep 7 Out
NULL,
// Ep 7 In
NULL,
// Ep 8 Out
NULL,
// Ep 8 In
NULL,
// Ep 9 Out
NULL,
// Ep 9 In
NULL,
// Ep 10 Out
NULL,
// Ep 10 In
NULL,
// Ep 11 Out
NULL,
// Ep 11 In
NULL,
// Ep 12 Out
NULL,
// Ep 12 In
NULL,
// Ep 13 Out
NULL,
// Ep 13 In
NULL,
// Ep 14 Out
NULL,
// Ep 14 In
NULL,
// Ep 15 Out
NULL,
// Ep 15 In
NULL,
// UsbClassEp0OutPacket
NULL,
// UsbVendorEp0OutPacket
NULL,
// UsbUserSofEvent
NULL,
// UsbUserClass
NULL,
// UsbUserVendor
NULL,
// UsbUserGetDescriptor
NULL,
// UsbUserConfigure
NULL,
// UsbUserReset
NULL,
// UsbUserConnect
NULL,
// UsbUserSuspend
NULL,
// UsbUserEpStall
NULL,
// UsbUserEpUnStall
NULL,
};
UsbEpCtrl_t UsbEp0Ctrl;
UsbSetupPacket_t UsbEp0SetupPacket;
#pragma data_alignment=4
Int8U EpCtrlDataBuf[Ep0MaxSize];
UsbDevCtrl_t UsbDevCtrl = {{UsbDevStatusUnknow,UsbDevStatusNoSuspend},0,0,0,0};
CommUserFpnt_t UsbCoreT9Fun;
#include "usb_common.c"
/*************************************************************************
* Function Name: EpCtrlSet_EA
* Parameters: volatile pInt32U pReg, Int32U Data
*
* Return: none
*
* Description: Set EP Addr
*
*************************************************************************/
void EpCtrlSet_EA(volatile pInt32U pReg, Int32U Data)
{
Data &= 0xF;
Data |= *pReg & 0x0700 ;
Data |= USB_CTRL_CLEAR_ONLY_MASK;
*pReg = Data;
}
/*************************************************************************
* Function Name: EpCtrlGet_EA
* Parameters: volatile pInt32U pReg
*
* Return: Int16U
*
* Description: Get EP Addr
*
*************************************************************************/
inline
Int16U EpCtrlGet_EA(volatile pInt32U pReg)
{
return(*pReg & 0x0F);
}
/*************************************************************************
* Function Name: EpCtrlSet_STAT_TX
* Parameters: volatile pInt32U pReg, EpState_t Data
*
* Return: none
*
* Description: Set EP IN State
*
*************************************************************************/
void EpCtrlSet_STAT_TX (volatile pInt32U pReg, EpState_t Data)
{
Int32U State;
// The EP can change state between read and write
// operations from VALID to NAK and result of
// set operation will be invalid!
if(EpCtrlGet_STAT_TX(pReg) != (Int32U)Data)
{
State = Data;
State <<= 4;
State ^= *pReg;
State |= USB_CTRL_CLEAR_ONLY_MASK;
State &= ~0x7040; // Clear the toggle bits without STAT_TX (4,5)
*pReg = State;
}
else
{
return;
}
if(EpCtrlGet_STAT_TX(pReg) != (Int32U)Data)
{
State = Data;
State <<= 4;
State ^= *pReg;
State |= USB_CTRL_CLEAR_ONLY_MASK;
State &= ~0x7040; // Clear the toggle bits without STAT_TX (4,5)
*pReg = State;
}
}
/*************************************************************************
* Function Name: EpCtrlGet_STAT_TX
* Parameters: volatile pInt32U pReg
*
* Return: Int32U
*
* Description: Get EP IN Status
*
*************************************************************************/
inline
Int32U EpCtrlGet_STAT_TX (volatile pInt32U pReg)
{
Int32U Data = *pReg;
return((Data & (0x3UL << 4)) >> 4);
}
/*************************************************************************
* Function Name: EpCtrlSet_DTOG_TX
* Parameters: volatile pInt32U pReg, Int32U Data
*
* Return: none
*
* Description: Set EP DTOG_TX bit (IN)
*
*************************************************************************/
void EpCtrlSet_DTOG_TX(volatile pInt32U pReg, Int32U Data)
{
Data = Data?(*pReg ^ (1UL<<6)):*pReg;
Data &= ~0x7030; // Clear the toggle bits without DTOG_TX (6)
Data |= USB_CTRL_CLEAR_ONLY_MASK;
*pReg = Data;
}
/*************************************************************************
* Function Name: EpCtrlToggle_DTOG_TX
* Parameters: volatile pInt32U pReg
*
* Return: none
*
* Description: Toggle EP DTOG_TX bit (IN)
*
*************************************************************************/
void EpCtrlToggle_DTOG_TX(volatile pInt32U pReg)
{
Int32U Data = *pReg | (1UL << 6);
Data &= ~0x7030; // Clear the toggle bits without DTOG_TX (6)
Data |= USB_CTRL_CLEAR_ONLY_MASK;
*pReg = Data;
}
/*************************************************************************
* Function Name: EpCtrlGet_DTOG_TX
* Parameters: volatile pInt32U pReg
*
* Return: Int32U
*
* Description: Get EP DTOG_TX bit (IN)
*
*************************************************************************/
inline
Int32U EpCtrlGet_DTOG_TX(volatile pInt32U pReg)
{
return(((*pReg & (1UL<<6))?1:0));
}
/*************************************************************************
* Function Name: EpCtrlClr_CTR_TX
* Parameters: volatile pInt32U pReg
*
* Return: none
*
* Description: Clear EP CTR_TX bit (IN)
*
*************************************************************************/
void EpCtrlClr_CTR_TX(volatile pInt32U pReg)
{
Int32U Data = *pReg;
Data &= ~(USB_CTRL_TOGGLE_MASK | 1UL << 7);
Data |= 1UL <<15; // Set RX_CTR
*pReg = Data;
}
/*************************************************************************
* Function Name: EpCtrlGet_CTR_TX
* Parameters: volatile pInt32U pReg
*
* Return: UserFunc_t
*
* Description: Get EP CTR_TX bit (IN)
*
*************************************************************************/
inline
Int32U EpCtrlGet_CTR_TX(volatile pInt32U pReg)
{
return(((*pReg & (0x1UL << 7))?1:0));
}
/*************************************************************************
* Function Name: EpCtrlSet_EP_KIND
* Parameters: volatile pInt32U pReg, Int32U Data
*
* Return: none
*
* Description: Set EP KIND bit
*
*************************************************************************/
void EpCtrlSet_EP_KIND (volatile pInt32U pReg, Int32U Data)
{
Data = Data ? (1UL << 8):0;
Data |= *pReg & ~(USB_CTRL_TOGGLE_MASK | (1UL << 8));
Data |= USB_CTRL_CLEAR_ONLY_MASK;
*pReg = Data;
}
/*************************************************************************
* Function Name: EpCtrlGet_EP_KIND
* Parameters: volatile pInt32U pReg
*
* Return: Int32U
*
* Description: Get EP KIND bit
*
*************************************************************************/
inline
Int32U EpCtrlGet_EP_KIND(volatile pInt32U pReg)
{
return(*pReg & (0x1UL << 8)?1:0);
}
/*************************************************************************
* Function Name: EpCtrlSet_EP_TYPE
* Parameters: volatile pInt32U pReg, EpType_t Data
*
* Return: none
*
* Description: Set EP type
*
*************************************************************************/
void EpCtrlSet_EP_TYPE(volatile pInt32U pReg, EpType_t Data)
{
Int32U Type;
Type = Data;
Type <<= 9;
Type |= *pReg & ~(USB_CTRL_TOGGLE_MASK | (0x3UL << 9));
Type |= USB_CTRL_CLEAR_ONLY_MASK;
*pReg = Type;
}
/*************************************************************************
* Function Name: EpCtrlGet_EP_TYPE
* Parameters: volatile pInt32U pReg
*
* Return: Int32U
*
* Description: Get EP type
*
*************************************************************************/
inline
Int32U EpCtrlGet_EP_TYPE(volatile pInt32U pReg)
{
Int32U Data = *pReg;
Data &= (3UL<<9);
return(Data >> 9);
}
/*************************************************************************
* Function Name: EpCtrlGet_SETUP
* Parameters: volatile pInt32U pReg
*
* Return: Int32U
*
* Description: Get EP SETUP bit
*
*************************************************************************/
inline
Int32U EpCtrlGet_SETUP(volatile pInt32U pReg)
{
Int32U Data = *pReg & (0x1UL << 11);
return(Data?1:0);
}
/*************************************************************************
* Function Name: EpCtrlSet_STAT_RX
* Parameters: volatile pInt32U pReg, EpState_t Data
*
* Return: none
*
* Description: Set EP STAT_RX (OUT)
*
*************************************************************************/
void EpCtrlSet_STAT_RX (volatile pInt32U pReg, EpState_t Data)
{
Int32U State;
// The EP can change state between read and write
// operations from VALID to NAK and result of
// set operation will be invalid!
if(EpCtrlGet_STAT_RX(pReg) != (Int32U)Data)
{
State = Data;
State <<= 12;
State ^= *pReg;
State |= USB_CTRL_CLEAR_ONLY_MASK;
State &= ~0x4070; // Clear the toggle bits without STAT_RX (12,13)
*pReg = State;
}
else
{
return;
}
if(EpCtrlGet_STAT_RX(pReg) != (Int32U)Data)
{
State = Data;
State <<= 12;
State ^= *pReg;
State |= USB_CTRL_CLEAR_ONLY_MASK;
State &= ~0x4070; // Clear the toggle bits without STAT_RX (12,13)
*pReg = State;
}
}
/*************************************************************************
* Function Name: EpCtrlGet_STAT_RX
* Parameters: volatile pInt32U pReg
*
* Return: Int32U
*
* Description: Get EP STAT_RX (OUT)
*
*************************************************************************/
inline
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -