Callisto4Bootloader: lib/bl_api.c Source File

Callisto4Bootloader

bl_api.c
Go to the documentation of this file.
1 /*
2 * Copyright 2017-2018 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7 #include "bl_api.h"
8
9 #include <cr_section_macros.h>
10 /*******************************************************************************
11 * Prototypes
12 ******************************************************************************/
13
14 /*******************************************************************************
15 * Variables
16 ******************************************************************************/
17 static bootloader_api_entry_t *g_bootloaderTree;
18
19 /*******************************************************************************
20 * Codes
21 ******************************************************************************/
22
23 void bl_api_init(void)
24 {
25 g_bootloaderTree = (bootloader_api_entry_t *)*(uint32_t *)0x0020001c;
26 }
27
29 // * Clock driver
30 // ******************************************************************************/
31 //void CLOCK_SetMux(clock_mux_t mux, uint32_t value)
32 //{
33 // g_bootloaderTree->clockDriver->CLOCK_SetMux(mux, value);
34 //}
35 //
36 //uint32_t CLOCK_GetMux(clock_mux_t mux)
37 //{
38 // return g_bootloaderTree->clockDriver->CLOCK_GetMux(mux);
39 //}
40 //
41 //void CLOCK_SetDiv(clock_div_t divider, uint32_t value)
42 //{
43 // g_bootloaderTree->clockDriver->CLOCK_SetDiv(divider, value);
44 //}
45 //
46 //uint32_t CLOCK_GetDiv(clock_div_t divider)
47 //{
48 // return g_bootloaderTree->clockDriver->CLOCK_GetDiv(divider);
49 //}
50 //
51 //void CLOCK_ControlGate(clock_ip_name_t name, clock_gate_value_t value)
52 //{
53 // g_bootloaderTree->clockDriver->CLOCK_ControlGate(name, value);
54 //}
55 //
56 //void CLOCK_EnableClock(clock_ip_name_t name)
57 //{
58 // g_bootloaderTree->clockDriver->CLOCK_EnableClock(name);
59 //}
60 //
61 //void CLOCK_DisableClock(clock_ip_name_t name)
62 //{
63 // g_bootloaderTree->clockDriver->CLOCK_DisableClock(name);
64 //}
65 //
66 //void CLOCK_SetMode(clock_mode_t mode)
67 //{
68 // g_bootloaderTree->clockDriver->CLOCK_SetMode(mode);
69 //}
70 //
71 //void CLOCK_SetPllBypass(CCM_ANALOG_Type *base, clock_pll_t pll, bool bypass)
72 //{
73 // g_bootloaderTree->clockDriver->CLOCK_SetPllBypass(base, pll, bypass);
74 //}
75 //
76 //uint32_t CLOCK_GetCpuClkFreq(void)
77 //{
78 // return g_bootloaderTree->clockDriver->CLOCK_GetCpuClkFreq();
79 //}
80 //
81 //uint32_t CLOCK_GetRtcFreq(void)
82 //{
83 // return g_bootloaderTree->clockDriver->CLOCK_GetRtcFreq();
84 //}
85 //
86 //void CLOCK_SetXtalFreq(uint32_t freq)
87 //{
88 // g_bootloaderTree->clockDriver->CLOCK_SetXtalFreq(freq);
89 //}
90 //
91 //void CLOCK_SetRtcXtalFreq(uint32_t freq)
92 //{
93 // g_bootloaderTree->clockDriver->CLOCK_SetRtcXtalFreq(freq);
94 //}
95 //
96 //void CLOCK_InitExternalClk(bool bypassXtalOsc)
97 //{
98 // g_bootloaderTree->clockDriver->CLOCK_InitExternalClk(bypassXtalOsc);
99 //}
100 //
101 //void CLOCK_DeinitExternalClk(void)
102 //{
103 // g_bootloaderTree->clockDriver->CLOCK_DeinitExternalClk();
104 //}
105 //
106 //void CLOCK_SwitchOsc(clock_osc_t osc)
107 //{
108 // g_bootloaderTree->clockDriver->CLOCK_SwitchOsc(osc);
109 //}
110 //
111 //void CLOCK_InitRcOsc24M(void)
112 //{
113 // g_bootloaderTree->clockDriver->CLOCK_InitRcOsc24M();
114 //}
115 //
116 //void CLOCK_DeinitRcOsc24M(void)
117 //{
118 // g_bootloaderTree->clockDriver->CLOCK_DeinitRcOsc24M();
119 //}
120 //
121 //uint32_t CLOCK_GetFreq(clock_name_t name)
122 //{
123 // return g_bootloaderTree->clockDriver->CLOCK_GetFreq(name);
124 //}
125 //
126 //bool CLOCK_EnableUsbhs0Clock(clock_usb_src_t src, uint32_t freq)
127 //{
128 // return g_bootloaderTree->clockDriver->CLOCK_EnableUsbhs0Clock(src, freq);
129 //}
130 //
131 //bool CLOCK_EnableUsbhs1Clock(clock_usb_src_t src, uint32_t freq)
132 //{
133 // return g_bootloaderTree->clockDriver->CLOCK_EnableUsbhs1Clock(src, freq);
134 //}
135 //
136 //bool CLOCK_EnableUsbhs0PhyPllClock(clock_usb_phy_src_t src, uint32_t freq)
137 //{
138 // return g_bootloaderTree->clockDriver->CLOCK_EnableUsbhs0PhyPllClock(src, freq);
139 //}
140 //
141 //void CLOCK_DisableUsbhs0PhyPllClock(void)
142 //{
143 // g_bootloaderTree->clockDriver->CLOCK_DisableUsbhs0PhyPllClock();
144 //}
145 //
146 //void CLOCK_InitArmPll(const clock_arm_pll_config_t *config)
147 //{
148 // g_bootloaderTree->clockDriver->CLOCK_InitArmPll(config);
149 //}
150 //
151 //void CLOCK_DeinitArmPll(void)
152 //{
153 // g_bootloaderTree->clockDriver->CLOCK_DeinitArmPll();
154 //}
155 //
156 //void CLOCK_InitSysPll(const clock_sys_pll_config_t *config)
157 //{
158 // g_bootloaderTree->clockDriver->CLOCK_InitSysPll(config);
159 //}
160 //
161 //void CLOCK_DeinitSysPll(void)
162 //{
163 // g_bootloaderTree->clockDriver->CLOCK_DeinitSysPll();
164 //}
165 //
166 //void CLOCK_InitUsb1Pll(const clock_usb_pll_config_t *config)
167 //{
168 // g_bootloaderTree->clockDriver->CLOCK_InitUsb1Pll(config);
169 //}
170 //
171 //void CLOCK_DeinitUsb1Pll(void)
172 //{
173 // g_bootloaderTree->clockDriver->CLOCK_DeinitUsb1Pll();
174 //}
175 //
176 //void CLOCK_InitUsb2Pll(const clock_usb_pll_config_t *config)
177 //{
178 // g_bootloaderTree->clockDriver->CLOCK_InitUsb2Pll(config);
179 //}
180 //
181 //void CLOCK_DeinitUsb2Pll(void)
182 //{
183 // g_bootloaderTree->clockDriver->CLOCK_DeinitUsb2Pll();
184 //}
185 //
186 //void CLOCK_InitAudioPll(const clock_audio_pll_config_t *config)
187 //{
188 // g_bootloaderTree->clockDriver->CLOCK_InitAudioPll(config);
189 //}
190 //
191 //void CLOCK_DeinitAudioPll(void)
192 //{
193 // g_bootloaderTree->clockDriver->CLOCK_DeinitAudioPll();
194 //}
195 //
196 //void CLOCK_InitVideoPll(const clock_video_pll_config_t *config)
197 //{
198 // g_bootloaderTree->clockDriver->CLOCK_InitVideoPll(config);
199 //}
200 //
201 //void CLOCK_DeinitVideoPll(void)
202 //{
203 // g_bootloaderTree->clockDriver->CLOCK_DeinitVideoPll();
204 //}
205 //
206 //void CLOCK_InitEnetPll(const clock_enet_pll_config_t *config)
207 //{
208 // g_bootloaderTree->clockDriver->CLOCK_InitEnetPll(config);
209 //}
210 //
211 //void CLOCK_DeinitEnetPll(void)
212 //{
213 // g_bootloaderTree->clockDriver->CLOCK_DeinitEnetPll();
214 //}
215 //
216 //uint32_t CLOCK_GetPllFreq(clock_pll_t pll)
217 //{
218 // return g_bootloaderTree->clockDriver->CLOCK_GetPllFreq(pll);
219 //}
220 //
221 //void CLOCK_InitSysPfd(clock_pfd_t pfd, uint8_t pfdFrac)
222 //{
223 // g_bootloaderTree->clockDriver->CLOCK_InitSysPfd(pfd, pfdFrac);
224 //}
225 //
226 //void CLOCK_DeinitSysPfd(clock_pfd_t pfd)
227 //{
228 // g_bootloaderTree->clockDriver->CLOCK_DeinitSysPfd(pfd);
229 //}
230 //
231 //void CLOCK_InitUsb1Pfd(clock_pfd_t pfd, uint8_t pfdFrac)
232 //{
233 // g_bootloaderTree->clockDriver->CLOCK_InitUsb1Pfd(pfd, pfdFrac);
234 //}
235 //
236 //void CLOCK_DeinitUsb1Pfd(clock_pfd_t pfd)
237 //{
238 // g_bootloaderTree->clockDriver->CLOCK_DeinitUsb1Pfd(pfd);
239 //}
240 //
241 //uint32_t CLOCK_GetSysPfdFreq(clock_pfd_t pfd)
242 //{
243 // return g_bootloaderTree->clockDriver->CLOCK_GetSysPfdFreq(pfd);
244 //}
245 //
246 //uint32_t CLOCK_GetUsb1PfdFreq(clock_pfd_t pfd)
247 //{
248 // return g_bootloaderTree->clockDriver->CLOCK_GetUsb1PfdFreq(pfd);
249 //}
250 //
251 //bool CLOCK_EnableUsbhs1PhyPllClock(clock_usb_phy_src_t src, uint32_t freq)
252 //{
253 // return g_bootloaderTree->clockDriver->CLOCK_EnableUsbhs1PhyPllClock(src, freq);
254 //}
255 //
256 //void CLOCK_DisableUsbhs1PhyPllClock(void)
257 //{
258 // g_bootloaderTree->clockDriver->CLOCK_DisableUsbhs1PhyPllClock();
259 //}
260
261 /*******************************************************************************
262 * RTWDOG driver
263 ******************************************************************************/
264 void RTWDOG_ClearStatusFlags(RTWDOG_Type *base, uint32_t mask)
265 {
266 g_bootloaderTree->rtwdogDriver->RTWDOG_ClearStatusFlags(base, mask);
267 }
268
269 void RTWDOG_GetDefaultConfig(rtwdog_config_t *config)
270 {
271 g_bootloaderTree->rtwdogDriver->RTWDOG_GetDefaultConfig(config);
272 }
273
274 void RTWDOG_Init(RTWDOG_Type *base, const rtwdog_config_t *config)
275 {
276 g_bootloaderTree->rtwdogDriver->RTWDOG_Init(base, config);
277 }
278
279 void RTWDOG_Deinit(RTWDOG_Type *base)
280 {
281 g_bootloaderTree->rtwdogDriver->RTWDOG_Deinit(base);
282 }
283
284 /*******************************************************************************
285 * WDOG driver
286 ******************************************************************************/
287
288 void WDOG_GetDefaultConfig(wdog_config_t *config)
289 {
290 g_bootloaderTree->wdogDriver->WDOG_GetDefaultConfig(config);
291 }
292
293 void WDOG_Init(WDOG_Type *base, const wdog_config_t *config)
294 {
295 g_bootloaderTree->wdogDriver->WDOG_Init(base, config);
296 }
297
298 void WDOG_Deinit(WDOG_Type *base)
299 {
300 g_bootloaderTree->wdogDriver->WDOG_Deinit(base);
301 }
302
303 uint16_t WDOG_GetStatusFlags(WDOG_Type *base)
304 {
305 return g_bootloaderTree->wdogDriver->WDOG_GetStatusFlags(base);
306 }
307
308 void WDOG_ClearInterruptStatus(WDOG_Type *base, uint16_t mask)
309 {
310 g_bootloaderTree->wdogDriver->WDOG_ClearInterruptStatus(base, mask);
311 }
312
313 void WDOG_Refresh(WDOG_Type *base)
314 {
315 g_bootloaderTree->wdogDriver->WDOG_Refresh(base);
316 }
317
318 /*******************************************************************************
319 * FlexSPI NOR driver
320 ******************************************************************************/
321 #if BL_FEATURE_HAS_FLEXSPI_NOR_ROMAPI
322
323 status_t flexspi_nor_flash_init(uint32_t instance, flexspi_nor_config_t *config)
324 {
325 return g_bootloaderTree->flexSpiNorDriver->init(instance, config);
326 }
327
328 status_t flexspi_nor_flash_page_program(uint32_t instance,
329 flexspi_nor_config_t *config,
330 uint32_t dstAddr,
331 const uint32_t *src)
332 {
333 return g_bootloaderTree->flexSpiNorDriver->program(instance, config, dstAddr, src);
334 }
335
336 status_t flexspi_nor_flash_erase_all(uint32_t instance, flexspi_nor_config_t *config)
337 {
338 return g_bootloaderTree->flexSpiNorDriver->erase_all(instance, config);
339 }
340
341 status_t flexspi_nor_get_config(uint32_t instance, flexspi_nor_config_t *config, serial_nor_config_option_t *option)
342 {
343 return g_bootloaderTree->flexSpiNorDriver->get_config(instance, config, option);
344 }
345
346 status_t flexspi_nor_flash_erase(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length)
347 {
348 return g_bootloaderTree->flexSpiNorDriver->erase(instance, config, start, length);
349 }
350
351
352
353 status_t flexspi_nor_flash_read(
354 uint32_t instance, flexspi_nor_config_t *config, uint32_t *dst, uint32_t start, uint32_t bytes)
355 {
356 return g_bootloaderTree->flexSpiNorDriver->read(instance, config, dst, start, bytes);
357 }
358 #endif // BL_FEATURE_HAS_FLEXSPI_NOR_ROMAPI
359
360
flexspi_nor_flash_page_program
status_t flexspi_nor_flash_page_program(uint32_t instance, flexspi_nor_config_t *config, uint32_t dstAddr, const uint32_t *src)
Program data to Serial NOR via FlexSPI.
wdog_driver_interface_t::WDOG_GetDefaultConfig
void(* WDOG_GetDefaultConfig)(wdog_config_t *config)
Definition: bl_api.h:107
flexspi_nor_flash_read
status_t flexspi_nor_flash_read(uint32_t instance, flexspi_nor_config_t *config, uint32_t *dst, uint32_t start, uint32_t bytes)
Read data from Serial NOR.
RTWDOG_Type
Definition: MIMXRT1062.h:36144
WDOG_GetStatusFlags
uint16_t WDOG_GetStatusFlags(WDOG_Type *base)
Gets the WDOG all reset status flags.
Definition: bl_api.c:298
flexspi_nor_driver_interface_t::read
status_t(* read)(uint32_t instance, flexspi_nor_config_t *config, uint32_t *dst, uint32_t addr, uint32_t lengthInBytes)
Definition: bl_api.h:29
bootloader_api_entry_t::rtwdogDriver
const rtwdog_driver_interface_t * rtwdogDriver
Definition: bl_api.h:130
bl_api_init
void bl_api_init(void)
Definition: bl_api.c:20
RTWDOG_Deinit
void RTWDOG_Deinit(RTWDOG_Type *base)
De-initializes the RTWDOG module.
Definition: bl_api.c:275
bootloader_api_entry_t::flexSpiNorDriver
const flexspi_nor_driver_interface_t * flexSpiNorDriver
FlexSPI NOR Flash API.
Definition: bl_api.h:127
wdog_driver_interface_t::WDOG_GetStatusFlags
uint16_t(* WDOG_GetStatusFlags)(WDOG_Type *base)
Definition: bl_api.h:113
wdog_driver_interface_t::WDOG_Refresh
void(* WDOG_Refresh)(WDOG_Type *base)
Definition: bl_api.h:118
WDOG_Type
Definition: MIMXRT1062.h:46321
flexspi_nor_driver_interface_t::init
status_t(* init)(uint32_t instance, flexspi_nor_config_t *config)
Definition: bl_api.h:25
g_bootloaderTree
static bootloader_api_entry_t * g_bootloaderTree
Definition: bl_api.c:15
WDOG_GetDefaultConfig
void WDOG_GetDefaultConfig(wdog_config_t *config)
Initializes the WDOG configuration structure.
Definition: bl_api.c:283
flexspi_nor_driver_interface_t::erase_all
status_t(* erase_all)(uint32_t instance, flexspi_nor_config_t *config)
Definition: bl_api.h:27
bootloader_api_entry_t::wdogDriver
const wdog_driver_interface_t * wdogDriver
Definition: bl_api.h:131
flexspi_nor_flash_erase
status_t flexspi_nor_flash_erase(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length)
Erase Flash Region specified by address and length.
rtwdog_driver_interface_t::RTWDOG_Init
void(* RTWDOG_Init)(RTWDOG_Type *base, const rtwdog_config_t *config)
Definition: bl_api.h:90
flexspi_nor_flash_erase_all
status_t flexspi_nor_flash_erase_all(uint32_t instance, flexspi_nor_config_t *config)
Erase all the Serial NOR devices connected on FlexSPI.
rtwdog_driver_interface_t::RTWDOG_ClearStatusFlags
void(* RTWDOG_ClearStatusFlags)(RTWDOG_Type *base, uint32_t mask)
Definition: bl_api.h:97
wdog_driver_interface_t::WDOG_Deinit
void(* WDOG_Deinit)(WDOG_Type *base)
Definition: bl_api.h:109
RTWDOG_ClearStatusFlags
void RTWDOG_ClearStatusFlags(RTWDOG_Type *base, uint32_t mask)
Clears the RTWDOG flag.
Definition: bl_api.c:260
flexspi_nor_get_config
status_t flexspi_nor_get_config(uint32_t instance, flexspi_nor_config_t *config, serial_nor_config_option_t *option)
Get FlexSPI NOR Configuration Block based on specified option.
WDOG_ClearInterruptStatus
void WDOG_ClearInterruptStatus(WDOG_Type *base, uint16_t mask)
Clears the WDOG flag.
Definition: bl_api.c:303
_wdog_config
Describes WDOG configuration structure.
Definition: fsl_wdog.h:39
flexspi_nor_driver_interface_t::erase
status_t(* erase)(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t lengthInBytes)
Definition: bl_api.h:28
RTWDOG_Init
void RTWDOG_Init(RTWDOG_Type *base, const rtwdog_config_t *config)
Initializes the RTWDOG module.
Definition: bl_api.c:270
flexspi_nor_flash_init
status_t flexspi_nor_flash_init(uint32_t instance, flexspi_nor_config_t *config)
Initialize Serial NOR devices via FlexSPI.
WDOG_Deinit
void WDOG_Deinit(WDOG_Type *base)
Shuts down the WDOG.
Definition: bl_api.c:293
WDOG_Init
void WDOG_Init(WDOG_Type *base, const wdog_config_t *config)
Initializes the WDOG.
Definition: bl_api.c:288
rtwdog_driver_interface_t::RTWDOG_Deinit
void(* RTWDOG_Deinit)(RTWDOG_Type *base)
Definition: bl_api.h:91
rtwdog_driver_interface_t::RTWDOG_GetDefaultConfig
void(* RTWDOG_GetDefaultConfig)(rtwdog_config_t *config)
Definition: bl_api.h:89
RTWDOG_GetDefaultConfig
void RTWDOG_GetDefaultConfig(rtwdog_config_t *config)
Initializes the RTWDOG configuration structure.
Definition: bl_api.c:265
_rtwdog_config
Describes RTWDOG configuration structure.
Definition: fsl_rtwdog.h:70
_serial_nor_config_option
Definition: flexspi_nor_flash.h:110
wdog_driver_interface_t::WDOG_Init
void(* WDOG_Init)(WDOG_Type *base, const wdog_config_t *config)
Definition: bl_api.h:108
bootloader_api_entry_t
Definition: bl_api.h:121
bl_api.h
wdog_driver_interface_t::WDOG_ClearInterruptStatus
void(* WDOG_ClearInterruptStatus)(WDOG_Type *base, uint16_t mask)
Definition: bl_api.h:114
WDOG_Refresh
void WDOG_Refresh(WDOG_Type *base)
Refreshes the WDOG timer.
Definition: bl_api.c:308
_flexspi_nor_config
Definition: flexspi_nor_flash.h:184
flexspi_nor_driver_interface_t::get_config
status_t(* get_config)(uint32_t instance, flexspi_nor_config_t *config, serial_nor_config_option_t *option)
Definition: bl_api.h:34
flexspi_nor_driver_interface_t::program
status_t(* program)(uint32_t instance, flexspi_nor_config_t *config, uint32_t dst_addr, const uint32_t *src)
Definition: bl_api.h:26