diff options
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1024/drivers/fsl_flexram_allocate.c')
-rw-r--r-- | lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1024/drivers/fsl_flexram_allocate.c | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1024/drivers/fsl_flexram_allocate.c b/lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1024/drivers/fsl_flexram_allocate.c new file mode 100644 index 000000000..2aa958521 --- /dev/null +++ b/lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1024/drivers/fsl_flexram_allocate.c | |||
@@ -0,0 +1,157 @@ | |||
1 | /* | ||
2 | * Copyright 2019-2020 NXP | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * | ||
6 | * SPDX-License-Identifier: BSD-3-Clause | ||
7 | */ | ||
8 | |||
9 | #include "fsl_flexram_allocate.h" | ||
10 | |||
11 | /******************************************************************************* | ||
12 | * Definitions | ||
13 | ******************************************************************************/ | ||
14 | |||
15 | /* Component ID definition, used by tools. */ | ||
16 | #ifndef FSL_COMPONENT_ID | ||
17 | #define FSL_COMPONENT_ID "driver.soc_flexram_allocate" | ||
18 | #endif | ||
19 | |||
20 | /******************************************************************************* | ||
21 | * Prototypes | ||
22 | ******************************************************************************/ | ||
23 | /*! | ||
24 | * @brief FLEXRAM map TCM size to register value | ||
25 | * | ||
26 | * @param tcmBankNum tcm banknumber | ||
27 | * @retval register value correspond to the tcm size | ||
28 | */ | ||
29 | static uint8_t FLEXRAM_MapTcmSizeToRegister(uint8_t tcmBankNum); | ||
30 | |||
31 | /******************************************************************************* | ||
32 | * Variables | ||
33 | ******************************************************************************/ | ||
34 | |||
35 | /******************************************************************************* | ||
36 | * Code | ||
37 | ******************************************************************************/ | ||
38 | static uint8_t FLEXRAM_MapTcmSizeToRegister(uint8_t tcmBankNum) | ||
39 | { | ||
40 | uint8_t tcmSizeConfig = 0U; | ||
41 | uint32_t totalTcmSize = 0U; | ||
42 | |||
43 | /* if bank number is a odd value, use a new bank number which bigger than target */ | ||
44 | do | ||
45 | { | ||
46 | if ((tcmBankNum & (tcmBankNum - 1U)) == 0U) | ||
47 | { | ||
48 | break; | ||
49 | } | ||
50 | } while (++tcmBankNum < (uint8_t)FSL_FEATURE_FLEXRAM_INTERNAL_RAM_TOTAL_BANK_NUMBERS); | ||
51 | |||
52 | totalTcmSize = (uint32_t)tcmBankNum * ((uint32_t)FSL_FEATURE_FLEXRAM_INTERNAL_RAM_BANK_SIZE >> 10U); | ||
53 | /* get bit '1' position */ | ||
54 | while (totalTcmSize != 0x00U) | ||
55 | { | ||
56 | if ((totalTcmSize & 1U) == 0U) | ||
57 | { | ||
58 | tcmSizeConfig++; | ||
59 | } | ||
60 | else | ||
61 | { | ||
62 | break; | ||
63 | } | ||
64 | totalTcmSize >>= 1U; | ||
65 | } | ||
66 | |||
67 | return tcmSizeConfig + 1U; | ||
68 | } | ||
69 | |||
70 | void FLEXRAM_SetTCMSize(uint8_t itcmBankNum, uint8_t dtcmBankNum) | ||
71 | { | ||
72 | assert(itcmBankNum <= (uint8_t)FSL_FEATURE_FLEXRAM_INTERNAL_RAM_TOTAL_BANK_NUMBERS); | ||
73 | assert(dtcmBankNum <= (uint8_t)FSL_FEATURE_FLEXRAM_INTERNAL_RAM_TOTAL_BANK_NUMBERS); | ||
74 | |||
75 | /* dtcm configuration */ | ||
76 | if (dtcmBankNum != 0U) | ||
77 | { | ||
78 | IOMUXC_GPR->GPR14 &= ~IOMUXC_GPR_GPR14_CM7_CFGDTCMSZ_MASK; | ||
79 | IOMUXC_GPR->GPR14 |= IOMUXC_GPR_GPR14_CM7_CFGDTCMSZ(FLEXRAM_MapTcmSizeToRegister(dtcmBankNum)); | ||
80 | IOMUXC_GPR->GPR16 |= IOMUXC_GPR_GPR16_INIT_DTCM_EN_MASK; | ||
81 | } | ||
82 | else | ||
83 | { | ||
84 | IOMUXC_GPR->GPR16 &= ~IOMUXC_GPR_GPR16_INIT_DTCM_EN_MASK; | ||
85 | } | ||
86 | |||
87 | /* itcm configuration */ | ||
88 | if (itcmBankNum != 0U) | ||
89 | { | ||
90 | IOMUXC_GPR->GPR14 &= ~IOMUXC_GPR_GPR14_CM7_CFGITCMSZ_MASK; | ||
91 | IOMUXC_GPR->GPR14 |= IOMUXC_GPR_GPR14_CM7_CFGITCMSZ(FLEXRAM_MapTcmSizeToRegister(itcmBankNum)); | ||
92 | IOMUXC_GPR->GPR16 |= IOMUXC_GPR_GPR16_INIT_ITCM_EN_MASK; | ||
93 | } | ||
94 | else | ||
95 | { | ||
96 | IOMUXC_GPR->GPR16 &= ~IOMUXC_GPR_GPR16_INIT_ITCM_EN_MASK; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | /*! | ||
101 | * brief FLEXRAM allocate on-chip ram for OCRAM,ITCM,DTCM | ||
102 | * This function is independent of FLEXRAM_Init, it can be called directly if ram re-allocate | ||
103 | * is needed. | ||
104 | * param config allocate configuration. | ||
105 | * retval kStatus_InvalidArgument the argument is invalid | ||
106 | * kStatus_Success allocate success | ||
107 | */ | ||
108 | status_t FLEXRAM_AllocateRam(flexram_allocate_ram_t *config) | ||
109 | { | ||
110 | assert(config != NULL); | ||
111 | |||
112 | uint8_t dtcmBankNum = config->dtcmBankNum; | ||
113 | uint8_t itcmBankNum = config->itcmBankNum; | ||
114 | uint8_t ocramBankNum = config->ocramBankNum; | ||
115 | uint8_t i = 0U; | ||
116 | uint32_t bankCfg = 0U; | ||
117 | status_t status = kStatus_Success; | ||
118 | |||
119 | /* check the arguments */ | ||
120 | if ((uint8_t)FSL_FEATURE_FLEXRAM_INTERNAL_RAM_TOTAL_BANK_NUMBERS < (dtcmBankNum + itcmBankNum + ocramBankNum)) | ||
121 | { | ||
122 | status = kStatus_InvalidArgument; | ||
123 | } | ||
124 | else | ||
125 | { | ||
126 | /* flexram bank config value */ | ||
127 | for (i = 0U; i < (uint8_t)FSL_FEATURE_FLEXRAM_INTERNAL_RAM_TOTAL_BANK_NUMBERS; i++) | ||
128 | { | ||
129 | if (i < ocramBankNum) | ||
130 | { | ||
131 | bankCfg |= ((uint32_t)kFLEXRAM_BankOCRAM) << (i * 2U); | ||
132 | continue; | ||
133 | } | ||
134 | |||
135 | if (i < (dtcmBankNum + ocramBankNum)) | ||
136 | { | ||
137 | bankCfg |= ((uint32_t)kFLEXRAM_BankDTCM) << (i * 2U); | ||
138 | continue; | ||
139 | } | ||
140 | |||
141 | if (i < (dtcmBankNum + ocramBankNum + itcmBankNum)) | ||
142 | { | ||
143 | bankCfg |= ((uint32_t)kFLEXRAM_BankITCM) << (i * 2U); | ||
144 | continue; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | IOMUXC_GPR->GPR17 = bankCfg; | ||
149 | |||
150 | /* set TCM size */ | ||
151 | FLEXRAM_SetTCMSize(itcmBankNum, dtcmBankNum); | ||
152 | /* select ram allocate source from FLEXRAM_BANK_CFG */ | ||
153 | FLEXRAM_SetAllocateRamSrc(kFLEXRAM_BankAllocateThroughBankCfg); | ||
154 | } | ||
155 | |||
156 | return status; | ||
157 | } | ||