1 /*
2 * Copyright 2022 NXP
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #ifndef _FSL_MEMORY_H_
8 #define _FSL_MEMORY_H_
9
10 #include "fsl_common.h"
11
12 /*******************************************************************************
13 * Definitions
14 ******************************************************************************/
15 /* Component ID definition, used by tools. */
16 #ifndef FSL_COMPONENT_ID
17 #define FSL_COMPONENT_ID "platform.drivers.memory"
18 #endif
19
20 #if (__CORTEX_M == 33U)
21 /* The CM33 subsystem local TCM start address, refer to Reference Manual for detailed information */
22 #define FSL_MEM_M33_TCM_BEGIN 0x20000000U
23 /* The CM33 subsystem local TCM end address, refer to Reference Manual for detailed information */
24 #define FSL_MEM_M33_TCM_END 0x2003FFFFU
25
26 #define FSL_MEM_M33_TCM_OFFSET 0x200000U
27 #elif (__CORTEX_M == 7U)
28 /* The CM7 subsystem local TCM start address, refer to Reference Manual for detailed information */
29 #define FSL_MEM_M7_TCM_BEGIN 0x2000000U
30 /* The CM7 subsystem local TCM end address, refer to Reference Manual for detailed information */
31 #define FSL_MEM_M7_TCM_END 0x2007FFFFU
32
33 #define FSL_MEM_M7_TCM_OFFSET 0x400000U
34 #else
35 #error "Device is not supported by this driver!"
36 #endif
37
38 typedef enum _mem_direction
39 {
40 kMEMORY_Local2DMA = 0,
41 kMEMORY_DMA2Local,
42 } mem_direction_t;
43
44 /*******************************************************************************
45 * API
46 ******************************************************************************/
47 #if defined(__cplusplus)
48 extern "C" {
49 #endif
50 /*!
51 * @brief Convert the memory map address.
52 *
53 * This function convert the address between system mapped address and native mapped address.
54 * There maybe offset between subsystem native address and system address for some memory,
55 * this funciton convert the address to different memory map.
56 * @param addr address need to be converted.
57 * @param direction convert direction.
58 * @return the converted address
59 */
MEMORY_ConvertMemoryMapAddress(uint32_t addr,mem_direction_t direction)60 static inline uint32_t MEMORY_ConvertMemoryMapAddress(uint32_t addr, mem_direction_t direction)
61 {
62 uint32_t dest;
63
64 switch (direction)
65 {
66 case kMEMORY_Local2DMA:
67 {
68 #if (__CORTEX_M == 33U)
69 if ((addr >= FSL_MEM_M33_TCM_BEGIN) && (addr <= FSL_MEM_M33_TCM_END))
70 {
71 dest = addr + FSL_MEM_M33_TCM_OFFSET;
72 }
73 #elif (__CORTEX_M == 7U)
74 if ((addr > FSL_MEM_M7_TCM_BEGIN) && (addr <= FSL_MEM_M7_TCM_END))
75 {
76 dest = addr + FSL_MEM_M7_TCM_OFFSET;
77 }
78 #endif
79 else
80 {
81 dest = addr;
82 }
83 break;
84 }
85 case kMEMORY_DMA2Local:
86 {
87 #if (__CORTEX_M == 33U)
88 if ((addr >= (FSL_MEM_M33_TCM_BEGIN + FSL_MEM_M33_TCM_OFFSET)) &&
89 (addr <= (FSL_MEM_M33_TCM_END + FSL_MEM_M33_TCM_OFFSET)))
90 {
91 dest = addr - FSL_MEM_M33_TCM_OFFSET;
92 }
93 #elif (__CORTEX_M == 7U)
94 if ((addr >= (FSL_MEM_M7_TCM_BEGIN + FSL_MEM_M7_TCM_OFFSET)) &&
95 (addr <= (FSL_MEM_M7_TCM_END + FSL_MEM_M7_TCM_OFFSET)))
96 {
97 dest = addr - FSL_MEM_M7_TCM_OFFSET;
98 }
99 #endif
100 else
101 {
102 dest = addr;
103 }
104 break;
105 }
106 default:
107 dest = addr;
108 break;
109 }
110
111 return dest;
112 }
113 #if defined(__cplusplus)
114 }
115 #endif /* __cplusplus */
116 #endif /* _FSL_MEMORY_H_ */
117