14
14
* limitations under the License.
15
15
*/
16
16
17
+ #include " drivers/internal/SFDP.h"
18
+ #include " platform/Callback.h"
17
19
#include " QSPIFBlockDevice.h"
18
20
#include < string.h>
19
21
#include " rtos/ThisThread.h"
@@ -48,8 +50,6 @@ using namespace mbed;
48
50
/* SFDP Header Parsing */
49
51
/* **********************/
50
52
#define QSPIF_RSFDP_DUMMY_CYCLES 8
51
- #define QSPIF_SFDP_HEADER_SIZE 8
52
- #define QSPIF_PARAM_HEADER_SIZE 8
53
53
54
54
/* Basic Parameters Table Parsing */
55
55
/* *********************************/
@@ -204,10 +204,8 @@ int QSPIFBlockDevice::init()
204
204
}
205
205
206
206
int status = QSPIF_BD_ERROR_OK;
207
- uint32_t basic_table_addr = 0 ;
208
- size_t basic_table_size = 0 ;
209
- uint32_t sector_map_table_addr = 0 ;
210
- size_t sector_map_table_size = 0 ;
207
+ sfdp_hdr_info hdr_info;
208
+ memset (&hdr_info, 0 , sizeof hdr_info);
211
209
212
210
_mutex.lock ();
213
211
@@ -251,14 +249,14 @@ int QSPIFBlockDevice::init()
251
249
}
252
250
253
251
/* *************************** Parse SFDP Header ***********************************/
254
- if (0 != _sfdp_parse_sfdp_headers (basic_table_addr, basic_table_size, sector_map_table_addr, sector_map_table_size )) {
252
+ if (0 != _sfdp_parse_sfdp_headers (hdr_info )) {
255
253
tr_error (" Init - Parse SFDP Headers Failed" );
256
254
status = QSPIF_BD_ERROR_PARSING_FAILED;
257
255
goto exit_point;
258
256
}
259
257
260
258
/* *************************** Parse Basic Parameters Table ***********************************/
261
- if (0 != _sfdp_parse_basic_param_table (basic_table_addr, basic_table_size)) {
259
+ if (0 != _sfdp_parse_basic_param_table (hdr_info. basic_table_addr , hdr_info. basic_table_size )) {
262
260
tr_error (" Init - Parse Basic Param Table Failed" );
263
261
status = QSPIF_BD_ERROR_PARSING_FAILED;
264
262
goto exit_point;
@@ -269,10 +267,10 @@ int QSPIFBlockDevice::init()
269
267
_device_size_bytes; // If there's no region map, we have a single region sized the entire device size
270
268
_region_high_boundary[0 ] = _device_size_bytes - 1 ;
271
269
272
- if ((sector_map_table_addr != 0 ) && (0 != sector_map_table_size)) {
273
- tr_debug (" Init - Parsing Sector Map Table - addr: 0x%lxh, Size: %d" , sector_map_table_addr,
274
- sector_map_table_size);
275
- if (0 != _sfdp_parse_sector_map_table (sector_map_table_addr, sector_map_table_size)) {
270
+ if ((hdr_info. sector_map_table_addr != 0 ) && (0 != hdr_info. sector_map_table_size )) {
271
+ tr_debug (" Init - Parsing Sector Map Table - addr: 0x%lxh, Size: %d" , hdr_info. sector_map_table_addr ,
272
+ hdr_info. sector_map_table_size );
273
+ if (0 != _sfdp_parse_sector_map_table (hdr_info. sector_map_table_addr , hdr_info. sector_map_table_size )) {
276
274
tr_error (" Init - Parse Sector Map Table Failed" );
277
275
status = QSPIF_BD_ERROR_PARSING_FAILED;
278
276
goto exit_point;
@@ -629,75 +627,16 @@ int QSPIFBlockDevice::remove_csel_instance(PinName csel)
629
627
/* ********************************************************/
630
628
/* ********* SFDP Parsing and Detection Functions *********/
631
629
/* ********************************************************/
632
- int QSPIFBlockDevice::_sfdp_parse_sfdp_headers (uint32_t &basic_table_addr, size_t &basic_table_size,
633
- uint32_t §or_map_table_addr, size_t §or_map_table_size)
630
+ int QSPIFBlockDevice::_sfdp_parse_sfdp_headers (mbed::sfdp_hdr_info &hdr_info)
634
631
{
635
- uint8_t sfdp_header[QSPIF_SFDP_HEADER_SIZE];
636
- uint8_t param_header[QSPIF_PARAM_HEADER_SIZE];
637
- size_t data_length = QSPIF_SFDP_HEADER_SIZE;
638
- bd_addr_t addr = 0x0 ;
639
-
640
- qspi_status_t status = _qspi_send_read_sfdp_command (addr, (char *) sfdp_header, data_length);
641
- if (status != QSPI_STATUS_OK) {
642
- tr_error (" Init - Read SFDP Failed" );
643
- return -1 ;
644
- }
645
-
646
- // Verify SFDP signature for sanity
647
- // Also check that major/minor version is acceptable
648
- if (!(memcmp (&sfdp_header[0 ], " SFDP" , 4 ) == 0 && sfdp_header[5 ] == 1 )) {
649
- tr_error (" Init - Verification of SFDP signature and version failed" );
650
- return -1 ;
651
- } else {
652
- tr_debug (" Init - Verification of SFDP signature and version succeeded" );
653
- }
654
-
655
- // Discover Number of Parameter Headers
656
- int number_of_param_headers = (int )(sfdp_header[6 ]) + 1 ;
657
- tr_debug (" Number of Param Headers: %d" , number_of_param_headers);
658
-
659
-
660
- addr += QSPIF_SFDP_HEADER_SIZE;
661
- data_length = QSPIF_PARAM_HEADER_SIZE;
662
-
663
- // Loop over Param Headers and parse them (currently supports Basic Param Table and Sector Region Map Table)
664
- for (int i_ind = 0 ; i_ind < number_of_param_headers; i_ind++) {
665
- status = _qspi_send_read_sfdp_command (addr, (char *) param_header, data_length);
666
- if (status != QSPI_STATUS_OK) {
667
- tr_error (" Init - Read Param Table %d Failed" , i_ind + 1 );
668
- return -1 ;
669
- }
670
-
671
- // The SFDP spec indicates the standard table is always at offset 0
672
- // in the parameter headers, we check just to be safe
673
- if (param_header[2 ] != 1 ) {
674
- tr_error (" Param Table %d - Major Version should be 1!" , i_ind + 1 );
675
- return -1 ;
676
- }
677
-
678
- if ((param_header[0 ] == 0 ) && (param_header[7 ] == 0xFF )) {
679
- // Found Basic Params Table: LSB=0x00, MSB=0xFF
680
- tr_debug (" Found Basic Param Table at Table: %d" , i_ind + 1 );
681
- basic_table_addr = ((param_header[6 ] << 16 ) | (param_header[5 ] << 8 ) | (param_header[4 ]));
682
- // Supporting up to 64 Bytes Table (16 DWORDS)
683
- basic_table_size = ((param_header[3 ] * 4 ) < SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES) ? (param_header[3 ] * 4 ) : 64 ;
684
- } else if ((param_header[0 ] == 81 ) && (param_header[7 ] == 0xFF )) {
685
- // Found Sector Map Table: LSB=0x81, MSB=0xFF
686
- tr_debug (" Found Sector Map Table at Table: %d" , i_ind + 1 );
687
- sector_map_table_addr = ((param_header[6 ] << 16 ) | (param_header[5 ] << 8 ) | (param_header[4 ]));
688
- sector_map_table_size = param_header[3 ] * 4 ;
689
- }
690
- addr += QSPIF_PARAM_HEADER_SIZE;
691
- }
692
-
693
- return 0 ;
632
+ return sfdp_parse_headers (callback (this , &QSPIFBlockDevice::_qspi_send_read_sfdp_command), hdr_info);
694
633
}
695
634
696
635
int QSPIFBlockDevice::_sfdp_parse_basic_param_table (uint32_t basic_table_addr, size_t basic_table_size)
697
636
{
698
637
uint8_t param_table[SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES]; /* Up To 16 DWORDS = 64 Bytes */
699
638
700
- qspi_status_t status = _qspi_send_read_sfdp_command (basic_table_addr, (char *) param_table, basic_table_size);
639
+ int status = _qspi_send_read_sfdp_command (basic_table_addr, (char *)param_table, basic_table_size);
701
640
if (status != QSPI_STATUS_OK) {
702
641
tr_error (" Init - Read SFDP First Table Failed" );
703
642
return -1 ;
@@ -1178,7 +1117,7 @@ int QSPIFBlockDevice::_sfdp_parse_sector_map_table(uint32_t sector_map_table_add
1178
1117
// Default set to all type bits 1-4 are common
1179
1118
int min_common_erase_type_bits = ERASE_BITMASK_ALL;
1180
1119
1181
- qspi_status_t status = _qspi_send_read_sfdp_command (sector_map_table_addr, (char *) sector_map_table, sector_map_table_size);
1120
+ int status = _qspi_send_read_sfdp_command (sector_map_table_addr, (char *)sector_map_table, sector_map_table_size);
1182
1121
if (status != QSPI_STATUS_OK) {
1183
1122
tr_error (" Init - Read SFDP First Table Failed" );
1184
1123
return -1 ;
@@ -1621,7 +1560,7 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_general_command(qspi_inst_t instructi
1621
1560
return QSPI_STATUS_OK;
1622
1561
}
1623
1562
1624
- qspi_status_t QSPIFBlockDevice::_qspi_send_read_sfdp_command (bd_addr_t addr, void *rx_buffer, bd_size_t rx_length)
1563
+ int QSPIFBlockDevice::_qspi_send_read_sfdp_command (bd_addr_t addr, void *rx_buffer, bd_size_t rx_length)
1625
1564
{
1626
1565
size_t rx_len = rx_length;
1627
1566
0 commit comments