SyterKit 0.4.0.x
SyterKit is a bare-metal framework
Loading...
Searching...
No Matches
usb_device.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0+ */
2
3#ifndef __USB_DEVICE_H__
4#define __USB_DEVICE_H__
5
6#include <stdarg.h>
7#include <stdbool.h>
8#include <stddef.h>
9#include <stdint.h>
10#include <types.h>
11
12#include "reg/reg-usb.h"
13
14/*
15 * Device and/or Interface Class codes
16 */
17#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
18#define USB_CLASS_AUDIO 1
19#define USB_CLASS_COMM 2
20#define USB_CLASS_HID 3
21#define USB_CLASS_PHYSICAL 5
22#define USB_CLASS_PRINTER 7
23#define USB_CLASS_MASS_STORAGE 8
24#define USB_CLASS_HUB 9
25#define USB_CLASS_DATA 10
26#define USB_CLASS_APP_SPEC 0xfe
27#define USB_CLASS_VENDOR_SPEC 0xff
28
29/*
30 * USB types
31 */
32#define USB_TYPE_STANDARD (0x00 << 5)
33#define USB_TYPE_CLASS (0x01 << 5)
34#define USB_TYPE_VENDOR (0x02 << 5)
35#define USB_TYPE_RESERVED (0x03 << 5)
36
37/*
38 * USB recipients
39 */
40#define USB_RECIP_DEVICE 0x00
41#define USB_RECIP_INTERFACE 0x01
42#define USB_RECIP_ENDPOINT 0x02
43#define USB_RECIP_OTHER 0x03
44
45/*
46 * USB directions
47 */
48#define USB_DIR_OUT 0
49#define USB_DIR_IN 0x80
50
51/*
52 * Descriptor types
53 */
54#define USB_DT_DEVICE 0x01
55#define USB_DT_CONFIG 0x02
56#define USB_DT_STRING 0x03
57#define USB_DT_INTERFACE 0x04
58#define USB_DT_ENDPOINT 0x05
59#define USB_DT_DEVICE_QUALIFIER 0x06
60
61#if defined(CONFIG_USBD_HS)
62#define USB_DT_QUAL 0x06
63#endif
64
65#define USB_DT_HID (USB_TYPE_CLASS | 0x01)
66#define USB_DT_REPORT (USB_TYPE_CLASS | 0x02)
67#define USB_DT_PHYSICAL (USB_TYPE_CLASS | 0x03)
68#define USB_DT_HUB (USB_TYPE_CLASS | 0x09)
69
70/*
71 * Descriptor sizes per descriptor type
72 */
73#define USB_DT_DEVICE_SIZE 18
74#define USB_DT_CONFIG_SIZE 9
75#define USB_DT_INTERFACE_SIZE 9
76#define USB_DT_ENDPOINT_SIZE 7
77#define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
78#define USB_DT_HUB_NONVAR_SIZE 7
79#define USB_DT_HID_SIZE 9
80
81/*
82 * Endpoints
83 */
84#define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
85#define USB_ENDPOINT_DIR_MASK 0x80
86
87#define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
88#define USB_ENDPOINT_XFER_CONTROL 0
89#define USB_ENDPOINT_XFER_ISOC 1
90#define USB_ENDPOINT_XFER_BULK 2
91#define USB_ENDPOINT_XFER_INT 3
92
93/*
94 * USB Packet IDs (PIDs)
95 */
96#define USB_PID_UNDEF_0 0xf0
97#define USB_PID_OUT 0xe1
98#define USB_PID_ACK 0xd2
99#define USB_PID_DATA0 0xc3
100#define USB_PID_PING 0xb4 /* USB 2.0 */
101#define USB_PID_SOF 0xa5
102#define USB_PID_NYET 0x96 /* USB 2.0 */
103#define USB_PID_DATA2 0x87 /* USB 2.0 */
104#define USB_PID_SPLIT 0x78 /* USB 2.0 */
105#define USB_PID_IN 0x69
106#define USB_PID_NAK 0x5a
107#define USB_PID_DATA1 0x4b
108#define USB_PID_PREAMBLE 0x3c /* Token mode */
109#define USB_PID_ERR 0x3c /* USB 2.0: handshake mode */
110#define USB_PID_SETUP 0x2d
111#define USB_PID_STALL 0x1e
112#define USB_PID_MDATA 0x0f /* USB 2.0 */
113
114/*
115 * Standard requests
116 */
117#define USB_REQ_GET_STATUS 0x00
118#define USB_REQ_CLEAR_FEATURE 0x01
119#define USB_REQ_SET_FEATURE 0x03
120#define USB_REQ_SET_ADDRESS 0x05
121#define USB_REQ_GET_DESCRIPTOR 0x06
122#define USB_REQ_SET_DESCRIPTOR 0x07
123#define USB_REQ_GET_CONFIGURATION 0x08
124#define USB_REQ_SET_CONFIGURATION 0x09
125#define USB_REQ_GET_INTERFACE 0x0A
126#define USB_REQ_SET_INTERFACE 0x0B
127#define USB_REQ_SYNCH_FRAME 0x0C
128
129#define USBD_DEVICE_REQUESTS(x) (((unsigned int) x <= USB_REQ_SYNCH_FRAME) ? usbd_device_requests[x] : "UNKNOWN")
130
131/*
132 * HID requests
133 */
134#define USB_REQ_GET_REPORT 0x01
135#define USB_REQ_GET_IDLE 0x02
136#define USB_REQ_GET_PROTOCOL 0x03
137#define USB_REQ_SET_REPORT 0x09
138#define USB_REQ_SET_IDLE 0x0A
139#define USB_REQ_SET_PROTOCOL 0x0B
140
141/*
142 * USB Spec Release number
143 */
144
145#if defined(CONFIG_USBD_HS)
146#define USB_BCD_VERSION 0x0200
147#else
148#define USB_BCD_VERSION 0x0110
149#endif
150
151/*
152 * Device Requests (c.f Table 9-2)
153 */
154
155#define USB_REQ_DIRECTION_MASK 0x80
156#define USB_REQ_TYPE_MASK 0x60
157#define USB_REQ_RECIPIENT_MASK 0x1f
158
159#define USB_REQ_DEVICE2HOST 0x80
160#define USB_REQ_HOST2DEVICE 0x00
161
162#define USB_REQ_TYPE_STANDARD 0x00
163#define USB_REQ_TYPE_CLASS 0x20
164#define USB_REQ_TYPE_VENDOR 0x40
165
166#define USB_REQ_RECIPIENT_DEVICE 0x00
167#define USB_REQ_RECIPIENT_INTERFACE 0x01
168#define USB_REQ_RECIPIENT_ENDPOINT 0x02
169#define USB_REQ_RECIPIENT_OTHER 0x03
170
171/*
172 * get status bits
173 */
174
175#define USB_STATUS_SELFPOWERED 0x01
176#define USB_STATUS_REMOTEWAKEUP 0x02
177
178#define USB_STATUS_HALT 0x01
179
180/*
181 * descriptor types
182 */
183
184#define USB_DESCRIPTOR_TYPE_DEVICE 0x01
185#define USB_DESCRIPTOR_TYPE_CONFIGURATION 0x02
186#define USB_DESCRIPTOR_TYPE_STRING 0x03
187#define USB_DESCRIPTOR_TYPE_INTERFACE 0x04
188#define USB_DESCRIPTOR_TYPE_ENDPOINT 0x05
189#define USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER 0x06
190#define USB_DESCRIPTOR_TYPE_OTHER_SPEED_CONFIGURATION 0x07
191#define USB_DESCRIPTOR_TYPE_INTERFACE_POWER 0x08
192#define USB_DESCRIPTOR_TYPE_HID 0x21
193#define USB_DESCRIPTOR_TYPE_REPORT 0x22
194
195#define USBD_DEVICE_DESCRIPTORS(x) (((unsigned int) x <= USB_DESCRIPTOR_TYPE_INTERFACE_POWER) ? usbd_device_descriptors[x] : "UNKNOWN")
196
197/*
198 * standard feature selectors
199 */
200#define USB_ENDPOINT_HALT 0x00
201#define USB_DEVICE_REMOTE_WAKEUP 0x01
202#define USB_TEST_MODE 0x02
203
212
221
230
239
248
257
266
275
286
287
296
302static inline void usb_device_ep0_config_ep0(uint32_t addr) {
304}
305
315
325
334
343
352
361
371
380
390
400
409
418
427
436
443 /* Clear transmit control and status register (TXCSR) */
444 writew(0x00, USBC_REG_TXCSR(addr));
445 /* Clear transmit endpoint maximum packet size (TXMAXP) */
446 writew(0x00, USBC_REG_TXMAXP(addr));
447}
448
454static inline void usb_device_clear_dma_trans(uint32_t addr) {
455 uint32_t reg_val;
456
457 reg_val = readl(addr + USBC_REG_o_PCTL);
458 reg_val &= ~(1 << 24);
459 writel(reg_val, addr + USBC_REG_o_PCTL);
460}
461
467static inline void usb_device_config_dma_trans(uint32_t addr) {
468 uint32_t reg_val;
469
470 reg_val = readl(addr + USBC_REG_o_PCTL);
471 reg_val |= (1 << 24);
472 writel(reg_val, addr + USBC_REG_o_PCTL);
473}
474
483static inline void usb_device_tx_config_ep(uint32_t addr, uint32_t ts_type, uint32_t is_double_fifo, uint32_t ep_maxpkt) {
484 uint16_t reg_val = 0;
485 uint16_t temp = 0;
486
487 /* configure TX CSR register */
488 reg_val = (1 << USBC_BP_TXCSR_D_MODE);
489 reg_val |= (1 << USBC_BP_TXCSR_D_CLEAR_DATA_TOGGLE);
490 reg_val |= (1 << USBC_BP_TXCSR_D_FLUSH_FIFO);
491 writew(reg_val, USBC_REG_TXCSR(addr));
492
493 if (is_double_fifo) {
494 writew(reg_val, USBC_REG_TXCSR(addr));
495 }
496
497 /* configure TX EP maximum packet size */
498 reg_val = readw(USBC_REG_TXMAXP(addr));
499 temp = ep_maxpkt & ((1 << USBC_BP_TXMAXP_PACKET_COUNT) - 1);
500 reg_val &= ~(0x1fff);
501 reg_val |= temp;
502 writew(reg_val, USBC_REG_TXMAXP(addr));
503
504 /* configure EP transfer type */
505 switch (ts_type) {
506 case USBC_TS_TYPE_ISO:
508 break;
509 case USBC_TS_TYPE_INT:
511 break;
514 break;
515 default:
517 break;
518 }
519}
520
526static inline void usb_device_tx_config_ep_dma(uint32_t addr) {
527 uint16_t ep_csr = 0;
528
529 /* set auto_set, tx_mode, dma_tx_en, and mode1 bits in TX CSR register */
530 ep_csr = readb(USBC_REG_TXCSR(addr) + 1);
531 ep_csr |= (1 << USBC_BP_TXCSR_D_AUTOSET) >> 8;
532 ep_csr |= (1 << USBC_BP_TXCSR_D_MODE) >> 8;
533 ep_csr |= (1 << USBC_BP_TXCSR_D_DMA_REQ_EN) >> 8;
534 ep_csr |= (1 << USBC_BP_TXCSR_D_DMA_REQ_MODE) >> 8;
535 writeb(ep_csr, (USBC_REG_TXCSR(addr) + 1));
536}
537
543static inline void usb_device_tx_clear_ep_dma(uint32_t addr) {
544 uint16_t ep_csr = 0;
545
546 /* clear auto_set, dma_tx_en, and mode1 bits in TX CSR register */
547 ep_csr = readb(USBC_REG_TXCSR(addr) + 1);
548 ep_csr &= ~((1 << USBC_BP_TXCSR_D_AUTOSET) >> 8);
549 ep_csr &= ~((1 << USBC_BP_TXCSR_D_DMA_REQ_EN) >> 8);
550 writeb(ep_csr, (USBC_REG_TXCSR(addr) + 1));
551
552 /* DMA_REQ_EN and DMA_REQ_MODE cannot be cleared in the same cycle */
553 ep_csr = readb(USBC_REG_TXCSR(addr) + 1);
554 ep_csr &= ~((1 << USBC_BP_TXCSR_D_DMA_REQ_MODE) >> 8);
555 writeb(ep_csr, (USBC_REG_TXCSR(addr) + 1));
556}
557
565 uint32_t temp = 0;
566
567 temp = readw(USBC_REG_TXCSR(addr));
569
570 return temp;
571}
572
580 uint32_t temp = 0;
581
582 temp = readw(USBC_REG_TXCSR(addr));
584
585 return temp;
586}
587
593static inline void usb_device_tx_write_data_half(uint32_t addr) {
594 uint16_t ep_csr = 0;
595
596 ep_csr = readw(USBC_REG_TXCSR(addr));
597 ep_csr |= 1 << USBC_BP_TXCSR_D_TX_READY;
598 ep_csr &= ~(1 << USBC_BP_TXCSR_D_UNDER_RUN);
599 writew(ep_csr, USBC_REG_TXCSR(addr));
600}
601
608 uint16_t ep_csr = 0;
609
610 ep_csr = readw(USBC_REG_TXCSR(addr));
611 ep_csr |= 1 << USBC_BP_TXCSR_D_TX_READY;
612 ep_csr &= ~(1 << USBC_BP_TXCSR_D_UNDER_RUN);
613 writew(ep_csr, USBC_REG_TXCSR(addr));
614}
615
624
634
640static inline void usb_device_tx_clear_stall(uint32_t addr) {
641 uint32_t reg_val;
642
643 reg_val = readw(USBC_REG_TXCSR(addr));
644 reg_val &= ~((1 << USBC_BP_TXCSR_D_SENT_STALL) | (1 << USBC_BP_TXCSR_D_SEND_STALL));
645 writew(reg_val, USBC_REG_TXCSR(addr));
646}
647
656
665
674
681 /* clear tx csr */
682 writew(0x00, USBC_REG_RXCSR(addr));
683
684 /* clear tx ep max packet */
685 writew(0x00, USBC_REG_RXMAXP(addr));
686}
687
696static inline void usb_device_rx_config_ep(uint32_t addr, uint32_t ts_type, uint32_t is_double_fifo, uint32_t ep_maxpkt) {
697 uint16_t reg_val = 0;
698 uint16_t temp = 0;
699
700 /* config tx csr */
702
703 if (is_double_fifo) {
705 }
706
707 /* config tx ep max packet */
708 reg_val = readw(USBC_REG_RXMAXP(addr));
709 temp = ep_maxpkt & ((1 << USBC_BP_RXMAXP_PACKET_COUNT) - 1);
710 reg_val &= ~(0x1fff); /*added by jerry*/
711 reg_val |= temp;
712 writew(reg_val, USBC_REG_RXMAXP(addr));
713
714 /* config ep transfer type */
715 switch (ts_type) {
716 case USBC_TS_TYPE_ISO:
718 break;
719 case USBC_TS_TYPE_INT:
721 break;
724 break;
725 default:
727 break;
728 }
729}
730
736static inline void usb_device_rx_config_ep_dma(uint32_t addr) {
737 uint16_t ep_csr = 0;
738
739 /* auto_clear, dma_rx_en, mode0 */
740 ep_csr = readb(USBC_REG_RXCSR(addr) + 1);
741 ep_csr |= ((1 << USBC_BP_RXCSR_D_AUTO_CLEAR) >> 8);
742 ep_csr &= ~((1 << USBC_BP_RXCSR_D_DMA_REQ_MODE) >> 8);
743 ep_csr |= ((1 << USBC_BP_RXCSR_D_DMA_REQ_EN) >> 8);
744 writeb(ep_csr, (USBC_REG_RXCSR(addr) + 1));
745}
746
752static inline void usb_device_rx_clear_ep_dma(uint32_t addr) {
753 uint16_t ep_csr = 0;
754
755 /*auto_clear, dma_rx_en, mode0*/
756 ep_csr = readb(USBC_REG_RXCSR(addr) + 1);
757 ep_csr &= ~((1 << USBC_BP_RXCSR_D_AUTO_CLEAR) >> 8);
758 ep_csr &= ~((1 << USBC_BP_RXCSR_D_DMA_REQ_MODE) >> 8);
759 ep_csr &= ~((1 << USBC_BP_RXCSR_D_DMA_REQ_EN) >> 8);
760 writeb(ep_csr, (USBC_REG_RXCSR(addr) + 1));
761}
762
772
778static inline void usb_device_rx_read_data_half(uint32_t addr) {
779 uint32_t reg_val = 0;
780
781 /*overrun, dataerr is used in iso transfer*/
782 reg_val = readw(USBC_REG_RXCSR(addr));
783 reg_val &= ~(1 << USBC_BP_RXCSR_D_RX_PKT_READY);
784 reg_val &= ~(1 << USBC_BP_RXCSR_D_OVERRUN);
785 reg_val &= ~(1 << USBC_BP_RXCSR_D_DATA_ERROR);
786 writew(reg_val, USBC_REG_RXCSR(addr));
787}
788
795 uint32_t reg_val = 0;
796
797 /*overrun, dataerr is used in iso transfer*/
798 reg_val = readw(USBC_REG_RXCSR(addr));
799 reg_val &= ~(1 << USBC_BP_RXCSR_D_RX_PKT_READY);
800 reg_val &= ~(1 << USBC_BP_RXCSR_D_OVERRUN);
801 reg_val &= ~(1 << USBC_BP_RXCSR_D_DATA_ERROR);
802 writew(reg_val, USBC_REG_RXCSR(addr));
803}
804
812static inline int usb_device_write_data_half(uint32_t addr, uint32_t ep_type) {
813 switch (ep_type) {
814 case USBC_EP_TYPE_EP0:
816 break;
817 case USBC_EP_TYPE_TX:
819 break;
820 case USBC_EP_TYPE_RX:
821 return -1;
822 default:
823 return -1;
824 }
825
826 return 0;
827}
828
836static inline int usb_device_write_data_complete(uint32_t addr, uint32_t ep_type) {
837 switch (ep_type) {
838 case USBC_EP_TYPE_EP0:
840 break;
841
842 case USBC_EP_TYPE_TX:
844 break;
845
846 case USBC_EP_TYPE_RX:
847 return -1;
848
849 default:
850 return -1;
851 }
852
853 return 0;
854}
855
863static inline int usb_device_read_data_half(uint32_t addr, uint32_t ep_type) {
864 switch (ep_type) {
865 case USBC_EP_TYPE_EP0:
867 break;
868
869 case USBC_EP_TYPE_TX:
870 return -1;
871
872 case USBC_EP_TYPE_RX:
874 break;
875
876 default:
877 return -1;
878 }
879
880 return 0;
881}
882
890static inline int usb_device_read_data_complete(uint32_t addr, uint32_t ep_type) {
891 switch (ep_type) {
892 case USBC_EP_TYPE_EP0:
894 break;
895
896 case USBC_EP_TYPE_TX:
897 return -1;
898
899 case USBC_EP_TYPE_RX:
901 break;
902
903 default:
904 return -1;
905 }
906
907 return 0;
908}
909
918
928
938
944static inline void usb_device_ep0_flush_fifo(uint32_t addr) {
946}
947
956
965
972
979void usb_device_set_address(uint64_t husb, uint8_t address);
980
988
996void usb_device_config_transfer_mode(uint64_t husb, uint8_t ts_type, uint8_t speed_mode);
997
1005
1013
1024int usb_device_config_ep(uint64_t husb, uint32_t ts_type, uint32_t ep_type, uint32_t is_double_fifo, uint32_t ep_maxpkt);
1025
1034
1042int usb_device_config_ep_dma(uint64_t husb, uint32_t ep_type);
1043
1051int usb_device_clear_ep_dma(uint64_t husb, uint32_t ep_type);
1052
1060int usb_device_get_ep_stall(uint64_t husb, uint32_t ep_type);
1061
1069int usb_device_ep_send_stall(uint64_t husb, uint32_t ep_type);
1070
1079
1087
1094
1103int usb_device_write_data_status(uint64_t husb, uint32_t ep_type, uint32_t complete);
1104
1113int usb_device_read_data_status(uint64_t husb, uint32_t ep_type, uint32_t complete);
1114
1123
1132
1141
1149
1156void usb_device_flush_fifo(uint64_t husb, uint32_t ep_type);
1157
1158
1159#endif// __USB_DEVICE_H__
u64_t uint64_t
Definition stdint.h:16
u32_t uint32_t
Definition stdint.h:13
u8_t uint8_t
Definition stdint.h:7
u16_t uint16_t
Definition stdint.h:10
#define writew(val, addr)
Write a 16-bit word value to the specified address.
Definition io.h:81
#define writeb(val, addr)
Write a byte value to the specified address.
Definition io.h:66
#define readb(addr)
Read a byte from the specified address.
Definition io.h:58
#define readw(addr)
Read a 16-bit word from the specified address.
Definition io.h:73
#define writel(val, addr)
Write a 32-bit double word value to the specified address.
Definition io.h:96
#define readl(addr)
Read a 32-bit double word from the specified address.
Definition io.h:88
#define USBC_BP_CSR0_D_SERVICED_SETUP_END
Definition reg-usb.h:329
#define USBC_BP_TXCSR_D_CLEAR_DATA_TOGGLE
Definition reg-usb.h:365
#define USBC_BP_RXCSR_D_FLUSH_FIFO
Definition reg-usb.h:410
#define USBC_BP_CSR0_D_SEND_STALL
Definition reg-usb.h:331
#define USBC_BP_TXCSR_D_FIFO_NOT_EMPTY
Definition reg-usb.h:370
#define USBC_BP_POWER_D_ISO_UPDATE_EN
Definition reg-usb.h:242
#define USBC_REG_PCTL(usbc_base_addr)
Definition reg-usb.h:109
#define USBC_BP_TXMAXP_PACKET_COUNT
Definition reg-usb.h:312
#define USBC_BP_CSR0_D_SETUP_END
Definition reg-usb.h:332
#define USBC_BP_RXCSR_D_AUTO_CLEAR
Definition reg-usb.h:400
#define USBC_BP_RXCSR_D_SENT_STALL
Definition reg-usb.h:408
#define USBC_BP_RXCSR_D_DATA_ERROR
Definition reg-usb.h:411
#define USBC_REG_TXMAXP(usbc_base_addr)
Definition reg-usb.h:119
#define USBC_REG_o_PCTL
Definition reg-usb.h:22
#define USBC_BP_TXCSR_D_DMA_REQ_EN
Definition reg-usb.h:361
#define USBC_BP_RXCSR_D_RX_PKT_READY
Definition reg-usb.h:414
#define USBC_BP_TXCSR_D_UNDER_RUN
Definition reg-usb.h:369
#define USBC_BP_CSR0_D_DATA_END
Definition reg-usb.h:333
#define USBC_BP_RXCSR_D_DMA_REQ_MODE
Definition reg-usb.h:404
#define USBC_BP_CSR0_D_FLUSH_FIFO
Definition reg-usb.h:328
#define USBC_REG_TXCSR(usbc_base_addr)
Definition reg-usb.h:122
#define USBC_BP_TXCSR_D_MODE
Definition reg-usb.h:360
#define USBC_BP_CSR0_D_RX_PKT_READY
Definition reg-usb.h:336
#define USBC_BP_CSR0_D_SERVICED_RX_PKT_READY
Definition reg-usb.h:330
#define USBC_BP_RXMAXP_PACKET_COUNT
Definition reg-usb.h:374
#define USBC_BP_CSR0_D_TX_PKT_READY
Definition reg-usb.h:335
#define USBC_BP_TXCSR_D_FLUSH_FIFO
Definition reg-usb.h:368
#define USBC_EP_TYPE_EP0
Definition reg-usb.h:529
#define USBC_BP_TXCSR_D_AUTOSET
Definition reg-usb.h:358
#define USBC_REG_RXMAXP(usbc_base_addr)
Definition reg-usb.h:124
#define USBC_EP_TYPE_TX
Definition reg-usb.h:530
#define USBC_BP_RXCSR_D_CLEAR_DATA_TOGGLE
Definition reg-usb.h:407
#define USBC_BP_TXCSR_D_DMA_REQ_MODE
Definition reg-usb.h:363
#define USBC_REG_RXCSR(usbc_base_addr)
Definition reg-usb.h:125
#define USBC_TS_TYPE_BULK
Definition reg-usb.h:509
#define USBC_BP_POWER_D_HIGH_SPEED_EN
Definition reg-usb.h:244
#define USBC_EP_TYPE_RX
Definition reg-usb.h:531
#define USBC_BP_RXCSR_D_SEND_STALL
Definition reg-usb.h:409
#define USBC_BP_TXCSR_D_ISO
Definition reg-usb.h:359
#define USBC_TS_TYPE_ISO
Definition reg-usb.h:507
#define USBC_TS_TYPE_INT
Definition reg-usb.h:508
#define USBC_BP_RXCSR_D_OVERRUN
Definition reg-usb.h:412
#define USBC_BP_TXCSR_D_SENT_STALL
Definition reg-usb.h:366
#define USBC_BP_TXCSR_D_TX_READY
Definition reg-usb.h:371
#define USBC_BP_TXCSR_D_SEND_STALL
Definition reg-usb.h:367
#define USBC_REG_CSR0(usbc_base_addr)
Definition reg-usb.h:121
#define USBC_BP_RXCSR_D_DMA_REQ_EN
Definition reg-usb.h:402
#define USBC_BP_RXCSR_D_ISO
Definition reg-usb.h:401
#define USBC_BP_CSR0_D_SENT_STALL
Definition reg-usb.h:334
#define usb_clear_bit16(bp, reg)
Definition usb.h:182
#define usb_set_bit16(bp, reg)
Definition usb.h:178
#define usb_get_bit16(bp, reg)
Definition usb.h:174
#define usb_set_bit8(bp, reg)
Definition usb.h:177
#define usb_clear_bit8(bp, reg)
Definition usb.h:181
static void usb_device_rx_send_stall(uint32_t addr)
Sends a stall on the receive endpoint of the USB device.
Definition usb_device.h:915
static void usb_device_rx_config_ep(uint32_t addr, uint32_t ts_type, uint32_t is_double_fifo, uint32_t ep_maxpkt)
Configures the receive endpoint of the USB device.
Definition usb_device.h:696
static int usb_device_write_data_complete(uint32_t addr, uint32_t ep_type)
Writes the rest of the data to the specified endpoint of the USB device.
Definition usb_device.h:836
static uint32_t usb_device_ep0_get_read_data_ready(uint32_t addr)
Check if Endpoint 0 (EP0) has received data ready flag for the USB device.
Definition usb_device.h:312
static uint32_t usb_device_rx_get_read_data_ready(uint32_t addr)
Checks if there is data ready to be read from the receive endpoint of the USB device.
Definition usb_device.h:769
int usb_device_clear_ep_dma(uint64_t husb, uint32_t ep_type)
Clear the DMA configuration for an endpoint of the USB device.
Definition usb_device.c:208
static void usb_device_tx_clear_ep_dma(uint32_t addr)
Clear the DMA transfer flag for the transmit endpoint (EP) of the USB device.
Definition usb_device.h:543
static uint32_t usb_device_tx_get_write_data_ready_fifo_empty(uint32_t addr)
Check if the FIFO of the transmit endpoint (EP) is empty for the USB device.
Definition usb_device.h:579
static void usb_device_transfer_type_ctrl(uint32_t addr)
Set the control transfer type for the USB device.
Definition usb_device.h:218
static void usb_device_transfer_type_int(uint32_t addr)
Set the interrupt transfer type for the USB device.
Definition usb_device.h:236
static void usb_device_transfer_type_default(uint32_t addr)
Disable all transfer types for the USB device.
Definition usb_device.h:209
static void usb_device_transfer_mode_ls(uint32_t addr)
Set the mode to Low Speed (LS) for the USB device.
Definition usb_device.h:283
int usb_device_config_ep_dma(uint64_t husb, uint32_t ep_type)
Configure an endpoint of the USB device to use DMA.
Definition usb_device.c:180
static void usb_device_ep0_send_stall(uint32_t addr)
Set the send stall flag for Endpoint 0 (EP0) of the USB device.
Definition usb_device.h:377
static void usb_device_config_dma_trans(uint32_t addr)
Configure the DMA transfer settings for the USB device.
Definition usb_device.h:467
static void usb_device_tx_send_stall(uint32_t addr)
Send a stall signal and flush the FIFO of the transmit endpoint (EP) of the USB device.
Definition usb_device.h:621
static void usb_device_ep0_clear_stall(uint32_t addr)
Clear the stall flag for Endpoint 0 (EP0) of the USB device.
Definition usb_device.h:386
static void usb_device_rx_read_data_half(uint32_t addr)
Reads half of the data from the receive endpoint of the USB device.
Definition usb_device.h:778
static void usb_device_transfer_mode_default(uint32_t addr)
Disable all transfer modes for the USB device.
Definition usb_device.h:254
uint32_t usb_device_get_read_data_ready(uint64_t husb, uint32_t ep_type)
Check if there is ready data to be read from an endpoint of the USB device.
Definition usb_device.c:364
static uint32_t usb_device_rx_get_ep_stall(uint32_t addr)
Gets the stall status of the specified endpoint of the USB device.
Definition usb_device.h:925
uint32_t usb_device_get_write_data_ready_fifo_empty(uint64_t husb, uint32_t ep_type)
Check if the FIFO of an endpoint of the USB device is empty and ready to write data.
Definition usb_device.c:413
int usb_device_read_data_status(uint64_t husb, uint32_t ep_type, uint32_t complete)
Check the read data status of an endpoint of the USB device.
Definition usb_device.c:350
static void usb_device_tx_config_ep_dma(uint32_t addr)
Configure the DMA transfer settings for the transmit endpoint (EP) of the USB device.
Definition usb_device.h:526
static uint32_t usb_device_ep0_get_stall(uint32_t addr)
Check if Endpoint 0 (EP0) has the stall flag set for the USB device.
Definition usb_device.h:368
static void usb_device_rx_clear_stall(uint32_t addr)
Clears the stall on the specified endpoint of the USB device.
Definition usb_device.h:934
static void usb_device_tx_bulk_ep_enable(uint32_t addr)
Enable bulk transfer for the USB device.
Definition usb_device.h:433
int usb_device_iso_update_enable(uint64_t husb)
Enable ISO update for the USB device.
Definition usb_device.c:437
static void usb_device_ep0_read_data_complete(uint32_t addr)
Clear the read data complete flag for Endpoint 0 (EP0) of the USB device.
Definition usb_device.h:340
static void usb_device_tx_write_data_complete(uint32_t addr)
Write all of the data to the transmit endpoint (EP) of the USB device.
Definition usb_device.h:607
static void usb_device_transfer_type_iso(uint32_t addr)
Set the ISO transfer type for the USB device.
Definition usb_device.h:227
void usb_device_connect_switch(uint64_t husb, uint32_t is_on)
Switch the USB device connection on or off.
Definition usb_device.c:101
int usb_device_ep_send_stall(uint64_t husb, uint32_t ep_type)
Send a stall condition on an endpoint of the USB device.
Definition usb_device.c:263
void usb_device_ctrl_clear_setup_end(uint64_t husb)
Clear the setup end status of the control endpoint of the USB device.
Definition usb_device.c:327
static void usb_device_ep0_config_ep0_default(uint32_t addr)
Configure Endpoint 0 (EP0) in default mode for the USB device.
Definition usb_device.h:293
static void usb_device_tx_write_data_half(uint32_t addr)
Write half of the data to the transmit endpoint (EP) of the USB device.
Definition usb_device.h:593
uint32_t usb_device_query_transfer_mode(uint64_t husb)
Query the transfer mode of the USB device.
Definition usb_device.c:39
static void usb_device_ep0_write_data_complete(uint32_t addr)
Set the write data complete flag for Endpoint 0 (EP0) of the USB device.
Definition usb_device.h:358
void usb_device_config_transfer_mode(uint64_t husb, uint8_t ts_type, uint8_t speed_mode)
Configure the transfer mode of the USB device.
Definition usb_device.c:53
static void usb_device_rx_clear_ep_dma(uint32_t addr)
Clears the DMA configuration for the receive endpoint of the USB device.
Definition usb_device.h:752
static void usb_device_rx_config_ep_dma(uint32_t addr)
Configures the DMA for the receive endpoint of the USB device.
Definition usb_device.h:736
static void usb_device_rx_config_ep_default(uint32_t addr)
Configure the default settings for the receive endpoint (EP) of the USB device.
Definition usb_device.h:680
static void usb_device_transfer_mode_hs(uint32_t addr)
Set the mode to High Speed (HS) for the USB device.
Definition usb_device.h:263
static void usb_device_tx_config_ep_default(uint32_t addr)
Configure the default settings for the transmit endpoint (EP) of the USB device.
Definition usb_device.h:442
int usb_device_write_data_status(uint64_t husb, uint32_t ep_type, uint32_t complete)
Check the write data status of an endpoint of the USB device.
Definition usb_device.c:336
static void usb_device_transfer_mode_fs(uint32_t addr)
Set the mode to Full Speed (FS) for the USB device.
Definition usb_device.h:272
uint32_t usb_device_query_power_status(uint64_t husb)
Query the power status of the USB device.
Definition usb_device.c:115
uint32_t usb_device_get_write_data_ready(uint64_t husb, uint32_t ep_type)
Check if an endpoint of the USB device is ready to write data.
Definition usb_device.c:389
static uint32_t usb_device_tx_get_ep_stall(uint32_t addr)
Check if the transmit endpoint (EP) of the USB device is stalled.
Definition usb_device.h:631
static void usb_device_ep0_read_data_half(uint32_t addr)
Clear the read data half flag for Endpoint 0 (EP0) of the USB device.
Definition usb_device.h:331
static void usb_device_transfer_type_bulk(uint32_t addr)
Set the bulk transfer type for the USB device.
Definition usb_device.h:245
static void usb_device_ep0_flush_fifo(uint32_t addr)
Flushes the FIFO for endpoint 0 of the USB device.
Definition usb_device.h:944
static void usb_device_rx_enable_iso_ep(uint32_t addr)
Enable the isochronous transfer type for the receive endpoint (EP) of the USB device.
Definition usb_device.h:653
static void usb_device_rx_enable_bulk_ep(uint32_t addr)
Enable the bulk transfer type for the receive endpoint (EP) of the USB device.
Definition usb_device.h:671
static int usb_device_write_data_half(uint32_t addr, uint32_t ep_type)
Writes half of the data to the specified endpoint of the USB device.
Definition usb_device.h:812
int usb_device_config_ep(uint64_t husb, uint32_t ts_type, uint32_t ep_type, uint32_t is_double_fifo, uint32_t ep_maxpkt)
Configure an endpoint of the USB device.
Definition usb_device.c:126
static void usb_device_ep0_write_data_half(uint32_t addr)
Clear the write data half flag for Endpoint 0 (EP0) of the USB device.
Definition usb_device.h:349
static void usb_device_rx_read_data_complete(uint32_t addr)
Reads the rest of the data from the receive endpoint of the USB device.
Definition usb_device.h:794
static void usb_device_ep0_clear_setup_end(uint32_t addr)
Clear the setup end flag for Endpoint 0 (EP0) of the USB device.
Definition usb_device.h:406
static void usb_device_tx_config_ep(uint32_t addr, uint32_t ts_type, uint32_t is_double_fifo, uint32_t ep_maxpkt)
Configure the transmit endpoint (EP) of the USB device.
Definition usb_device.h:483
static void usb_device_tx_int_ep_enable(uint32_t addr)
Enable interrupt transfer for the USB device.
Definition usb_device.h:424
static uint32_t usb_device_ep0_get_write_data_ready(uint32_t addr)
Check if Endpoint 0 (EP0) has write data ready flag for the USB device.
Definition usb_device.h:322
static void usb_device_rx_enable_int_ep(uint32_t addr)
Enable the interrupt transfer type for the receive endpoint (EP) of the USB device.
Definition usb_device.h:662
static int usb_device_read_data_complete(uint32_t addr, uint32_t ep_type)
Reads the rest of the data from the specified endpoint of the USB device.
Definition usb_device.h:890
static void usb_device_tx_flush_fifo(uint32_t addr)
Flushes the transmit FIFO for the specified endpoint of the USB device.
Definition usb_device.h:953
static int usb_device_read_data_half(uint32_t addr, uint32_t ep_type)
Reads half of the data from the specified endpoint of the USB device.
Definition usb_device.h:863
int usb_device_config_ep_default(uint64_t husb, uint32_t ep_type)
Configure a default endpoint of the USB device.
Definition usb_device.c:153
static void usb_device_rx_flush_fifo(uint32_t addr)
Flushes the receive FIFO for the specified endpoint of the USB device.
Definition usb_device.h:962
static void usb_device_tx_iso_ep_enable(uint32_t addr)
Enable ISO transfer for the USB device.
Definition usb_device.h:415
static uint32_t usb_device_ep0_get_setup_end(uint32_t addr)
Check if Endpoint 0 (EP0) has the setup end flag set for the USB device.
Definition usb_device.h:397
static uint32_t usb_device_tx_get_write_data_ready(uint32_t addr)
Check if the transmit endpoint (EP) is ready to write data for the USB device.
Definition usb_device.h:564
uint32_t usb_device_ctrl_get_setup_end(uint64_t husb)
Get the setup end status of the control endpoint of the USB device.
Definition usb_device.c:317
void usb_device_flush_fifo(uint64_t husb, uint32_t ep_type)
Flush the FIFO of an endpoint of the USB device.
Definition usb_device.c:448
static void usb_device_ep0_config_ep0(uint32_t addr)
Configure Endpoint 0 (EP0) for the USB device.
Definition usb_device.h:302
static void usb_device_tx_clear_stall(uint32_t addr)
Clear the stall signal and reset the FIFO of the transmit endpoint (EP) of the USB device.
Definition usb_device.h:640
void usb_device_set_address_default(uint64_t husb)
Set the default address for the USB device.
Definition usb_device.c:19
int usb_device_get_ep_stall(uint64_t husb, uint32_t ep_type)
Get the stall status of an endpoint of the USB device.
Definition usb_device.c:236
static void usb_device_clear_dma_trans(uint32_t addr)
Clear the DMA transfer flag for the USB device.
Definition usb_device.h:454
void usb_device_set_address(uint64_t husb, uint8_t address)
Set the address for the USB device.
Definition usb_device.c:29
int usb_device_ep_clear_stall(uint64_t husb, uint32_t ep_type)
Clear the stall condition on an endpoint of the USB device.
Definition usb_device.c:290