1 /*
2 * Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6 
7 /***********************************************************************************************************************
8  * Includes
9  **********************************************************************************************************************/
10 #ifndef R_FLASH_HP_H
11 #define R_FLASH_HP_H
12 
13 #include "bsp_api.h"
14 
15 /* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
16 FSP_HEADER
17 
18 #include "r_flash_api.h"
19 #include "r_flash_hp_cfg.h"
20 
21 /*******************************************************************************************************************//**
22  * @ingroup HAL_Library
23  * @addtogroup FLASH_HP
24  * @{
25  **********************************************************************************************************************/
26 
27 /***********************************************************************************************************************
28  * Macro definitions
29  **********************************************************************************************************************/
30 
31 /* If Code Flash programming is enabled, then all API functions must execute out of RAM. */
32 #if (FLASH_HP_CFG_CODE_FLASH_PROGRAMMING_ENABLE == 1)
33  #if defined(__ICCARM__)
34   #pragma section=".ramfunc"
35  #endif
36  #if defined(__ARMCC_VERSION) || defined(__GNUC__)
37   #define PLACE_IN_RAM_SECTION    __attribute__((noinline)) BSP_PLACE_IN_SECTION(".ramfunc")
38  #else
39   #define PLACE_IN_RAM_SECTION    BSP_PLACE_IN_SECTION(".ramfunc")
40  #endif
41 #else
42  #define PLACE_IN_RAM_SECTION
43 #endif
44 
45 /***********************************************************************************************************************
46  * Typedef definitions
47  **********************************************************************************************************************/
48 
49 /** Possible Flash operation states */
50 typedef enum e_flash_bgo_operation
51 {
52     FLASH_OPERATION_NON_BGO,
53     FLASH_OPERATION_DF_BGO_WRITE,
54     FLASH_OPERATION_DF_BGO_ERASE,
55     FLASH_OPERATION_DF_BGO_BLANKCHECK,
56 } flash_bgo_operation_t;
57 
58 /** Flash HP instance control block. DO NOT INITIALIZE. */
59 typedef struct st_flash_hp_instance_ctrl
60 {
61     uint32_t              opened;      ///< To check whether api has been opened or not.
62     flash_cfg_t const   * p_cfg;
63     uint32_t              timeout_write_cf;
64     uint32_t              timeout_write_df;
65     uint32_t              timeout_dbfull;
66     uint32_t              timeout_blank_check;
67     uint32_t              timeout_write_config;
68     uint32_t              timeout_erase_cf_small_block;
69     uint32_t              timeout_erase_cf_large_block;
70     uint32_t              timeout_erase_df_block;
71     uint32_t              source_start_address;
72     uint32_t              dest_end_address;
73     uint32_t              operations_remaining;
74     flash_bgo_operation_t current_operation;      ///< Operation in progress, for example, FLASH_OPERATION_CF_ERASE
75 
76     void (* p_callback)(flash_callback_args_t *); // Pointer to callback
77     flash_callback_args_t * p_callback_memory;    // Pointer to optional callback argument memory
78     void const            * p_context;            // Pointer to context to be passed into callback function
79 } flash_hp_instance_ctrl_t;
80 
81 /**********************************************************************************************************************
82  * Exported global variables
83  **********************************************************************************************************************/
84 
85 /** @cond INC_HEADER_DEFS_SEC */
86 /** Filled in Interface API structure for this Instance. */
87 extern const flash_api_t g_flash_on_flash_hp;
88 
89 /** @endcond */
90 
91 fsp_err_t R_FLASH_HP_Open(flash_ctrl_t * const p_api_ctrl, flash_cfg_t const * const p_cfg);
92 
93 fsp_err_t R_FLASH_HP_Write(flash_ctrl_t * const p_api_ctrl,
94                            uint32_t const       src_address,
95                            uint32_t             flash_address,
96                            uint32_t const       num_bytes);
97 
98 fsp_err_t R_FLASH_HP_Erase(flash_ctrl_t * const p_api_ctrl, uint32_t const address, uint32_t const num_blocks);
99 
100 fsp_err_t R_FLASH_HP_BlankCheck(flash_ctrl_t * const p_api_ctrl,
101                                 uint32_t const       address,
102                                 uint32_t             num_bytes,
103                                 flash_result_t     * blank_check_result);
104 
105 fsp_err_t R_FLASH_HP_Close(flash_ctrl_t * const p_api_ctrl);
106 
107 fsp_err_t R_FLASH_HP_StatusGet(flash_ctrl_t * const p_api_ctrl, flash_status_t * const p_status);
108 
109 fsp_err_t R_FLASH_HP_AccessWindowSet(flash_ctrl_t * const p_api_ctrl, uint32_t const start_addr,
110                                      uint32_t const end_addr);
111 
112 fsp_err_t R_FLASH_HP_AccessWindowClear(flash_ctrl_t * const p_api_ctrl);
113 
114 fsp_err_t R_FLASH_HP_IdCodeSet(flash_ctrl_t * const  p_api_ctrl,
115                                uint8_t const * const p_id_code,
116                                flash_id_code_mode_t  mode);
117 
118 fsp_err_t R_FLASH_HP_Reset(flash_ctrl_t * const p_api_ctrl);
119 
120 fsp_err_t R_FLASH_HP_UpdateFlashClockFreq(flash_ctrl_t * const p_api_ctrl);
121 
122 fsp_err_t R_FLASH_HP_StartUpAreaSelect(flash_ctrl_t * const      p_api_ctrl,
123                                        flash_startup_area_swap_t swap_type,
124                                        bool                      is_temporary);
125 fsp_err_t R_FLASH_HP_CallbackSet(flash_ctrl_t * const          p_api_ctrl,
126                                  void (                      * p_callback)(flash_callback_args_t *),
127                                  void const * const            p_context,
128                                  flash_callback_args_t * const p_callback_memory);
129 fsp_err_t R_FLASH_HP_BankSwap(flash_ctrl_t * const p_api_ctrl);
130 fsp_err_t R_FLASH_HP_InfoGet(flash_ctrl_t * const p_api_ctrl, flash_info_t * const p_info);
131 
132 /*******************************************************************************************************************//**
133  * @} (end defgroup FLASH_HP)
134  **********************************************************************************************************************/
135 #if !BSP_FEATURE_FLASH_HP_VERSION
136  #error "r_flash_hp is not a supported module for this board type."
137 #endif
138 
139 /* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
140 FSP_FOOTER
141 
142 #endif
143