dev_snd.c
3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*HEADER******************************************************************
**************************************************************************
***
*** Copyright (c) 2001-2002 ARC International.
*** All rights reserved
***
*** This software embodies materials and concepts which are
*** confidential to ARC International and is made
*** available solely pursuant to the terms of a written license
*** agreement with ARC International
***
*** $Workfile:devapi.c$
*** $Revision: 1.6 $
*** $Date: 2003/06/08 00:08:28 $
***
*** Comments:
*** This file contains the USB device API.
***
**************************************************************************
*END*********************************************************************/
#include "os_bb.h"
#include "osint.h"
#include "../host.h"
/*FUNCTION*----------------------------------------------------------------
*
* Function Name : _usb_device_send_data
* Returned Value : USB_OK or error code
* Comments :
* The Send Data routine is non-blocking routine that causes a block of data up
* to 64k bytes long to be made available for transmission to the USB host. The
* inputs to send data are bEP a byte endpoint number in the range 0-15
* Send_Data returns a status byte indicating whether the transfer
* will be initiated.
*
*END*--------------------------------------------------------------------*/
uint_8 _usb_device_send_data
(
/* [IN] handle to USB device */
_usb_device_handle handle,
/* [IN] Endpoint to send data to */
uint_8 endpoint_number,
/* [IN] Pointer to data to send */
uchar_ptr buff_ptr,
/* [IN] Length of data to send */
uint_32 size
)
{
XD_STRUCT_PTR pxd;
USB_DEV_STATE_STRUCT_PTR usb_dev_ptr;
usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle;
USB_lock();
pxd = &usb_dev_ptr->XDSEND[endpoint_number];
/*
** Check if the endpoint is disabled
*/
if (pxd->STATUS == USB_STATUS_DISABLED) {
USB_unlock();
return USBERR_ENDPOINT_DISABLED;
}
/*
** Check if any transfer is in progress on this endpoint
*/
if (pxd->STATUS == USB_STATUS_TRANSFER_IN_PROGRESS) {
USB_unlock();
return USBERR_TRANSFER_IN_PROGRESS;
}
if (pxd->TYPE == USB_ISOCHRONOUS_ENDPOINT) {
/* if Isochronous */
if (size > pxd->MAXPACKET) {
/*
** if asked for more than maxPacket
** limit request to maxPacket
*/
size = pxd->MAXPACKET;
}
}
/* The endpoint is enabled and no transfers are pending so queue the
** transmit transfer.
*/
pxd->STARTADDRESS = buff_ptr;
pxd->NEXTADDRESS = buff_ptr;
pxd->TODO = size;
pxd->SOFAR = 0;
pxd->UNACKNOWLEDGEDBYTES = size;
pxd->DIRECTION = USB_SEND;
#if BBPLAYER
/*
* Writeback the cache, since hw is not io coherent
*/
osWritebackDCache(buff_ptr, size);
//PRINTF("dev_send_data: ep %d, buf 0x%x, size %d\n", endpoint_number, buff_ptr, size);
#endif
/* return successful transfer initiation status. */
pxd->STATUS = USB_STATUS_TRANSFER_PENDING;
_usb_dci_vusb11_submit_transfer(handle, USB_SEND, endpoint_number);
/*
** If the endpoint is currently stalled notify the user after the
** transfer has been queued. By queuing the transfer the
** operation to revert the stall condition may be separated from
** the the data transfer code.
*/
if (pxd->STATUS == USB_STATUS_STALLED) {
USB_unlock();
return USBERR_ENDPOINT_STALLED;
}
USB_unlock();
return USB_OK;
}