1 /*
2  * Copyright (c) 2006-2022, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date         Author      Notes
8  * 2011-05-06   onelife     Initial creation by using USART module
9  */
10 
11 #ifndef __DEV_SFLASH_H__
12 #define __DEV_SFLASH_H__
13 
14 /* Includes ------------------------------------------------------------------*/
15 /* Exported types ------------------------------------------------------------*/
16 enum sflash_inst_type_t
17 {
18     /* Instruction only */
19     sflash_inst_wren = 0x00,
20     sflash_inst_wrdi,
21     sflash_inst_rdid_l,
22     sflash_inst_rdid_s,
23     sflash_inst_rdsr,
24     sflash_inst_wrsr,
25     sflash_inst_be,
26     sflash_inst_dp,
27     sflash_inst_rdp,
28     /* Instruction and address */
29     sflash_inst_wrlr,
30     sflash_inst_rdlr,
31     sflash_inst_read,
32     sflash_inst_potp,
33     sflash_inst_pp,
34     sflash_inst_difp,
35     sflash_inst_sse,
36     sflash_inst_se,
37     /* Instruction, address and dummy read */
38     sflash_inst_read_f,
39     sflash_inst_dofr,
40     sflash_inst_rotp
41 };
42 
43 /* Exported constants --------------------------------------------------------*/
44 /* Exported macro ------------------------------------------------------------*/
45 #define SFLASH_SPI_COMMAND_SKIP     (1)
46 #define SFLASH_SPI_READ_SKIP        (2)
47 
48 #define SFLASH_INST_CODE_WREN       (0x06)
49 #define SFLASH_INST_CODE_WRDI       (0x04)
50 #define SFLASH_INST_CODE_RDID_L     (0x9F)
51 #define SFLASH_INST_CODE_RDID_S     (0x9E)
52 #define SFLASH_INST_CODE_RDSR       (0x05)
53 #define SFLASH_INST_CODE_WRSR       (0x01)
54 #define SFLASH_INST_CODE_WRLR       (0xE5)
55 #define SFLASH_INST_CODE_RDLR       (0xE8)
56 #define SFLASH_INST_CODE_READ       (0x03)
57 #define SFLASH_INST_CODE_READ_F     (0x0B)
58 #define SFLASH_INST_CODE_DOFR       (0x3B)
59 #define SFLASH_INST_CODE_ROTP       (0x4B)
60 #define SFLASH_INST_CODE_POTP       (0x42)
61 #define SFLASH_INST_CODE_PP         (0x02)
62 #define SFLASH_INST_CODE_DIFP       (0xA2)
63 #define SFLASH_INST_CODE_SSE        (0x20)
64 #define SFLASH_INST_CODE_SE         (0xD8)
65 #define SFLASH_INST_CODE_BE         (0xC7)
66 #define SFLASH_INST_CODE_DP         (0xB9)
67 #define SFLASH_INST_CODE_RDP        (0xAB)
68 
69 #define SFLASH_REPLY_LEN_WREN       (0)
70 #define SFLASH_REPLY_LEN_WRDI       (0)
71 #define SFLASH_REPLY_LEN_RDID_L     (20)
72 #define SFLASH_REPLY_LEN_RDID_S     (3)
73 #define SFLASH_REPLY_LEN_RDSR       (1)
74 #define SFLASH_REPLY_LEN_WRSR       (1)
75 #define SFLASH_REPLY_LEN_WRLR       (1)
76 #define SFLASH_REPLY_LEN_RDLR       (1)
77 #define SFLASH_REPLY_LEN_READ       (-1)
78 #define SFLASH_REPLY_LEN_READ_F     (-1)
79 #define SFLASH_REPLY_LEN_DOFR       (-1)
80 #define SFLASH_REPLY_LEN_ROTP       (65)
81 #define SFLASH_REPLY_LEN_POTP       (65)
82 #define SFLASH_REPLY_LEN_PP         (256)
83 #define SFLASH_REPLY_LEN_DIFP       (256)
84 #define SFLASH_REPLY_LEN_SSE        (0)
85 #define SFLASH_REPLY_LEN_SE         (0)
86 #define SFLASH_REPLY_LEN_BE         (0)
87 #define SFLASH_REPLY_LEN_DP         (0)
88 #define SFLASH_REPLY_LEN_RDP        (0)
89 
90 /* Exported functions ------------------------------------------------------- */
91 rt_err_t efm_spiFlash_init(void);
92 rt_err_t efm_spiFlash_deinit(void);
93 rt_uint32_t efm_spiFlash_cmd(
94     enum sflash_inst_type_t command,
95     rt_uint32_t address,
96     rt_uint8_t *buffer,
97     rt_uint32_t size);
98 
99 #endif /* __DEV_SFLASH_H__ */
100