• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _USB_EHCI_PRIV_H
2 #define _USB_EHCI_PRIV_H
3 
4 #include "usbh_core.h"
5 #include "usbh_hub.h"
6 #include "usb_hc_ehci.h"
7 
8 #ifndef USBH_IRQHandler
9 #define USBH_IRQHandler USBH_IRQHandler
10 #endif
11 
12 #define EHCI_HCCR        ((struct ehci_hccr *)CONFIG_USB_EHCI_HCCR_BASE)
13 #define EHCI_HCOR        ((struct ehci_hcor *)CONFIG_USB_EHCI_HCOR_BASE)
14 
15 #define EHCI_PTR2ADDR(x) ((uint32_t)(x) & ~0x1F)
16 #define EHCI_ADDR2QH(x)  ((struct ehci_qh_hw *)((uint32_t)(x) & ~0x1F))
17 #define EHCI_ADDR2QTD(x) ((struct ehci_qtd_hw *)((uint32_t)(x) & ~0x1F))
18 #define EHCI_ADDR2ITD(x) ((struct ehci_itd_hw *)((uint32_t)(x) & ~0x1F))
19 
20 #if CONFIG_USB_EHCI_FRAME_LIST_SIZE == 1024
21 #define EHCI_PERIOIDIC_QH_NUM 11
22 #elif CONFIG_USB_EHCI_FRAME_LIST_SIZE == 512
23 #define EHCI_PERIOIDIC_QH_NUM 10
24 #elif CONFIG_USB_EHCI_FRAME_LIST_SIZE == 256
25 #define EHCI_PERIOIDIC_QH_NUM 9
26 #else
27 #error Unsupported frame size list size
28 #endif
29 
30 #define CONFIG_USB_EHCI_QH_NUM  CONFIG_USBHOST_PIPE_NUM
31 #define CONFIG_USB_EHCI_QTD_NUM (CONFIG_USBHOST_PIPE_NUM * 3)
32 #define CONFIG_USB_EHCI_ITD_NUM 20
33 
34 extern uint8_t usbh_get_port_speed(const uint8_t port);
35 
36 struct ehci_qh_hw;
37 struct ehci_itd_hw;
38 struct ehci_pipe {
39     uint8_t dev_addr;
40     uint8_t ep_addr;
41     uint8_t ep_type;
42     uint8_t ep_interval;
43     uint8_t speed;
44     uint8_t mult;
45     uint16_t ep_mps;
46     bool toggle;
47     bool inuse;
48     uint32_t xfrd;
49     bool waiter;
50     usb_osal_sem_t waitsem;
51     struct usbh_hubport *hport;
52     struct usbh_urb *urb;
53     uint8_t mf_unmask;
54     uint8_t mf_valid;
55     uint8_t iso_packet_idx;
56     uint8_t remain_itd_num;
57 };
58 
59 struct ehci_qh_hw {
60     struct ehci_qh hw;
61     uint32_t first_qtd;
62     struct usbh_urb *urb;
63     uint8_t remove_in_iaad;
64 } __attribute__((aligned(32)));
65 
66 struct ehci_qtd_hw {
67     struct ehci_qtd hw;
68     struct usbh_urb *urb;
69     uint32_t total_len;
70 } __attribute__((aligned(32)));
71 
72 struct ehci_itd_hw {
73     struct ehci_itd hw;
74     struct usbh_urb *urb;
75     struct ehci_pipe *pipe;
76     uint16_t start_frame;
77     usb_slist_t list;
78 } __attribute__((aligned(32)));
79 
80 struct ehci_hcd {
81     bool ehci_qh_used[CONFIG_USB_EHCI_QH_NUM];
82     bool ehci_qtd_used[CONFIG_USB_EHCI_QTD_NUM];
83     bool ehci_itd_used[CONFIG_USB_EHCI_ITD_NUM];
84     struct ehci_pipe pipe_pool[CONFIG_USB_EHCI_QH_NUM];
85 };
86 
87 extern struct ehci_hcd g_ehci_hcd;
88 extern uint32_t g_framelist[];
89 
90 int ehci_iso_pipe_init(struct ehci_pipe *pipe, struct usbh_urb *urb);
91 void ehci_remove_itd_urb(struct usbh_urb *urb);
92 void ehci_scan_isochronous_list(void);
93 
94 #endif