5 #include "hci_transport.h"
9 //#define DEBUG_COMPLETE_PKT_NUM
10 //#define USE_WRITE_PACKET_BUFFER /* write to ring buffer at first */
11 //#define usb_class_intf_to_dev(c) container_of(c, struct dev_class, dev)
13 #ifdef USE_WRITE_PACKET_BUFFER
14 #define USB_READ_TASK_DEF_PRIORITY 10
16 #define USB_READ_TASK_DEF_PRIORITY 10
19 #define USB_READ_TASK_STACKSIZE 2000 //1600
21 // constants used for selecting the SCO pipe
22 #define SCO_INTERFACE_NUMBER 1
23 #define SCO_DEFAULT_ALT_SETTING 0 // by default, SCO is off
24 #define SCO_MAX_ALT_SETTING 5
26 #define SCO_DEF_SAMPLE_SIZE 8
27 #define SCO_DEF_WRITE_LOW_NUM_PACKETS 4
28 #define SCO_DEF_WRITE_HIGH_NUM_PACKETS 8
29 #define SCO_DEF_PACKET_SIZE 27
31 #define SCO_WRITE_FRAMES_PER_PACKET 3 /* one packet send in there frames */
32 #define SCO_READ_FRAMES_PER_PACKET 3 /* one packet recv in there frames */
34 #define SCO_READ_PACKETS_PER_TRANSFER 9 /* one sco transfer includes nine packets */
35 #define MAX_SCO_READ_PACKETS_PER_TRANSFER 15
36 #define MAX_SCO_READ_FRAMES_PER_TRANSFER (MAX_SCO_READ_PACKETS_PER_TRANSFER * SCO_READ_FRAMES_PER_PACKET) /* 3x15 */
39 #define DEFPACKETSIZE /* 256 */384 /* 256Bytes per packet for receive */
40 #define DEFBLOCKSIZE 6 /*5*/ /* default buffers is 5 packet */
43 #ifdef USE_SCO_TRANSFER
44 #define NUM_SCO_ENDPOINTS 6
45 #define NUM_SCO_IN_PIPES 1
46 #define NUM_SCO_OUT_PIPES 1
48 //#define NUM_SCO_ENDPOINTS 0
49 //#define NUM_SCO_IN_PIPES 0
50 //#define NUM_SCO_OUT_PIPES 0
57 #define PACKET_COMMAND 2
60 #define PACKET_COMMAND 1
63 #define SCO_HEADER_SIZE 3 /* core4.0 spec HCI DATA FORMATS */
64 #define ACL_HEADER_SIZE 4
65 #define EVENT_HEADER_SIZE 2
67 #define PACKET_SIZE_R 1024 // (/*64*/2 * 1024 + 128) // same as adk stack packetStore size
68 #define PACKET_SIZE_W (2048)
70 typedef struct _packet
73 /* if noffset == nSize then discard this packet. */
75 struct _packet
* next
;
77 unsigned char data
[1];
78 } PACKET
, * PACKET_T
;
80 typedef struct _completed_packet
{
81 struct _completed_packet
* next
;
85 unsigned char cdata
[1];
89 typedef struct usb_pipe
91 /* mqx pipe handle => usb_hostdev_get_pipe_handle pipe_handle_t */
94 /* we don't use pointer for avoid the mem fragment */
97 /* mqx _usb_host_set_up_tr => _usb_host_get_tr_element tr will linked on the tr_list_ptr ( _usb_host_get_transfer_status ) */
100 PACKET
* last_packet
;
102 /* size of all items that linked in the packet list pointed by packets */
106 #ifdef USE_SCO_TRANSFER
107 typedef struct _sco_data
110 unsigned int sco_read_frames
;
111 unsigned int close_sco_io
;
113 uint_8 endp_sco_alt_setting
[NUM_SCO_ENDPOINTS
];
114 int sco_in_count
, sco_out_count
;
115 unsigned int suggested_sco_alt_setting
;
117 unsigned int in_transfer_lens
[MAX_SCO_READ_FRAMES_PER_TRANSFER
];
118 unsigned int out_transfer_lens
[SCO_WRITE_FRAMES_PER_PACKET
];
119 } SCO_DATA
, _PTR_ SCO_DATA_PRT
;
122 typedef struct _usb_write_packet
{
123 tr_user_t h_transfer
; /* don't use pointer */
125 unsigned char * buffer
;
126 #ifdef USE_SCO_TRANSFER
127 unsigned int lens
[SCO_WRITE_FRAMES_PER_PACKET
];
129 } usb_write_packet_t
;
131 typedef struct _usb_descriptor
{
132 usb_write_packet_t packet
;
133 unsigned int idx_start
;
134 unsigned int returned
;
135 unsigned int total_len
;
138 #define RING_BUFFER_SIZE 10240
139 #define MAX_ASYNC_PACKET_SIZE 2048
140 #define RING_BUFFER_END (RING_BUFFER_SIZE - MAX_ASYNC_PACKET_SIZE)
141 #define MAX_ASYNC_PACKETS 32
143 typedef struct _ring_buffer
145 unsigned int idx_current
;
146 unsigned int free_space
;
147 unsigned char * buffer
;
148 unsigned int packets
;
149 unsigned int last_returned_desc
;
150 unsigned int next_desc
;
151 usb_descriptor_t desc
[MAX_ASYNC_PACKETS
];
152 unsigned int idx_complete
;
153 unsigned int complete
[MAX_ASYNC_PACKETS
];
154 OS_Mutex_handle
/* unsigned int*/ r_lock
;
157 /* gloab usb device handle */
158 typedef struct usb_device_struct
160 USB_DEV_HANDLE
/* APP_DEVICE_STRUCT */ usb_dev
;
162 fixed_mem_id_t fmem_id
;
163 ring_buffer_t ring_buffer
;
166 struct usb_pipe usb_pipes
[NUM_IN_PIPES
];
168 PIPE_HANDLE out_pipes
[NUM_OUT_PIPES
];
170 unsigned int closing
;
172 unsigned int initialized
;
174 /* set to DEFPACKETSIZE at first ,the second instead of the minimux max packet size of all pipes */
175 unsigned int packet_size
;
176 unsigned int block_size
;
177 unsigned int min_packet_size
;
178 #ifdef USE_SCO_TRANSFER
179 SCO_DATA_PRT sco_pdata
; /* alloc at sco attach */
181 completed_packet_t
* packet_list
;
182 completed_packet_t
* last_packet
;
184 // usb bt class event bits
185 #define READ_EVENT_ISO_MASK (1 << EVENT_ISOCH)
186 #define READ_EVENT_BULK_MASK (1 << EVENT_BULK)
187 #define READ_EVENT_INTERRUPT_MASK (1 << EVENT_INTERRUPT)
189 #define WRITEN_EVENT_MASK (1 << EVENT_WRITTEN )
190 #define CLOSE_EVENT_MASK (1 << EVENT_CLOSE)
191 #define PACKETS_EVENT_MASK (1 << EVENT_PACKETS)
192 OS_Event_handle usbdev_event
;
194 uint32_t task_handle
;
195 } USB_DEVICE_STRUCT
, _PTR_ USB_DEVICE_STRUCT_PTR
;
198 /* declare drv function */
200 // extern usb driver function
201 extern BOOL
issue_cmd_transfer(
203 tr_user_t
* h_tr_ptr
,
204 unsigned char * buff_ptr
,
205 unsigned int buf_len
);
207 extern BOOL
issue_event_transfer(
209 tr_user_t
* h_tr_ptr
,
210 unsigned char * buff_ptr
,
211 unsigned int buf_len
);
213 extern BOOL
issue_acl_transfer(
215 tr_user_t
* h_tr_ptr
,
217 pointer cb_unblocked_param
,
218 unsigned char * buff_ptr
,
219 unsigned int buf_len
);
221 extern int open_acl_interface(void * usb_dev
);
222 extern void close_acl_interface(void * usb_dev
);
223 extern void close_transfer(tr_user_t
* h_tr_ptr
);
224 extern BOOL
transfer_completed(tr_user_t
* h_tr_ptr
); // judge the complete of a transfer
225 extern BOOL
get_transfer_status(tr_user_t
* h_tr_ptr
,unsigned int * transfered
);
227 extern BOOL
usb_drv_init();
229 #ifdef USE_SCO_TRANSFER
230 // extern unsigned short drv_sco_packet_maxsize(void * usb_dev,int in_out,int ep_num);
231 extern unsigned short get_sco_endp_max_packetsize(void * usb_dev
,int idx
, int in_out
);
232 extern int open_sco_interface(void * usb_dev
, int altsetting
);
233 extern int close_sco_interface(void * usb_dev
,int altsetting
);
234 extern BOOL
issue_sco_transfer(
235 /* pipe_handle_t h_pipe, */
237 tr_user_t
* h_tr_ptr
,
238 uint32_t flags
, /* block or nonblock */
239 /* Callback parameter */
240 pointer cb_unblocked_param
,
241 uint32_t frames
, /* number of frames in transfer */
242 unsigned int * lens_ptr
, /* array of lengths (one entry per frame) */
243 unsigned char * buff_ptr
/* data buffer */
248 #endif /* _USB_HCI_H_ */