/* This source file is part of the AVR Software Framework 2.0.0 release */
/*This file is prepared for Doxygen automatic documentation generation.*/
/*! \file ******************************************************************
*
* \brief Management of the USB host controller.
*
* This file manages the host controller, the host enumeration process and
* the suspend/resume host requests.
*
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
* - Supported devices: All AVR32 devices with a USB module can be used.
* - AppNote:
*
* \author Atmel Corporation: http://www.atmel.com \n
* Support and FAQ: http://support.atmel.no/
*
***************************************************************************/
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The name of Atmel may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 4. This software may only be redistributed and used in connection with an Atmel
* AVR product.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
*
*/
//_____ I N C L U D E S ___________________________________________________
#include "conf_usb.h"
#if USB_HOST_FEATURE == ENABLED
#ifdef FREERTOS_USED
#include "libfreertos.h"
#include "FreeRTOSConfig.h"
#include "FreeRTOSTask.h"
#endif
#include "usb_drv.h"
#include "usb_task.h"
#include "usb_host_enum.h"
#include "usb_host_task.h"
#include "chip.h"
//_____ M A C R O S ________________________________________________________
//_____ D E F I N I T I O N S ______________________________________________
static const char log_device_connected[] = "Device connected\n";
static const char log_unsupported_device[] = "Unsupported device\n";
static const char log_device_enumerated[] = "Device enumerated\n";
static const char log_usb_suspended[] = "USB suspended\n";
static const char log_usb_resumed[] = "USB resumed\n";
#if USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE
volatile Bool g_sav_int_sof_enable;
volatile S_pipe_int it_pipe_str[MAX_PEP_NB];
#endif
//!
//! Public: U8 device_state
//! Its value represents the current state of the
//! device connected to the USB host controller
//! Value can be:
//! - DEVICE_ATTACHED
//! - DEVICE_POWERED
//! - DEVICE_SUSPENDED
//! - DEVICE_DEFAULT
//! - DEVICE_ADDRESSED
//! - DEVICE_CONFIGURED
//! - DEVICE_ERROR
//! - DEVICE_UNATTACHED
//! - DEVICE_READY
//! - DEVICE_WAIT_RESUME
//!
volatile U8 device_state;
volatile U8 usb_device_connected;
//! For control requests management over control pipe
volatile S_usb_setup_data usb_request;
//!
//! Public: U8 data_stage[SIZEOF_DATA_STAGE]
//! Internal RAM buffer for USB data stage content
//! This buffer is required to setup host enumeration process
//! It contains the device descriptors received.
//! Depending on the device descriptors length, its size can be optimized
//! with the SIZEOF_DATA_STAGE define of conf_usb.h file
//!
U8 data_stage[SIZEOF_DATA_STAGE];
volatile U8 device_status;
volatile Bool request_resume;
//! As internal host Start-of-Frame counter
static U16 sof_cnt;
#ifdef FREERTOS_USED
//! Handle to the USB Host task
xTaskHandle usb_host_tsk = NULL;
#endif
//_____ D E C L A R A T I O N S ____________________________________________
//!
//! @brief This function initializes the USB host controller.
//!
//! This function enables the USB controller for host-mode operation.
//!
void usb_host_task_init(void)
{
//! @todo Implement this on the silicon version
//Pll_start_auto();
//Wait_pll_ready();
Disable_global_interrupt();
Usb_disable();
(void)Is_usb_enabled();
Enable_global_interrupt();
Usb_disable_otg_pad();
Usb_enable_otg_pad();
Usb_enable();
Usb_unfreeze_clock();
(void)Is_usb_clock_frozen();
#if USB_VBOF_ACTIVE_LEVEL == HIGH
Usb_set_vbof_active_high();
#else // USB_VBOF_ACTIVE_LEVEL == LOW
Usb_set_vbof_active_low();
#endif
Usb_output_vbof_pin();
// Usb_disable_vbus_hw_control(); // Force VBus generation without time-out
Usb_enable_vbus_hw_control();
Host_enable_device_disconnection_interrupt();
#if USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE
reset_it_pipe_str();
#endif
device_state = DEVICE_UNATTACHED;
Host_clear_device_status();
Host_ack_request_resume();
sof_cnt = 0;
#ifdef FREERTOS_USED
if ( xTaskCreate( usb_host_task, configTSK_USB_HST_NAME, configTSK_USB_HST_STACK_SIZE, NULL, configTSK_USB_HST_PRIORITY, &usb_host_tsk ) != pdPASS )
{
printf( "Failed to create usb_host_task\r\n" ) ;
}
#endif // FREERTOS_USED
}
//!
//! @brief Entry point of the USB host management
//!
//! The aim is to manage the target device connection and enumeration.
//! Depending on device_state, the function performs the required operations
//! to get the device enumerated and configured.
//! Once the device is operational, device_state is DEVICE_READY.
//! This state should be tested by the host task before sending any
//! applicative request to the device.
//! This function is called from the usb_task function depending on the USB
//! operating mode (device or host) currently engaged.
//!
//! \image html usb_host_task.jpg "USB Host Task Overview"
//!
#ifdef FREERTOS_USED
void usb_host_task(void *pvParameters)
#else
void usb_host_task(void)
#endif
{
static Bool sav_int_sof_enable;
U8 pipe;
#ifdef FREERTOS_USED
portTickType xLastWakeTime;
xLastWakeTime = xTaskGetTickCount();
while (TRUE)
{
vTaskDelayUntil(&xLastWakeTime, configTSK_USB_HST_PERIOD);
#endif // FREERTOS_USED
switch (device_state)
{
//------------------------------------------------------
// DEVICE_UNATTACHED state
//
// - Default init state
// - Try to give device power supply
//
case DEVICE_UNATTACHED:
nb_interface_supported = 0;
Host_clear_device_status(); // Reset device status
Usb_clear_all_event(); // Clear all software events
Host_disable_sof();
host_disable_all_pipes();
Usb_enable_vbus(); // Give at least device power supply!
// If VBus OK, wait for device connection
if (Is_usb_vbus_high()) device_state = DEVICE_ATTACHED;
break;
//------------------------------------------------------
// DEVICE_ATTACHED state
//
// - VBus is on
// - Try to detect device connection
//
case DEVICE_ATTACHED:
// if (Is_host_device_connection()) // Device pull-up detected
if( usb_device_connected == 1 )
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
usb_host.rar (20个子文件)
usb_host
class
hid
hid.h 19KB
host_hid
host_hid.c 9KB
host_hid.h 7KB
mass_storage
examples
scsi_decoder
scsi_decoder.c 22KB
scsi_decoder.h 23KB
dfu
examples
audio
examples
cdc
examples
usb_drv.c 36KB
usb_ids.h 12KB
FreeRTOSTask.h 4KB
enum
host
usb_host_enum.h 14KB
usb_host_task.h 9KB
usb_host_enum.c 22KB
usb_host_task.c 40KB
usb_task.h 10KB
device
usb_device_task.c 6KB
usb_standard_request.h 5KB
usb_device_task.h 4KB
usb_standard_request.c 25KB
usb_task.c 23KB
usb_drv.h 107KB
compiler.h 38KB
共 20 条
- 1
资源评论
四散
- 粉丝: 49
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功