//-----------------------------------------------------------------------------
// F34x_USB_Standard_Requests.c
//-----------------------------------------------------------------------------
// Copyright 2005 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This source file contains the subroutines used to handle incoming
// setup packets. These are called by Handle_Setup in USB_ISR.c and used for
// USB chapter 9 compliance.
//
// How To Test: See Readme.txt
//
//
// FID: 34X000022
// Target: C8051F34x
// Tool chain: Keil C51 7.50 / Keil EVAL C51
// Silicon Laboratories IDE version 2.6
// Command Line: See Readme.txt
// Project Name: F34x_USB_Interrupt
//
//
// Release 1.0
// -Initial Revision (GP)
// -22 NOV 2005
// -Ported from 'F320_USB_Bulk
//
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "c8051F340.h"
#include "F34x_USB_Register.h"
#include "F34x_USB_Main.h"
#include "F34x_USB_Descriptor.h"
//-----------------------------------------------------------------------------
// Externs
//-----------------------------------------------------------------------------
// These are created in USB_DESCRIPTOR.h
extern device_descriptor DeviceDesc;
extern configuration_descriptor ConfigDesc;
extern interface_descriptor InterfaceDesc;
extern endpoint_descriptor Endpoint1Desc;
extern endpoint_descriptor Endpoint2Desc;
extern BYTE* StringDescTable[];
extern setup_buffer Setup; // Buffer for current device request
extern unsigned int DataSize;
extern unsigned int DataSent;
extern BYTE* DataPtr;
extern BYTE Ep_Status[]; // Contains status bytes for EP 0-2
extern BYTE USB_State; // Determines current usb device state
//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------
// These are response packets used for communication with host
code BYTE ONES_PACKET[2] = {0x01, 0x00};
code BYTE ZERO_PACKET[2] = {0x00, 0x00};
//-----------------------------------------------------------------------------
// Support Subroutines
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Get_Status
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters : None
//
// This routine returns a two byte status packet to the host
//
//-----------------------------------------------------------------------------
void Get_Status(void)
{
if (Setup.wValue.c[MSB] || Setup.wValue.c[LSB] ||
// If non-zero return length or data length not equal to 2 then send a stall
// indicating invalid request
Setup.wLength.c[MSB] || (Setup.wLength.c[LSB] != 2))
{
Force_Stall();
}
// Determine if recipient was device, interface, or EP
switch(Setup.bmRequestType)
{
// If recipient was device
case OUT_DEVICE:
if (Setup.wIndex.c[MSB] || Setup.wIndex.c[LSB])
{
// Send stall if request is invalid
Force_Stall();
}
else
{
// Otherwise send 0x00, indicating bus power and no
// remote wake-up supported
DataPtr = (BYTE*)&ZERO_PACKET;
DataSize = 2;
}
break;
// See if recipient was interface
case OUT_INTERFACE:
// Only valid if device is configured and non-zero index
if ((USB_State != DEV_CONFIGURED) ||
Setup.wIndex.c[MSB] || Setup.wIndex.c[LSB])
{
// Otherwise send stall to host
Force_Stall();
}
else
{
// Status packet always returns 0x00
DataPtr = (BYTE*)&ZERO_PACKET;
DataSize = 2;
}
break;
// See if recipient was an endpoint
case OUT_ENDPOINT:
// Make sure device is configured and index msb = 0x00
if ((USB_State != DEV_CONFIGURED) || Setup.wIndex.c[MSB])
{
Force_Stall(); // otherwise return stall to host
}
else
{
// Handle case if request is directed to EP 1
if (Setup.wIndex.c[LSB] == IN_EP1)
{
if (Ep_Status[1] == EP_HALT)
{
// If endpoint is halted, return 0x01,0x00
DataPtr = (BYTE*)&ONES_PACKET;
DataSize = 2;
}
else
{
// Otherwise return 0x00,0x00 to indicate endpoint active
DataPtr = (BYTE*)&ZERO_PACKET;
DataSize = 2;
}
}
else
{
// If request is directed to endpoint 2, send either
// 0x01,0x00 if endpoint halted or 0x00,0x00 if endpoint is active
if (Setup.wIndex.c[LSB] == OUT_EP2)
{
if (Ep_Status[2] == EP_HALT)
{
DataPtr = (BYTE*)&ONES_PACKET;
DataSize = 2;
}
else
{
DataPtr = (BYTE*)&ZERO_PACKET;
DataSize = 2;
}
}
else
{
Force_Stall(); // Send stall if unexpected data
}
}
}
break;
default:
Force_Stall();
break;
}
if (Ep_Status[0] != EP_STALL)
{
// Set serviced Setup Packet, Endpoint 0 intransmit mode,
// and reset DataSent counter
POLL_WRITE_BYTE(E0CSR, rbSOPRDY);
Ep_Status[0] = EP_TX;
DataSent = 0;
}
}
//-----------------------------------------------------------------------------
// Clear_Feature
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters : None
//
// This routine can clear Halt Endpoint features on endpoint 1 and 2.
//
//-----------------------------------------------------------------------------
void Clear_Feature(
USB.rar_C8051F340 ssd19_USB充电_usb数据_计步_计步器
版权申诉
115 浏览量
2022-09-24
16:28:03
上传
评论
收藏 98KB RAR 举报
JaniceLu
- 粉丝: 79
- 资源: 1万+
最新资源
- WebCrawler.scr
- 【计算机专业毕业设计】大学生就业信息管理系统设计源码.zip
- YOLO 数据集:8种路面缺陷病害检测【包含划分好的数据集、类别class文件、数据可视化脚本】
- JAVA实现Modbus RTU或Modbus TCPIP案例.zip
- 基于YOLOv8的FPS TPS AI自动锁定源码+使用步骤说明.zip
- JAVA实现Modbus RTU或Modbus TCPIP案例.zip
- 基于yolov8+streamlit的火灾检测部署源码+模型.zip
- 测试aaaaaaabbbbb
- VID20240521070643.mp4
- Android系统原理与开发学习要点详解-培训课件.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈