Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

When a class instance is created, a control structure is allocated and associated to a specific class instance. The class uses this control structure for its internal operations. All the Micrium USB classes define a class control structure data type.  shows Listing - Class Instance Control Structure shows the declaration of such data structure.

Anchor
Listing - Class Instance Control Structure
Listing - Class Instance Control Structure

Code Block
languagecpp
linenumberstrue
struct usbd_xxxx_ctrl {
    CPU_INT08U        DevNbr;                                                 (1)
    CPU_INT08U        ClassNbr;                                               (2)
    USBD_XXXX_STATE   State;                                                  (3)
    USBD_XXXX_COMM   *CommPtr;                                                (4)
    ...                                                                       (5)
};


Panel
bgColor#f0f0f0

(1) The device number to which the class instance is associated with.

(2) The class instance number.

(3) The class instance state.

(4) A pointer to a class instance communication structure. This structure holds information regarding the interface’s endpoints used for data communication.

(5) Class-specific fields.


During the communication phase, the class communication structure is used by the class for data transfers on the endpoints. It allows you to route the transfer to the proper endpoint within the interface. There will be one class communication structure per configuration to which the class instance has been added.  presents this structureListing - Class Instance Communication Structure presents this structure.

Anchor
Listing - Class Instance Communication Structure
Listing - Class Instance Communication Structure

Code Block
languagecpp
linenumberstrue
struct usbd_xxxx_comm {                                            
   USBD_XXXX_CTRL  *CtrlPtr;                                                  (1)
   CPU_INT08U       ClassEpInAddr;                                            (2)
   CPU_INT08U       ClassEpOutAdd2;                                           (2)
    ...                                                                       (2)
};


Panel
bgColor#f0f0f0

(1) A pointer to the class instance control structure to which the communication relates to.

(2) Class-specific fields. In general, this structure stores mainly endpoint addresses related to the class. Depending on the class, the structure may store other types of information. For instance, the Mass Storage Class stores information about the Command Block and Status Wrappers.


Micrium’s USB classes define a class state for each class instance created. The class state values are implemented in the form of an enumeration:

Anchor
Listing - Enumeration of Class State Values
Listing - Enumeration of Class State Values

Code Block
languagecpp
linenumberstrue
typedef  enum  usbd_xxxx_state {                    
    USBD_XXXX_STATE_NONE = 0,
    USBD_XXXX_STATE_INIT,
    USBD_XXXX_STATE_CFG
} USBD_XXXX_STATE;


Listing - Enumeration of Class State Values defines a class state machine which applies to all the Micrium classes. Three class states are used.


Panel
borderWidth0
titleFigure - Class State Machine

Class State MachineImage Added


Panel
bgColor#f0f0f0

(1) A class instance has been added to a configuration, the class instance state transitions to the ‘Init’ state. No data communication on the class endpoint(s) can occur yet.

(2) The host has sent the SET_CONFIGURATION request to activate a certain configuration. The Core layer calls a class callback informing about the completion of the standard enumeration. The class instance state transitions to the ‘Cfg’ state. This state indicates that the device has transitioned to the ‘Configured’ state defined by the Universal Serial Bus Specification revision 2.0. The data communication may begin. Some classes such as the MSC class may require that the host sends some class-specific requests before the communication on the endpoints really starts.

(3) The Core layer calls another class callback informing that the host has sent a SET_CONFIGURATION request with a new configuration number or with the value 0 indicating a configuration reset, or that the device has been physically disconnected from the host. In all these cases, the current active configuration becomes inactive. The class instance state transitions to the ‘Init’ state. Any ongoing transfers on the endpoints managed by the class instance have been aborted by the Core layer. No more communication is possible until the host sends a new SET_CONFIGURATION request with a non-null value or until the device is plugged again to the host.