mikroSDK Reference Manual
dwc2_xmc.h
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2021 Rafael Silva (@perigoso)
5 * Copyright (c) 2021, Ha Thach (tinyusb.org)
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 *
25 * This file is part of the TinyUSB stack.
26 */
27
28#ifndef _DWC2_XMC_H_
29#define _DWC2_XMC_H_
30
31#ifdef __cplusplus
32 extern "C" {
33#endif
34
35#include "xmc_device.h"
36
37#define DWC2_EP_MAX 7
38
39static const dwc2_controller_t _dwc2_controller[] =
40{
41 // Note: XMC has some custom control registers before DWC registers
42 { .reg_base = USB0_BASE, .irqnum = USB0_0_IRQn, .ep_count = DWC2_EP_MAX, .ep_fifo_size = 2048 }
43};
44
45TU_ATTR_ALWAYS_INLINE
46static inline void dwc2_dcd_int_enable(uint8_t rhport)
47{
48 NVIC_EnableIRQ(_dwc2_controller[rhport].irqnum);
49}
50
51TU_ATTR_ALWAYS_INLINE
52static inline void dwc2_dcd_int_disable (uint8_t rhport)
53{
54 NVIC_DisableIRQ(_dwc2_controller[rhport].irqnum);
55}
56
57static inline void dwc2_remote_wakeup_delay(void)
58{
59 // try to delay for 1 ms
60// uint32_t count = SystemCoreClock / 1000;
61// while ( count-- ) __NOP();
62}
63
64// MCU specific PHY init, called BEFORE core reset
65static inline void dwc2_phy_init(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
66{
67 (void) dwc2;
68 (void) hs_phy_type;
69
70 // Enable PHY
71 //USB->ROUTE = USB_ROUTE_PHYPEN;
72}
73
74// MCU specific PHY update, it is called AFTER init() and core reset
75static inline void dwc2_phy_update(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
76{
77 (void) dwc2;
78 (void) hs_phy_type;
79
80 // XMC Manual: turn around must be 5 (reset & default value)
81 // dwc2->gusbcfg = (dwc2->gusbcfg & ~GUSBCFG_TRDT_Msk) | (5u << GUSBCFG_TRDT_Pos);
82}
83
84#ifdef __cplusplus
85}
86#endif
87
88#endif
#define USB0_BASE
Definition MK60D10.h:12513
Definition dwc2_type.h:28
Definition dwc2_type.h:191