1 /*
2 * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
3 * Copyright 2016-2020 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #ifndef _FSL_COMMON_DSP_H_
10 #define _FSL_COMMON_DSP_H_
11
12 /*!
13 * @addtogroup ksdk_common
14 * @{
15 */
16
17 /*******************************************************************************
18 * Definitions
19 ******************************************************************************/
20
21 /*! @name Timer utilities */
22 /* @{ */
23 /*! Macro to convert a microsecond period to raw count value */
24 #define USEC_TO_COUNT(us, clockFreqInHz) (uint64_t)(((uint64_t)(us) * (clockFreqInHz)) / 1000000U)
25 /*! Macro to convert a raw count value to microsecond */
26 #define COUNT_TO_USEC(count, clockFreqInHz) (uint64_t)((uint64_t)(count) * 1000000U / (clockFreqInHz))
27
28 /*! Macro to convert a millisecond period to raw count value */
29 #define MSEC_TO_COUNT(ms, clockFreqInHz) (uint64_t)((uint64_t)(ms) * (clockFreqInHz) / 1000U)
30 /*! Macro to convert a raw count value to millisecond */
31 #define COUNT_TO_MSEC(count, clockFreqInHz) (uint64_t)((uint64_t)(count) * 1000U / (clockFreqInHz))
32 /* @} */
33
34 #define SDK_ISR_EXIT_BARRIER
35
36 /*! @name Alignment variable definition macros */
37 /* @{ */
38 /*! Macro to define a variable with alignbytes alignment */
39 #define SDK_ALIGN(var, alignbytes) var __attribute__((aligned(alignbytes)))
40
41 /*! Macro to define a variable with L1 d-cache line size alignment */
42 #if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
43 #define SDK_L1DCACHE_ALIGN(var) SDK_ALIGN(var, FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
44 #endif
45
46 /*! Macro to define a variable with L2 cache line size alignment */
47 #if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)
48 #define SDK_L2CACHE_ALIGN(var) SDK_ALIGN(var, FSL_FEATURE_L2CACHE_LINESIZE_BYTE)
49 #endif
50
51 /*! Macro to change a value to a given size aligned value */
52 #define SDK_SIZEALIGN(var, alignbytes) \
53 ((unsigned int)((var) + ((alignbytes)-1U)) & (unsigned int)(~(unsigned int)((alignbytes)-1U)))
54 /* @} */
55
56 /*! @name Non-cacheable region definition macros */
57 /* For initialized non-zero non-cacheable variables, please using "AT_NONCACHEABLE_SECTION_INIT(var) ={xx};" or
58 * "AT_NONCACHEABLE_SECTION_ALIGN_INIT(var) ={xx};" in your projects to define them, for zero-inited non-cacheable variables,
59 * please using "AT_NONCACHEABLE_SECTION(var);" or "AT_NONCACHEABLE_SECTION_ALIGN(var);" to define them, these zero-inited variables
60 * will be initialized to zero in system startup.
61 */
62 /* @{ */
63
64 #define AT_NONCACHEABLE_SECTION_INIT(var) __attribute__((section("NonCacheable.init"))) var
65 #define AT_NONCACHEABLE_SECTION(var) __attribute__((section("NonCacheable"))) var
66 #define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) \
67 __attribute__((section("NonCacheable.init"))) var __attribute__((aligned(alignbytes)))
68 #define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \
69 __attribute__((section("NonCacheable"))) var __attribute__((aligned(alignbytes)))
70
71 /* @} */
72
73 /*!
74 * @name Time sensitive region
75 * @{
76 */
77 #if (defined(FSL_SDK_DRIVER_QUICK_ACCESS_ENABLE) && FSL_SDK_DRIVER_QUICK_ACCESS_ENABLE)
78
79 #define AT_QUICKACCESS_SECTION_CODE(func) __attribute__((section("CodeQuickAccess"), __noinline__)) func
80 #define AT_QUICKACCESS_SECTION_DATA(func) __attribute__((section("DataQuickAccess"))) func
81
82 #else /* __FSL_SDK_DRIVER_QUICK_ACCESS_ENABLE */
83
84 #define AT_QUICKACCESS_SECTION_CODE(func) func
85 #define AT_QUICKACCESS_SECTION_DATA(func) func
86
87 #endif /* __FSL_SDK_DRIVER_QUICK_ACCESS_ENABLE */
88 /* @} */
89
90 /* Macros for compatibility. */
91 #define NVIC_SetPriorityGrouping(value) do {} while(0)
92 #define NVIC_GetPriorityGrouping() do {} while(0)
93 #define NVIC_EnableIRQ(value) do {} while(0)
94 #define NVIC_GetEnableIRQ(value) do {} while(0)
95 #define NVIC_DisableIRQ(value) do {} while(0)
96 #define NVIC_GetPendingIRQ(value) do {} while(0)
97 #define NVIC_SetPendingIRQ(value) do {} while(0)
98 #define NVIC_ClearPendingIRQ(value) do {} while(0)
99 #define NVIC_GetActive(value) do {} while(0)
100
101 /*
102 * The fsl_clock.h is included here because it needs MAKE_VERSION/MAKE_STATUS/status_t
103 * defined in previous of this file.
104 */
105 #include "fsl_clock.h"
106
107 /*******************************************************************************
108 * API
109 ******************************************************************************/
110
111 #if defined(__cplusplus)
112 extern "C" {
113 #endif
114
115 /*!
116 * @brief Enable specific interrupt.
117 *
118 * Empty function for build compatibility.
119 *
120 * @param interrupt The IRQ number.
121 * @return Always return kStatus_Success.
122 */
EnableIRQ(IRQn_Type interrupt)123 static inline status_t EnableIRQ(IRQn_Type interrupt)
124 {
125 return kStatus_Success;
126 }
127
128 /*!
129 * @brief Disable specific interrupt.
130 *
131 * Empty function for build compatibility.
132 *
133 * @param interrupt The IRQ number.
134 * @return Always return kStatus_Success.
135 */
DisableIRQ(IRQn_Type interrupt)136 static inline status_t DisableIRQ(IRQn_Type interrupt)
137 {
138 return kStatus_Success;
139 }
140
141 /*!
142 * @brief Disable the global IRQ
143 *
144 * Empty function for build compatibility.
145 *
146 * @return Always return 0;
147 */
DisableGlobalIRQ(void)148 static inline uint32_t DisableGlobalIRQ(void)
149 {
150 return 0;
151 }
152
153 /*!
154 * @brief Enable the global IRQ
155 *
156 * Empty function for build compatibility.
157 *
158 * @param primask Not used.
159 */
EnableGlobalIRQ(uint32_t primask)160 static inline void EnableGlobalIRQ(uint32_t primask)
161 {
162 }
163
164 #if defined(__cplusplus)
165 }
166 #endif
167
168 /*! @} */
169
170 #endif /* _FSL_COMMON_DSP_H_ */
171