]> rtime.felk.cvut.cz Git - lincan.git/blob - embedded/libs4c/usb/base/usb/usb.h
Merge master into can-usb1 branch to include proc update for 3.12+ kernels.
[lincan.git] / embedded / libs4c / usb / base / usb / usb.h
1 /**************************************************************/
2 /***   Module : USB module - header file                    ***/
3 /***   Author : Roman Bartosinski (C) 28.04.2002            ***/
4 /***   Modify : 08.08.2002                                  ***/
5 /***   Rewrite: 05.09.2002                                  ***/
6 /**************************************************************/
7
8 #ifndef _USB_MODULE_
9   #define _USB_MODULE_
10
11   #include "usb_spec.h"
12   #include "usb_devdes.h"
13
14 #if defined(SDCC) || defined(__KEIL__) || defined(__C51__)
15   /*8051 special handling*/
16   #define REENTRANT_SIGN __reentrant
17 #else
18   #define __xdata         /*nothing*/
19   #define REENTRANT_SIGN  /*nothing*/
20 #endif
21
22 #define USB_WITH_CB_FNC
23 //#define USB_WITH_UDEV_FNC
24
25 #ifdef USB_WITH_UDEV_FNC
26   #define USB_UDEV_REENTRANT_SIGN REENTRANT_SIGN
27 #else /*USB_WITH_UDEV_FNC*/
28   #define USB_UDEV_REENTRANT_SIGN /*nothing*/
29 #endif /*USB_WITH_UDEV_FNC*/
30
31 /* control endpoint */
32   #define MAX_CONTROL_XFER_DATA_SIZE 8
33
34   struct usb_ep_t;
35
36   typedef void endfnc_t( struct  usb_ep_t *ep) REENTRANT_SIGN;
37
38   #define USB_NEXT_PKT_SEND 0
39   #define USB_NEXT_PKT_REC  1
40
41   #define USB_COMPLETE_OK   0
42   #define USB_COMPLETE_FAIL -1
43
44   typedef struct usb_ep_t {
45     struct usb_device_t *udev;      /* pointer to parent device */
46     unsigned short max_packet_size; /* max. size of endpoint package, e.g. PDI_EP0_PACKET_SIZE */
47     unsigned char *ptr;             /* pointer to current transmitted data */
48     unsigned int  size;             /* full size of current transmitted data */
49     unsigned int  actual;           /* transmitted data size */
50     endfnc_t *efnc;                 /* ??? */
51     unsigned char flags;            /* endpoint flags & state - idle,receiving, transmitting  ??? HERE ??? */
52     unsigned char epnum;            /* endpoint number (index) - endpoint0 must be set to 0 */
53     unsigned short event_mask;      /* event(interrupt) mask for this endpoint, e.g. PDI_INT_EP1_IN for pdiusbd1x */
54    #ifdef USB_WITH_CB_FNC
55     int (*next_pkt_fnc)(struct usb_ep_t *ep, int len, int codeval) REENTRANT_SIGN;
56     int (*complete_fnc)(struct usb_ep_t *ep, int status) REENTRANT_SIGN;
57     long user_data;
58    #endif /*USB_WITH_CB_FNC*/
59   } usb_ep_t;
60
61 /* USB device */
62   typedef struct usb_device_t {
63     unsigned char id;               /* device ID ??? */
64     unsigned char flags;            /* usb device flags + endpoint0 events */
65     unsigned char ep_events;        /* one bit for each endpoint (without ep0) event,(bit0 for udev->ep[0], bit1 for udev->ep[1], ...)*/
66     unsigned char configuration;    /* current configuration */
67 //    unsigned char interface;        /* current interface */
68 //    unsigned char altinterface;     /* current alternative interface */
69
70     int (*vendor_fnc)( struct usb_device_t *udev) REENTRANT_SIGN;     /* pointer to vendor request processing function */
71     int (*class_fnc)( struct usb_device_t *udev) REENTRANT_SIGN;      /* pointer to class request processing function */
72     int (*standard_fnc)( struct usb_device_t *udev) REENTRANT_SIGN;     /* pointer to standard request processing function */
73
74     //int (stdreq[13])( struct usb_device_t *udev) REENTRANT_SIGN;    /* pointer to array of standard request processing functions - not used in actual implementation */
75
76     const USB_DEVICE_DESCRIPTORS_TABLE *devdes_table;
77
78    #ifdef USB_WITH_UDEV_FNC
79     int (*init)( struct usb_device_t *udev) REENTRANT_SIGN;              /* function for hw specific part of initialize usb device */
80     int (*set_addr)( struct usb_device_t *udev, unsigned char addr) REENTRANT_SIGN;  /* set device address */
81     int (*set_configuration)( struct usb_device_t *udev, unsigned char iCfg) REENTRANT_SIGN;  /* set device configuration */
82     int (*connect)( struct usb_device_t *udev) REENTRANT_SIGN;           /* function for hw specific part of connecting device to usb */
83     int (*disconnect)( struct usb_device_t *udev) REENTRANT_SIGN;        /* function for hw specific part of disconnecting device to usb */
84     void (*ack_setup)( struct usb_device_t *udev) REENTRANT_SIGN;        /* function for hw specific part of control response acknowledge */
85     void (*ack_control_setup)( struct usb_device_t *udev) REENTRANT_SIGN;        /* function for hw specific part of control response acknowledge */
86     int (*check_events)( struct usb_device_t *udev) REENTRANT_SIGN;      /* hw specific part of function for checking events */
87     void (*stall)( usb_ep_t *ep) REENTRANT_SIGN;                         /* hw specific function to stall endpoint */
88     void (*unstall)( usb_ep_t *ep) REENTRANT_SIGN;                       /* hw specific function to unstall endpoint */
89     int (*read_endpoint)( usb_ep_t *ep, void *ptr, int size) REENTRANT_SIGN;
90     int (*write_endpoint)( usb_ep_t *ep, const void *ptr, int size) REENTRANT_SIGN;
91    #endif /*USB_WITH_UDEV_FNC*/
92
93 //    USB_DEVICE_REQUEST *request;   /* current usb request - only if there is a valid usb request in processing */
94     USB_DEVICE_REQUEST request;    /* usb device request */
95
96     unsigned char cntep;           /* number of device endpoints in ep array without EP0 */
97     usb_ep_t ep0;                  /* endpoint 0 */
98     usb_ep_t *ep;                 /* others endpoints in array */
99   } usb_device_t;
100
101
102 /* endpoint flags */
103   /* endpoint state */
104   #define USB_STATE_IDLE       0x00
105   #define USB_STATE_TRANSMIT   0x01
106   #define USB_STATE_RECEIVE    0x02
107   #define USB_STATE_MASK       0x03
108
109 /* usb_device flags */
110   #define USB_FLAG_CONFIGURED   0x01
111   #define USB_FLAG_BUS_RESET    0x02
112   #define USB_FLAG_SUSPEND      0x04
113   #define USB_FLAG_SETUP        0x08 // setup_packet
114   #define USB_FLAG_REMOTE_WAKE  0x10
115
116   #define USB_FLAG_EVENT_RX0  0x40
117   #define USB_FLAG_EVENT_TX0  0x80
118
119
120
121 /* device functions - inline ??? */
122   int usb_init( usb_device_t *udev);
123   int usb_connect( usb_device_t *udev);
124   int usb_disconnect( usb_device_t *udev);
125   void usb_stall( usb_ep_t *ep);
126   void usb_unstall( usb_ep_t *ep);
127
128   #define usb_stall_ep0( udev) \
129     do { \
130       usb_stall( &(udev->ep0)); \
131     } while(0)
132
133 /* check usb events(interrupts) */
134   int usb_check_events( usb_device_t *udev);
135 /* response to standard constrol requests */
136   int usb_control_response( usb_device_t *udev);
137 /* send control data */
138   void usb_send_control_data( usb_device_t *udev, unsigned char *pData, unsigned short len);
139   void usb_set_control_endfnc( usb_device_t *udev, endfnc_t *efnc);// REENTRANT_SIGN;
140   void usb_ack_setup( usb_ep_t *ep);
141
142
143 /* Standard requests functions */
144 //  typedef int (*usb_stdreq_fnc_t)( usb_device_t *udev) REENTRANT_SIGN;
145 //  extern xdata usb_stdreq_fnc_t usb_standard_requests[13];
146
147 int usb_standard_control_response(usb_device_t *udev)  REENTRANT_SIGN;
148
149 #ifdef USB_WITH_UDEV_FNC
150
151   #define usb_udev_is_fnc(_M_udev, _M_fnc) (_M_udev->_M_fnc)
152
153   #define usb_udev_init(_M_udev) (_M_udev->init(_M_udev))
154   #define usb_udev_set_addr(_M_udev, _M_addr) (_M_udev->set_addr(_M_udev, _M_addr))
155   #define usb_udev_set_configuration(_M_udev, _M_iCfg) (_M_udev->set_configuration(_M_udev, _M_iCfg))
156   #define usb_udev_connect(_M_udev) (_M_udev->connect(_M_udev))
157   #define usb_udev_disconnect(_M_udev) (_M_udev->disconnect(_M_udev))
158   #define usb_udev_ack_setup(_M_udev) (_M_udev->ack_setup(_M_udev))
159   #define usb_udev_ack_control_setup(_M_udev) (_M_udev->ack_control_setup(_M_udev))
160   #define usb_udev_check_events(_M_udev) (_M_udev->check_events(_M_udev))
161
162   #define usb_udev_stall(_M_ep) ((_M_ep)->udev->stall(_M_ep))
163   #define usb_udev_unstall(_M_ep) ((_M_ep)->udev->unstall(_M_ep))
164
165   #define usb_udev_read_endpoint(_M_ep, _M_ptr, _M_size) \
166         ((_M_ep)->udev->read_endpoint(_M_ep, _M_ptr, _M_size))
167
168   #define usb_udev_write_endpoint(_M_ep, _M_ptr, _M_size) \
169         ((_M_ep)->udev->write_endpoint(_M_ep, _M_ptr, _M_size))
170
171 #else /*USB_WITH_UDEV_FNC*/
172
173   #define USB_PDI_DIRECT_FNC
174   #include "usb/pdi.h"
175
176 #endif /*USB_WITH_UDEV_FNC*/
177
178 #endif