1 /**
2 ****************************************************************************************
3 * @file gr55xx_hal_exflash.c
4 * @author BLE Driver Team
5 * @brief EXFLASH HAL module driver.
6 ****************************************************************************************
7 * @attention
8 #####Copyright (c) 2019 GOODIX
9 All rights reserved.
10
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13 * Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18 * Neither the name of GOODIX nor the names of its contributors may be used
19 to endorse or promote products derived from this software without
20 specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
26 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33 ****************************************************************************************
34 */
35
36 /* Includes ------------------------------------------------------------------*/
37 #include "gr55xx_hal.h"
38 #include "gr55xx_rom_symbol.h"
39
40 #if defined(HAL_EXFLASH_MODULE_ENABLED) && (defined(GR5515_D) || defined(GR5515_E))
41
42 /* Private variables ---------------------------------------------------------*/
43
44 static hal_exflash_callback_t exflash_callback = {
45 .exflash_msp_init = hal_exflash_msp_init,
46 .exflash_msp_deinit = hal_exflash_msp_deinit
47 };
48
49 /* Private function prototypes -----------------------------------------------*/
50
hal_exflash_init(exflash_handle_t * p_exflash)51 hal_status_t hal_exflash_init(exflash_handle_t *p_exflash)
52 {
53 hal_exflash_register_callback(&exflash_callback);
54
55 hal_status_t ret;
56 GLOBAL_EXCEPTION_DISABLE();
57 ret = hal_exflash_init_ext(p_exflash);
58 GLOBAL_EXCEPTION_ENABLE();
59
60 return ret;
61 }
62
hal_exflash_deinit(exflash_handle_t * p_exflash)63 hal_status_t hal_exflash_deinit(exflash_handle_t *p_exflash)
64 {
65 hal_exflash_register_callback(&exflash_callback);
66
67 hal_status_t ret;
68 GLOBAL_EXCEPTION_DISABLE();
69 ret = hal_exflash_deinit_ext(p_exflash);
70 GLOBAL_EXCEPTION_ENABLE();
71
72 return ret;
73 }
74
hal_exflash_msp_init(exflash_handle_t * p_exflash)75 __WEAK void hal_exflash_msp_init(exflash_handle_t *p_exflash)
76 {
77 /* Prevent unused argument(s) compilation warning */
78 return;
79
80 /* NOTE : This function should not be modified, when the callback is needed,
81 the hal_exflash_msp_init can be implemented in the user file
82 */
83 }
84
hal_exflash_msp_deinit(exflash_handle_t * p_exflash)85 __WEAK void hal_exflash_msp_deinit(exflash_handle_t *p_exflash)
86 {
87 /* Prevent unused argument(s) compilation warning */
88 return;
89
90 /* NOTE : This function should not be modified, when the callback is needed,
91 the hal_exflash_msp_deinit can be implemented in the user file
92 */
93 }
94
hal_xqspi_init_ext(xqspi_handle_t * p_xqspi)95 SECTION_RAM_CODE hal_status_t hal_xqspi_init_ext(xqspi_handle_t *p_xqspi)
96 {
97 #if ENCRYPT_ENABLE
98 return hal_xqspi_init_ext_patch(p_xqspi);
99 #else
100 return hal_xqspi_init_ext_rom(p_xqspi);
101 #endif
102 }
103
hal_exflash_read(exflash_handle_t * p_exflash,uint32_t addr,uint8_t * p_data,uint32_t size)104 hal_status_t hal_exflash_read(exflash_handle_t *p_exflash, uint32_t addr, uint8_t *p_data, uint32_t size)
105 {
106 #if (ENCRYPT_ENABLE || (CHIP_TYPE == 1) || (EXT_EXFLASH_ENABLE == 1))
107 return hal_exflash_read_patch(p_exflash, addr, p_data, size);
108 #else
109 return hal_exflash_read_rom(p_exflash, addr, p_data, size);
110 #endif
111 }
112
113 #endif /* HAL_EXFLASH_MODULE_ENABLED */
114