Callisto4Bootloader: lib/bl_api.h Source File

Callisto4Bootloader

bl_api.h
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
8 #ifndef __BL_API_H__
9 #define __BL_API_H__
10
11 //#include <fsl_flexspi.h>
12 //#include "fsl_device_registers.h"
13 #include "fsl_clock.h"
14 #include "flexspi_nor_flash.h"
15 #include "fsl_rtwdog.h"
16 #include "fsl_wdog.h"
17 //#include <string.h>
18
19 /*******************************************************************************
20 * Definitions
21 ******************************************************************************/
22 typedef struct
23 {
24 uint32_t version;
25 status_t (*init)(uint32_t instance, flexspi_nor_config_t *config);
26 status_t (*program)(uint32_t instance, flexspi_nor_config_t *config, uint32_t dst_addr, const uint32_t *src);
27 status_t (*erase_all)(uint32_t instance, flexspi_nor_config_t *config);
28 status_t (*erase)(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t lengthInBytes);
29 status_t (*read)(
30 uint32_t instance, flexspi_nor_config_t *config, uint32_t *dst, uint32_t addr, uint32_t lengthInBytes);
31 void (*clear_cache)(uint32_t instance);
32 status_t (*xfer)(uint32_t instance, flexspi_xfer_t *xfer);
33 status_t (*update_lut)(uint32_t instance, uint32_t seqIndex, const uint32_t *lutBase, uint32_t seqNumber);
34 status_t (*get_config)(uint32_t instance, flexspi_nor_config_t *config, serial_nor_config_option_t *option);
35 } flexspi_nor_driver_interface_t;
36
37 typedef struct
38 {
39 uint32_t version;
40 void (*CLOCK_SetMux)(clock_mux_t mux, uint32_t value);
41 uint32_t (*CLOCK_GetMux)(clock_mux_t mux);
42 void (*CLOCK_SetDiv)(clock_div_t divider, uint32_t value);
43 uint32_t (*CLOCK_GetDiv)(clock_div_t divider);
44 void (*CLOCK_ControlGate)(clock_ip_name_t name, clock_gate_value_t value);
45 void (*CLOCK_EnableClock)(clock_ip_name_t name);
46 void (*CLOCK_DisableClock)(clock_ip_name_t name);
47 void (*CLOCK_SetMode)(clock_mode_t mode);
48 void (*CLOCK_SetPllBypass)(CCM_ANALOG_Type *base, clock_pll_t pll, bool bypass);
49 uint32_t (*CLOCK_GetFreq)(clock_name_t name);
50 uint32_t (*CLOCK_GetCpuClkFreq)(void);
51 void (*CLOCK_InitExternalClk)(bool bypassXtalOsc);
52 void (*CLOCK_DeinitExternalClk)(void);
53 void (*CLOCK_SwitchOsc)(clock_osc_t osc);
54 uint32_t (*CLOCK_GetRtcFreq)(void);
55 void (*CLOCK_SetXtalFreq)(uint32_t freq);
56 void (*CLOCK_SetRtcXtalFreq)(uint32_t freq);
57 void (*CLOCK_InitRcOsc24M)(void);
58 void (*CLOCK_DeinitRcOsc24M)(void);
59 void (*CLOCK_InitArmPll)(const clock_arm_pll_config_t *config);
60 void (*CLOCK_DeinitArmPll)(void);
61 void (*CLOCK_InitSysPll)(const clock_sys_pll_config_t *config);
62 void (*CLOCK_DeinitSysPll)(void);
63 void (*CLOCK_InitUsb1Pll)(const clock_usb_pll_config_t *config);
64 void (*CLOCK_DeinitUsb1Pll)(void);
65 void (*CLOCK_InitUsb2Pll)(const clock_usb_pll_config_t *config);
66 void (*CLOCK_DeinitUsb2Pll)(void);
67 void (*CLOCK_InitAudioPll)(const clock_audio_pll_config_t *config);
68 void (*CLOCK_DeinitAudioPll)(void);
69 void (*CLOCK_InitVideoPll)(const clock_video_pll_config_t *config);
70 void (*CLOCK_DeinitVideoPll)(void);
71 void (*CLOCK_InitEnetPll)(const clock_enet_pll_config_t *config);
72 void (*CLOCK_DeinitEnetPll)(void);
73 uint32_t (*CLOCK_GetPllFreq)(clock_pll_t pll);
74 void (*CLOCK_InitSysPfd)(clock_pfd_t pfd, uint8_t pfdFrac);
75 void (*CLOCK_DeinitSysPfd)(clock_pfd_t pfd);
76 void (*CLOCK_InitUsb1Pfd)(clock_pfd_t pfd, uint8_t pfdFrac);
77 void (*CLOCK_DeinitUsb1Pfd)(clock_pfd_t pfd);
78 uint32_t (*CLOCK_GetSysPfdFreq)(clock_pfd_t pfd);
79 uint32_t (*CLOCK_GetUsb1PfdFreq)(clock_pfd_t pfd);
80 bool (*CLOCK_EnableUsbhs0Clock)(clock_usb_src_t src, uint32_t freq);
81 bool (*CLOCK_EnableUsbhs0PhyPllClock)(clock_usb_phy_src_t src, uint32_t freq);
82 void (*CLOCK_DisableUsbhs0PhyPllClock)(void);
83 bool (*CLOCK_EnableUsbhs1Clock)(clock_usb_src_t src, uint32_t freq);
84 bool (*CLOCK_EnableUsbhs1PhyPllClock)(clock_usb_phy_src_t src, uint32_t freq);
85 void (*CLOCK_DisableUsbhs1PhyPllClock)(void);
86 } clock_driver_interface_t;
87
88 typedef struct
89 {
90 void (*RTWDOG_GetDefaultConfig)(rtwdog_config_t *config);
91 void (*RTWDOG_Init)(RTWDOG_Type *base, const rtwdog_config_t *config);
92 void (*RTWDOG_Deinit)(RTWDOG_Type *base);
93 void (*RTWDOG_Enable)(RTWDOG_Type *base);
94 void (*RTWDOG_Disable)(RTWDOG_Type *base);
95 void (*RTWDOG_EnableInterrupts)(RTWDOG_Type *base, uint32_t mask);
96 void (*RTWDOG_DisableInterrupts)(RTWDOG_Type *base, uint32_t mask);
97 uint32_t (*RTWDOG_GetStatusFlags)(RTWDOG_Type *base);
98 void (*RTWDOG_ClearStatusFlags)(RTWDOG_Type *base, uint32_t mask);
99 void (*RTWDOG_SetTimeoutValue)(RTWDOG_Type *base, uint16_t timeoutCount);
100 void (*RTWDOG_SetWindowValue)(RTWDOG_Type *base, uint16_t windowValue);
101 void (*RTWDOG_Unlock)(RTWDOG_Type *base);
102 void (*RTWDOG_Refresh)(RTWDOG_Type *base);
103 uint16_t (*RTWDOG_GetCounterValue)(RTWDOG_Type *base);
104 } rtwdog_driver_interface_t;
105
106 typedef struct
107 {
108 void (*WDOG_GetDefaultConfig)(wdog_config_t *config);
109 void (*WDOG_Init)(WDOG_Type *base, const wdog_config_t *config);
110 void (*WDOG_Deinit)(WDOG_Type *base);
111 void (*WDOG_Enable)(WDOG_Type *base);
112 void (*WDOG_Disable)(WDOG_Type *base);
113 void (*WDOG_EnableInterrupts)(WDOG_Type *base, uint16_t mask);
114 uint16_t (*WDOG_GetStatusFlags)(WDOG_Type *base);
115 void (*WDOG_ClearInterruptStatus)(WDOG_Type *base, uint16_t mask);
116 void (*WDOG_SetTimeoutValue)(WDOG_Type *base, uint16_t timeoutCount);
117 void (*WDOG_SetInterrputTimeoutValue)(WDOG_Type *base, uint16_t timeoutCount);
118 void (*WDOG_DisablePowerDownEnable)(WDOG_Type *base);
119 void (*WDOG_Refresh)(WDOG_Type *base);
120 } wdog_driver_interface_t;
121
122 typedef struct
123 {
124 const uint32_t version;
125 const char *copyright;
126 void (*runBootloader)(void *arg);
127 const uint32_t *reserved0;
128 const flexspi_nor_driver_interface_t *flexSpiNorDriver;
129 const uint32_t *reserved1;
130 const clock_driver_interface_t *clockDriver;
131 const rtwdog_driver_interface_t *rtwdogDriver;
132 const wdog_driver_interface_t *wdogDriver;
133 const uint32_t *reserved2;
134 } bootloader_api_entry_t;
135
136 enum
137 {
138 kEnterBootloader_Tag = 0xEB,
139 kEnterBootloader_Mode_Default = 0,
140 kEnterBootloader_Mode_SerialDownloader = 1,
141
142 kEnterBootloader_SerialInterface_Auto = 0,
143 kEnterBootloader_SerialInterface_USB = 1,
144 kEnterBootloader_SerialInterface_UART = 2,
145
146 kEnterBootloader_ImageIndex_Max = 3,
147 };
148
149 enum
150 {
151 kFlexSpiNorDriver_Version_1_5 = MAKE_VERSION(1, 5, 0),
152 };
153
154 typedef union
155 {
156 struct
157 {
158 uint32_t imageIndex : 4;
159 uint32_t reserved : 12;
160 uint32_t serialBootInterface : 4;
161 uint32_t bootMode : 4;
162 uint32_t tag : 8;
163 } B;
164 uint32_t U;
165 } run_bootloader_ctx_t;
166
167 void bl_api_init(void);
168
169 #endif //__BL_API_H__
RTWDOG_Enable
static void RTWDOG_Enable(RTWDOG_Type *base)
Enables the RTWDOG module.
Definition: fsl_rtwdog.h:189
kEnterBootloader_Tag
Definition: bl_api.h:137
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
WDOG_EnableInterrupts
static void WDOG_EnableInterrupts(WDOG_Type *base, uint16_t mask)
Enables the WDOG interrupt.
Definition: fsl_wdog.h:205
WDOG_Disable
static void WDOG_Disable(WDOG_Type *base)
Disables the WDOG module.
Definition: fsl_wdog.h:159
WDOG_SetInterrputTimeoutValue
static void WDOG_SetInterrputTimeoutValue(WDOG_Type *base, uint16_t timeoutCount)
Sets the WDOG interrupt count timeout value.
Definition: fsl_wdog.h:268
RTWDOG_Deinit
void RTWDOG_Deinit(RTWDOG_Type *base)
De-initializes the RTWDOG module.
Definition: bl_api.c:275
bl_api_init
void bl_api_init(void)
Definition: bl_api.c:20
kEnterBootloader_SerialInterface_Auto
Definition: bl_api.h:141
fsl_wdog.h
run_bootloader_ctx_t
Definition: bl_api.h:153
kEnterBootloader_SerialInterface_USB
Definition: bl_api.h:142
CCM_ANALOG_Type
Definition: MIMXRT1062.h:7252
_FlexSpiXfer
FlexSPI Transfer Context.
Definition: fsl_flexspi.h:258
rtwdog_driver_interface_t
Definition: bl_api.h:87
flexspi_nor_driver_interface_t::xfer
status_t(* xfer)(uint32_t instance, flexspi_xfer_t *xfer)
Definition: bl_api.h:32
kEnterBootloader_ImageIndex_Max
Definition: bl_api.h:145
clock_driver_interface_t
Definition: bl_api.h:36
WDOG_Type
Definition: MIMXRT1062.h:46321
flexspi_nor_driver_interface_t
Definition: bl_api.h:21
RTWDOG_DisableInterrupts
static void RTWDOG_DisableInterrupts(RTWDOG_Type *base, uint32_t mask)
Disables the RTWDOG interrupt.
Definition: fsl_rtwdog.h:237
WDOG_Enable
static void WDOG_Enable(WDOG_Type *base)
Enables the WDOG module.
Definition: fsl_wdog.h:146
RTWDOG_GetCounterValue
static uint16_t RTWDOG_GetCounterValue(RTWDOG_Type *base)
Gets the RTWDOG counter value.
Definition: fsl_rtwdog.h:361
RTWDOG_SetTimeoutValue
static void RTWDOG_SetTimeoutValue(RTWDOG_Type *base, uint16_t timeoutCount)
Sets the RTWDOG timeout value.
Definition: fsl_rtwdog.h:288
WDOG_GetDefaultConfig
void WDOG_GetDefaultConfig(wdog_config_t *config)
Initializes the WDOG configuration structure.
Definition: bl_api.c:283
kEnterBootloader_Mode_SerialDownloader
Definition: bl_api.h:139
flexspi_nor_flash.h
kFlexSpiNorDriver_Version_1_5
Definition: bl_api.h:150
WDOG_DisablePowerDownEnable
static void WDOG_DisablePowerDownEnable(WDOG_Type *base)
Disable the WDOG power down enable bit.
Definition: fsl_wdog.h:281
RTWDOG_ClearStatusFlags
void RTWDOG_ClearStatusFlags(RTWDOG_Type *base, uint32_t mask)
Clears the RTWDOG flag.
Definition: bl_api.c:260
WDOG_ClearInterruptStatus
void WDOG_ClearInterruptStatus(WDOG_Type *base, uint16_t mask)
Clears the WDOG flag.
Definition: bl_api.c:303
RTWDOG_Disable
static void RTWDOG_Disable(RTWDOG_Type *base)
Disables the RTWDOG module.
Definition: fsl_rtwdog.h:203
RTWDOG_Refresh
static void RTWDOG_Refresh(RTWDOG_Type *base)
Refreshes the RTWDOG timer.
Definition: fsl_rtwdog.h:340
_wdog_config
Describes WDOG configuration structure.
Definition: fsl_wdog.h:39
RTWDOG_Init
void RTWDOG_Init(RTWDOG_Type *base, const rtwdog_config_t *config)
Initializes the RTWDOG module.
Definition: bl_api.c:270
RTWDOG_GetStatusFlags
static uint32_t RTWDOG_GetStatusFlags(RTWDOG_Type *base)
Gets the RTWDOG all status flags.
Definition: fsl_rtwdog.h:257
RTWDOG_SetWindowValue
static void RTWDOG_SetWindowValue(RTWDOG_Type *base, uint16_t windowValue)
Sets the RTWDOG window value.
Definition: fsl_rtwdog.h:303
WDOG_Deinit
void WDOG_Deinit(WDOG_Type *base)
Shuts down the WDOG.
Definition: bl_api.c:293
wdog_driver_interface_t
Definition: bl_api.h:105
WDOG_Init
void WDOG_Init(WDOG_Type *base, const wdog_config_t *config)
Initializes the WDOG.
Definition: bl_api.c:288
flexspi_nor_driver_interface_t::version
uint32_t version
Definition: bl_api.h:24
kEnterBootloader_SerialInterface_UART
Definition: bl_api.h:143
RTWDOG_Unlock
static void RTWDOG_Unlock(RTWDOG_Type *base)
Unlocks the RTWDOG register written.
Definition: fsl_rtwdog.h:319
RTWDOG_EnableInterrupts
static void RTWDOG_EnableInterrupts(RTWDOG_Type *base, uint32_t mask)
Enables the RTWDOG interrupt.
Definition: fsl_rtwdog.h:220
WDOG_SetTimeoutValue
static void WDOG_SetTimeoutValue(WDOG_Type *base, uint16_t timeoutCount)
Sets the WDOG timeout value.
Definition: fsl_wdog.h:253
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
bootloader_api_entry_t
Definition: bl_api.h:121
kEnterBootloader_Mode_Default
Definition: bl_api.h:138
fsl_rtwdog.h
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