1
/* Cypress West Bridge API header file (cyasmtp.h)
2
## ===========================
3
## Copyright (C) 2010 Cypress Semiconductor
5
## This program is free software; you can redistribute it and/or
6
## modify it under the terms of the GNU General Public License
7
## as published by the Free Software Foundation; either version 2
8
## of the License, or (at your option) any later version.
10
## This program is distributed in the hope that it will be useful,
11
## but WITHOUT ANY WARRANTY; without even the implied warranty of
12
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
## GNU General Public License for more details.
15
## You should have received a copy of the GNU General Public License
16
## along with this program; if not, write to the Free Software
17
## Foundation, Inc., 51 Franklin Street
18
## Fifth Floor, Boston, MA 02110-1301, USA.
19
## ===========================
22
#ifndef _INCLUDED_CYASMTP_H_
23
#define _INCLUDED_CYASMTP_H_
27
#include "cyas_cplus_start.h"
29
/*@@Media Transfer Protocol (MTP) Overview
31
The MTP API has been designed to allow MTP enabled West Bridge
32
devices to implement the MTP protocol while maintaining high
33
performance. West Bridge has the capability to enter into a
34
Turbo mode during a MTP SendObject or GetObject operation
35
enabling it to directly stream the data into or out of the
36
attached SD card with minimal involvement from the Processor.
39
The MTP API is designed to act as a pass through implementation
40
of the MTP protocol for all operations. Each MTP transaction
41
received from the Host is passed through West Bridge and along
42
to the Processor. The Processor can then respond to the
43
transaction and pass data and/or responses back to the Host
46
The MTP API also allows for a high speed handling of MTP
47
SendObject and GetObject operations, referred to as Turbo MTP.
48
During a Turbo MTP operation West Bridge is responsible for
49
reading or writing the data for the MTP operation directly from
50
or to the SD card with minimal interaction from the Processor.
51
The is done by having the Processor transfer a Block Table
52
to West Bridge which contains the locations on the SD card that
53
need to be read or written. During the handling of a Turbo
54
Operation the Processor will then only periodically need to
55
send a new Block Table to West Bridge when the first is used up.
56
See the CyAsMTPInitSendObject and CyAsMTPInitGetObject functions
59
In order to enable the MTP API you must first have a MTP enabled
60
West Bridge loaded with MTP firmware. You then must start the USB
61
and Storage APIs before starting the MTP API. See CyAsMTPStart
67
When using MTP firmware endpoints 2 and 6 are dedicated
68
to bulk MTP traffic and endpoint 1 is available for MTP
72
When using a MTP enabled West Brdige device endpoints 2 and
73
6 are made available for use to implement the MTP protocol.
74
These endpoints have a few special restrictions noted below
75
but otherwise the existing USB APIs can be used normally with
78
1. CyAsUsbSetNak, CyAsUsbClearNak, and CyAsUsbGetNak are
79
disabled for these endpoints
80
2. During a turbo operation CyAsUsbSetStall, CyAsUsbClearStall,
81
and CyAsUsbGetStall are disabled.
87
This constants defines the maximum number of
88
entries in the Block Table used to describe
89
the locations for Send/GetObject operations.
95
#define CY_AS_MAX_BLOCK_TABLE_ENTRIES 64
98
Endpoint to be used for MTP reads from the USB host.
100
#define CY_AS_MTP_READ_ENDPOINT (2)
103
Endpoint to be used fro MTP writes to the USB host.
105
#define CY_AS_MTP_WRITE_ENDPOINT (6)
107
/******************************************
109
******************************************/
112
The BlockTable used for turbo operations.
115
This struct is used to specify the blocks
116
to be used for both read/write and send/getObject
119
The start block is a starting Logical Block Address
120
and num block is the number of blocks in that contiguous
123
start_blocks[i]->[-------] <- start_blocks[i] + num_blocks[i]
125
If you need fewer than CY_AS_MAX_BLOCK_TABLE_ENTRIES
126
the remainder should be left empty. Empty is defined
127
as num_blocks equal to 0.
130
* CyAsMTPInitSendObject
131
* CyAsMTPInitGetObject
134
typedef struct cy_as_mtp_block_table {
135
uint32_t start_blocks[CY_AS_MAX_BLOCK_TABLE_ENTRIES];
136
uint16_t num_blocks[CY_AS_MAX_BLOCK_TABLE_ENTRIES];
137
} cy_as_mtp_block_table;
140
This type specifies the type of MTP event that has occurred.
143
MTP events are used to communicate that West Bridge has
144
either finished the handling of the given operation, or
145
that it requires additional data to complete the operation.
147
In no case does West Bridge send any MTP protocol responses,
148
this always remain the responsibility of the client.
151
* CyAsMTPInitSendObject
152
* CyAsMTPInitGetObject
153
* CyAsMTPSendBlockTable
156
typedef enum cy_as_mtp_event {
157
/* This event is sent when West Bridge
158
has finished writing the data from a
159
send_object. west bridge will -not- send
161
cy_as_mtp_send_object_complete,
163
/* This event is sent when West Bridge
164
has finished sending the data for a
165
get_object operation. west bridge will
166
-not- send the MTP response. */
167
cy_as_mtp_get_object_complete,
169
/* This event is called when West Bridge
170
needs a new block_table. this is only a
171
notification, to transfer a block_table
172
to west bridge the cy_as_mtp_send_block_table
173
use the function. while west bridge is waiting
174
for a block_table during a send_object it
175
may need to NAK the endpoint. it is important
176
that the cy_as_mtp_send_block_table call is made
177
in a timely manner as eventually a delay
178
will result in an USB reset. this event has
180
cy_as_mtp_block_table_needed
184
Data for the CyAsMTPSendObjectComplete event.
187
Notification that a SendObject operation has been
188
completed. The status of the operation is given
189
(to distinguish between a cancelled and a success
190
for example) as well as the block count. The blocks
191
are used in order based on the current block table.
192
If more than one block table was used for a given
193
SendObject the count will include the total number
196
This callback will be made only once per SendObject
197
operation and it will only be called after all of
198
the data has been committed to the SD card.
204
typedef struct cy_as_mtp_send_object_complete_data {
205
cy_as_return_status_t status;
207
uint32_t transaction_id;
208
} cy_as_mtp_send_object_complete_data;
211
Data for the CyAsMTPGetObjectComplete event.
214
Notification that a GetObject has finished. This
215
event allows the P side to know when to send the MTP
216
response for the GetObject operation.
222
typedef struct cy_as_mtp_get_object_complete_data {
223
cy_as_return_status_t status;
225
} cy_as_mtp_get_object_complete_data;
231
Callback used to communicate that a SendObject
232
operation has finished.
237
typedef void (*cy_as_mtp_event_callback)(
238
cy_as_device_handle handle,
239
cy_as_mtp_event evtype,
244
This is the callback function called after asynchronous API
245
functions have completed.
248
When calling API functions from callback routines (interrupt
249
handlers usually) the async version of these functions must
250
be used. This callback is called when an asynchronous API
251
function has completed.
253
typedef void (*cy_as_mtp_function_callback)(
254
/* Handle to the device to configure */
255
cy_as_device_handle handle,
256
/* The error status of the operation */
257
cy_as_return_status_t status,
258
/* A client supplied 32 bit tag */
262
/**************************************
264
**************************************/
267
This function starts the MTP stack.
270
Initializes West Bridge for MTP activity and registers the MTP
273
Before calling CyAsMTPStart, CyAsUsbStart and CyAsStorageStart must be
274
called (in either order).
276
MTPStart must be called before the device is enumerated. Please
277
see the documentation for CyAsUsbSetEnumConfig and CyAsUsbEnumControl
278
for details on enumerating a device for MTP.
280
Calling MTPStart will not affect any ongoing P<->S traffic.
282
This requires a MTP firmware image to be loaded on West Bridge.
285
* CY_AS_ERROR_SUCCESS
286
* CY_AS_ERROR_INVALID_HANDLE
287
* CY_AS_ERROR_NOT_CONFIGURED
288
* CY_AS_ERROR_NO_FIRMWARE
289
* CY_AS_ERROR_IN_SUSPEND
290
* CY_AS_ERROR_INVALID_IN_CALLBACK
291
* CY_AS_ERROR_STARTSTOP_PENDING
292
* CY_AS_ERROR_NOT_RUNNING - CyAsUsbStart or CyAsStorageStart
293
* have not been called
294
* CY_AS_ERROR_NOT_SUPPORTED - West Bridge is not running
295
* firmware with MTP support
296
* CY_AS_ERROR_OUT_OF_MEMORY
297
* CY_AS_ERROR_INVALID_RESPONSE
304
* CyAsUsbSetEnumConfig
307
cy_as_return_status_t
309
cy_as_device_handle handle,
310
cy_as_mtp_event_callback event_c_b,
311
cy_as_function_callback cb,
317
This function stops the MTP stack.
320
Stops all MTP activity. Any ongoing transfers are
323
This will not cause a UsbDisconnect but all
324
MTP activity (both pass through and turbo) will
328
* CY_AS_ERROR_SUCCESS
329
* CY_AS_ERROR_INVALID_HANDLE
330
* CY_AS_ERROR_NOT_CONFIGURED
331
* CY_AS_ERROR_NO_FIRMWARE
332
* CY_AS_ERROR_NOT_RUNNING
333
* CY_AS_ERROR_IN_SUSPEND
334
* CY_AS_ERROR_INVALID_IN_CALLBACK
335
* CY_AS_ERROR_STARTSTOP_PENDING
336
* CY_AS_ERROR_OUT_OF_MEMORY
337
* CY_AS_ERROR_INVALID_RESPONSE
343
cy_as_return_status_t
345
cy_as_device_handle handle,
346
cy_as_function_callback cb,
351
This function sets up a Turbo SendObject operation.
354
Calling this function will setup West Bridge to
355
enable Tubo handling of the next SendObject
356
operation received. This will pass down the initial
357
block table to the firmware and setup a direct u->s
358
write for the SendObject operation.
360
If this function is not called before a SendObject
361
operation is seen the SendObject operation and data
362
will be passed along to the P port like any other MTP
363
command. It would then be the responsibility of the
364
client to perform a normal StorageWrite call to
365
store the data on the SD card. N.B. This will be
366
very slow compared with the Turbo handling.
368
The completion of this function only signals that
369
West Bridge has been set up to receive the next SendObject
370
operation. When the SendObject operation has been fully
371
handled and the data written to the SD card a separate
372
event will be triggered.
375
* CY_AS_ERROR_SUCCESS
376
* CY_AS_ERROR_INVALID_HANDLE
377
* CY_AS_ERROR_NOT_CONFIGURED
378
* CY_AS_ERROR_NO_FIRMWARE
379
* CY_AS_ERROR_IN_SUSPEND
380
* CY_AS_ERROR_NOT_RUNNING
381
* CY_AS_ERROR_OUT_OF_MEMORY
382
* CY_AS_ERROR_ASYNC_PENDING
383
* CY_AS_ERROR_INVALID_RESPONSE
384
* CY_AS_ERROR_NOT_SUPPORTED - West Bridge is not running
385
* firmware with MTP support
388
* CyAsMTPCancelSendObject
389
* CyAsMTPInitGetObject
391
* CyAsMTPSendBlockTable
393
cy_as_return_status_t
394
cy_as_mtp_init_send_object(
395
cy_as_device_handle handle,
396
cy_as_mtp_block_table *blk_table,
398
cy_as_function_callback cb,
403
This function cancels an ongoing MTP operation.
406
Causes West Bridge to cancel an ongoing SendObject
407
operation. Note this is only a cancel to West Bridge,
408
the MTP operation still needs to be canceled by
411
West Bridge will automatically set a Stall on the endpoint
412
when the cancel is received.
414
This function is only valid after CyAsMTPInitSendObject
415
has been called, but before the CyAsMTPSendObjectComplete
419
* CY_AS_ERROR_SUCCESS
420
* CY_AS_ERROR_INVALID_HANDLE
421
* CY_AS_ERROR_NOT_RUNNING
422
* CY_AS_ERROR_OUT_OF_MEMORY
423
* CY_AS_ERROR_INVALID_RESPONSE
424
* CY_AS_ERROR_NOT_SUPPORTED - West Bridge is not running
425
* firmware with MTP support
426
* CY_AS_ERROR_NO_OPERATION_PENDING
429
* CyAsMTPInitSendObject
431
cy_as_return_status_t
432
cy_as_mtp_cancel_send_object(
433
cy_as_device_handle handle,
434
cy_as_function_callback cb,
439
This function sets up a turbo GetObject operation.
442
Called by the P in response to a GetObject
443
operation. This provides West Bridge with the block
444
addresses for the Object data that needs to be
447
It is the responsibility of the Processor to send the MTP
448
operation before calling CyAsMTPInitGetObject. West Bridge
449
will then send the data phase of the transaction,
450
automatically creating the required container for Data.
451
Once all of the Data has been transferred a callback will
452
be issued to inform the Processor that the Data phase has
453
completed allowing it to send the required MTP response.
455
If an entire Block Table is used then after the
456
last block is transferred the CyAsMTPBtCallback
457
will be called to allow an additional Block Table(s)
461
* CY_AS_ERROR_SUCCESS
462
* CY_AS_ERROR_INVALID_HANDLE
463
* CY_AS_ERROR_NOT_CONFIGURED
464
* CY_AS_ERROR_NO_FIRMWARE
465
* CY_AS_ERROR_NOT_RUNNING
466
* CY_AS_ERROR_IN_SUSPEND
467
* CY_AS_ERROR_OUT_OF_MEMORY
468
* CY_AS_ERROR_ASYNC_PENDING
469
* CY_AS_ERROR_INVALID_RESPONSE
470
* CY_AS_ERROR_NOT_SUPPORTED - West Bridge is not running
471
* firmware with MTP support
474
* CyAsMTPInitSendObject
475
* CyAsMTPCancelGetObject
477
* CyAsMTPSendBlockTable
479
cy_as_return_status_t
480
cy_as_mtp_init_get_object(
481
cy_as_device_handle handle,
482
cy_as_mtp_block_table *table_p,
484
uint32_t transaction_id,
485
cy_as_function_callback cb,
490
This function cancels an ongoing turbo GetObject
494
Causes West Bridge to cancel an ongoing GetObject
495
operation. Note this is only a cancel to West Bridge,
496
the MTP operation still needs to be canceled by
499
This function is only valid after CyAsMTPGetSendObject
500
has been called, but before the CyAsMTPGetObjectComplete
504
* CY_AS_ERROR_SUCCESS
505
* CY_AS_ERROR_INVALID_HANDLE
506
* CY_AS_ERROR_NOT_RUNNING
507
* CY_AS_ERROR_OUT_OF_MEMORY
508
* CY_AS_ERROR_INVALID_RESPONSE
509
* CY_AS_ERROR_NOT_SUPPORTED - West Bridge is not running
510
* firmware with MTP support
511
* CY_AS_ERROR_NO_OPERATION_PENDING
514
* CyAsMTPInitGetObject
516
cy_as_return_status_t
517
cy_as_mtp_cancel_get_object(
518
cy_as_device_handle handle,
519
cy_as_function_callback cb,
524
This function is used to transfer a BlockTable as part of
525
an ongoing MTP operation.
528
This function is called in response to the
529
CyAsMTPBlockTableNeeded event. This allows the client to
530
pass in a BlockTable structure to West Bridge.
532
The memory associated with the table will be copied and
533
can be safely disposed of when the function returns if
534
called synchronously, or when the callback is made if
535
called asynchronously.
537
This function is used for both SendObject and GetObject
538
as both can generate the CyAsMTPBlockTableNeeded event.
541
* CY_AS_ERROR_SUCCESS
542
* CY_AS_ERROR_INVALID_HANDLE
543
* CY_AS_ERROR_NOT_CONFIGURED
544
* CY_AS_ERROR_NO_FIRMWARE
545
* CY_AS_ERROR_NOT_RUNNING
546
* CY_AS_ERROR_IN_SUSPEND
547
* CY_AS_ERROR_OUT_OF_MEMORY
548
* CY_AS_ERROR_ASYNC_PENDING
549
* CY_AS_ERROR_INVALID_RESPONSE
550
* CY_AS_ERROR_NOT_SUPPORTED - West Bridge is not running
551
* firmware with MTP support
554
* CyAsMTPInitSendObject
555
* CyAsMTPInitGetObject
557
cy_as_return_status_t
558
cy_as_mtp_send_block_table(
559
cy_as_device_handle handle,
560
cy_as_mtp_block_table *table,
561
cy_as_function_callback cb,
566
This function is used to mark the start of a storage
567
read/write burst from the P port processor.
570
This function is used to mark the start of a storage
571
read/write burst from the processor. All USB host access
572
into the mass storage / MTP endpoints will be blocked
573
while the read/write burst is ongoing, and will be allowed
574
to resume only after CyAsMTPStorageOnlyStop is called.
575
The burst mode is used to reduce the firmware overhead
576
due to configuring the internal data paths repeatedly,
577
and can help improve performance when a sequence of
578
read/writes is performed in a burst.
580
This function will not generate a special mailbox request,
581
it will only set a flag on the next Storage Read/Write
582
operation. Until such a call is made West Bridge will
583
continue to accept incoming packets from the Host.
585
* Valid in Asynchronous Callback: YES
588
* CY_AS_ERROR_INVALID_HANDLE - Invalid West Bridge device
589
* handle was passed in.
590
* CY_AS_ERROR_NOT_CONFIGURED - West Bridge device has not
592
* CY_AS_ERROR_NO_FIRMWARE - Firmware is not active on West
594
* CY_AS_ERROR_NOT_RUNNING - Storage stack is not running.
595
* CY_AS_ERROR_SUCCESS - Burst mode has been started.
598
* CyAsStorageReadWriteBurstStop
600
cy_as_return_status_t
601
cy_as_mtp_storage_only_start(
602
/* Handle to the West Bridge device. */
603
cy_as_device_handle handle
607
This function is used to mark the end of a storage read/write
608
burst from the P port processor.
611
This function is used to mark the end of a storage read/write
612
burst from the processor. At this point, USB access to the
613
mass storage / MTP endpoints on the West Bridge device will be
616
* Valid in Asynchronous Callback: NO
619
* CY_AS_ERROR_INVALID_HANDLE - Invalid West Bridge device handle
621
* CY_AS_ERROR_NOT_CONFIGURED - West Bridge device has not been
623
* CY_AS_ERROR_NO_FIRMWARE - Firmware is not active on West Bridge
625
* CY_AS_ERROR_NOT_RUNNING - Storage stack is not running.
626
* CY_AS_ERROR_INVALID_IN_CALLBACK - This API cannot be called
628
* CY_AS_ERROR_OUT_OF_MEMORY - Failed to allocate memory to
629
* process the request.
630
* CY_AS_ERROR_TIMEOUT - Failed to send request to firmware.
631
* CY_AS_ERROR_SUCCESS - Burst mode has been stopped.
634
* CyAsStorageReadWriteBurstStart
636
cy_as_return_status_t
637
cy_as_mtp_storage_only_stop(
638
/* Handle to the West Bridge device. */
639
cy_as_device_handle handle,
640
cy_as_function_callback cb,
644
#include "cyas_cplus_end.h"