1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#ifndef __INCLUDED_CYASDEVICE_H__
23#define __INCLUDED_CYASDEVICE_H__
24
25#include "cyashal.h"
26#include "cyasprotocol.h"
27#include "cyasusb.h"
28#include "cyasstorage.h"
29#include "cyasmtp.h"
30#include "cyas_cplus_start.h"
31
32
33
34
35
36
37#define CY_AS_P2S_WRITE_ENDPOINT (0x04)
38#define CY_AS_P2S_READ_ENDPOINT (0x08)
39
40
41#define CY_AS_FIRMWARE_ENDPOINT (0x02)
42
43
44#define CY_AS_MAXIMUM_FIRMWARE_SIZE (24 * 1024)
45
46
47#define CY_AS_EP0_MAX_WRITE_SIZE (128)
48#define CY_AS_EP1_MAX_WRITE_SIZE (64)
49
50
51
52
53#define CY_AS_DEVICE_STATE_PIN_STANDBY (0x00000001)
54
55#define CY_AS_DEVICE_STATE_CONFIGURED (0x00000002)
56
57#define CY_AS_DEVICE_STATE_FIRMWARE_LOADED (0x00000004)
58
59#define CY_AS_DEVICE_STATE_LOWLEVEL_MODULE (0x00000008)
60
61#define CY_AS_DEVICE_STATE_DMA_MODULE (0x00000010)
62
63#define CY_AS_DEVICE_STATE_INTR_MODULE (0x00000020)
64
65#define CY_AS_DEVICE_STATE_STORAGE_MODULE (0x00000040)
66
67#define CY_AS_DEVICE_STATE_USB_MODULE (0x00000080)
68
69#define CY_AS_DEVICE_STATE_STORAGE_SCSIMSG (0x00000100)
70
71#define CY_AS_DEVICE_STATE_STORAGE_ASYNC_PENDING (0x00000200)
72
73#define CY_AS_DEVICE_STATE_USB_CONNECTED (0x00000400)
74
75#define CY_AS_DEVICE_STATE_USB_HIGHSPEED (0x00000800)
76
77#define CY_AS_DEVICE_STATE_IN_CALLBACK (0x00001000)
78
79#define CY_AS_DEVICE_STATE_IN_SETUP_PACKET (0x00004000)
80
81#define CY_AS_DEVICE_STATE_REGISTER_STANDBY (0x00008000)
82
83#define CY_AS_DEVICE_STATE_CRYSTAL (0x00010000)
84
85#define CY_AS_DEVICE_STATE_WAKING (0x00020000)
86
87#define CY_AS_DEVICE_STATE_EP0_STALLED (0x00040000)
88
89#define CY_AS_DEVICE_STATE_SUSPEND (0x00080000)
90
91#define CY_AS_DEVICE_STATE_RESETP (0x00100000)
92
93#define CY_AS_DEVICE_STATE_STANDP (0x00200000)
94
95#define CY_AS_DEVICE_STATE_SSSP (0x00400000)
96
97#define CY_AS_DEVICE_STATE_USSP (0x00800000)
98
99#define CY_AS_DEVICE_STATE_MSSP (0x01000000)
100
101#define CY_AS_DEVICE_STATE_P2SDMA_START (0x02000000)
102
103
104
105#define CY_AS_DMA_ENDPOINT_STATE_ENABLED (0x0001)
106
107#define CY_AS_DMA_ENDPOINT_STATE_SLEEPING (0x0002)
108
109#define CY_AS_DMA_ENDPOINT_STATE_DMA_RUNNING (0x0004)
110
111#define CY_AS_DMA_ENDPOINT_STATE_IN_TRANSIT (0x0008)
112
113#define CY_AS_DMA_ENDPOINT_STATE_DIRECTION (0x0010)
114
115
116
117#define CY_AS_REQUEST_LIST_STATE_MASK (0x0f)
118
119#define CY_AS_REQUEST_LIST_STATE_QUEUED (0x00)
120
121#define CY_AS_REQUEST_LIST_STATE_WAITING (0x01)
122
123#define CY_AS_REQUEST_LIST_STATE_RECEIVED (0x02)
124
125#define CY_AS_REQUEST_LIST_STATE_CANCELING (0x03)
126
127#define CY_AS_REQUEST_LIST_STATE_SYNC (0x80)
128
129
130
131#define CY_AS_REQUEST_RESPONSE_DELAY_ACK (0x01)
132
133#define CY_AS_REQUEST_RESPONSE_EX (0x02)
134
135#define CY_AS_REQUEST_RESPONSE_MS (0x04)
136
137
138#define CY_AS_DEVICE_HANDLE_SIGNATURE (0x01211219)
139
140
141
142
143
144#define CY_AS_NUM_EP(dev_p, num) ((dev_p)->endp[(num)])
145
146
147
148
149
150typedef struct cy_as_device cy_as_device;
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165typedef void (*cy_as_dma_callback)(
166
167 cy_as_device *dev_p,
168
169 cy_as_end_point_number_t ep,
170
171 void *mem_p,
172
173 uint32_t size,
174
175 cy_as_return_status_t error
176 );
177
178
179
180
181
182
183
184
185typedef struct cy_as_dma_queue_entry {
186
187 void *buf_p;
188
189 uint32_t size;
190
191 uint32_t offset;
192
193 cy_bool packet;
194
195 cy_bool readreq;
196
197 cy_as_dma_callback cb;
198
199 struct cy_as_dma_queue_entry *next_p;
200} cy_as_dma_queue_entry;
201
202
203
204
205
206
207
208
209typedef struct cy_as_dma_end_point {
210
211 cy_as_end_point_number_t ep;
212
213 uint8_t state;
214
215 uint16_t maxhwdata;
216
217 uint32_t maxhaldata;
218
219 cy_as_dma_queue_entry *queue_p;
220
221 cy_as_dma_queue_entry *last_p;
222
223
224 cy_as_hal_sleep_channel channel;
225} cy_as_dma_end_point;
226
227#define cy_as_end_point_number_is_usb(n) \
228 ((n) != 2 && (n) != 4 && (n) != 6 && (n) != 8)
229#define cy_as_end_point_number_is_storage(n) \
230 ((n) == 2 || (n) == 4 || (n) == 6 || (n) == 8)
231
232#define cy_as_dma_end_point_is_enabled(ep) \
233 ((ep)->state & CY_AS_DMA_ENDPOINT_STATE_ENABLED)
234#define cy_as_dma_end_point_enable(ep) \
235 ((ep)->state |= CY_AS_DMA_ENDPOINT_STATE_ENABLED)
236#define cy_as_dma_end_point_disable(ep) \
237 ((ep)->state &= ~CY_AS_DMA_ENDPOINT_STATE_ENABLED)
238
239#define cy_as_dma_end_point_is_sleeping(ep) \
240 ((ep)->state & CY_AS_DMA_ENDPOINT_STATE_SLEEPING)
241#define cy_as_dma_end_point_set_sleep_state(ep) \
242 ((ep)->state |= CY_AS_DMA_ENDPOINT_STATE_SLEEPING)
243#define cy_as_dma_end_point_set_wake_state(ep) \
244 ((ep)->state &= ~CY_AS_DMA_ENDPOINT_STATE_SLEEPING)
245
246#define cy_as_dma_end_point_is_running(ep) \
247 ((ep)->state & CY_AS_DMA_ENDPOINT_STATE_DMA_RUNNING)
248#define cy_as_dma_end_point_set_running(ep) \
249 ((ep)->state |= CY_AS_DMA_ENDPOINT_STATE_DMA_RUNNING)
250#define cy_as_dma_end_point_set_stopped(ep) \
251 ((ep)->state &= ~CY_AS_DMA_ENDPOINT_STATE_DMA_RUNNING)
252
253#define cy_as_dma_end_point_in_transit(ep) \
254 ((ep)->state & CY_AS_DMA_ENDPOINT_STATE_IN_TRANSIT)
255#define cy_as_dma_end_point_set_in_transit(ep) \
256 ((ep)->state |= CY_AS_DMA_ENDPOINT_STATE_IN_TRANSIT)
257#define cy_as_dma_end_point_clear_in_transit(ep) \
258 ((ep)->state &= ~CY_AS_DMA_ENDPOINT_STATE_IN_TRANSIT)
259
260#define cy_as_dma_end_point_is_direction_in(ep) \
261 (((ep)->state & CY_AS_DMA_ENDPOINT_STATE_DIRECTION) == \
262 CY_AS_DMA_ENDPOINT_STATE_DIRECTION)
263#define cy_as_dma_end_point_is_direction_out(ep) \
264 (((ep)->state & CY_AS_DMA_ENDPOINT_STATE_DIRECTION) == 0)
265#define cy_as_dma_end_point_set_direction_in(ep) \
266 ((ep)->state |= CY_AS_DMA_ENDPOINT_STATE_DIRECTION)
267#define cy_as_dma_end_point_set_direction_out(ep) \
268 ((ep)->state &= ~CY_AS_DMA_ENDPOINT_STATE_DIRECTION)
269
270#define cy_as_dma_end_point_is_usb(p) \
271 cy_as_end_point_number_is_usb((p)->ep)
272#define cy_as_dma_end_point_is_storage(p) \
273 cy_as_end_point_number_is_storage((p)->ep)
274
275typedef struct cy_as_ll_request_response {
276
277 uint16_t box0;
278
279 uint16_t stored;
280
281 uint16_t length;
282
283 uint16_t flags;
284
285 uint16_t data[1];
286} cy_as_ll_request_response;
287
288
289
290
291typedef void (*cy_as_response_callback)(
292
293 cy_as_device *dev_p,
294
295 uint8_t context,
296
297 cy_as_ll_request_response *rqt,
298
299 cy_as_ll_request_response *resp,
300
301 cy_as_return_status_t status
302 );
303
304typedef struct cy_as_ll_request_list_node {
305
306 cy_as_ll_request_response *rqt;
307
308 cy_as_ll_request_response *resp;
309
310 uint16_t length;
311
312 cy_as_response_callback callback;
313
314 uint8_t state;
315
316 struct cy_as_ll_request_list_node *next;
317} cy_as_ll_request_list_node;
318
319#define cy_as_request_get_node_state(node_p) \
320 ((node_p)->state & CY_AS_REQUEST_LIST_STATE_MASK)
321#define cy_as_request_set_node_state(node_p, st) \
322 ((node_p)->state = \
323 ((node_p)->state & ~CY_AS_REQUEST_LIST_STATE_MASK) | (st))
324
325#define cy_as_request_node_is_sync(node_p) \
326 ((node_p)->state & CY_AS_REQUEST_LIST_STATE_SYNC)
327#define cy_as_request_node_set_sync(node_p) \
328 ((node_p)->state |= CY_AS_REQUEST_LIST_STATE_SYNC)
329#define cy_as_request_node_clear_sync(node_p) \
330 ((node_p)->state &= ~CY_AS_REQUEST_LIST_STATE_SYNC)
331
332#ifndef __doxygen__
333typedef enum cy_as_c_b_node_type {
334 CYAS_INVALID,
335 CYAS_USB_FUNC_CB,
336 CYAS_USB_IO_CB,
337 CYAS_STORAGE_IO_CB,
338 CYAS_FUNC_CB
339} cy_as_c_b_node_type;
340
341typedef struct cy_as_func_c_b_node {
342 cy_as_c_b_node_type node_type;
343 cy_as_function_callback cb_p;
344 uint32_t client_data;
345 cy_as_funct_c_b_type data_type;
346 void *data;
347 struct cy_as_func_c_b_node *next_p;
348} cy_as_func_c_b_node;
349
350extern cy_as_func_c_b_node*
351cy_as_create_func_c_b_node_data(cy_as_function_callback
352 cb, uint32_t client, cy_as_funct_c_b_type type, void *data);
353
354extern cy_as_func_c_b_node*
355cy_as_create_func_c_b_node(cy_as_function_callback cb,
356 uint32_t client);
357
358extern void
359cy_as_destroy_func_c_b_node(cy_as_func_c_b_node *node);
360
361typedef struct cy_as_mtp_func_c_b_node {
362 cy_as_c_b_node_type type;
363 cy_as_mtp_function_callback cb_p;
364 uint32_t client_data;
365 struct cy_as_mtp_func_c_b_node *next_p;
366} cy_as_mtp_func_c_b_node;
367
368extern cy_as_mtp_func_c_b_node*
369cy_as_create_mtp_func_c_b_node(cy_as_mtp_function_callback cb,
370 uint32_t client);
371
372extern void
373cy_as_destroy_mtp_func_c_b_node(cy_as_mtp_func_c_b_node *node);
374
375typedef struct cy_as_usb_func_c_b_node {
376 cy_as_c_b_node_type type;
377 cy_as_usb_function_callback cb_p;
378 uint32_t client_data;
379 struct cy_as_usb_func_c_b_node *next_p;
380} cy_as_usb_func_c_b_node;
381
382extern cy_as_usb_func_c_b_node*
383cy_as_create_usb_func_c_b_node(cy_as_usb_function_callback cb,
384 uint32_t client);
385
386extern void
387cy_as_destroy_usb_func_c_b_node(cy_as_usb_func_c_b_node *node);
388
389typedef struct cy_as_usb_io_c_b_node {
390 cy_as_c_b_node_type type;
391 cy_as_usb_io_callback cb_p;
392 struct cy_as_usb_io_c_b_node *next_p;
393} cy_as_usb_io_c_b_node;
394
395extern cy_as_usb_io_c_b_node*
396cy_as_create_usb_io_c_b_node(cy_as_usb_io_callback cb);
397
398extern void
399cy_as_destroy_usb_io_c_b_node(cy_as_usb_io_c_b_node *node);
400
401typedef struct cy_as_storage_io_c_b_node {
402 cy_as_c_b_node_type type;
403 cy_as_storage_callback cb_p;
404
405 cy_as_media_type media;
406
407
408 uint32_t device_index;
409
410
411 uint32_t unit;
412
413
414 uint32_t block_addr;
415
416
417 cy_as_oper_type oper;
418 cy_as_ll_request_response *req_p;
419 cy_as_ll_request_response *reply_p;
420 struct cy_as_storage_io_c_b_node *next_p;
421} cy_as_storage_io_c_b_node;
422
423extern cy_as_storage_io_c_b_node*
424cy_as_create_storage_io_c_b_node(cy_as_storage_callback cb,
425 cy_as_media_type media, uint32_t device_index,
426 uint32_t unit, uint32_t block_addr, cy_as_oper_type oper,
427 cy_as_ll_request_response *req_p,
428 cy_as_ll_request_response *reply_p);
429
430extern void
431cy_as_destroy_storage_io_c_b_node(cy_as_storage_io_c_b_node *node);
432
433typedef struct cy_as_c_b_queue {
434 void *head_p;
435 void *tail_p;
436 uint32_t count;
437 cy_as_c_b_node_type type;
438} cy_as_c_b_queue;
439
440extern cy_as_c_b_queue *
441cy_as_create_c_b_queue(cy_as_c_b_node_type type);
442
443extern void
444cy_as_destroy_c_b_queue(cy_as_c_b_queue *queue);
445
446
447extern void
448cy_as_insert_c_b_node(cy_as_c_b_queue *queue_p, void *cbnode);
449
450
451extern void
452cy_as_remove_c_b_node(cy_as_c_b_queue *queue_p);
453
454
455extern void
456cy_as_remove_c_b_tail_node(cy_as_c_b_queue *queue_p);
457
458
459extern void
460cy_as_clear_c_b_queue(cy_as_c_b_queue *queue_p);
461
462extern cy_as_return_status_t
463cy_as_misc_send_request(cy_as_device *dev_p,
464 cy_as_function_callback cb,
465 uint32_t client,
466 cy_as_funct_c_b_type type,
467 void *data,
468 cy_as_c_b_queue *queue,
469 uint16_t req_type,
470 cy_as_ll_request_response *req_p,
471 cy_as_ll_request_response *reply_p,
472 cy_as_response_callback rcb);
473
474extern void
475cy_as_misc_cancel_ex_requests(cy_as_device *dev_p);
476
477
478
479
480
481extern void
482cy_as_usb_cleanup(
483 cy_as_device *dev_p);
484
485
486
487
488
489extern void
490cy_as_storage_cleanup(
491 cy_as_device *dev_p);
492#endif
493
494
495
496
497
498
499
500
501
502
503
504typedef struct cy_as_context {
505
506 uint8_t number;
507
508
509 cy_as_hal_sleep_channel channel;
510
511 cy_as_ll_request_response *req_p;
512
513 uint16_t request_length;
514
515 cy_as_response_callback request_callback;
516
517 cy_as_ll_request_list_node *request_queue_p;
518
519 cy_as_ll_request_list_node *last_node_p;
520
521 uint16_t queue_index;
522
523 uint16_t rqt_index;
524
525 uint16_t data_queue[128];
526
527} cy_as_context;
528
529#define cy_as_context_is_waiting(ctxt) \
530 ((ctxt)->state & CY_AS_CTXT_STATE_WAITING_RESPONSE)
531#define cy_as_context_set_waiting(ctxt) \
532 ((ctxt)->state |= CY_AS_CTXT_STATE_WAITING_RESPONSE)
533#define cy_as_context_clear_waiting(ctxt) \
534 ((ctxt)->state &= ~CY_AS_CTXT_STATE_WAITING_RESPONSE)
535
536
537
538
539
540
541
542
543
544typedef struct cy_as_sdio_device {
545
546 uint8_t function_init_map;
547 uint8_t function_suspended_map;
548
549 cy_as_sdio_card card;
550
551 cy_as_sdio_func function[7];
552
553} cy_as_sdio_device;
554
555
556
557
558
559#define cy_as_sdio_get_function_code(handle, bus, i) \
560 (((cy_as_device *)handle)->sdiocard[bus].function[i-1].function_code)
561
562#define cy_as_sdio_get_function_ext_code(handle, bus, i) \
563 (((cy_as_device *)handle)->sdiocard[bus].\
564 function[i-1].extended_func_code)
565
566#define cy_as_sdio_get_function_p_s_n(handle, bus, i) \
567 (((cy_as_device *)handle)->sdiocard[bus].function[i-1].card_psn)
568
569#define cy_as_sdio_get_function_blocksize(handle, bus, i) \
570 (((cy_as_device *)handle)->sdiocard[bus].function[i-1].blocksize)
571
572#define cy_as_sdio_get_function_max_blocksize(handle, bus, i) \
573 (((cy_as_device *)handle)->sdiocard[bus].function[i-1].maxblocksize)
574
575#define cy_as_sdio_get_function_csa_support(handle, bus, i) \
576 (((cy_as_device *)handle)->sdiocard[bus].function[i-1].csa_bits)
577
578#define cy_as_sdio_get_function_wakeup_support(handle, bus, i) \
579 (((cy_as_device *)handle)->sdiocard[bus].function[i-1]. wakeup_support)
580
581#define cy_as_sdio_set_function_block_size(handle, bus, i, blocksize) \
582 (((cy_as_device *)handle)->sdiocard[bus].function[i-1].blocksize = \
583 blocksize)
584
585#define cy_as_sdio_get_card_num_functions(handle, bus) \
586 (((cy_as_device *)handle)->sdiocard[bus].card.num_functions)
587
588#define cy_as_sdio_get_card_mem_present(handle, bus) \
589 (((cy_as_device *)handle)->sdiocard[bus].card.memory_present)
590
591#define cy_as_sdio_get_card_manf_id(handle, bus) \
592 (((cy_as_device *)handle)->sdiocard[bus].card.manufacturer__id)
593
594#define cy_as_sdio_get_card_manf_info(handle, bus) \
595 (((cy_as_device *)handle)->sdiocard[bus].card.manufacturer_info)
596
597#define cy_as_sdio_get_card_blocksize(handle, bus) \
598 (((cy_as_device *)handle)->sdiocard[bus].card.blocksize)
599
600#define cy_as_sdio_get_card_max_blocksize(handle, bus) \
601 (((cy_as_device *)handle)->sdiocard[bus].card.maxblocksize)
602
603#define cy_as_sdio_get_card_sdio_version(handle, bus) \
604 (((cy_as_device *)handle)->sdiocard[bus].card.sdio_version)
605
606#define cy_as_sdio_get_card_capability(handle, bus) \
607 (((cy_as_device *)handle)->sdiocard[bus].card.card_capability)
608
609#define cy_as_sdio_get_function_init_map(handle, bus) \
610 (((cy_as_device *)handle)->sdiocard[bus].function_init_map)
611
612#define cy_as_sdio_check_function_initialized(handle, bus, i) \
613 (((cy_as_sdio_get_function_init_map(handle, bus)) & (0x01<<i)) ? 1 : 0)
614
615#define cy_as_sdio_set_card_block_size(handle, bus, blocksize) \
616 (((cy_as_device *)handle)->sdiocard[bus].card.blocksize = blocksize)
617
618#define cy_as_sdio_check_support_bus_suspend(handle, bus) \
619 ((cy_as_sdio_get_card_capability(handle, bus) & CY_SDIO_SBS) ? 1 : 0)
620
621#define cy_as_sdio_check_function_suspended(handle, bus, i) \
622 ((((cy_as_device *)handle)->sdiocard[bus].function_suspended_map & \
623 (0x01<<i)) ? 1 : 0)
624
625#define cy_as_sdio_set_function_suspended(handle, bus, i) \
626 ((((cy_as_device *)handle)->sdiocard[bus].function_suspended_map) \
627 |= (0x01<<i))
628
629#define cy_as_sdio_clear_function_suspended(handle, bus, i) \
630 ((((cy_as_device *)handle)->sdiocard[bus].function_suspended_map) \
631 &= (~(0x01<<i)))
632
633
634
635
636
637
638struct cy_as_device {
639
640
641 uint32_t sig;
642
643 uint16_t silicon_id;
644
645 struct cy_as_device *next_p;
646
647 cy_as_hal_device_tag tag;
648
649 uint32_t state;
650
651 cy_bool use_int_drq;
652
653
654
655 cy_as_dma_end_point *endp[16];
656
657 cy_as_dma_queue_entry *dma_freelist_p;
658
659
660
661 cy_as_context *context[CY_RQT_CONTEXT_COUNT];
662
663 cy_as_return_status_t ll_error;
664
665 cy_bool ll_sending_rqt;
666
667 cy_bool ll_abort_curr_rqt;
668
669 cy_bool ll_queued_data;
670
671
672
673 cy_as_misc_event_callback misc_event_cb;
674
675
676
677 uint32_t storage_count;
678
679 cy_as_storage_event_callback_dep storage_event_cb;
680
681 cy_as_storage_event_callback storage_event_cb_ms;
682
683 cy_as_return_status_t storage_error;
684
685 cy_bool storage_wait;
686
687 cy_as_ll_request_response *storage_rw_req_p;
688
689 cy_as_ll_request_response *storage_rw_resp_p;
690
691 cy_as_storage_callback_dep storage_cb;
692
693 cy_as_storage_callback storage_cb_ms;
694
695 cy_as_bus_number_t storage_bus_index;
696
697
698 uint32_t storage_device_index;
699
700 uint32_t storage_unit;
701
702
703 uint32_t storage_block_addr;
704
705 cy_as_oper_type storage_oper;
706
707 cy_as_end_point_number_t storage_read_endpoint;
708
709 cy_as_end_point_number_t storage_write_endpoint;
710 cy_as_device_desc storage_device_info
711 [CY_AS_MAX_BUSES][CY_AS_MAX_STORAGE_DEVICES];
712
713
714
715
716 uint16_t epasync;
717
718 uint32_t usb_count;
719
720 uint8_t usb_phy_config;
721
722 cy_as_c_b_queue *usb_func_cbs;
723
724 cy_as_usb_end_point_config usb_config[16];
725
726 cy_as_usb_event_callback_dep usb_event_cb;
727
728 cy_as_usb_event_callback usb_event_cb_ms;
729
730 cy_as_return_status_t usb_error;
731
732 cy_as_usb_io_callback usb_cb[16];
733
734 void *usb_pending_buffer;
735
736 uint32_t usb_pending_size;
737
738 cy_bool usb_spacket[16];
739
740 uint32_t usb_actual_cnt;
741
742 uint8_t usb_ep1cfg[2];
743
744 uint16_t usb_lepcfg[10];
745
746 uint16_t usb_pepcfg[4];
747
748 uint8_t *usb_ep_data;
749
750 uint32_t usb_delay_ack_count;
751
752 uint32_t usb_max_tx_size;
753
754
755 cy_as_ll_request_response *usb_ep0_dma_req;
756
757 cy_as_ll_request_response *usb_ep0_dma_resp;
758
759 cy_as_ll_request_response *usb_ep1_dma_req;
760
761 cy_as_ll_request_response *usb_ep1_dma_resp;
762
763 cy_as_ll_request_response *usb_ep0_dma_req_save;
764 cy_as_ll_request_response *usb_ep0_dma_resp_save;
765
766
767
768 uint32_t mtp_count;
769
770 cy_as_mtp_event_callback mtp_event_cb;
771
772 cy_as_mtp_block_table *tp_blk_tbl;
773
774 cy_as_c_b_queue *func_cbs_mtp;
775 cy_as_c_b_queue *func_cbs_usb;
776 cy_as_c_b_queue *func_cbs_stor;
777 cy_as_c_b_queue *func_cbs_misc;
778 cy_as_c_b_queue *func_cbs_res;
779
780
781 cy_as_usb_event usb_last_event;
782
783 uint8_t media_supported[CY_AS_MAX_BUSES];
784
785
786 cy_as_sdio_device sdiocard[CY_AS_MAX_BUSES];
787
788 cy_bool is_mtp_firmware;
789
790 cy_bool is_mtp_data_pending;
791
792
793 cy_bool mtp_turbo_active;
794
795 uint16_t mtp_data_len;
796
797 cy_as_return_status_t mtp_error;
798
799 cy_as_function_callback mtp_cb;
800
801 uint32_t mtp_client;
802
803 cy_as_funct_c_b_type mtp_op;
804
805
806 cy_bool is_storage_only_mode;
807
808 uint32_t stby_int_mask;
809};
810
811#define cy_as_device_is_configured(dp) \
812 ((dp)->state & CY_AS_DEVICE_STATE_CONFIGURED)
813#define cy_as_device_set_configured(dp) \
814 ((dp)->state |= CY_AS_DEVICE_STATE_CONFIGURED)
815#define cy_as_device_set_unconfigured(dp) \
816 ((dp)->state &= ~CY_AS_DEVICE_STATE_CONFIGURED)
817
818#define cy_as_device_is_dma_running(dp) \
819 ((dp)->state & CY_AS_DEVICE_STATE_DMA_MODULE)
820#define cy_as_device_set_dma_running(dp) \
821 ((dp)->state |= CY_AS_DEVICE_STATE_DMA_MODULE)
822#define cy_as_device_set_dma_stopped(dp) \
823 ((dp)->state &= ~CY_AS_DEVICE_STATE_DMA_MODULE)
824
825#define cy_as_device_is_low_level_running(dp) \
826 ((dp)->state & CY_AS_DEVICE_STATE_LOWLEVEL_MODULE)
827#define cy_as_device_set_low_level_running(dp) \
828 ((dp)->state |= CY_AS_DEVICE_STATE_LOWLEVEL_MODULE)
829#define cy_as_device_set_low_level_stopped(dp) \
830 ((dp)->state &= ~CY_AS_DEVICE_STATE_LOWLEVEL_MODULE)
831
832#define cy_as_device_is_intr_running(dp) \
833 ((dp)->state & CY_AS_DEVICE_STATE_INTR_MODULE)
834#define cy_as_device_set_intr_running(dp) \
835 ((dp)->state |= CY_AS_DEVICE_STATE_INTR_MODULE)
836#define cy_as_device_set_intr_stopped(dp) \
837 ((dp)->state &= ~CY_AS_DEVICE_STATE_INTR_MODULE)
838
839#define cy_as_device_is_firmware_loaded(dp) \
840 ((dp)->state & CY_AS_DEVICE_STATE_FIRMWARE_LOADED)
841#define cy_as_device_set_firmware_loaded(dp) \
842 ((dp)->state |= CY_AS_DEVICE_STATE_FIRMWARE_LOADED)
843#define cy_as_device_set_firmware_not_loaded(dp) \
844 ((dp)->state &= ~CY_AS_DEVICE_STATE_FIRMWARE_LOADED)
845
846#define cy_as_device_is_storage_running(dp) \
847 ((dp)->state & CY_AS_DEVICE_STATE_STORAGE_MODULE)
848#define cy_as_device_set_storage_running(dp) \
849 ((dp)->state |= CY_AS_DEVICE_STATE_STORAGE_MODULE)
850#define cy_as_device_set_storage_stopped(dp) \
851 ((dp)->state &= ~CY_AS_DEVICE_STATE_STORAGE_MODULE)
852
853#define cy_as_device_is_usb_running(dp) \
854 ((dp)->state & CY_AS_DEVICE_STATE_USB_MODULE)
855#define cy_as_device_set_usb_running(dp) \
856 ((dp)->state |= CY_AS_DEVICE_STATE_USB_MODULE)
857#define cy_as_device_set_usb_stopped(dp) \
858 ((dp)->state &= ~CY_AS_DEVICE_STATE_USB_MODULE)
859
860#define cy_as_device_wants_scsi_messages(dp) \
861 (((dp)->state & CY_AS_DEVICE_STATE_STORAGE_SCSIMSG) \
862 ? cy_true : cy_false)
863#define cy_as_device_set_scsi_messages(dp) \
864 ((dp)->state |= CY_AS_DEVICE_STATE_STORAGE_SCSIMSG)
865#define cy_as_device_clear_scsi_messages(dp) \
866 ((dp)->state &= ~CY_AS_DEVICE_STATE_STORAGE_SCSIMSG)
867
868#define cy_as_device_is_storage_async_pending(dp) \
869 ((dp)->state & CY_AS_DEVICE_STATE_STORAGE_ASYNC_PENDING)
870#define cy_as_device_set_storage_async_pending(dp) \
871 ((dp)->state |= CY_AS_DEVICE_STATE_STORAGE_ASYNC_PENDING)
872#define cy_as_device_clear_storage_async_pending(dp) \
873 ((dp)->state &= ~CY_AS_DEVICE_STATE_STORAGE_ASYNC_PENDING)
874
875#define cy_as_device_is_usb_connected(dp) \
876 ((dp)->state & CY_AS_DEVICE_STATE_USB_CONNECTED)
877#define cy_as_device_set_usb_connected(dp) \
878 ((dp)->state |= CY_AS_DEVICE_STATE_USB_CONNECTED)
879#define cy_as_device_clear_usb_connected(dp) \
880 ((dp)->state &= ~CY_AS_DEVICE_STATE_USB_CONNECTED)
881
882#define cy_as_device_is_usb_high_speed(dp) \
883 ((dp)->state & CY_AS_DEVICE_STATE_USB_HIGHSPEED)
884#define cy_as_device_set_usb_high_speed(dp) \
885 ((dp)->state |= CY_AS_DEVICE_STATE_USB_HIGHSPEED)
886#define cy_as_device_clear_usb_high_speed(dp) \
887 ((dp)->state &= ~CY_AS_DEVICE_STATE_USB_HIGHSPEED)
888
889#define cy_as_device_is_in_callback(dp) \
890 ((dp)->state & CY_AS_DEVICE_STATE_IN_CALLBACK)
891#define cy_as_device_set_in_callback(dp) \
892 ((dp)->state |= CY_AS_DEVICE_STATE_IN_CALLBACK)
893#define cy_as_device_clear_in_callback(dp) \
894 ((dp)->state &= ~CY_AS_DEVICE_STATE_IN_CALLBACK)
895
896#define cy_as_device_is_setup_i_o_performed(dp) \
897 ((dp)->state & CY_AS_DEVICE_STATE_SETUP_IO_PERFORMED)
898#define cy_as_device_set_setup_i_o_performed(dp) \
899 ((dp)->state |= CY_AS_DEVICE_STATE_SETUP_IO_PERFORMED)
900#define cy_as_device_clear_setup_i_o_performed(dp) \
901 ((dp)->state &= ~CY_AS_DEVICE_STATE_SETUP_IO_PERFORMED)
902
903#define cy_as_device_is_ack_delayed(dp) \
904 ((dp)->usb_delay_ack_count > 0)
905#define cy_as_device_set_ack_delayed(dp) \
906 ((dp)->usb_delay_ack_count++)
907#define cy_as_device_rem_ack_delayed(dp) \
908 ((dp)->usb_delay_ack_count--)
909#define cy_as_device_clear_ack_delayed(dp) \
910 ((dp)->usb_delay_ack_count = 0)
911
912#define cy_as_device_is_setup_packet(dp) \
913 ((dp)->state & CY_AS_DEVICE_STATE_IN_SETUP_PACKET)
914#define cy_as_device_set_setup_packet(dp) \
915 ((dp)->state |= CY_AS_DEVICE_STATE_IN_SETUP_PACKET)
916#define cy_as_device_clear_setup_packet(dp) \
917 ((dp)->state &= ~CY_AS_DEVICE_STATE_IN_SETUP_PACKET)
918
919#define cy_as_device_is_ep0_stalled(dp) \
920 ((dp)->state & CY_AS_DEVICE_STATE_EP0_STALLED)
921#define cy_as_device_set_ep0_stalled(dp) \
922 ((dp)->state |= CY_AS_DEVICE_STATE_EP0_STALLED)
923#define cy_as_device_clear_ep0_stalled(dp) \
924 ((dp)->state &= ~CY_AS_DEVICE_STATE_EP0_STALLED)
925
926#define cy_as_device_is_register_standby(dp) \
927 ((dp)->state & CY_AS_DEVICE_STATE_REGISTER_STANDBY)
928#define cy_as_device_set_register_standby(dp) \
929 ((dp)->state |= CY_AS_DEVICE_STATE_REGISTER_STANDBY)
930#define cy_as_device_clear_register_standby(dp) \
931 ((dp)->state &= ~CY_AS_DEVICE_STATE_REGISTER_STANDBY)
932
933#define cy_as_device_is_pin_standby(dp) \
934 ((dp)->state & CY_AS_DEVICE_STATE_PIN_STANDBY)
935#define cy_as_device_set_pin_standby(dp) \
936 ((dp)->state |= CY_AS_DEVICE_STATE_PIN_STANDBY)
937#define cy_as_device_clear_pin_standby(dp) \
938 ((dp)->state &= ~CY_AS_DEVICE_STATE_PIN_STANDBY)
939
940#define cy_as_device_is_crystal(dp) \
941 ((dp)->state & CY_AS_DEVICE_STATE_CRYSTAL)
942#define cy_as_device_is_external_clock(dp) \
943 (!((dp)->state & CY_AS_DEVICE_STATE_CRYSTAL))
944#define cy_as_device_set_crystal(dp) \
945 ((dp)->state |= CY_AS_DEVICE_STATE_CRYSTAL)
946#define cy_as_device_set_external_clock(dp) \
947 ((dp)->state &= ~CY_AS_DEVICE_STATE_CRYSTAL)
948
949#define cy_as_device_is_waking(dp) \
950 ((dp)->state & CY_AS_DEVICE_STATE_WAKING)
951#define cy_as_device_set_waking(dp) \
952 ((dp)->state |= CY_AS_DEVICE_STATE_WAKING)
953#define cy_as_device_clear_waking(dp) \
954 ((dp)->state &= ~CY_AS_DEVICE_STATE_WAKING)
955
956#define cy_as_device_is_in_suspend_mode(dp) \
957 ((dp)->state & CY_AS_DEVICE_STATE_SUSPEND)
958#define cy_as_device_set_suspend_mode(dp) \
959 ((dp)->state |= CY_AS_DEVICE_STATE_SUSPEND)
960#define cy_as_device_clear_suspend_mode(dp) \
961 ((dp)->state &= ~CY_AS_DEVICE_STATE_SUSPEND)
962
963#define cy_as_device_is_reset_pending(dp) \
964 ((dp)->state & CY_AS_DEVICE_STATE_RESETP)
965#define cy_as_device_set_reset_pending(dp) \
966 ((dp)->state |= CY_AS_DEVICE_STATE_RESETP)
967#define cy_as_device_clear_reset_pending(dp) \
968 ((dp)->state &= ~CY_AS_DEVICE_STATE_RESETP)
969
970#define cy_as_device_is_standby_pending(dp) \
971 ((dp)->state & CY_AS_DEVICE_STATE_STANDP)
972#define cy_as_device_set_standby_pending(dp) \
973 ((dp)->state |= CY_AS_DEVICE_STATE_STANDP)
974#define cy_as_device_clear_standby_pending(dp) \
975 ((dp)->state &= ~CY_AS_DEVICE_STATE_STANDP)
976
977#define cy_as_device_is_s_s_s_pending(dp) \
978 ((dp)->state & CY_AS_DEVICE_STATE_SSSP)
979#define cy_as_device_set_s_s_s_pending(dp) \
980 ((dp)->state |= CY_AS_DEVICE_STATE_SSSP)
981#define cy_as_device_clear_s_s_s_pending(dp) \
982 ((dp)->state &= ~CY_AS_DEVICE_STATE_SSSP)
983
984#define cy_as_device_is_u_s_s_pending(dp) \
985 ((dp)->state & CY_AS_DEVICE_STATE_USSP)
986#define cy_as_device_set_u_s_s_pending(dp) \
987 ((dp)->state |= CY_AS_DEVICE_STATE_USSP)
988#define cy_as_device_clear_u_s_s_pending(dp) \
989 ((dp)->state &= ~CY_AS_DEVICE_STATE_USSP)
990
991#define cy_as_device_is_m_s_s_pending(dp) \
992 ((dp)->state & CY_AS_DEVICE_STATE_MSSP)
993#define cy_as_device_set_m_s_s_pending(dp) \
994 ((dp)->state |= CY_AS_DEVICE_STATE_MSSP)
995#define cy_as_device_clear_m_s_s_pending(dp) \
996 ((dp)->state &= ~CY_AS_DEVICE_STATE_MSSP)
997
998#define cy_as_device_is_p2s_dma_start_recvd(dp) \
999 ((dp)->state & CY_AS_DEVICE_STATE_P2SDMA_START)
1000#define cy_as_device_set_p2s_dma_start_recvd(dp) \
1001 ((dp)->state |= CY_AS_DEVICE_STATE_P2SDMA_START)
1002#define cy_as_device_clear_p2s_dma_start_recvd(dp) \
1003 ((dp)->state &= ~CY_AS_DEVICE_STATE_P2SDMA_START)
1004
1005#define cy_as_device_is_usb_async_pending(dp, ep) \
1006 ((dp)->epasync & (1 << ep))
1007#define cy_as_device_set_usb_async_pending(dp, ep) \
1008 ((dp)->epasync |= (1 << ep))
1009#define cy_as_device_clear_usb_async_pending(dp, ep) \
1010 ((dp)->epasync &= ~(1 << ep))
1011
1012#define cy_as_device_is_nand_storage_supported(dp) \
1013 ((dp)->media_supported[0] & 1)
1014
1015
1016#define cy_as_device_is_astoria_dev(dp) \
1017 (((dp)->silicon_id == CY_AS_MEM_CM_WB_CFG_ID_HDID_ASTORIA_VALUE) || \
1018 ((dp)->silicon_id == CY_AS_MEM_CM_WB_CFG_ID_HDID_ASTORIA_FPGA_VALUE))
1019#define cy_as_device_is_antioch_dev(dp) \
1020 ((dp)->silicon_id == CY_AS_MEM_CM_WB_CFG_ID_HDID_ANTIOCH_VALUE)
1021
1022#ifdef CY_AS_LOG_SUPPORT
1023extern void cy_as_log_debug_message(int value, const char *msg);
1024#else
1025#define cy_as_log_debug_message(value, msg)
1026#endif
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050extern cy_as_device *
1051cy_as_device_find_from_tag(
1052 cy_as_hal_device_tag tag
1053 );
1054
1055#include "cyas_cplus_end.h"
1056
1057#endif
1058