app_graphics_ospi.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file app_graphics_ospi.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of OSPI app library.
7  *
8  ****************************************************************************************
9  * @attention
10  #####Copyright (c) 2021 GOODIX
11  All rights reserved.
12 
13  Redistribution and use in source and binary forms, with or without
14  modification, are permitted provided that the following conditions are met:
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  * Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  * Neither the name of GOODIX nor the names of its contributors may be used
21  to endorse or promote products derived from this software without
22  specific prior written permission.
23 
24  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  POSSIBILITY OF SUCH DAMAGE.
35  ****************************************************************************************
36  */
37 
38 
39 /** @addtogroup PERIPHERAL Peripheral Driver
40  * @{
41  */
42 
43 /** @addtogroup APP_DRIVER APP DRIVER
44  * @{
45  */
46 
47 /** @defgroup APP_GRAPHICS_OSPI OSPI
48  * @brief OSPI APP module driver.
49  * @{
50  */
51 
52 #ifndef __APP_GRAPHICS_OSPI_H__
53 #define __APP_GRAPHICS_OSPI_H__
54 
55 #include "gr55xx.h"
56 #include "gr55xx_ll_ospi_x.h"
57 #include "stdbool.h"
58 #include "app_drv_error.h"
59 #include "app_drv_config.h"
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 /** @addtogroup APP_GRAPHICS_OSPI_ENUM Enumerations
66  * @{
67  */
68 
69 /**
70  * @brief OSPI Clock Frequency Enumerations definition
71  */
72 typedef enum {
78 
79 
80 /**
81  * @brief OSPI PHY Delay Value Enumerations definition
82  */
83 typedef enum {
84  OSPI_PHY_DELAY_TAP_2 = 0x01, /* phy delay 2 about ? ns */
85  OSPI_PHY_DELAY_TAP_3 = 0x02, /* phy delay 3 about ? ns */
86  OSPI_PHY_DELAY_TAP_4 = 0x03, /* phy delay 4 about ? ns */
88 
89 /**
90  * @brief PSRAM Drive Strength Enumerations definition
91  */
92 typedef enum {
93  OSPI_PSRAM_DRV_STR_FULL = 0x00, /* about 25 Ohm */
94  OSPI_PSRAM_DRV_STR_HALF = 0x01, /* about 50 Ohm */
95  OSPI_PSRAM_DRV_STR_ONE_FORTH = 0x02, /* about 100 Ohm */
96  OSPI_PSRAM_DRV_STR_ONE_EIGHTH = 0x03, /* about 200 Ohm */
98 
99 /**
100  * @brief PSRAM Read Latency Enumerations definition
101  */
102 typedef enum {
109 
110 /**
111  * @brief PSRAM Write Latency Enumerations definition
112  */
113 typedef enum {
120 
121 /**
122  * @brief PSRAM Access Mode Enumerations definition
123  */
124 typedef enum {
125  OSPI_ACCESS_MEMORY = 0, /* read & write the psram */
126  OSPI_ACCESS_REGISTER, /* use to access the register */
129 
130 /**
131  * @brief PSRAM Work Mode Enumerations definition
132  */
133 typedef enum {
134  OSPI_STATE_DEEP_SLEEP = 0, /* deep sleep, all memory data loss except register data */
135  OSPI_STATE_HALF_SLEEP = 1, /* half sleep, all data kept */
136  OSPI_STATE_ACTIVE = 2, /* active, not sleep */
138 
139 /**
140  * @brief PSRAM Partial Array Refresh Enumerations definition
141  */
142 typedef enum {
143  OSPI_PASR_FULL = 0x00, /* refresh full array */
144  OSPI_PASR_BOTTOM_4MB = 0x01, /* refresh Bottom 4MB array, [000000h,3FFFFFh] */
145  OSPI_PASR_BOTTOM_2MB = 0x02, /* refresh Bottom 2MB array, [000000h,1FFFFFh] */
146  OSPI_PASR_BOTTOM_1MB = 0x03, /* refresh Bottom 1MB array, [000000h,0FFFFFh] */
147  OSPI_PASR_NONE = 0x04, /* refresh None */
148  OSPI_PASR_TOP_4MB = 0x05, /* refresh Top 4MB array, [400000h,7FFFFFh] */
149  OSPI_PASR_TOP_2MB = 0x06, /* refresh Top 2MB array, [600000h,7FFFFFh] */
150  OSPI_PASR_TOP_1MB = 0x07, /* refresh Top 1MB array, [700000h,7FFFFFh] */
151  OSPI_PASR_MAX, /* MAX mark */
153 
154 
155 /** @} */
156 
157 /** @addtogroup APP_OSPI_STRUCTURES Structures
158  * @{
159  */
160 
161 /**
162  * @brief Define init params for OSPI
163  */
164 typedef struct {
165  app_ospi_clock_freq_e ospi_freq; /**< Specify ospi freq, Ref Optional values of app_ospi_clock_freq_e */
166  app_ospi_psram_drv_strength_e drv_strength; /**< Specify psram's drive strength, Ref Optional values of app_ospi_psram_drv_strength_e */
167  app_ospi_psram_rd_latency_e rd_lc; /**< Specify psram's read latency, Ref Optional values of app_ospi_clock_freq_e */
168  app_ospi_psram_wr_latency_e wr_lc; /**< Specify psram's write latency, Ref Optional values of app_ospi_clock_freq_e */
169  uint32_t phy_delay; /**< Specify the delay tap for ospi phy, Ref Optional values of app_ospi_phy_delay_e */
170  uint8_t is_read_prefetch; /**< Specify whether to enable the read prefetch feature or not */
172 
173 /** @} */
174 
175 /** @addtogroup APP_OSPI_TYPEDEFS Type definitions
176  * @{
177  */
178 
179 /**
180  * @brief Define IRQ handler for OSPI
181  */
182 typedef void (* ospi_irq_handler)(void);
183 
184 /**
185  * @brief Define PSRAM reload function for OSPI
186  */
187 typedef void (* psram_reload_func_t)(void);
188 
189 /** @} */
190 
191 /**
192  * @defgroup APP_OSPI_MACRO Defines
193  * @{
194  */
195 
196 /* Exported constants --------------------------------------------------------*/
197 /** @defgroup APP_OSPI_Exported_Constants OSPI Exported Constants
198  * @{
199  */
200 #define OSPI_PSRAM_DEVICE_ID 0x13 /**< PSRAM ID */
201 #define OSPI_PSRAM_MIN_XIP_ADDRESS OSPI0_XIP_BASE /**< XIP Base Address */
202 #define OSPI_PSRAM_MAX_XIP_ADDRESS (OSPI0_XIP_BASE + 0x7FFFFF) /**< 64Mbit Space */
203 #define OSPI_PSRAM_BYTE_SIZE (0x800000) /**< 64Mbit Space */
204 
205 /**
206  * @brief PSRAM init parameter definition
207  */
208 #define PSRAM_INIT_PARAMS_Default \
209  { \
210  .ospi_freq = OSPI_CLOCK_FREQ_48MHz, \
211  .drv_strength = OSPI_PSRAM_DRV_STR_ONE_EIGHTH, \
212  .rd_lc = OSPI_PSRAM_RD_LATENCY_3, \
213  .wr_lc = OSPI_PSRAM_WR_LATENCY_3, \
214  .phy_delay = 1, \
215  .is_read_prefetch = 0, \
216  }
217 /** @} */
218 
219 /** @} */
220 
221 
222 /** @addtogroup APP_OSPI_DRIVER_FUNCTIONS Functions
223  * @{
224  */
225 
226 /**
227  ****************************************************************************************
228  * @brief Initialize the APP OSPI DRIVER according to the specified parameters.
229  *
230  * @param[in] p_params: Pointer to app_graphics_ospi_params_t parameter which contains the
231  * configuration information for the specified OSPI module.
232  *
233  * @return APP_DRV_*
234  ****************************************************************************************
235  */
237 
238 /**
239  ****************************************************************************************
240  * @brief De-Initialize the APP OSPI DRIVER .
241  *
242  ****************************************************************************************
243  */
245 
246 /**
247  ****************************************************************************************
248  * @brief Reset the OSPI Controller.
249  *
250  ****************************************************************************************
251  */
253 
254 /**
255  ****************************************************************************************
256  * @brief Register the OSPI reload function for PSRAM recovery after deep sleep.
257  *
258  * @param[in] psram_reload_func: Reload the resources to PSRAM after PSRAM deep sleep.
259  ****************************************************************************************
260  */
262 
263 /**
264  ****************************************************************************************
265  * @brief Set the OSPI low power state for system sleep.
266  *
267  * @param[in] state: Ref the @ref app_ospi_work_state_e
268  ****************************************************************************************
269  */
271 
272 /**
273  ****************************************************************************************
274  * @brief Get the OSPI low power state for system sleep.
275  *
276  * @return state: Ref the @ref app_ospi_work_state_e
277  ****************************************************************************************
278  */
280 
281 /**
282  ****************************************************************************************
283  * @brief Get the OSPI.PSRAM Base Address
284  *
285  * @return OSPI.PSRAM Base Address
286  ****************************************************************************************
287  */
289 
290 /**
291  ****************************************************************************************
292  * @brief Set Partial Refresh Array for OSPI PSRAM
293  *
294  * @param[in] area: please refer to app_ospi_pasr_e Enumerations
295  *
296  ****************************************************************************************
297  */
299 
300 /**
301  ****************************************************************************************
302  * @brief Set Partial Refresh Array for OSPI PSRAM with PSRAM used address
303  *
304  * @param[in] psram_addr: PSRAM highest used address
305  *
306  ****************************************************************************************
307  */
308 void app_graphics_ospi_pasr_update(uint32_t psram_addr);
309 
310 /**
311  ****************************************************************************************
312  * @brief Check address is located at ospi.psram or not
313  *
314  * @return OSPI.PSRAM Base Address
315  ****************************************************************************************
316  */
317 __STATIC_INLINE bool app_graphics_is_ospi_address(uint32_t address) {
318  return ((address >= OSPI_PSRAM_MIN_XIP_ADDRESS) && (address <= OSPI_PSRAM_MAX_XIP_ADDRESS));
319 }
320 
321 /**
322  ****************************************************************************************
323  * @brief Enable/Disable read prefetch of OSPI PSRAM
324  *
325  * @return OSPI.PSRAM Base Address
326  ****************************************************************************************
327  */
328 __STATIC_INLINE void app_graphics_ospi_set_read_prefetch(bool enable) {
329  ll_ospi_x_set_read_prefetch(OSPI0, enable ? 1 : 0);
330 }
331 
332 /**
333  ****************************************************************************************
334  * @brief Get read prefetch state of OSPI PSRAM
335  *
336  * @return OSPI.PSRAM Base Address
337  ****************************************************************************************
338  */
339 __STATIC_INLINE bool app_graphics_ospi_get_read_prefetch(void) {
340  return ll_ospi_x_is_read_prefetch_enabled(OSPI0);
341 }
342 
343 /**
344  ****************************************************************************************
345  * @brief Get the OSPI.PSRAM Size in Bytes
346  *
347  * @return OSPI.PSRAM Space Size in Bytes
348  ****************************************************************************************
349  */
351 
352 /**
353  ****************************************************************************************
354  * @brief Set the OSPI work state.
355  * @param[in] state: please refer to app_ospi_work_state_e Enumerations
356  ****************************************************************************************
357  */
359 
360 /** @} */
361 
362 #ifdef __cplusplus
363 }
364 #endif
365 
366 #endif /* __APP_GRAPHICS_OSPI_H__ */
367 
368 /** @} */
369 /** @} */
370 /** @} */
OSPI_ACCESS_MEMORY
@ OSPI_ACCESS_MEMORY
Definition: app_graphics_ospi.h:125
OSPI_PASR_FULL
@ OSPI_PASR_FULL
Definition: app_graphics_ospi.h:143
OSPI_PSRAM_WR_LATENCY_4
@ OSPI_PSRAM_WR_LATENCY_4
Definition: app_graphics_ospi.h:115
OSPI_CLOCK_FREQ_16MHz
@ OSPI_CLOCK_FREQ_16MHz
Definition: app_graphics_ospi.h:76
app_graphics_ospi_get_base_address
uint32_t app_graphics_ospi_get_base_address(void)
Get the OSPI.PSRAM Base Address.
OSPI_CLOCK_FREQ_32MHz
@ OSPI_CLOCK_FREQ_32MHz
Definition: app_graphics_ospi.h:74
OSPI_PSRAM_MIN_XIP_ADDRESS
#define OSPI_PSRAM_MIN_XIP_ADDRESS
Definition: app_graphics_ospi.h:201
OSPI_PSRAM_DRV_STR_HALF
@ OSPI_PSRAM_DRV_STR_HALF
Definition: app_graphics_ospi.h:94
OSPI_PHY_DELAY_TAP_4
@ OSPI_PHY_DELAY_TAP_4
Definition: app_graphics_ospi.h:86
OSPI_ACCESS_UNSET
@ OSPI_ACCESS_UNSET
Definition: app_graphics_ospi.h:127
app_graphics_ospi_params_t::phy_delay
uint32_t phy_delay
Definition: app_graphics_ospi.h:169
app_graphics_ospi_params_t::ospi_freq
app_ospi_clock_freq_e ospi_freq
Definition: app_graphics_ospi.h:165
OSPI_PASR_BOTTOM_1MB
@ OSPI_PASR_BOTTOM_1MB
Definition: app_graphics_ospi.h:146
OSPI_PSRAM_DRV_STR_ONE_FORTH
@ OSPI_PSRAM_DRV_STR_ONE_FORTH
Definition: app_graphics_ospi.h:95
app_ospi_work_state_e
app_ospi_work_state_e
PSRAM Work Mode Enumerations definition.
Definition: app_graphics_ospi.h:133
app_graphics_ospi_register_psram_reload_func
void app_graphics_ospi_register_psram_reload_func(psram_reload_func_t psram_reload_func)
Register the OSPI reload function for PSRAM recovery after deep sleep.
app_graphics_ospi_pasr_update
void app_graphics_ospi_pasr_update(uint32_t psram_addr)
Set Partial Refresh Array for OSPI PSRAM with PSRAM used address.
OSPI_PSRAM_RD_LATENCY_6
@ OSPI_PSRAM_RD_LATENCY_6
Definition: app_graphics_ospi.h:106
app_ospi_access_mode_e
app_ospi_access_mode_e
PSRAM Access Mode Enumerations definition.
Definition: app_graphics_ospi.h:124
OSPI_PSRAM_WR_LATENCY_7
@ OSPI_PSRAM_WR_LATENCY_7
Definition: app_graphics_ospi.h:118
gr55xx_ll_ospi_x.h
Header file containing functions prototypes of SPI LL library.
app_graphics_ospi_set_sleep_state
void app_graphics_ospi_set_sleep_state(app_ospi_work_state_e state)
Set the OSPI low power state for system sleep.
app_graphics_ospi_params_t::wr_lc
app_ospi_psram_wr_latency_e wr_lc
Definition: app_graphics_ospi.h:168
app_ospi_psram_rd_latency_e
app_ospi_psram_rd_latency_e
PSRAM Read Latency Enumerations definition.
Definition: app_graphics_ospi.h:102
OSPI_PHY_DELAY_TAP_3
@ OSPI_PHY_DELAY_TAP_3
Definition: app_graphics_ospi.h:85
OSPI_PASR_BOTTOM_2MB
@ OSPI_PASR_BOTTOM_2MB
Definition: app_graphics_ospi.h:145
app_graphics_ospi_set_pasr
void app_graphics_ospi_set_pasr(app_ospi_pasr_e area)
Set Partial Refresh Array for OSPI PSRAM.
app_ospi_phy_delay_e
app_ospi_phy_delay_e
OSPI PHY Delay Value Enumerations definition.
Definition: app_graphics_ospi.h:83
OSPI_PSRAM_RD_LATENCY_4
@ OSPI_PSRAM_RD_LATENCY_4
Definition: app_graphics_ospi.h:104
app_ospi_pasr_e
app_ospi_pasr_e
PSRAM Partial Array Refresh Enumerations definition.
Definition: app_graphics_ospi.h:142
ospi_irq_handler
void(* ospi_irq_handler)(void)
Define IRQ handler for OSPI.
Definition: app_graphics_ospi.h:182
app_graphics_ospi_get_sleep_state
app_ospi_work_state_e app_graphics_ospi_get_sleep_state(void)
Get the OSPI low power state for system sleep.
psram_reload_func_t
void(* psram_reload_func_t)(void)
Define PSRAM reload function for OSPI.
Definition: app_graphics_ospi.h:187
OSPI_PSRAM_WR_LATENCY_6
@ OSPI_PSRAM_WR_LATENCY_6
Definition: app_graphics_ospi.h:117
app_ospi_psram_wr_latency_e
app_ospi_psram_wr_latency_e
PSRAM Write Latency Enumerations definition.
Definition: app_graphics_ospi.h:113
OSPI_PSRAM_RD_LATENCY_3
@ OSPI_PSRAM_RD_LATENCY_3
Definition: app_graphics_ospi.h:103
app_graphics_ospi_params_t::is_read_prefetch
uint8_t is_read_prefetch
Definition: app_graphics_ospi.h:170
OSPI_STATE_DEEP_SLEEP
@ OSPI_STATE_DEEP_SLEEP
Definition: app_graphics_ospi.h:134
app_graphics_ospi_params_t
Define init params for OSPI.
Definition: app_graphics_ospi.h:164
OSPI_PASR_TOP_1MB
@ OSPI_PASR_TOP_1MB
Definition: app_graphics_ospi.h:150
app_graphics_is_ospi_address
__STATIC_INLINE bool app_graphics_is_ospi_address(uint32_t address)
Check address is located at ospi.psram or not.
Definition: app_graphics_ospi.h:317
app_ospi_psram_drv_strength_e
app_ospi_psram_drv_strength_e
PSRAM Drive Strength Enumerations definition.
Definition: app_graphics_ospi.h:92
OSPI_CLOCK_FREQ_48MHz
@ OSPI_CLOCK_FREQ_48MHz
Definition: app_graphics_ospi.h:73
OSPI_ACCESS_REGISTER
@ OSPI_ACCESS_REGISTER
Definition: app_graphics_ospi.h:126
OSPI_STATE_ACTIVE
@ OSPI_STATE_ACTIVE
Definition: app_graphics_ospi.h:136
OSPI_PASR_MAX
@ OSPI_PASR_MAX
Definition: app_graphics_ospi.h:151
OSPI_PASR_TOP_4MB
@ OSPI_PASR_TOP_4MB
Definition: app_graphics_ospi.h:148
OSPI_STATE_HALF_SLEEP
@ OSPI_STATE_HALF_SLEEP
Definition: app_graphics_ospi.h:135
app_graphics_ospi_params_t::rd_lc
app_ospi_psram_rd_latency_e rd_lc
Definition: app_graphics_ospi.h:167
app_graphics_ospi_init
uint16_t app_graphics_ospi_init(app_graphics_ospi_params_t *p_params)
Initialize the APP OSPI DRIVER according to the specified parameters.
app_graphics_ospi_set_power_state
void app_graphics_ospi_set_power_state(app_ospi_work_state_e state)
Set the OSPI work state.
OSPI_PASR_TOP_2MB
@ OSPI_PASR_TOP_2MB
Definition: app_graphics_ospi.h:149
OSPI_PSRAM_MAX_XIP_ADDRESS
#define OSPI_PSRAM_MAX_XIP_ADDRESS
Definition: app_graphics_ospi.h:202
app_graphics_ospi_get_byte_size
uint32_t app_graphics_ospi_get_byte_size(void)
Get the OSPI.PSRAM Size in Bytes.
OSPI_PSRAM_RD_LATENCY_7
@ OSPI_PSRAM_RD_LATENCY_7
Definition: app_graphics_ospi.h:107
OSPI_PHY_DELAY_TAP_2
@ OSPI_PHY_DELAY_TAP_2
Definition: app_graphics_ospi.h:84
app_graphics_ospi_get_read_prefetch
__STATIC_INLINE bool app_graphics_ospi_get_read_prefetch(void)
Get read prefetch state of OSPI PSRAM.
Definition: app_graphics_ospi.h:339
app_graphics_ospi_set_read_prefetch
__STATIC_INLINE void app_graphics_ospi_set_read_prefetch(bool enable)
Enable/Disable read prefetch of OSPI PSRAM.
Definition: app_graphics_ospi.h:328
OSPI_PSRAM_DRV_STR_FULL
@ OSPI_PSRAM_DRV_STR_FULL
Definition: app_graphics_ospi.h:93
app_graphics_ospi_deinit
void app_graphics_ospi_deinit(void)
De-Initialize the APP OSPI DRIVER .
OSPI_PASR_BOTTOM_4MB
@ OSPI_PASR_BOTTOM_4MB
Definition: app_graphics_ospi.h:144
app_graphics_ospi_params_t::drv_strength
app_ospi_psram_drv_strength_e drv_strength
Definition: app_graphics_ospi.h:166
app_ospi_clock_freq_e
app_ospi_clock_freq_e
OSPI Clock Frequency Enumerations definition.
Definition: app_graphics_ospi.h:72
OSPI_PSRAM_DRV_STR_ONE_EIGHTH
@ OSPI_PSRAM_DRV_STR_ONE_EIGHTH
Definition: app_graphics_ospi.h:96
app_drv_error.h
Header file of app driver error code.
app_drv_config.h
Header file of app driver config code.
OSPI_PSRAM_WR_LATENCY_5
@ OSPI_PSRAM_WR_LATENCY_5
Definition: app_graphics_ospi.h:116
OSPI_PSRAM_WR_LATENCY_3
@ OSPI_PSRAM_WR_LATENCY_3
Definition: app_graphics_ospi.h:114
app_graphics_ospi_reset
void app_graphics_ospi_reset(void)
Reset the OSPI Controller.
OSPI_PSRAM_RD_LATENCY_5
@ OSPI_PSRAM_RD_LATENCY_5
Definition: app_graphics_ospi.h:105
OSPI_CLOCK_FREQ_24MHz
@ OSPI_CLOCK_FREQ_24MHz
Definition: app_graphics_ospi.h:75
OSPI_PASR_NONE
@ OSPI_PASR_NONE
Definition: app_graphics_ospi.h:147