//###########################################################################
//
// FILE: usb.c
//
// TITLE: Driver for the USB Interface.
//
//###########################################################################
// $TI Release: F2837xS Support Library v3.12.00.00 $
// $Release Date: Fri Feb 12 19:06:50 IST 2021 $
// $Copyright:
// Copyright (C) 2014-2021 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_usb.h"
#include "debug.h"
#include "sysctl.h"
#include "usb.h"
//*****************************************************************************
//
// Amount to shift the RX interrupt sources by in the flags used in the
// interrupt calls.
//
//*****************************************************************************
#define USB_INTEP_RX_SHIFT 16
//*****************************************************************************
//
// Amount to shift the RX endpoint status sources by in the flags used in the
// calls.
//
//*****************************************************************************
#define USB_RX_EPSTATUS_SHIFT 16
//*****************************************************************************
//
// Converts from an endpoint specifier to the offset of the endpoint's
// control/status registers.
//
//*****************************************************************************
#define EP_OFFSET(Endpoint) (Endpoint - 0x10)
//*****************************************************************************
//
// Sets one of the indexed registers.
//
// \param ui32Base specifies the USB module base address.
// \param ui32Endpoint is the endpoint index to target for this write.
// \param ui32IndexedReg is the indexed register to write to.
// \param ui8Value is the value to write to the register.
//
// This function is used to access the indexed registers for each endpoint.
// The only registers that are indexed are the FIFO configuration registers,
// which are not used after configuration.
//
// \return None.
//
//*****************************************************************************
static void
_USBIndexWrite(uint32_t ui32Base, uint32_t ui32Endpoint,
uint32_t ui32IndexedReg, uint32_t ui32Value, uint32_t ui32Size)
{
uint32_t ui32Index;
//
// Check the arguments.
//
ASSERT(ui32Base == USBA_BASE);
ASSERT((ui32Endpoint == 0) || (ui32Endpoint == 1) || (ui32Endpoint == 2) ||
(ui32Endpoint == 3));
ASSERT((ui32Size == 1) || (ui32Size == 2));
//
// Save the old index in case it was in use.
//
ui32Index = HWREGB(ui32Base + USB_O_EPIDX);
//
// Set the index.
//
HWREGB(ui32Base + USB_O_EPIDX) = ui32Endpoint;
//
// Determine the size of the register value.
//
if(ui32Size == 1)
{
//
// Set the value.
//
HWREGB(ui32Base + ui32IndexedReg) = ui32Value;
}
else
{
//
// Set the value.
//
HWREGH(ui32Base + ui32IndexedReg) = ui32Value;
}
//
// Restore the old index in case it was in use.
//
HWREGB(ui32Base + USB_O_EPIDX) = ui32Index;
}
//*****************************************************************************
//
// Reads one of the indexed registers.
//
// \param ui32Base specifies the USB module base address.
// \param ui32Endpoint is the endpoint index to target for this write.
// \param ui32IndexedReg is the indexed register to write to.
//
// This function is used internally to access the indexed registers for each
// endpoint. The only registers that are indexed are the FIFO configuration
// registers, which are not used after configuration.
//
// \return The value in the register requested.
//
//*****************************************************************************
static uint32_t
_USBIndexRead(uint32_t ui32Base, uint32_t ui32Endpoint,
uint32_t ui32IndexedReg, uint32_t ui32Size)
{
uint8_t ui8Index;
uint8_t ui8Value;
//
// Check the arguments.
//
ASSERT(ui32Base == USBA_BASE);
ASSERT((ui32Endpoint == 0) || (ui32Endpoint == 1) || (ui32Endpoint == 2) ||
(ui32Endpoint == 3));
ASSERT((ui32Size == 1) || (ui32Size == 2));
//
// Save the old index in case it was in use.
//
ui8Index = HWREGB(ui32Base + USB_O_EPIDX);
//
// Set the index.
//
HWREGB(ui32Base + USB_O_EPIDX) = ui32Endpoint;
//
// Determine the size of the register value.
//
if(ui32Size == 1)
{
//
// Get the value.
//
ui8Value = HWREGB(ui32Base + ui32IndexedReg);
}
else
{
//
// Get the value.
//
ui8Value = HWREGH(ui32Base + ui32IndexedReg);
}
//
// Restore the old index in case it was in use.
//
HWREGB(ui32Base + USB_O_EPIDX) = ui8Index;
//
// Return the register's value.
//
return(ui8Value);
}
//*****************************************************************************
//
//! Puts the USB bus in a suspended state.
//!
//! \param ui32Base specifies the USB module base address.
//!
//! When used in host mode, this function puts the USB bus in the suspended
//! state.
//!
//! \note This function must only be called in host mode.
//!
//! \return None.
//
//*****************************************************************************
void
USBHostSuspend(uint32_t ui32Base)
{
//
// Check the arguments.
//
ASSERT(ui32Base == USBA_BASE);
//
// Send the suspend signaling to the USB bus.
//
HWREGB(ui32Base + USB_O_POWER) |= USB_POWER_SUSPEND;
}
//*****************************************************************************
//
//! Handles the USB bus reset condition.
//!
//! \param ui32Base specifies the USB module base address.
//! \param bStart specifies whether to start or stop signaling reset on the USB
//! bus.
//!
//! When this function is called with the \e bStart parameter set to \b true,
//! this function causes the start of a reset condition on the USB bus.
//! The caller must then delay at least 20ms before calling this function
//! again with the \e bStart parameter set to \b false.
//!
//! \note This function must only be called in host mode.
//!
//! \return None
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
TMS320 F2837x LED控制例程 (153个子文件)
F2837xS_CodeStartBranch.asm 5KB
usb.c 127KB
mcbsp.c 46KB
sysctl.c 44KB
memcfg.c 21KB
can.c 20KB
device.c 15KB
epwm.c 13KB
gpio.c 12KB
dcsm.c 11KB
sci.c 11KB
led_ex1_blinky.c 11KB
interrupt.c 9KB
dma.c 9KB
upp.c 9KB
adc.c 9KB
spi.c 8KB
xbar.c 7KB
cmpss.c 7KB
i2c.c 7KB
sdfm.c 6KB
clb.c 5KB
eqep.c 5KB
flash.c 5KB
dac.c 3KB
cla.c 3KB
cputimer.c 3KB
ecap.c 3KB
version.c 2KB
hrpwm.c 2KB
emif.c 2KB
asysctl.c 2KB
.ccsproject 713B
TMS320F28377S.ccxml 1KB
2837xS_Generic_FLASH_lnk.cmd 17KB
2837xS_Generic_RAM_lnk.cmd 4KB
.cproject 33KB
led_ex1_blinky.d 14KB
led_ex1_blinky.d 14KB
device.d 14KB
device.d 14KB
hw_gpio.h 267KB
epwm.h 241KB
hw_usb.h 221KB
mcbsp.h 114KB
sysctl.h 103KB
hw_outputxbar.h 94KB
hw_clbxbar.h 87KB
hw_epwmxbar.h 81KB
adc.h 72KB
hw_sysctl.h 68KB
hw_hrpwm.h 60KB
hw_epwm.h 59KB
hrpwm.h 58KB
upp.h 55KB
eqep.h 55KB
can.h 54KB
hw_memcfg.h 53KB
hw_adc.h 51KB
xbar.h 50KB
clb.h 50KB
flash.h 48KB
sci.h 46KB
emif.h 44KB
i2c.h 43KB
spi.h 43KB
memcfg.h 42KB
cmpss.h 41KB
ecap.h 37KB
sdfm.h 37KB
pin_map.h 37KB
gpio.h 37KB
hw_pie.h 36KB
hw_clb.h 36KB
cla.h 32KB
usb.h 32KB
dma.h 30KB
hw_can.h 26KB
hw_dcsm.h 25KB
hw_sdfm.h 23KB
dcsm.h 22KB
hw_xbar.h 19KB
interrupt.h 19KB
dac.h 17KB
hw_upp.h 16KB
cputimer.h 16KB
hw_flash.h 15KB
hw_mcbsp.h 14KB
hw_emif.h 14KB
hw_cla.h 13KB
hw_cmpss.h 12KB
hw_eqep.h 12KB
hw_ints.h 12KB
device.h 11KB
hw_i2c.h 10KB
hw_sci.h 10KB
hw_memmap.h 9KB
hw_dma.h 9KB
hw_ecap.h 8KB
hw_spi.h 8KB
共 153 条
- 1
- 2
synthesis_UMR
- 粉丝: 30
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0