mikroSDK Reference Manual
dwc2_gd32.h
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2021, Ha Thach (tinyusb.org)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
27
28#ifndef DWC2_GD32_H_
29#define DWC2_GD32_H_
30
31#ifdef __cplusplus
32 extern "C" {
33#endif
34
35#ifdef __PROJECT_MIKROSDK_MIKROE__
36// Note: Added for MikroE implementation.
37#include "interrupts.h"
38#endif
39
40#define DWC2_REG_BASE 0x50000000UL
41#define DWC2_EP_MAX 4
42
43static const dwc2_controller_t _dwc2_controller[] =
44{
45 { .reg_base = DWC2_REG_BASE, .irqnum = 86, .ep_count = DWC2_EP_MAX, .ep_fifo_size = 1280 }
46};
47
48extern uint32_t SystemCoreClock;
49
50// The GD32VF103 is a RISC-V MCU, which implements the ECLIC Core-Local
51// Interrupt Controller by Nuclei. It is nearly API compatible to the
52// NVIC used by ARM MCUs.
53#define ECLIC_INTERRUPT_ENABLE_BASE 0xD2001001UL
54
55TU_ATTR_ALWAYS_INLINE
56static inline void __eclic_enable_interrupt (uint32_t irq) {
57 *(volatile uint8_t*)(ECLIC_INTERRUPT_ENABLE_BASE + (irq * 4)) = 1;
58}
59
60TU_ATTR_ALWAYS_INLINE
61static inline void __eclic_disable_interrupt (uint32_t irq){
62 *(volatile uint8_t*)(ECLIC_INTERRUPT_ENABLE_BASE + (irq * 4)) = 0;
63}
64
65TU_ATTR_ALWAYS_INLINE
66static inline void dwc2_dcd_int_enable(uint8_t rhport)
67{
68 #ifdef __PROJECT_MIKROSDK_MIKROE__
69 // Note: Added for MikroE implementation.
70 interrupt_enable(_dwc2_controller[rhport].irqnum);
71 #else
72 __eclic_enable_interrupt(_dwc2_controller[rhport].irqnum);
73 #endif
74}
75
76TU_ATTR_ALWAYS_INLINE
77static inline void dwc2_dcd_int_disable (uint8_t rhport)
78{
79 #ifdef __PROJECT_MIKROSDK_MIKROE__
80 // Note: Added for MikroE implementation.
81 interrupt_disable(_dwc2_controller[rhport].irqnum);
82 #else
83 __eclic_disable_interrupt(_dwc2_controller[rhport].irqnum);
84 #endif
85}
86
87static inline void dwc2_remote_wakeup_delay(void)
88{
89 // try to delay for 1 ms
90 uint32_t count = SystemCoreClock / 1000;
91 while ( count-- ) __asm volatile ("nop");
92}
93
94// MCU specific PHY init, called BEFORE core reset
95static inline void dwc2_phy_init(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
96{
97 (void) dwc2;
98 (void) hs_phy_type;
99
100 // nothing to do
101}
102
103// MCU specific PHY update, it is called AFTER init() and core reset
104static inline void dwc2_phy_update(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
105{
106 (void) dwc2;
107 (void) hs_phy_type;
108
109 // nothing to do
110}
111
112#ifdef __cplusplus
113}
114#endif
115
116#endif /* DWC2_GD32_H_ */
Definition dwc2_type.h:28
Definition dwc2_type.h:191