XCORE SDK
XCORE Software Development Kit
sfdp.h
1 // Copyright 2021 XMOS LIMITED.
2 // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 
4 #ifndef SFDP_H_
5 #define SFDP_H_
6 
7 #include <stdlib.h>
8 #include <stdint.h>
9 #include <stdbool.h>
10 
11 #define SFDP_READ_INSTRUCTION 0x5A
12 
13 typedef struct {
14  uint32_t signature;
15  uint8_t minor_revision;
16  uint8_t major_revision;
17  uint8_t nph;
18  uint8_t : 8;
20 
21 typedef struct {
22  uint8_t id_lsb;
23  uint8_t minor_revision;
24  uint8_t major_revision;
25  uint8_t length;
26  uint32_t table_address : 24;
27  uint8_t id_msb;
29 
30 enum {
31  sfdp_3_byte_address = 0,
32  sfdp_3_or_4_byte_address = 1,
33  sfdp_4_byte_address = 2,
34 };
35 
36 #define SFDP_BUSY_POLL_LEGACY_BM 0x01
37 #define SFDP_BUSY_POLL_ALT1_BM 0x02
38 
39 typedef struct {
40  /* 1st DWORD */
41  uint32_t : 2; /* legacy */
42  uint32_t : 1; /* legacy */
43  uint32_t : 1; /* legacy */
44  uint32_t : 1; /* legacy */
45  uint32_t : 3; /* unused */
46  uint32_t : 8; /* erase table used instead */
47  uint32_t : 1; /* supports 1-1-2 fast read */
48  uint32_t address_bytes : 2;
49  uint32_t : 1; /* DTR clocking */
50  uint32_t : 1; /* supports 1-2-2 fast read */
51  uint32_t supports_144_fast_read: 1;
52  uint32_t supports_114_fast_read: 1;
53  uint32_t : 9; /* unused */
54 
55  /* 2nd DWORD */
56  uint32_t memory_density : 30;
57  uint32_t memory_density_is_exponent : 1;
58 
59  /* 3rd DWORD */
60  uint8_t quad_144_read_dummy_clocks : 5;
61  uint8_t quad_144_read_mode_clocks : 3;
62  uint8_t quad_144_read_cmd;
63  uint8_t quad_114_read_dummy_clocks : 5;
64  uint8_t quad_114_read_mode_clocks : 3;
65  uint8_t quad_114_read_cmd;
66 
67  /* 4th DWORD */
68  uint32_t : 32;
69  /* 5th DWORD */
70  uint32_t : 32;
71  /* 6th DWORD */
72  uint32_t : 32;
73  /* 7th DWORD */
74  uint32_t : 32;
75 
76  /* 8th and 9th DWORD */
77  struct {
78  uint8_t size;
79  uint8_t cmd;
80  } erase_info[4];
81 
82  /* 10th DWORD */
83  uint32_t : 32; /* typical and maximum erase times */
84  /* TODO could be nice for timeouts */
85 
86  /* 11th DWORD */
87  /* typical and max chip erase and program times. page size. */
88  uint32_t typ_to_max_prog_time_multiplier : 4;
89  uint32_t page_size : 4;
90  uint32_t page_prog_time_typ : 6;
91  uint32_t byte_prog_time_first_typ : 5;
92  uint32_t byte_prog_time_addl_typ : 5;
93  uint32_t chip_erase_time_typ : 7;
94  uint32_t : 1; /* reserved */
95 
96  /* 12th DWORD */
97  uint32_t : 32; /* suspend/resume info */
98 
99  /* 13th DWORD */
100  uint32_t : 32; /* suspend/resume instructions */
101 
102  /* 14th DWORD */
103  uint32_t : 2; /* reserved */
104  uint32_t busy_poll_methods : 6;
105  uint32_t : 7; /* powerdown info */
106  uint32_t : 8; /* powerdown info */
107  uint32_t : 8; /* powerdown info */
108  uint32_t : 1; /* powerdown info */
109 
110  /* 15th DWORD */
111  uint32_t : 4; /* 4-4-4 mode disable */
112  uint32_t : 5; /* 4-4-4 mode enable */
113  uint32_t xip_mode_supported : 1;
114  uint32_t xip_mode_exit_method : 6;
115  uint32_t xip_mode_entry_method : 4;
116  uint32_t quad_enable_method : 3;
117  uint32_t hold_reset_disable : 1;
118  uint32_t : 8; /* reserved */
119 
120  /* 16th DWORD */
121  uint32_t status_reg_1_info : 7;
122  uint32_t : 1; /* reserved */
123  uint32_t soft_reset_sequence : 6;
124  uint32_t four_byte_address_exit_method : 10;
125  uint32_t four_byte_address_enter_method : 8;
126 
128 
129 typedef struct {
130  sfdp_header_t sfdp_header;
131  sfdp_parameter_header_t basic_parameter_header;
132  sfdp_parameter_table_t basic_parameter_table;
133 } sfdp_info_t;
134 
135 #define SFDP_READ_CALLBACK_ATTR __attribute__((fptrgroup("sfdp_read_cb_fptr_grp")))
136 
137 typedef void (*sfdp_read_cb_t)(void *flash_ctx, void *data, uint32_t address, size_t len);
138 
139 size_t sfdp_flash_size_kbytes(sfdp_info_t *sfdp_info);
140 size_t sfdp_flash_page_size_bytes(sfdp_info_t *sfdp_info);
141 int sfdp_busy_poll_method(sfdp_info_t *sfdp_info,
142  uint8_t *instruction,
143  uint8_t *bit,
144  uint8_t *ready_value);
145 int sfdp_quad_enable_method(sfdp_info_t *sfdp_info,
146  uint8_t *qe_reg,
147  uint8_t *qe_bit,
148  uint8_t *sr2_read_instruction,
149  uint8_t *sr2_write_instruction);
150 
151 bool sfdp_discover(sfdp_info_t *sfdp_info,
152  void *serial_flash_ctx,
153  sfdp_read_cb_t sfdp_read);
154 
155 #endif /* SFDP_H_ */
Definition: sfdp.h:13
Definition: sfdp.h:129
Definition: sfdp.h:21
Definition: sfdp.h:39