reconstruct USB host project directory

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2206 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
qiuyiuestc@gmail.com committed 2012-07-07 08:49:28 +00:00
1 parent 25268ad23d
commit 64c485f5fc
12 files changed
+24 -705

No files matched your search

+11 -6
View File
@@ -1,9 +1,14 @@
Import('RTT_ROOT')
# for module compiling
import os
from building import *
cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = [cwd]
group = DefineGroup('Drivers', src, depend = ['RT_USING_USB_DEVICE'], CPPPATH = CPPPATH)
cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)
Return('group')
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))
Return('objs')
+1 -4
View File
@@ -13,10 +13,7 @@
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "driver.h"
#include "core.h"
#include "hcd.h"
#include <drivers/usb_host.h>
#include "adk.h"
#ifdef RT_USB_CLASS_ADK
+1 -5
View File
@@ -13,11 +13,7 @@
*/
#include <rtthread.h>
#include "usbhost.h"
#include "core.h"
#include "driver.h"
#include "hcd.h"
#include "hub.h"
#include <drivers/usb_host.h>
static struct uinstance uinst[USB_MAX_DEVICE];
-116
View File
@@ -1,116 +0,0 @@
/*
* File : core.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2011-12-12 Yi Qiu first version
*/
#ifndef __CORE_H__
#define __CORE_H__
#include <rtthread.h>
#include "usbspec.h"
#include "usbhost.h"
#define USB_MAX_DEVICE 32
#define USB_MAX_INTERFACE 8
#define PORT_NUM 4
#define SIZEOF_USB_REQUEST 8
struct uhcd;
struct uifinst;
struct uhubinst;
typedef void (*func_callback)(void *context);
enum umsg_type
{
USB_MSG_CONNECT_CHANGE,
USB_MSG_CALLBACK,
};
typedef enum umsg_type umsg_type;
#define UINST_STATUS_IDLE 0
#define UINST_STATUS_BUSY 1
#define UINST_STATUS_ERROR 2
struct uinstance
{
struct udevice_descriptor dev_desc;
ucfg_desc_t cfg_desc;
struct uhcd *hcd;
rt_uint8_t status;
rt_uint8_t type;
rt_uint8_t index;
rt_uint8_t address;
rt_uint8_t speed;
rt_uint8_t max_packet_size;
rt_uint8_t port;
struct uhubinst* parent;
struct uifinst* ifinst[USB_MAX_INTERFACE];
};
typedef struct uinstance* uinst_t;
struct uifinst
{
uinst_t uinst;
uintf_desc_t intf_desc;
ucd_t drv;
void *user_data;
};
typedef struct uifinst* uifinst_t;
#define UPIPE_STATUS_OK 0
#define UPIPE_STATUS_STALL 1
#define UPIPE_STATUS_ERROR 2
struct upipe
{
rt_uint32_t status;
struct uendpoint_descriptor ep;
uifinst_t ifinst;
func_callback callback;
void* user_data;
};
typedef struct upipe* upipe_t;
struct umsg
{
umsg_type type;
union
{
struct uhubinst* uhub;
struct
{
func_callback function;
void *context;
}cb;
}content;
};
typedef struct umsg* umsg_t;
uinst_t rt_usb_alloc_instance(void);
rt_err_t rt_usb_attatch_instance(uinst_t uinst);
rt_err_t rt_usb_detach_instance(uinst_t uinst);
rt_err_t rt_usb_get_descriptor(uinst_t uinst, rt_uint8_t type, void* buffer,
int nbytes);
rt_err_t rt_usb_set_configure(uinst_t uinst, int config);
rt_err_t rt_usb_set_address(uinst_t uinst);
rt_err_t rt_usb_set_interface(uinst_t uinst, int intf);
rt_err_t rt_usb_clear_feature(uinst_t uinst, int endpoint, int feature);
rt_err_t rt_usb_get_interface_descriptor(ucfg_desc_t cfg_desc, int num,
uintf_desc_t* intf_desc);
rt_err_t rt_usb_get_endpoint_descriptor(uintf_desc_t intf_desc, int num,
uep_desc_t* ep_desc);
#endif
+1 -2
View File
@@ -13,8 +13,7 @@
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "driver.h"
#include <drivers/usb_host.h>
static rt_list_t _driver_list;
+3 -5
View File
@@ -13,9 +13,7 @@
*/
#include <rtthread.h>
#include "core.h"
#include "hcd.h"
#include "hub.h"
#include <drivers/usb_host.h>
#define USB_THREAD_STACK_SIZE 2048
@@ -589,12 +587,12 @@ rt_err_t rt_usb_post_event(struct umsg* msg, rt_size_t size)
}
/**
* This function will initialize usb system.
* This function will initialize usb hub thread.
*
* @return none.
*
*/
void rt_usb_system_init(void)
void rt_usb_hub_thread(void)
{
rt_thread_t thread;
-101
View File
@@ -1,101 +0,0 @@
/*
* File : hub.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2011-12-12 Yi Qiu first version
*/
#ifndef __HUB_H__
#define __HUB_H__
#include <rtthread.h>
typedef struct uhubinst* uhubinst_t;
struct uhubinst
{
struct uhub_descriptor hub_desc;
rt_uint8_t num_ports;
rt_uint32_t port_status[PORT_NUM];
struct uinstance* child[PORT_NUM];
rt_bool_t is_roothub;
upipe_t pipe_in;
rt_uint8_t buffer[8];
struct uinstance* self;
struct uhcd *hcd;
};
#define RH_GET_PORT_STATUS 0
#define RH_SET_PORT_STATUS 1
#define RH_CLEAR_PORT_FEATURE 2
#define RH_SET_PORT_FEATURE 3
/*
* Port feature numbers
*/
#define PORT_FEAT_CONNECTION 0
#define PORT_FEAT_ENABLE 1
#define PORT_FEAT_SUSPEND 2
#define PORT_FEAT_OVER_CURRENT 3
#define PORT_FEAT_RESET 4
#define PORT_FEAT_POWER 8
#define PORT_FEAT_LOWSPEED 9
#define PORT_FEAT_HIGHSPEED 10
#define PORT_FEAT_C_CONNECTION 16
#define PORT_FEAT_C_ENABLE 17
#define PORT_FEAT_C_SUSPEND 18
#define PORT_FEAT_C_OVER_CURRENT 19
#define PORT_FEAT_C_RESET 20
/*
The HcRhPortStatus[1:NDP] register is used to control and report port events on a per-port
basis. NumberDownstreamPorts represents the number of HcRhPortStatus registers that are
implemented in hardware. The lower word is used to reflect the port status, whereas the upper
word reflects the status change bits. Some status bits are implemented with special write behavior
(see below). If a transaction (token through handshake) is in progress when a write to change
port status occurs, the resulting port status change must be postponed until the transaction
completes. Reserved bits should always be written '0'.
*/
#define PORT_CCS 0x00000001UL /* R:CurrentConnectStatus - W:ClearPortEnable */
#define PORT_PES 0x00000002UL /* R:PortEnableStatus - W:SetPortEnable */
#define PORT_PSS 0x00000004UL /* R:PortSuspendStatus - W:SetPortSuspend */
#define PORT_POCI 0x00000008UL /* R:PortOverCurrentIndicator - W:ClearSuspendStatus */
#define PORT_PRS 0x00000010UL /* R:PortResetStatus - W: SetPortReset */
#define PORT_PPS 0x00000100UL /* R:PortPowerStatus - W: SetPortPower */
#define PORT_LSDA 0x00000200UL /* R:LowSpeedDeviceAttached - W:ClearPortPower */
#define PORT_CCSC 0x00010000UL
#define PORT_PESC 0x00020000UL
#define PORT_PSSC 0x00040000UL
#define PORT_POCIC 0x00080000UL
#define PORT_PRSC 0x00100000UL
/*
*Hub Status & Hub Change bit masks
*/
#define HUB_STATUS_LOCAL_POWER 0x0001
#define HUB_STATUS_OVERCURRENT 0x0002
#define HUB_CHANGE_LOCAL_POWER 0x0001
#define HUB_CHANGE_OVERCURRENT 0x0002
rt_err_t rt_usb_hub_get_descriptor(uinst_t uinst, rt_uint8_t *buffer,
rt_size_t size);
rt_err_t rt_usb_hub_get_status(uinst_t uinst, rt_uint8_t* buffer);
rt_err_t rt_usb_hub_get_port_status(uhubinst_t uhub, rt_uint16_t port,
rt_uint8_t* buffer);
rt_err_t rt_usb_hub_clear_port_feature(uhubinst_t uhub, rt_uint16_t port,
rt_uint16_t feature);
rt_err_t rt_usb_hub_set_port_feature(uhubinst_t uhub, rt_uint16_t port,
rt_uint16_t feature);
rt_err_t rt_usb_hub_reset_port(uhubinst_t uhub, rt_uint16_t port);
rt_err_t rt_usb_post_event(struct umsg* msg, rt_size_t size);
#endif
+7 -32
View File
@@ -12,9 +12,7 @@
* 2011-3-12 Yi Qiu first version
*/
#include <rtthread.h>
#include "usbhost.h"
#include "core.h"
#include "hub.h"
#include <drivers/usb_host.h>
#if defined(RT_USB_HID_KEYBOARD) || defined(RT_USB_HID_MOUSE)
#include <hid.h>
@@ -26,16 +24,15 @@
*
* @return none.
*/
void rt_usbhost_init(void)
void rt_usb_host_init(void)
{
ucd_t drv;
rt_device_t dev;
#ifdef RT_USB_CLASS_HID
uprotocal_t protocal;
#endif
/* initialize usb hub */
rt_usb_system_init();
/* initialize usb hub thread */
rt_usb_hub_thread();
/* initialize class driver */
rt_usb_class_driver_init();
@@ -65,35 +62,13 @@ void rt_usbhost_init(void)
#endif
#ifdef RT_USB_CLASS_ADK
/* register adk class driver */
drv = rt_usb_class_driver_adk();
rt_usb_class_driver_register(drv);
/* register adk class driver */
drv = rt_usb_class_driver_adk();
rt_usb_class_driver_register(drv);
#endif
/* register hub class driver */
drv = rt_usb_class_driver_hub();
rt_usb_class_driver_register(drv);
#ifdef RT_USB_HCD_MUSB
/* register musb host controller driver */
dev = rt_usb_hcd_musb();
rt_device_register(dev, "musb", 0);
rt_device_init(dev);
#endif
#ifdef RT_USB_HCD_OHCI
/* register ohci host controller driver */
dev = rt_usb_hcd_ohci();
rt_device_register(dev, "ohci", 0);
rt_device_init(dev);
#endif
#ifdef RT_USB_HCD_STM32
/* register ohci host controller driver */
dev = rt_usb_hcd_susb();
rt_device_register(dev, "susb", 0);
rt_device_init(dev);
#endif
}
@@ -1,43 +0,0 @@
#ifndef __DRIVER_H__
#define __DRIVER_H__
#include <rtthread.h>
enum uclass_type
{
rt_usb_Class_MassStor = 0,
rt_usb_Class_Hid,
rt_usb_Class_Hub,
};
struct uclass_driver
{
rt_list_t list;
int class_code;
int subclass_code;
rt_err_t (*run)(void* arg);
rt_err_t (*stop)(void* arg);
void* user_data;
};
typedef struct uclass_driver* ucd_t;
struct uprotocal
{
rt_list_t list;
int pro_id;
rt_err_t (*init)(void* arg);
rt_err_t (*callback)(void* arg);
};
typedef struct uprotocal* uprotocal_t;
rt_err_t rt_usb_class_driver_init(void);
rt_err_t rt_usb_class_driver_register(ucd_t drv);
rt_err_t rt_usb_class_driver_unregister(ucd_t drv);
rt_err_t rt_usb_class_driver_run(ucd_t drv, void* args);
rt_err_t rt_usb_class_driver_stop(ucd_t drv, void* args);
ucd_t rt_usb_class_driver_find(int class_code, int subclass_code);
#endif
@@ -1,124 +0,0 @@
/*
* File : hcd.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2011-12-12 Yi Qiu first version
*/
#ifndef __HCD_H__
#define __HCD_H__
#include <rtthread.h>
#include "usbspec.h"
struct uhcd_ops
{
int (*ctl_xfer)(uinst_t inst, ureq_t setup, void* buffer, int nbytes,
int timeout);
int (*bulk_xfer)(upipe_t pipe, void* buffer, int nbytes, int timeout);
int (*int_xfer)(upipe_t pipe, void* buffer, int nbytes, int timeout);
int (*iso_xfer)(upipe_t pipe, void* buffer, int nbytes, int timeout);
rt_err_t (*alloc_pipe)(struct upipe** pipe, uifinst_t ifinst, uep_desc_t ep,
func_callback callback);
rt_err_t (*free_pipe)(upipe_t pipe);
rt_err_t (*hub_ctrl)(rt_uint16_t port, rt_uint8_t cmd, void *args);
};
struct uhcd
{
struct rt_device parent;
struct uhcd_ops* ops;
};
typedef struct uhcd* uhcd_t;
rt_inline rt_err_t rt_usb_hcd_alloc_pipe(uhcd_t hcd, upipe_t* pipe,
uifinst_t ifinst, uep_desc_t ep, func_callback callback)
{
if(ifinst == RT_NULL) return -RT_EIO;
/* parameter check */
RT_ASSERT(hcd != RT_NULL);
RT_ASSERT(hcd->ops != RT_NULL);
RT_ASSERT(hcd->ops->alloc_pipe!= RT_NULL);
return hcd->ops->alloc_pipe(pipe, ifinst, ep, callback);
}
rt_inline rt_err_t rt_usb_hcd_free_pipe(uhcd_t hcd, upipe_t pipe)
{
RT_ASSERT(pipe != RT_NULL);
/* parameter check */
RT_ASSERT(hcd != RT_NULL);
RT_ASSERT(hcd->ops != RT_NULL);
RT_ASSERT(hcd->ops->free_pipe!= RT_NULL);
return hcd->ops->free_pipe(pipe);
}
rt_inline int rt_usb_hcd_bulk_xfer(uhcd_t hcd, upipe_t pipe, void* buffer,
int nbytes, int timeout)
{
if(pipe == RT_NULL) return -1;
if(pipe->ifinst == RT_NULL) return -1;
if(pipe->ifinst->uinst == RT_NULL) return -1;
if(pipe->ifinst->uinst->status == UINST_STATUS_IDLE)
return -1;
/* parameter check */
RT_ASSERT(hcd != RT_NULL);
RT_ASSERT(hcd->ops != RT_NULL);
RT_ASSERT(hcd->ops->bulk_xfer!= RT_NULL);
return hcd->ops->bulk_xfer(pipe, buffer, nbytes, timeout);
}
rt_inline int rt_usb_hcd_control_xfer(uhcd_t hcd, uinst_t uinst, ureq_t setup,
void* buffer, int nbytes, int timeout)
{
if(uinst->status == UINST_STATUS_IDLE) return -1;
/* parameter check */
RT_ASSERT(hcd != RT_NULL);
RT_ASSERT(hcd->ops != RT_NULL);
RT_ASSERT(hcd->ops->ctl_xfer!= RT_NULL);
return hcd->ops->ctl_xfer(uinst, setup, buffer, nbytes, timeout);
}
rt_inline int rt_usb_hcd_int_xfer(uhcd_t hcd, upipe_t pipe, void* buffer,
int nbytes, int timeout)
{
if(pipe == RT_NULL) return -1;
if(pipe->ifinst == RT_NULL) return -1;
if(pipe->ifinst->uinst == RT_NULL) return -1;
if(pipe->ifinst->uinst->status == UINST_STATUS_IDLE)
return -1;
RT_ASSERT(hcd != RT_NULL);
RT_ASSERT(hcd->ops != RT_NULL);
RT_ASSERT(hcd->ops->int_xfer!= RT_NULL);
return hcd->ops->int_xfer(pipe, buffer, nbytes, timeout);
}
rt_inline rt_err_t rt_usb_hcd_hub_control(uhcd_t hcd, rt_uint16_t port,
rt_uint8_t cmd, void *args)
{
RT_ASSERT(hcd != RT_NULL);
RT_ASSERT(hcd->ops != RT_NULL);
RT_ASSERT(hcd->ops->hub_ctrl != RT_NULL);
return hcd->ops->hub_ctrl(port, cmd, args);
}
#endif
@@ -1,42 +0,0 @@
/*
* File : usbhost.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2011-3-12 Yi Qiu first version
*/
#ifndef __RT_USB_HOST_INIT_H__
#define __RT_USB_HOST_INIT_H__
#include <rtthread.h>
#include "driver.h"
#define RT_DEBUG_USB 1
void rt_usbhost_init(void);
void rt_usb_system_init(void);
/* usb class driver definition */
ucd_t rt_usb_class_driver_hid(void);
ucd_t rt_usb_class_driver_hub(void);
ucd_t rt_usb_class_driver_storage(void);
ucd_t rt_usb_class_driver_adk(void);
/* usb hid protocal definition */
uprotocal_t rt_usb_hid_protocal_kbd(void);
uprotocal_t rt_usb_hid_protocal_mouse(void);
/* usb host controller driver definition */
rt_device_t rt_usb_hcd_musb(void);
rt_device_t rt_usb_hcd_ohci(void);
rt_device_t rt_usb_hcd_susb(void);
#endif
File diff suppressed because it is too large. Load diff