mikroSDK Reference Manual
ci_hs_imxrt.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#ifndef _CI_HS_IMXRT_H_
28#define _CI_HS_IMXRT_H_
29
30#include "fsl_device_registers.h"
31
32#if !defined(USB1_BASE) && defined(USB_OTG1_BASE)
33#define USB1_BASE USB_OTG1_BASE
34#endif
35
36#if !defined(USB2_BASE) && defined(USB_OTG2_BASE)
37#define USB2_BASE USB_OTG2_BASE
38#endif
39
40// RT1040 calls its only USB USB_OTG (no 1)
41#if defined(MIMXRT1042_SERIES)
42#define USB_OTG1_IRQn USB_OTG_IRQn
43#endif
44
45static const ci_hs_controller_t _ci_controller[] =
46{
47 // RT1010 and RT1020 only has 1 USB controller
48 #if FSL_FEATURE_SOC_USBHS_COUNT == 1
49 { .reg_base = USB_BASE , .irqnum = USB_OTG1_IRQn }
50 #else
51 { .reg_base = USB1_BASE, .irqnum = USB_OTG1_IRQn},
52 { .reg_base = USB2_BASE, .irqnum = USB_OTG2_IRQn}
53 #endif
54};
55
56#define CI_HS_REG(_port) ((ci_hs_regs_t*) _ci_controller[_port].reg_base)
57
58//------------- DCD -------------//
59#define CI_DCD_INT_ENABLE(_p) NVIC_EnableIRQ (_ci_controller[_p].irqnum)
60#define CI_DCD_INT_DISABLE(_p) NVIC_DisableIRQ(_ci_controller[_p].irqnum)
61
62//------------- HCD -------------//
63#define CI_HCD_INT_ENABLE(_p) NVIC_EnableIRQ (_ci_controller[_p].irqnum)
64#define CI_HCD_INT_DISABLE(_p) NVIC_DisableIRQ(_ci_controller[_p].irqnum)
65
66//------------- DCache -------------//
67TU_ATTR_ALWAYS_INLINE static inline bool imxrt_is_cache_mem(uintptr_t addr) {
68 return !(0x20000000 <= addr && addr < 0x20100000);
69}
70
71TU_ATTR_ALWAYS_INLINE static inline bool imxrt_dcache_clean(void const* addr, uint32_t data_size) {
72 const uintptr_t addr32 = (uintptr_t) addr;
73 if (imxrt_is_cache_mem(addr32)) {
74 TU_ASSERT(tu_is_aligned32(addr32));
75 SCB_CleanDCache_by_Addr((uint32_t *) addr32, (int32_t) data_size);
76 }
77 return true;
78}
79
80TU_ATTR_ALWAYS_INLINE static inline bool imxrt_dcache_invalidate(void const* addr, uint32_t data_size) {
81 const uintptr_t addr32 = (uintptr_t) addr;
82 if (imxrt_is_cache_mem(addr32)) {
83 // Invalidating does not push cached changes back to RAM so we need to be
84 // *very* careful when we do it. If we're not aligned, then we risk resetting
85 // values back to their RAM state.
86 TU_ASSERT(tu_is_aligned32(addr32));
87 SCB_InvalidateDCache_by_Addr((void*) addr32, (int32_t) data_size);
88 }
89 return true;
90}
91
92TU_ATTR_ALWAYS_INLINE static inline bool imxrt_dcache_clean_invalidate(void const* addr, uint32_t data_size) {
93 const uintptr_t addr32 = (uintptr_t) addr;
94 if (imxrt_is_cache_mem(addr32)) {
95 TU_ASSERT(tu_is_aligned32(addr32));
96 SCB_CleanInvalidateDCache_by_Addr((uint32_t *) addr32, (int32_t) data_size);
97 }
98 return true;
99}
100
101#endif
__STATIC_FORCEINLINE void SCB_CleanInvalidateDCache_by_Addr(uint32_t *addr, int32_t dsize)
D-Cache Clean and Invalidate by address.
Definition core_cm7.h:2572
__STATIC_FORCEINLINE void SCB_InvalidateDCache_by_Addr(void *addr, int32_t dsize)
D-Cache Invalidate by address.
Definition core_cm7.h:2512
__STATIC_FORCEINLINE void SCB_CleanDCache_by_Addr(uint32_t *addr, int32_t dsize)
D-Cache Clean by address.
Definition core_cm7.h:2542
Definition ci_hs_type.h:143