ald_nor_lcd.h 6.8 KB
Newer Older
W
wangyq2018 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/**
  *********************************************************************************
  *
  * @file    ald_nor_lcd.h
  * @brief   Header file of EBI_NOR_LCD module driver
  *
  * @version V1.0
  * @date    07 Dec 2019
  * @author  AE Team
  * @note
  *
  * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
  *
  *********************************************************************************
  */

#ifndef __ALD_NOR_LCD_H_
#define __ALD_NOR_LCD_H_

#ifdef __cplusplus
 extern "C" {
#endif

#include "ald_ebi.h"

/** @addtogroup ES32FXXX_ALD
  * @{
  */

/** @addtogroup NOR_LCD
  * @{
  */ 

/**
  * @defgroup NOR_LCD_Private_Constants NOR LCD Private Constants
  * @{
  */

/* NOR device IDs addresses */
W
wangyq2018 已提交
40 41 42 43
#define MC_ADDRESS               ((uint16_t)0x0000U)
#define DEVICE_CODE1_ADDR        ((uint16_t)0x0001U)
#define DEVICE_CODE2_ADDR        ((uint16_t)0x000EU)
#define DEVICE_CODE3_ADDR        ((uint16_t)0x000FU)
W
wangyq2018 已提交
44 45

/* NOR CFI IDs addresses */
W
wangyq2018 已提交
46 47 48 49
#define CFI1_ADDRESS             ((uint16_t)0x10U)
#define CFI2_ADDRESS             ((uint16_t)0x11U)
#define CFI3_ADDRESS             ((uint16_t)0x12U)
#define CFI4_ADDRESS             ((uint16_t)0x13U)
W
wangyq2018 已提交
50 51

/* NOR operation wait timeout */
W
wangyq2018 已提交
52
#define NOR_TMEOUT               ((uint16_t)0xFFFFU)
W
wangyq2018 已提交
53 54

/* NOR memory data width */
W
wangyq2018 已提交
55 56
#define NOR_MEMORY_8B            ((uint8_t)0x0U)
#define NOR_MEMORY_16B           ((uint8_t)0x1U)
W
wangyq2018 已提交
57 58 59 60 61 62 63

/* NOR memory device read/write start address */
#define NOR_MEMORY_ADRESS1       EBI_BANK1_1
#define NOR_MEMORY_ADRESS2       EBI_BANK1_2
#define NOR_MEMORY_ADRESS3       EBI_BANK1_3
#define NOR_MEMORY_ADRESS4       EBI_BANK1_4

W
wangyq2018 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
#define NOR_CMD_ADDRESS_FIRST                 (uint16_t)0x0555U
#define NOR_CMD_ADDRESS_FIRST_CFI             (uint16_t)0x0055U
#define NOR_CMD_ADDRESS_SECOND                (uint16_t)0x02AAU
#define NOR_CMD_ADDRESS_THIRD                 (uint16_t)0x0555U
#define NOR_CMD_ADDRESS_FOURTH                (uint16_t)0x0555U
#define NOR_CMD_ADDRESS_FIFTH                 (uint16_t)0x02AAU
#define NOR_CMD_ADDRESS_SIXTH                 (uint16_t)0x0555U

#define NOR_CMD_DATA_READ_RESET               (uint16_t)0x00F0U
#define NOR_CMD_DATA_FIRST                    (uint16_t)0x00AAU
#define NOR_CMD_DATA_SECOND                   (uint16_t)0x0055U
#define NOR_CMD_DATA_AUTO_SELECT              (uint16_t)0x0090U
#define NOR_CMD_DATA_PROGRAM                  (uint16_t)0x00A0U
#define NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD   (uint16_t)0x0080U
#define NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH  (uint16_t)0x00AAU
#define NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH   (uint16_t)0x0055U
#define NOR_CMD_DATA_CHIP_ERASE               (uint16_t)0x0010U
#define NOR_CMD_DATA_CFI                      (uint16_t)0x0098U
#define NOR_CMD_DATA_BUFFER_AND_PROG          (uint8_t)0x25U
#define NOR_CMD_DATA_BUFFER_AND_PROG_CONFIRM  (uint8_t)0x29U
#define NOR_CMD_DATA_BLOCK_ERASE              (uint8_t)0x30U
#define NOR_MASK_STATUS_DQ5                   (uint16_t)0x0020U
#define NOR_MASK_STATUS_DQ6                   (uint16_t)0x0040U
W
wangyq2018 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
/**
  * @}
  */

/** @defgroup NOR_LCD_Private_Macros NOR_LCD Private Macros
  * @{
  */
#define NOR_ADDR_SHIFT(NOR_ADDR, NOR_MEMORY_WIDTH_, ADDRESS)	\
	((uint32_t)(((NOR_MEMORY_WIDTH_) == NOR_MEMORY_16B) ? 	\
	((uint32_t)((NOR_ADDR) + (2U * (ADDRESS)))):		\
	((uint32_t)((NOR_ADDR) + (ADDRESS)))))
#define NOR_WRITE(ADDR, DATA)  (*(__IO uint16_t *)((uint32_t)(ADDR)) = (DATA))
/**
  * @}
  */

/** @defgroup NOR_LCD_Public_Types NOR_LCD Public Types
  * @{
  */ 
/** 
  * @brief  ALD SRAM State structures definition  
  */ 
typedef enum {
	ALD_NOR_STATE_RESET     = 0x00U,	/**< NOR not yet initialized or disabled */
	ALD_NOR_STATE_READY     = 0x01U,	/**< NOR initialized and ready for use */
	ALD_NOR_STATE_BUSY      = 0x02U,	/**< NOR internal processing is ongoing */
	ALD_NOR_STATE_ERROR     = 0x03U,	/**< NOR error state */ 
	ALD_NOR_STATE_PROTECTED = 0x04U		/**< NOR NORSRAM device write protected */
} ald_nor_state_t;

/**
  * @brief  EBI NOR Status typedef
  */
typedef enum {
W
wangyq2018 已提交
121 122 123 124
	ALD_NOR_STATUS_SUCCESS = 0U,	/**< NOR status success */
	ALD_NOR_STATUS_ONGOING,		/**< NOR status ongoing */
	ALD_NOR_STATUS_ERROR,		/**< NOR status error */
	ALD_NOR_STATUS_TIMEOUT,		/**< NOR status timeout */
W
wangyq2018 已提交
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
} nor_status_t;

/**
  * @brief  EBI NOR ID typedef
  */
typedef struct {
	uint16_t m_code;	/**< Defines the device's manufacturer code used to identify the memory */
	uint16_t device_code1;	/**< DEVICE_CODE1_ADDR code1 */
	uint16_t device_code2;	/**< DEVICE_CODE1_ADDR code2 */
	uint16_t device_code3;	/**< DEVICE_CODE1_ADDR code3 */
} nor_id_t;

/**
  * @brief  EBI NOR CFI typedef
  */
typedef struct {
	uint16_t cfi_1;  /**< NOR CFI 1 */
	uint16_t cfi_2;  /**< NOR CFI 2 */
	uint16_t cfi_3;  /**< NOR CFI 3 */
	uint16_t cfi_4;  /**< NOR CFI 4 */
} nor_cfi_t;

/** 
  * @brief  NOR handle Structure definition  
  */ 
typedef struct {
	EBI_NOR_SRAM_TypeDef *instance;		/**< Register base address */ 
	EBI_NOR_SRAM_EXTENDED_TypeDef *ext;	/**< Extended mode register base address */
	ald_ebi_nor_sram_init_t init;		/**< NOR device control configuration parameters */
	lock_state_t lock;			/**< NOR locking object */ 
	__IO ald_nor_state_t state;		/**< NOR device access state */
} nor_handle_t;
/**
  * @}
  */

/** @addtogroup NOR_Public_Functions
 *  @{
 */
/** @addtogroup NOR_Public_Functions_Group1
 *  @{
 */
/* Initialization/de-initialization functions */  
ald_status_t ald_nor_init(nor_handle_t *hperh, ald_ebi_nor_sram_timing_t *timing, ald_ebi_nor_sram_timing_t *ext_timing);
ald_status_t ald_nor_deinit(nor_handle_t *hperh);
/**
  * @}
  */
/** @addtogroup NOR_LCD_Public_Functions_Group2
 *  @{
 */
/* I/O operation functions */
ald_status_t ald_nor_read_id(nor_handle_t *hperh, nor_id_t *id);
ald_status_t ald_nor_return_readmode(nor_handle_t *hperh);
ald_status_t ald_nor_read(nor_handle_t *hperh, uint32_t *addr, uint16_t *data);
ald_status_t ald_nor_program(nor_handle_t *hperh, uint32_t *addr, uint16_t *data);
ald_status_t ald_nor_read_buffer(nor_handle_t *hperh, uint32_t addr, uint16_t *data, uint32_t size);
ald_status_t ald_nor_program_buffer(nor_handle_t *hperh, uint32_t addr, uint16_t *data, uint32_t size);
ald_status_t ald_nor_erase_block(nor_handle_t *hperh, uint32_t blkaddr, uint32_t addr);
ald_status_t ald_nor_erase_chip(nor_handle_t *hperh);
ald_status_t ald_nor_read_cfi(nor_handle_t *hperh, nor_cfi_t *cfi);
/**
  * @}
  */
/** @addtogroup NOR_LCD_Public_Functions_Group3
 *  @{
 */
/* Control functions */
ald_status_t ald_nor_write_enable(nor_handle_t *hperh);
ald_status_t ald_nor_write_disable(nor_handle_t *hperh);
/**
  * @}
  */
/** @addtogroup NOR_LCD_Public_Functions_Group4
 *  @{
 */
/* State functions */
ald_nor_state_t ald_nor_get_state(nor_handle_t *hperh);
nor_status_t ald_nor_get_status(nor_handle_t *hperh, uint32_t addr, uint32_t timeout);
/**
  * @}
  */
/**
  * @}
  */
/**
  * @}
  */ 
/**
  * @}
  */
#ifdef __cplusplus
}
#endif

#endif /* __ALD_NOR_LCD_H__ */