PDL for FM4
Version1.2
Peripheral Driverl Library for FM4
Main Page
Modules
Data Structures
Files
File List
Globals
UsbDeviceLibUsb.c
Go to the documentation of this file.
1
/*******************************************************************************
2
* Copyright (C) 2013 Spansion LLC. All Rights Reserved.
3
*
4
* This software is owned and published by:
5
* Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
6
*
7
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9
*
10
* This software contains source code for use with Spansion
11
* components. This software is licensed by Spansion to be adapted only
12
* for use in systems utilizing Spansion components. Spansion shall not be
13
* responsible for misuse or illegal use of this software for devices not
14
* supported herein. Spansion is providing this software "AS IS" and will
15
* not be responsible for issues arising from incorrect user implementation
16
* of the software.
17
*
18
* SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
19
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
20
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
21
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
22
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
23
* WARRANTY OF NONINFRINGEMENT.
24
* SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
25
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
26
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
27
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
28
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
29
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
30
* SAVINGS OR PROFITS,
31
* EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
33
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
34
* FROM, THE SOFTWARE.
35
*
36
* This software may be replicated in part or whole for the licensed use,
37
* with the restriction that this Disclaimer and Copyright notice must be
38
* included with each copy of this software, whether used in part or whole,
39
* at all times.
40
*/
41
/******************************************************************************/
54
/*****************************************************************************/
55
/* Include files */
56
/*****************************************************************************/
57
#include "
UsbDeviceLibUsb.h
"
58
59
#if ((FM_PERIPHERAL_USB_DEVICE_ENABLED == ON) && (USBDEVICELIBUSB_ENABLED == ON))
60
61
/*****************************************************************************/
62
/* Local pre-processor symbols/macros ('#define') */
63
/*****************************************************************************/
64
65
66
67
/*****************************************************************************/
68
/* Global variable definitions (declared in header file with 'extern') */
69
/*****************************************************************************/
70
71
/*****************************************************************************/
72
/* Local type definitions ('typedef') */
73
/*****************************************************************************/
74
75
76
77
/*****************************************************************************/
78
/* Local variable definitions ('static') */
79
/*****************************************************************************/
80
81
static
uint8_t
DataReceivedFlags
= 0;
//Status for received data
82
static
uint8_t
DataSentFlags
= 0;
//Status for sent data
83
84
85
static
uint32_t
u32LastReceivedSize1
;
// last received size EP1
86
static
stc_usbn_endpoint_buffer_t
stcEpBuffer1
;
//struct for custom buffer EP1
87
static
uint8_t
pu8BufferEp1
[
BUFFER_SIZE_ENDPOINT1
];
// custom buffer EP1
88
static
stc_usbn_endpoint_data_t
*
pstcEpOUT1
;
89
90
static
stc_usbn_endpoint_data_t
*
pstcEpIN2
;
91
stc_usbn_endpoint_buffer_t
stcEpBuffer2
;
//struct for custom buffer EP2v
92
93
94
/*****************************************************************************/
95
/* Local function prototypes ('static') */
96
/*****************************************************************************/
97
98
99
100
static
void
UsbDeviceLibUsb_RxCallbackEp1
(stc_usbn_t* pstcUsb,
struct
stc_usbn_endpoint_data
* pstcEndpoint);
101
102
static
void
UsbDeviceLibUsb_TxCallbackEp2
(stc_usbn_t* pstcUsb,
struct
stc_usbn_endpoint_data
* pstcEndpoint);
103
104
105
/*****************************************************************************/
106
/* Function implementation - global ('extern') and local ('static') */
107
/*****************************************************************************/
108
116
void
UsbDeviceLibUsb_Init
(stc_usbn_t* pstcUsb)
117
{
118
stc_usbdevice_class_config_t
stcUsbClassConfig;
119
stc_usbdevice_endpoint_config_t
stcEndpointConfig;
120
uint8_t* pu8Interface = NULL;
121
uint8_t u8InterfaceLength = 0;
122
123
stcUsbClassConfig.
u8InterfaceNumber
= 0;
124
stcUsbClassConfig.
u8InterfaceClass
= 0xFF;
125
stcUsbClassConfig.
u8InterfaceSubClass
= 0x00;
126
stcUsbClassConfig.
u8InterfaceProtocoll
= 0x00;
127
stcUsbClassConfig.
pfnSetupRequestCallback
=
ClassSetupRequest0
;
128
stcUsbClassConfig.
pfnConnectionCallback
= NULL;
129
stcUsbClassConfig.
pfnDisconnectionCallback
= NULL;
130
stcUsbClassConfig.
pfnConfCallback
= NULL;
131
UsbDevice_RegisterVendorClass
(pstcUsb,&stcUsbClassConfig,&pu8Interface,&u8InterfaceLength);
132
133
stcEndpointConfig.
u8EndpointAddress
= 1;
134
stcEndpointConfig.
pfnRxTxCallback
=
UsbDeviceLibUsb_RxCallbackEp1
;
135
stcEndpointConfig.
pstcEndpointBuffer
= &
stcEpBuffer1
;
136
pstcEpOUT1 =
UsbDevice_SetupEndpoint
(pstcUsb, &stcEndpointConfig);
137
UsbDevice_ReceiveData
(pstcUsb, pstcEpOUT1,
pu8BufferEp1
,
BUFFER_SIZE_ENDPOINT1
,
UsbIRQ
);
138
139
stcEndpointConfig.
u8EndpointAddress
= 0x80 | 2;
140
stcEndpointConfig.
pfnRxTxCallback
=
UsbDeviceLibUsb_TxCallbackEp2
;
141
stcEndpointConfig.
pstcEndpointBuffer
= &
stcEpBuffer2
;
142
pstcEpIN2 =
UsbDevice_SetupEndpoint
(pstcUsb, &stcEndpointConfig);
143
144
}
145
155
static
void
ClassSetupRequest0
(stc_usbn_t* pstcUsb,
stc_usb_request_t
* pstcSetup)
156
{
157
158
}
159
168
static
void
UsbDeviceLibUsb_RxCallbackEp1
(stc_usbn_t* pstcUsb,
struct
stc_usbn_endpoint_data
* pstcEndpoint)
169
{
170
u32LastReceivedSize1
= pstcEndpoint->
pstcEndpointBuffer
->
u32DataSize
;;
171
DataReceivedFlags
|= (1<<1);
// setting data received flag
172
173
//Add your code here to process the received buffer
174
UsbDevice_ReceiveData
(pstcUsb, pstcEpOUT1,
pu8BufferEp1
,
BUFFER_SIZE_ENDPOINT1
,
UsbIRQ
);
175
}
176
177
184
uint32_t
UsbDeviceLibUsb_GetReceivedDataEndpoint1
(uint8_t** ppu8Buffer)
185
{
186
if
((
DataReceivedFlags
& (1<<1)) == 0)
187
{
188
return
0;
// nothing to receive
189
}
190
DataReceivedFlags
-= (1<<1);
191
*ppu8Buffer = pstcEpOUT1->
pstcEndpointBuffer
->
pu8Buffer
;
192
return
u32LastReceivedSize1
;
193
}
194
195
207
boolean_t
UsbDeviceLibUsb_SendDataVia2
(stc_usbn_t* pstcUsb, uint8_t* pu8Buffer, uint32_t u32DataSize,
en_usbsend_mode_t
enMode)
208
{
209
if
(
UsbDevice_GetStatus
(pstcUsb) ==
UsbConfigured
)
210
{
211
DataSentFlags
&= ~(1<<2);
212
213
UsbDevice_SendData
(pstcUsb, pstcEpIN2, pu8Buffer, u32DataSize, enMode);
214
if
(enMode ==
UsbPOLL
)
215
{
216
DataSentFlags
|= (1<<2);
217
}
218
return
1;
219
}
220
return
0;
221
}
222
230
static
void
UsbDeviceLibUsb_TxCallbackEp2
(stc_usbn_t* pstcUsb,
struct
stc_usbn_endpoint_data
* pstcEndpoint)
231
{
232
DataSentFlags
|= (1<<2);
233
}
239
uint8_t
UsbDeviceLibUsb_DataSent2
(
void
)
240
{
241
if
((
DataSentFlags
& (1<<2)) > 0)
242
{
243
return
1;
244
}
245
else
246
{
247
return
0;
248
}
249
}
250
#endif
PDL_1_2
library
midware
usb
device
UsbDeviceLibUsb.c
Generated on Wed May 28 2014 09:28:11 for PDL for FM4 by
1.8.3.1