host_rcv.c
3.16 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
/*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
***
*** File: hostapi.c
***
*** Comments:
*** This file contains the USB Host API specific functions.
***
**************************************************************************
*END*********************************************************************/
#include "os_bb.h"
#include "osint.h"
/*FUNCTION*-------------------------------------------------------------
*
* Function Name : _usb_host_recv_data
* Returned Value : error or status of the transfer
* Comments :
* The Receive Data routine is non-blocking routine that causes a buffer
* to be made available for data recieved from the
* USB host.
*END*-----------------------------------------------------------------*/
uint_8 _usb_host_recv_data
(
/* [IN] the USB Host state structure */
_usb_host_handle handle,
/* Index into the Pipe Descriptor Array */
int_16 pipeid,
/* Address for the data */
uchar_ptr buff_ptr,
/* Number of bytes to Receive */
uint_32 length
)
{ /* Body */
PIPE_DESCRIPTOR_STRUCT_PTR pipe_descr_ptr;
USB_HOST_STATE_STRUCT_PTR usb_host_ptr;
usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)handle;
/* Check if this is a valid pipe id */
if (pipeid < usb_host_ptr->MAX_PIPES) {
pipe_descr_ptr = &usb_host_ptr->PIPE_DESCRIPTOR_BASE_PTR[pipeid];
} else {
return USBERR_INVALID_PIPE_ID;
} /* Endif */
USB_lock();
/* Check if a previously queued packet is still pending */
if (pipe_descr_ptr->STATUS != USB_STATUS_IDLE) {
USB_unlock();
return USB_STATUS_TRANSFER_IN_PROGRESS;
} else {
USB_unlock();
/* Initialize the pipe desciptor with the new receive transfer request
** for this pipe
*/
pipe_descr_ptr->SOFAR = 0;
pipe_descr_ptr->RX_PTR = buff_ptr;
if ((pipe_descr_ptr->PIPETYPE == USB_ISOCHRONOUS_PIPE) &&
(pipe_descr_ptr->TODO1 > pipe_descr_ptr->MAX_PKT_SIZE))
{
/* For isochronous pipe, we are accepting a maximum of MAX_PKT_SIZE
** transfer
*/
pipe_descr_ptr->TODO1 = pipe_descr_ptr->MAX_PKT_SIZE;
} else {
pipe_descr_ptr->TODO1 = length;
} /* Endif */
USB_lock();
/* successful transfer initiation status. */
pipe_descr_ptr->STATUS = USB_STATUS_TRANSFER_QUEUED;
_usb_hci_vusb11_recv_data(handle, pipe_descr_ptr);
pipe_descr_ptr->PACKETPENDING = TRUE;
USB_unlock();
} /* Endif */
return USB_STATUS_TRANSFER_QUEUED;
} /* Endbody */