xref: /btstack/port/renesas-ek-ra6m4a-da14531/e2-project/ra/fsp/inc/instances/r_flash_hp.h (revision c30869498fb8e98c1408c9db0e7624f02f483b73)
1 /***********************************************************************************************************************
2  * Copyright [2020-2022] Renesas Electronics Corporation and/or its affiliates.  All Rights Reserved.
3  *
4  * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products
5  * of Renesas Electronics Corp. and its affiliates ("Renesas").  No other uses are authorized.  Renesas products are
6  * sold pursuant to Renesas terms and conditions of sale.  Purchasers are solely responsible for the selection and use
7  * of Renesas products and Renesas assumes no liability.  No license, express or implied, to any intellectual property
8  * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas
9  * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION
10  * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT
11  * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES
12  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR
13  * DOCUMENTATION.  RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH.  TO THE MAXIMUM
14  * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION
15  * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING,
16  * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS,
17  * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY
18  * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS.
19  **********************************************************************************************************************/
20 
21 /***********************************************************************************************************************
22  * Includes
23  **********************************************************************************************************************/
24 #ifndef R_FLASH_HP_H
25 #define R_FLASH_HP_H
26 
27 #include "bsp_api.h"
28 
29 /* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
30 FSP_HEADER
31 
32 #include "r_flash_api.h"
33 #include "r_flash_hp_cfg.h"
34 
35 /*******************************************************************************************************************//**
36  * @ingroup HAL_Library
37  * @addtogroup FLASH_HP
38  * @{
39  **********************************************************************************************************************/
40 
41 /***********************************************************************************************************************
42  * Macro definitions
43  **********************************************************************************************************************/
44 
45 /* If Code Flash programming is enabled, then all API functions must execute out of RAM. */
46 #if (FLASH_HP_CFG_CODE_FLASH_PROGRAMMING_ENABLE == 1)
47  #if defined(__ICCARM__)
48   #pragma section=".code_in_ram"
49  #endif
50  #if defined(__ARMCC_VERSION) || defined(__GNUC__)
51   #define PLACE_IN_RAM_SECTION    __attribute__((noinline)) BSP_PLACE_IN_SECTION(".code_in_ram")
52  #else
53   #define PLACE_IN_RAM_SECTION    BSP_PLACE_IN_SECTION(".code_in_ram")
54  #endif
55 #else
56  #define PLACE_IN_RAM_SECTION
57 #endif
58 
59 /***********************************************************************************************************************
60  * Typedef definitions
61  **********************************************************************************************************************/
62 
63 /** Possible Flash operation states */
64 typedef enum e_flash_bgo_operation
65 {
66     FLASH_OPERATION_NON_BGO,
67     FLASH_OPERATION_DF_BGO_WRITE,
68     FLASH_OPERATION_DF_BGO_ERASE,
69     FLASH_OPERATION_DF_BGO_BLANKCHECK,
70 } flash_bgo_operation_t;
71 
72 /** Flash HP instance control block. DO NOT INITIALIZE. */
73 typedef struct st_flash_hp_instance_ctrl
74 {
75     uint32_t              opened;      ///< To check whether api has been opened or not.
76     flash_cfg_t const   * p_cfg;
77     uint32_t              timeout_write_cf;
78     uint32_t              timeout_write_df;
79     uint32_t              timeout_dbfull;
80     uint32_t              timeout_blank_check;
81     uint32_t              timeout_write_config;
82     uint32_t              timeout_erase_cf_small_block;
83     uint32_t              timeout_erase_cf_large_block;
84     uint32_t              timeout_erase_df_block;
85     uint32_t              source_start_address;
86     uint32_t              dest_end_address;
87     uint32_t              operations_remaining;
88     flash_bgo_operation_t current_operation;      ///< Operation in progress, for example, FLASH_OPERATION_CF_ERASE
89 
90     void (* p_callback)(flash_callback_args_t *); // Pointer to callback
91     flash_callback_args_t * p_callback_memory;    // Pointer to optional callback argument memory
92     void const            * p_context;            // Pointer to context to be passed into callback function
93 } flash_hp_instance_ctrl_t;
94 
95 /**********************************************************************************************************************
96  * Exported global variables
97  **********************************************************************************************************************/
98 
99 /** @cond INC_HEADER_DEFS_SEC */
100 /** Filled in Interface API structure for this Instance. */
101 extern const flash_api_t g_flash_on_flash_hp;
102 
103 /** @endcond */
104 
105 fsp_err_t R_FLASH_HP_Open(flash_ctrl_t * const p_api_ctrl, flash_cfg_t const * const p_cfg);
106 
107 fsp_err_t R_FLASH_HP_Write(flash_ctrl_t * const p_api_ctrl,
108                            uint32_t const       src_address,
109                            uint32_t             flash_address,
110                            uint32_t const       num_bytes);
111 
112 fsp_err_t R_FLASH_HP_Erase(flash_ctrl_t * const p_api_ctrl, uint32_t const address, uint32_t const num_blocks);
113 
114 fsp_err_t R_FLASH_HP_BlankCheck(flash_ctrl_t * const p_api_ctrl,
115                                 uint32_t const       address,
116                                 uint32_t             num_bytes,
117                                 flash_result_t     * blank_check_result);
118 
119 fsp_err_t R_FLASH_HP_Close(flash_ctrl_t * const p_api_ctrl);
120 
121 fsp_err_t R_FLASH_HP_StatusGet(flash_ctrl_t * const p_api_ctrl, flash_status_t * const p_status);
122 
123 fsp_err_t R_FLASH_HP_AccessWindowSet(flash_ctrl_t * const p_api_ctrl, uint32_t const start_addr,
124                                      uint32_t const end_addr);
125 
126 fsp_err_t R_FLASH_HP_AccessWindowClear(flash_ctrl_t * const p_api_ctrl);
127 
128 fsp_err_t R_FLASH_HP_IdCodeSet(flash_ctrl_t * const  p_api_ctrl,
129                                uint8_t const * const p_id_code,
130                                flash_id_code_mode_t  mode);
131 
132 fsp_err_t R_FLASH_HP_Reset(flash_ctrl_t * const p_api_ctrl);
133 
134 fsp_err_t R_FLASH_HP_UpdateFlashClockFreq(flash_ctrl_t * const p_api_ctrl);
135 
136 fsp_err_t R_FLASH_HP_StartUpAreaSelect(flash_ctrl_t * const      p_api_ctrl,
137                                        flash_startup_area_swap_t swap_type,
138                                        bool                      is_temporary);
139 fsp_err_t R_FLASH_HP_CallbackSet(flash_ctrl_t * const          p_api_ctrl,
140                                  void (                      * p_callback)(flash_callback_args_t *),
141                                  void const * const            p_context,
142                                  flash_callback_args_t * const p_callback_memory);
143 fsp_err_t R_FLASH_HP_BankSwap(flash_ctrl_t * const p_api_ctrl);
144 fsp_err_t R_FLASH_HP_InfoGet(flash_ctrl_t * const p_api_ctrl, flash_info_t * const p_info);
145 
146 /*******************************************************************************************************************//**
147  * @} (end defgroup FLASH_HP)
148  **********************************************************************************************************************/
149 #if !BSP_FEATURE_FLASH_HP_VERSION
150  #error "r_flash_hp is not a supported module for this board type."
151 #endif
152 
153 /* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
154 FSP_FOOTER
155 
156 #endif
157