State – Comtrol eCos User Manual

Page 704

Advertising
background image

Control Endpoints

...

const usbs_enumeration_data* enumeration_data;

void

(*start_fn)(usbs_control_endpoint*);

...

};

It is the responsibility of higher-level code, usually the application, to define the USB enumeration data. This
needs to be installed in the control endpoint data structure early on during system startup, before the USB device
is actually started and any interaction with the host is possible. Details of the enumeration data are supplied in
the section

USB Enumeration Data

. Typically, the enumeration data is constant for a given peripheral, although it

can be constructed dynamically if necessary. However, the enumeration data cannot change while the peripheral is
connected to a host: the peripheral cannot easily claim to be a keyboard one second and a printer the next.

The

start_fn

member is normally accessed via the utility

usbs_start

rather than directly. It is provided by the

device driver and should be invoked once the system is fully initialized and interaction with the host is possible.
A typical implementation would change the USB data pins from tristated to active. If the peripheral is already
plugged into a host then the latter should detect this change and start interacting with the peripheral, including
requesting the enumeration data.

State

There are three usbs_control_endpoint fields related to the current state of a USB slave device, plus some state
constants and an enumeration of the possible state changes:

typedef struct usbs_control_endpoint {

...

int

state;

void

(*state_change_fn)(struct usbs_control_endpoint*, void*,

usbs_state_change, int);

void*

state_change_data;

...

};

#define USBS_STATE_DETACHED

0x01

#define USBS_STATE_ATTACHED

0x02

#define USBS_STATE_POWERED

0x03

#define USBS_STATE_DEFAULT

0x04

#define USBS_STATE_ADDRESSED

0x05

#define USBS_STATE_CONFIGURED

0x06

#define USBS_STATE_MASK

0x7F

#define USBS_STATE_SUSPENDED

(1

<<

7)

typedef enum {

USBS_STATE_CHANGE_DETACHED

= 1,

USBS_STATE_CHANGE_ATTACHED

= 2,

USBS_STATE_CHANGE_POWERED

= 3,

USBS_STATE_CHANGE_RESET

= 4,

USBS_STATE_CHANGE_ADDRESSED

= 5,

USBS_STATE_CHANGE_CONFIGURED

= 6,

USBS_STATE_CHANGE_DECONFIGURED

= 7,

USBS_STATE_CHANGE_SUSPENDED

= 8,

USBS_STATE_CHANGE_RESUMED

= 9

600

Advertising