A little more USB host logic

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3179 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2010-12-15 03:30:20 +00:00
parent b2c56a0d80
commit b13740af0a
2 changed files with 110 additions and 23 deletions

View File

@ -39,6 +39,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <debug.h> #include <debug.h>
@ -64,6 +65,10 @@ struct usbhost_state_s
struct usbhost_class_s class; struct usbhost_class_s class;
/* This is an instance of the USB host driver bound to this class instance */
struct usbhost_driver_s *drvr;
/* The remainder of the fields are provide o the mass storage class */ /* The remainder of the fields are provide o the mass storage class */
int crefs; /* Reference count on the driver instance */ int crefs; /* Reference count on the driver instance */
@ -79,6 +84,11 @@ struct usbhost_state_s
static struct usbhost_class_s *usbhost_create(struct usbhost_driver_s *drvr); static struct usbhost_class_s *usbhost_create(struct usbhost_driver_s *drvr);
/* struct usbhost_class_s methods */
static int usbhost_configdesc(struct usbhost_class_s *class,
const uint8_t *configdesc, int desclen);
/* struct block_operations methods */ /* struct block_operations methods */
static int usbhost_open(FAR struct inode *inode); static int usbhost_open(FAR struct inode *inode);
@ -142,7 +152,7 @@ static const struct block_operations g_bops =
* Name: usbhost_create * Name: usbhost_create
* *
* Description: * Description:
* This function implements the create() method of struct usb_registry_s. * This function implements the create() method of struct usbhost_registry_s.
* The create() method is a callback into the class implementation. It is * The create() method is a callback into the class implementation. It is
* used to (1) create a new instance of the USB host class state and to (2) * used to (1) create a new instance of the USB host class state and to (2)
* bind a USB host driver "session" to the class instance. Use of this * bind a USB host driver "session" to the class instance. Use of this
@ -168,10 +178,65 @@ static const struct block_operations g_bops =
static struct usbhost_class_s *usbhost_create(struct usbhost_driver_s *drvr, static struct usbhost_class_s *usbhost_create(struct usbhost_driver_s *drvr,
const struct usbhost_id_s *id) const struct usbhost_id_s *id)
{ {
#warning "Not implemented" struct usbhost_state_s *priv;
/* Allocate a USB host mass storage class instance */
priv = (struct usbhost_state_s *)malloc(sizeof(struct usbhost_state_s));
if (priv)
{
/* Initialize the allocated storage class instance */
memset(priv, 0, sizeof(struct usbhost_state_s);
priv->class.configdesc = usbhost_configdesc;
priv->crefs = 1;
/* Bind the driver to the storage class instance */
priv->drvr = drvr;
/* NOTE: We do not yet know the geometry of the USB mass storage device */
/* Return the instance of the USB mass storage class */
return &priv->class;
}
/* Return NULL on all failures */
return NULL; return NULL;
} }
/****************************************************************************
* struct usbhost_class_s methods
****************************************************************************/
/****************************************************************************
* Name: usbhost_configdesc
*
* Description:
* This function implemented the configdesc() method of struct
* usbhost_class_s. This method is a callback into the class
* implementation. It is used to provide the device's configuration
* descriptor to the class so that the class may initialize properly
*
* Input Parameters:
* class - The USB host class entry previously obtained from a call to create().
* configdesc - A pointer to a uint8_t buffer container the configuration descripor.
* desclen - The length in bytes of the configuration descriptor.
*
* Returned Values:
* On success, zero (OK) is returned. On a failure, a negated errno value is
* returned indicating the nature of the failure
*
****************************************************************************/
static int usbhost_configdesc(struct usbhost_class_s *class,
const uint8_t *configdesc, int desclen)
{
#warning "Missing Implementation"
return -ENOSYS;
}
/**************************************************************************** /****************************************************************************
* struct block_operations methods * struct block_operations methods
****************************************************************************/ ****************************************************************************/

View File

@ -58,7 +58,7 @@
* Name: CLASS_CREATE * Name: CLASS_CREATE
* *
* Description: * Description:
* This macro will call the create() method of struct usb_registry_s. The create() * This macro will call the create() method of struct usbhost_registry_s. The create()
* method is a callback into the class implementation. It is used to (1) create * method is a callback into the class implementation. It is used to (1) create
* a new instance of the USB host class state and to (2) bind a USB host driver * a new instance of the USB host class state and to (2) bind a USB host driver
* "session" to the class instance. Use of this create() method will support * "session" to the class instance. Use of this create() method will support
@ -83,7 +83,29 @@
* *
************************************************************************************/ ************************************************************************************/
#definei CLASS_CREATE(reg, drvr, id) (reg->create(drvr)) #define CLASS_CREATE(reg, drvr, id) (reg->create(drvr))
/************************************************************************************
* Name: CLASS_CONFIGDESC
*
* Description:
* This macro will call the configdesc() method of struct usbhost_class_s. This
* method is a callback into the class implementation. It is used to provide the
* device's configuration descriptor to the class so that the class may initialize
* properly
*
* Input Parameters:
* class - The USB host class entry previously obtained from a call to create().
* configdesc - A pointer to a uint8_t buffer container the configuration descripor.
* desclen - The length in bytes of the configuration descriptor.
*
* Returned Values:
* On success, zero (OK) is returned. On a failure, a negated errno value is
* returned indicating the nature of the failure
*
************************************************************************************/
#definei CLASS_CONFIGDESC(class, configdesc, desclen) (class->create(class, configdesc, desclen))
/************************************************************************************ /************************************************************************************
* Public Types * Public Types