29#if CFG_TUD_ENABLED && defined(TUP_USBIP_CHIPIDEA_FS)
34#if defined(TUP_USBIP_CHIPIDEA_FS_KINETIS)
36#elif defined(TUP_USBIP_CHIPIDEA_FS_MCX)
39 #error "MCU is not supported"
111 uint8_t setup_packet[8];
125 const unsigned out_odd =
_dcd.endpoint[0][0].odd;
126 const unsigned in_odd =
_dcd.endpoint[0][1].odd;
127 TU_ASSERT(0 ==
_dcd.bdt[0][0][out_odd].own, );
129 _dcd.bdt[0][0][out_odd].data = 0;
130 _dcd.bdt[0][0][out_odd ^ 1].data = 1;
131 _dcd.bdt[0][1][in_odd].data = 1;
132 _dcd.bdt[0][1][in_odd ^ 1].data = 0;
134 _dcd.setup_packet,
sizeof(
_dcd.setup_packet));
139 for (
int i = 0; i < 16; ++i) {
140 uint32_t
const ep_ctl = CI_REG->EP[i].CTL;
142 if (ep_ctl & USB_ENDPT_EPSTALL_MASK) {
147 CI_REG->EP[i].CTL = ep_ctl & ~USB_ENDPT_EPSTALL_MASK;
154 const unsigned s = CI_REG->STAT;
155 CI_REG->INT_STAT = USB_ISTAT_TOKDNE_MASK;
157 uint8_t
const epnum = (s >> USB_STAT_ENDP_SHIFT);
158 uint8_t
const dir = (s & USB_STAT_TX_MASK) >> USB_STAT_TX_SHIFT;
159 unsigned const odd = (s & USB_STAT_ODD_MASK) ? 1 : 0;
165 const unsigned pid = bd->
tok_pid;
176 CI_REG->CTL &= ~USB_CTL_TXSUSPENDTOKENBUSY_MASK;
180 const unsigned bc = bd->
bc;
181 const unsigned remaining = ep->remaining - bc;
182 if (remaining && bc == ep->max_packet_size) {
184 ep->remaining = remaining;
185 const int next_remaining = remaining - ep->max_packet_size;
186 if (next_remaining > 0) {
188 bd->
addr += ep->max_packet_size * 2;
189 bd->
bc = next_remaining > ep->max_packet_size ? ep->max_packet_size: next_remaining;
195 const unsigned length = ep->length;
199 if (0 == epnum && 0 == length) {
205 CI_REG->ADDR =
_dcd.addr;
214 CI_REG->USBCTRL &= ~USB_USBCTRL_SUSP_MASK;
215 CI_REG->CTL |= USB_CTL_ODDRST_MASK;
217 CI_REG->INT_EN = USB_INTEN_USBRSTEN_MASK | USB_INTEN_TOKDNEEN_MASK | USB_INTEN_SLEEPEN_MASK |
218 USB_INTEN_ERROREN_MASK | USB_INTEN_STALLEN_MASK;
220 CI_REG->EP[0].CTL = USB_ENDPT_EPHSHK_MASK | USB_ENDPT_EPRXEN_MASK | USB_ENDPT_EPTXEN_MASK;
221 for (
unsigned i = 1; i < 16; ++i) {
222 CI_REG->EP[i].CTL = 0;
225 for (
unsigned i = 0; i <
sizeof(
_dcd.bdt)/
sizeof(*bd); ++i, ++bd) {
234 _dcd.endpoint[0][0] = ep0;
235 _dcd.endpoint[0][1] = ep0;
236 tu_memclr(
_dcd.endpoint[1],
sizeof(
_dcd.endpoint) -
sizeof(
_dcd.endpoint[0]));
239 CI_REG->CTL &= ~USB_CTL_ODDRST_MASK;
246 const unsigned inten = CI_REG->INT_EN;
248 CI_REG->INT_EN = (inten & ~USB_INTEN_SLEEPEN_MASK) | USB_INTEN_RESUMEEN_MASK;
249 CI_REG->USBTRC0 |= USB_USBTRC0_USBRESMEN_MASK;
250 CI_REG->USBCTRL |= USB_USBCTRL_SUSP_MASK;
258 const unsigned inten = CI_REG->INT_EN;
260 CI_REG->USBCTRL &= ~USB_USBCTRL_SUSP_MASK;
261 CI_REG->USBTRC0 &= ~USB_USBTRC0_USBRESMEN_MASK;
262 CI_REG->INT_EN = (inten & ~USB_INTEN_RESUMEEN_MASK) | USB_INTEN_SLEEPEN_MASK;
275 #if defined(FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED) && FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED == 1
276 uint32_t clk_recover_irc_en = CI_REG->CLK_RECOVER_IRC_EN;
277 uint32_t clk_recover_ctrl = CI_REG->CLK_RECOVER_CTRL;
280 CI_REG->USBTRC0 |= USB_USBTRC0_USBRESET_MASK;
281 while (CI_REG->USBTRC0 & USB_USBTRC0_USBRESET_MASK);
284 #if defined(FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED) && FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED == 1
285 CI_REG->CLK_RECOVER_IRC_EN = clk_recover_irc_en;
286 CI_REG->CLK_RECOVER_CTRL |= clk_recover_ctrl;
290 CI_REG->USBTRC0 |= TU_BIT(6);
291 CI_REG->BDT_PAGE1 = (uint8_t)((uintptr_t)
_dcd.bdt >> 8);
292 CI_REG->BDT_PAGE2 = (uint8_t)((uintptr_t)
_dcd.bdt >> 16);
293 CI_REG->BDT_PAGE3 = (uint8_t)((uintptr_t)
_dcd.bdt >> 24);
295 CI_REG->INT_EN = USB_INTEN_USBRSTEN_MASK;
313 CI_REG->CTL |= USB_CTL_RESUME_MASK;
316 while (cnt--) __NOP();
318 CI_REG->CTL &= ~USB_CTL_RESUME_MASK;
325 CI_REG->CONTROL |= USB_CONTROL_DPPULLUPNONOTG_MASK;
326 CI_REG->CTL |= USB_CTL_USBENSOFEN_MASK;
333 CI_REG->CONTROL &= ~USB_CONTROL_DPPULLUPNONOTG_MASK;
356 const unsigned odd = ep->
odd;
363 unsigned val = USB_ENDPT_EPCTLDIS_MASK;
365 val |= dir ? USB_ENDPT_EPTXEN_MASK : USB_ENDPT_EPRXEN_MASK;
366 CI_REG->EP[epn].CTL |= val;
372 bd[odd ^ 1].
data = 1;
382 for (
unsigned i = 1; i < 16; ++i) {
383 CI_REG->EP[i].CTL = 0;
389 for (
unsigned i = 2; i <
sizeof(
_dcd.bdt)/
sizeof(*bd); ++i, ++bd) {
394 for (
unsigned i = 2; i <
sizeof(
_dcd.endpoint)/
sizeof(*ep); ++i, ++ep) {
408 const unsigned msk = dir ? USB_ENDPT_EPTXEN_MASK : USB_ENDPT_EPRXEN_MASK;
412 CI_REG->EP[epn].CTL &= ~msk;
428 TU_ASSERT(0 == bd->
own);
460 CI_REG->EP[epn].CTL |= USB_ENDPT_EPSTALL_MASK;
463 const unsigned odd =
_dcd.endpoint[epn][dir].odd;
465 TU_ASSERT(0 == bd->
own,);
482 const unsigned odd =
_dcd.endpoint[epn][dir].odd;
484 TU_VERIFY(bd[odd].own,);
496 bd[odd ^ 1].
data = 1;
499 const uint32_t ep_ctl = CI_REG->EP[epn].CTL;
500 if (ep_ctl & USB_ENDPT_EPSTALL_MASK) {
501 CI_REG->EP[epn].CTL = ep_ctl & ~USB_ENDPT_EPSTALL_MASK;
512 uint32_t is = CI_REG->INT_STAT;
513 uint32_t msk = CI_REG->INT_EN;
516 CI_REG->INT_STAT = is & ~msk;
519 if (is & USB_ISTAT_ERROR_MASK) {
521 uint32_t es = CI_REG->ERR_STAT;
522 CI_REG->ERR_STAT = es;
523 CI_REG->INT_STAT = is;
526 if (is & USB_ISTAT_USBRST_MASK) {
527 CI_REG->INT_STAT = is;
531 if (is & USB_ISTAT_SLEEP_MASK) {
536 CI_REG->INT_STAT = USB_ISTAT_SLEEP_MASK;
541 if (is & USB_ISTAT_RESUME_MASK) {
543 KHCI->ISTAT = USB_ISTAT_RESUME_MASK;
548 if (CI_REG->USBTRC0 & USB_USBTRC0_USB_RESUME_INT_MASK) {
553 if (is & USB_ISTAT_SOFTOK_MASK) {
554 CI_REG->INT_STAT = USB_ISTAT_SOFTOK_MASK;
558 if (is & USB_ISTAT_STALL_MASK) {
559 CI_REG->INT_STAT = USB_ISTAT_STALL_MASK;
563 if (is & USB_ISTAT_TOKDNE_MASK) {
static TU_ATTR_ALWAYS_INLINE void dcd_event_bus_signal(uint8_t rhport, dcd_eventid_t eid, bool in_isr)
static TU_ATTR_ALWAYS_INLINE void dcd_event_xfer_complete(uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes, uint8_t result, bool in_isr)
static TU_ATTR_ALWAYS_INLINE void dcd_event_setup_received(uint8_t rhport, uint8_t const *setup, bool in_isr)
void dcd_int_disable(uint8_t rhport)
static TU_ATTR_ALWAYS_INLINE void dcd_event_bus_reset(uint8_t rhport, tusb_speed_t speed, bool in_isr)
void dcd_int_enable(uint8_t rhport)
static void process_bus_reset(uint8_t rhport)
struct TU_ATTR_PACKED endpoint_state_t
void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
void dcd_int_handler(uint8_t rhport)
void dcd_disconnect(uint8_t rhport)
static void process_tokdne(uint8_t rhport)
void dcd_edpt_close_all(uint8_t rhport)
bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *ep_desc)
void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
TU_VERIFY_STATIC(sizeof(buffer_descriptor_t)==8, "size is not correct")
static void process_stall(uint8_t rhport)
void dcd_connect(uint8_t rhport)
bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes)
CFG_TUD_MEM_SECTION TU_ATTR_ALIGNED(512)
void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
struct TU_ATTR_PACKED buffer_descriptor_t
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t *rh_init)
static void process_bus_sleep(uint8_t rhport)
void dcd_remote_wakeup(uint8_t rhport)
static void process_bus_resume(uint8_t rhport)
void dcd_sof_enable(uint8_t rhport, bool en)
xfer_td_t xfer[EP_CBI_COUNT+1][2]
static void prepare_next_setup_packet(uint8_t rhport)
AUDIO Channel Cluster Descriptor (4.1)
uint8_t data[CFG_TUD_NCM_IN_NTB_MAX_SIZE]
uint8_t bmAttributes
See: audio_clock_source_attribute_t.
static TU_ATTR_ALWAYS_INLINE uint8_t tu_edpt_number(uint8_t addr)
static TU_ATTR_ALWAYS_INLINE uint16_t tu_edpt_packet_size(tusb_desc_endpoint_t const *desc_ep)
TU_ATTR_PACKED_END TU_ATTR_BIT_FIELD_ORDER_END static TU_ATTR_ALWAYS_INLINE tusb_dir_t tu_edpt_dir(uint8_t addr)
static TU_ATTR_ALWAYS_INLINE uint8_t tu_edpt_addr(uint8_t num, uint8_t dir)