1 /**
2   *********************************************************************************
3   *
4   * @file    ald_sram.h
5   * @brief   Header file of EBI_SRAM driver
6   *
7   * @version V1.0
8   * @date    07 Dec 2019
9   * @author  AE Team
10   * @note
11   *          Change Logs:
12   *          Date            Author          Notes
13   *          07 Dec 2019     AE Team         The first version
14   *
15   * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
16   *
17   * SPDX-License-Identifier: Apache-2.0
18   *
19   * Licensed under the Apache License, Version 2.0 (the License); you may
20   * not use this file except in compliance with the License.
21   * You may obtain a copy of the License at
22   *
23   * www.apache.org/licenses/LICENSE-2.0
24   *
25   * Unless required by applicable law or agreed to in writing, software
26   * distributed under the License is distributed on an AS IS BASIS, WITHOUT
27   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28   * See the License for the specific language governing permissions and
29   * limitations under the License.
30   **********************************************************************************
31   */
32 
33 #ifndef __ALD_SRAM_H__
34 #define __ALD_SRAM_H__
35 
36 #ifdef __cplusplus
37  extern "C" {
38 #endif
39 
40 #include "ald_ebi.h"
41 #include "ald_dma.h"
42 
43 /** @addtogroup ES32FXXX_ALD
44   * @{
45   */
46 
47 /** @addtogroup SRAM
48   * @{
49   */
50 
51 /** @defgroup SRAM_Public_Types SRAM Public Types
52   * @{
53   */
54 
55 /**
56   * @brief  ALD SRAM State structures definition
57   */
58 typedef enum {
59 	ALD_SRAM_STATE_RESET     = 0x00U,	/**< SRAM not yet initialized or disabled */
60 	ALD_SRAM_STATE_READY     = 0x01U,	/**< SRAM initialized and ready for use */
61 	ALD_SRAM_STATE_BUSY      = 0x02U,	/**< SRAM internal process is ongoing */
62 	ALD_SRAM_STATE_ERROR     = 0x03U,	/**< SRAM error state */
63 	ALD_SRAM_STATE_PROTECTED = 0x04U	/**< SRAM peripheral NORSRAM device write protected */
64 } ald_sram_state_t;
65 
66 /**
67   * @brief  SRAM handle Structure definition
68   */
69 typedef struct {
70 	EBI_NOR_SRAM_TypeDef *instance;		/**< Register base address */
71 	EBI_NOR_SRAM_EXTENDED_TypeDef *ext;	/**< Extended mode register base address */
72 	ald_ebi_nor_sram_init_t init;		/**< SRAM device control configuration parameters */
73 	lock_state_t lock;			/**< SRAM locking object */
74 	__IO ald_sram_state_t state;		/**< SRAM device access state */
75 
76 	dma_handle_t hdma;			/**< SRAM DMA Handle parameters */
77 	void(*cplt_cbk)(void *arg);             /**< DMA transmit completely callback function */
78 
79 } sram_handle_t;
80 /**
81   * @}
82   */
83 
84 /** @addtogroup SRAM_Public_Functions
85   * @{
86   */
87 /** @addtogroup SRAM_Public_Functions_Group1
88   * @{
89   */
90 /* Initialization functions */
91 ald_status_t ald_sram_init(sram_handle_t *hperh, ald_ebi_nor_sram_timing_t *timing, ald_ebi_nor_sram_timing_t *ext_timing);
92 ald_status_t  ald_sram_deinit(sram_handle_t *hperh);
93 /**
94   * @}
95   */
96 /** @addtogroup SRAM_Public_Functions_Group2
97   * @{
98   */
99 /* I/O operation functions */
100 ald_status_t ald_sram_read_8b(sram_handle_t *hperh, uint32_t *addr, uint8_t *buf, uint32_t size);
101 ald_status_t ald_sram_write_8b(sram_handle_t *hperh, uint32_t *addr, uint8_t *buf, uint32_t size);
102 ald_status_t ald_sram_read_16b(sram_handle_t *hperh, uint32_t *addr, uint16_t *buf, uint32_t size);
103 ald_status_t ald_sram_write_16b(sram_handle_t *hperh, uint32_t *addr, uint16_t *buf, uint32_t size);
104 ald_status_t ald_sram_read_32b(sram_handle_t *hperh, uint32_t *addr, uint32_t *buf, uint32_t size);
105 ald_status_t ald_sram_write_32b(sram_handle_t *hperh, uint32_t *addr, uint32_t *buf, uint32_t size);
106 #ifdef ALD_DMA
107 ald_status_t ald_sram_read_by_dma(sram_handle_t *hperh, uint16_t *addr, uint16_t *buf, uint16_t size, uint8_t ch);
108 ald_status_t ald_sram_write_by_dma(sram_handle_t *hperh, uint16_t *addr, uint16_t *buf, uint16_t size, uint8_t ch);
109 #endif
110 /**
111   * @}
112   */
113 /** @addtogroup SRAM_Public_Functions_Group3
114   * @{
115   */
116 /* Control functions */
117 ald_status_t ald_sram_write_enable(sram_handle_t *hperh);
118 ald_status_t ald_sram_write_disable(sram_handle_t *hperh);
119 /**
120   * @}
121   */
122 /** @addtogroup SRAM_Public_Functions_Group4
123   * @{
124   */
125 /* State functions */
126 ald_sram_state_t ald_sram_get_state(sram_handle_t *hperh);
127 /**
128   * @}
129   */
130 /**
131   * @}
132   */
133 /**
134   * @}
135   */
136 /**
137   * @}
138   */
139 #ifdef __cplusplus
140 }
141 #endif
142 #endif  /* __ALD_SRAM_H__ */
143