⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_prop.c

📁 意法半導體STR710,USB範例程式,模擬U盤
💻 C
字号:
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
PROJECT  : ARM USB: BULK Tutorial
MODULE  :  USB_prop.c
AUTHOR :  MCD Application Team
CREATION DATE : 21/04/2004
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
DESCRIPTION:	All processings related to LOOPBACK device
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/

#include "USB_lib.h"
#include "USB_conf.h"
#include "USB_prop.h"
#include "USB_desc.h"
#include "USB_pwr.h"
#include "71x_lib.h"
#define USBHPIRQchannel 6
#define USBLPIRQchannel 26

WORD ByteCounter;
extern void StartDblBuff(void);

/* ----------------------------------------------------------------------------*/
/*  Structures initializations */
/* ----------------------------------------------------------------------------*/

DEVICE Device_Table = {
/*sb	ENDP0, */
	EP_NUM, 
	1 
};

DEVICE_PROP	Device_Property = {
	BULK_Loop_Init,	
	BULK_Loop_Reset,
	BULK_Loop_Status_IN,
	BULK_Loop_Status_Out,
	BULK_Loop_Data_Setup,
	BULK_Loop_NoData_Setup,
	BULK_Loop_GetDeviceDescriptor,
	BULK_Loop_GetConfigDescriptor,
	BULK_Loop_GetStringDescriptor,
	/*MOUSE_EP0Buffer*/0, 
	STD_MAXPACKETSIZE  
};
/* ---------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------- */
void BULK_Loop_Init(void)
{
  DEVICE_INFO *pInfo = &Device_Info;
 
  /* Connect the device */ 
  PowerOn();	
	
  /* USB interrupts initialization */
  _SetISTR(0);               /* clear pending interrupts */
  wInterrupt_Mask = IMR_MSK;  
  _SetCNTR(wInterrupt_Mask); /* set interrupts mask */

  /* Enable EIC */	
  EIC_IRQChannelPriorityConfig(USBHP_IRQChannel,2);//         EIC->SIR[USBHPIRQchannel]|=0x02;
  EIC_IRQChannelPriorityConfig(USBLP_IRQChannel,2);//         EIC->SIR[USBLPIRQchannel]|=0x02;
  EIC_IRQChannelConfig(USBHP_IRQChannel,ENABLE);//EIC->IER=(0x00001<<USBHPIRQchannel)|(0x0001<<USBLPIRQchannel);
  EIC_IRQChannelConfig(USBLP_IRQChannel,ENABLE);
  EIC_IRQConfig(ENABLE);//EIC->ICR=0x0001; 

  /* Wait until device is configured */
  while (pInfo->Current_Configuration == 0)
    NOP_Process();
		
  bDeviceState = CONFIGURED;	

}/* BULK_Loop_Init */

/* ---------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------- */
void BULK_Loop_Reset()
{
  ByteCounter = 0;
  SetBTABLE(BTABLE_ADDRESS); 

  /* Set BULK_LOOP_DEVICE as not configured */
  Device_Info.Current_Configuration = 0;

  /*** Endpoint0 initialization ***/
  SetEPType(ENDP0, EP_CONTROL);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR); 
  SetEPRxCount(ENDP0, STD_MAXPACKETSIZE);
  SetEPRxValid(ENDP0);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR); 
  SetEPTxCount(ENDP0, 0);
  SetEPTxStatus(ENDP0, EP_TX_NAK);
  Clear_Status_Out(ENDP0);

  /*** INTERRUPT ENDPOINT initialization ***/
  SetEPType(INT_ENDP, EP_INTERRUPT);
  SetEPRxAddr(INT_ENDP, INT_ENDP_RXADDR); 
  SetEPRxCount(INT_ENDP, 2);
  SetEPRxValid(INT_ENDP);
  SetEPTxCount(INT_ENDP, 0);
  SetEPTxStatus(INT_ENDP,EP_TX_NAK);

  /*** BULK OUT double-buffered endpoint initialization ***/
  SetEPType(BULK_OUT_ENDP, EP_BULK);
  SetEPDblBuffAddr(BULK_OUT_ENDP, BULK_OUT_BUF0_ADDR, BULK_OUT_BUF1_ADDR);
  SetEPDblBuffCount(BULK_OUT_ENDP, EP_DBUF_OUT, BULK_PAY_LOAD);

  /*** BULK IN  double buffered endpoint initialization ***/
  SetEPType(BULK_IN_ENDP, EP_BULK);
  SetEPDblBuffAddr(BULK_IN_ENDP, BULK_IN_BUF0_ADDR, BULK_IN_BUF1_ADDR);
  SetEPDblBuffCount(BULK_IN_ENDP, EP_DBUF_IN, BULK_PAY_LOAD);

  /*** Enable the function address ***/
  SetDeviceAddress(0);

  /* enable bulk mode */
  StartDblBuff();
	
} /* BULK_Loop_Reset */

/* ---------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------- */
#define BULK_Loop_SetConfiguration Standard_SetConfiguration
#define BULK_Loop_SetInterface Standard_SetInterface
#define BULK_Loop_GetConfiguration	Standard_GetConfiguration
#define BULK_Loop_GetInterface		Standard_GetInterface
/* ---------------------------------------------------------------------------- */
/* dummy procedure */
/* ---------------------------------------------------------------------------- */
RESULT BULK_Loop_Data_Setup(BYTE Request_No)
{
  DEVICE_INFO *pInfo = pInformation; 
  BYTE *(*CopyRoutine)(WORD); 
  BYTE *pbLen;
  WORD wLen;

  CopyRoutine = NULL; 
   
  if (Request_No == GET_CONFIGURATION) {
    if ( Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT) )
      CopyRoutine = Standard_GetConfiguration;
      }
        else if (Request_No == GET_INTERFACE) {
          if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
            CopyRoutine = Standard_GetInterface;
        }
	if (CopyRoutine == NULL) 
      return UNSUPPORT; 

   pInfo->Ctrl_Info.CopyData = CopyRoutine; 
   pInfo->Ctrl_Info.Usb_wOffset = 0; 
/*   pInfo->Ctrl_Info.Usb_wLength = (WORD)(*CopyRoutine)(0);  */
   pbLen = (*CopyRoutine)(0);
   wLen = (WORD)((DWORD)pbLen);
   pInfo->Ctrl_Info.Usb_wLength = wLen;
   return SUCCESS; 
} /* BULK_Loop_Data_Setup */
/* ---------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------- */
RESULT BULK_Loop_NoData_Setup(BYTE RequestNo)
{
	DEVICE_INFO		*pInfo = pInformation;

	if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) {
		if (RequestNo == SET_CONFIGURATION)
			return BULK_Loop_SetConfiguration();
		else if (RequestNo == SET_INTERFACE)
			return BULK_Loop_SetInterface();
	}

	return UNSUPPORT;
} /* BULK_Loop_NoData_Setup */

/* ---------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------- */
ONE_DESCRIPTOR Device_Descriptor = {
	(BYTE*)BULK_Loop_DeviceDescriptor,
	BULK_LOOP_SIZ_DEVICE_DESC
};

BYTE *BULK_Loop_GetDeviceDescriptor(WORD Length)
{
	return Standard_GetDescriptorData( Length, &Device_Descriptor );
}

/* ---------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------- */
ONE_DESCRIPTOR Config_Descriptor = {
	(BYTE*)BULK_Loop_ConfigDescriptor,
	BULK_LOOP_SIZ_CONFIG_DESC
};

BYTE *BULK_Loop_GetConfigDescriptor(WORD Length)
{
	return Standard_GetDescriptorData( Length, &Config_Descriptor );
}

/* ---------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------- */
ONE_DESCRIPTOR String_Descriptor = {
	(BYTE*)BULK_Loop_StringDescriptor,
	BULK_LOOP_SIZ_STRING_DESC
};

BYTE *BULK_Loop_GetStringDescriptor(WORD Length)
{
	return Standard_GetStringDescriptor( Length, &String_Descriptor );
}

/* ---------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------- */
ONE_DESCRIPTOR Interface_Descriptor = {
	(BYTE *)BULK_Loop_ConfigDescriptor + BULK_LOOP_OFF_INTERFACE_DESC,
	BULK_LOOP_SIZ_INTERFACE_DESC
};

BYTE *BULK_Loop_GetInterfaceDescriptor(WORD Length)
{
	return Standard_GetDescriptorData(	Length, &Interface_Descriptor );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -