1414#include "freertos/task.h"
1515#include "esp_timer.h"
1616#include "ccomp_timer.h"
17+ #include "string.h"
1718
1819#include "sdmmc_cmd.h"
1920#include "driver/sdmmc_host.h"
@@ -43,7 +44,7 @@ typedef struct {
4344---------------------------------------------------------------*/
4445static sdmmc_card_t s_card ;
4546
46- static void s_master_init (test_sdio_param_t * host_param , essl_handle_t * out_handle )
47+ static void s_master_init (test_sdio_param_t * host_param , essl_handle_t * out_handle , sdmmc_card_t * * out_card )
4748{
4849 sdmmc_host_t host_config = (sdmmc_host_t )SDMMC_HOST_DEFAULT ();
4950 host_config .flags = host_param -> host_flags ;
@@ -81,6 +82,10 @@ static void s_master_init(test_sdio_param_t *host_param, essl_handle_t *out_hand
8182 TEST_ESP_OK (essl_sdio_init_dev (out_handle , & essl_sdio_config ));
8283
8384 TEST_ESP_OK (essl_init (* out_handle , TEST_TIMEOUT_MAX ));
85+
86+ if (out_card ) {
87+ * out_card = card ;
88+ }
8489}
8590
8691static void s_master_deinit (void )
@@ -114,7 +119,7 @@ TEST_CASE("SDIO_SDMMC: test interrupt", "[sdio]")
114119 .max_freq_khz = SDMMC_FREQ_HIGHSPEED ,
115120 };
116121 //essl init and sdmmc init
117- s_master_init (& test_param , & handle );
122+ s_master_init (& test_param , & handle , NULL );
118123
119124 TEST_ESP_OK (essl_set_intr_ena (handle , TEST_INT_MASK_ALL , TEST_TIMEOUT_MAX ));
120125 ret = essl_wait_int (handle , 0 );
@@ -149,7 +154,7 @@ TEST_CASE("SDIO_SDMMC: test register", "[sdio]")
149154 .max_freq_khz = SDMMC_FREQ_HIGHSPEED ,
150155 };
151156 //essl init and sdmmc init
152- s_master_init (& test_param , & handle );
157+ s_master_init (& test_param , & handle , NULL );
153158
154159 uint32_t init_val = 30 ;
155160 srand (850 );
@@ -183,7 +188,7 @@ TEST_CASE("SDIO_SDMMC: test reset", "[sdio]")
183188 .max_freq_khz = SDMMC_FREQ_HIGHSPEED ,
184189 };
185190 //essl init and sdmmc init
186- s_master_init (& test_param , & handle );
191+ s_master_init (& test_param , & handle , NULL );
187192
188193 //wait for the slave to stop, reset and start again
189194 vTaskDelay (10 );
@@ -215,6 +220,66 @@ TEST_CASE("SDIO_SDMMC: test reset", "[sdio]")
215220 s_master_deinit ();
216221}
217222
223+ /*---------------------------------------------------------------
224+ SDMMC_SDIO: test fixed addr
225+ ---------------------------------------------------------------*/
226+ #include "soc/soc.h"
227+ #define HOST_SLCHOST_CONF_W0_REG (DR_REG_SLCHOST_BASE + 0x6C)
228+
229+ TEST_CASE ("SDIO_SDMMC: test fixed addr" , "[sdio]" )
230+ {
231+ essl_handle_t handle = NULL ;
232+ sdmmc_card_t * card ;
233+ test_sdio_param_t test_param = {
234+ .host_flags = SDMMC_HOST_FLAG_4BIT | SDMMC_HOST_FLAG_ALLOC_ALIGNED_BUF ,
235+ .max_freq_khz = SDMMC_FREQ_HIGHSPEED ,
236+ };
237+ //essl init and sdmmc init
238+ s_master_init (& test_param , & handle , & card );
239+
240+ vTaskDelay (10 );
241+
242+ const int test_size = 128 ;
243+ const int write_addr = 6 ;
244+ uint8_t buf [test_size ] = {};
245+ srand (850 );
246+ for (int i = 0 ; i < test_size ; i ++ ) {
247+ buf [i ] = rand ();
248+ }
249+ ESP_LOG_BUFFER_HEX ("write_val" , buf , test_size );
250+
251+ TEST_ESP_OK (sdmmc_io_write_bytes (card , 1 , ((HOST_SLCHOST_CONF_W0_REG + write_addr ) & 0x3FF ) | SDMMC_IO_FIXED_ADDR , buf , test_size ));
252+
253+ const int max_size = 64 ;
254+ uint8_t read_buf [max_size ] = {};
255+ TEST_ESP_OK (sdmmc_io_read_bytes (card , 1 , HOST_SLCHOST_CONF_W0_REG & 0x3FF , read_buf , max_size ));
256+ ESP_LOG_BUFFER_HEX ("read_all" , read_buf , max_size );
257+ for (int i = 0 ; i < max_size ; i ++ ) {
258+ if (i >= 24 && i < 28 ) {
259+ continue ;
260+ }
261+ if (i >= 32 && i < 48 ) {
262+ continue ;
263+ }
264+ if (i == write_addr ) {
265+ TEST_ASSERT_EQUAL_HEX8 (buf [test_size - 1 ], read_buf [i ]);
266+ } else {
267+ TEST_ASSERT_EQUAL_HEX8 (0xcc , read_buf [i ]);
268+ }
269+ }
270+
271+ const int read_size = (test_size > max_size ? max_size : test_size );
272+ memset (read_buf , 0 , read_size );
273+ TEST_ESP_OK (sdmmc_io_read_bytes (card , 1 , ((HOST_SLCHOST_CONF_W0_REG + write_addr ) & 0x3FF ) | SDMMC_IO_FIXED_ADDR , read_buf , read_size ));
274+ ESP_LOG_BUFFER_HEX ("read_fixed" , read_buf , read_size );
275+ for (int i = 0 ; i < read_size ; i ++ ) {
276+ TEST_ASSERT_EQUAL_HEX8 (buf [test_size - 1 ], read_buf [i ]);
277+ }
278+
279+ s_send_finish_test (handle );
280+ s_master_deinit ();
281+ }
282+
218283/*---------------------------------------------------------------
219284 Transaction Tests
220285---------------------------------------------------------------*/
@@ -241,7 +306,7 @@ static void test_from_host(bool check_data)
241306 ESP_LOGI (TAG , "host speed: %" PRIu32 " kHz" , test_param_lists [i ].max_freq_khz );
242307
243308 essl_handle_t handle = NULL ;
244- s_master_init (& test_param_lists [i ], & handle );
309+ s_master_init (& test_param_lists [i ], & handle , NULL );
245310
246311 // Two counters are used. The `esp_timer_get_time()` is for the typical time, and the
247312 // `ccomp_timer` is for performance test to reduce influence caused by cache miss.
@@ -298,7 +363,7 @@ static void test_to_host(bool check_data)
298363 ESP_LOGI (TAG , "host speed: %" PRIu32 " kHz" , test_param_lists [i ].max_freq_khz );
299364
300365 essl_handle_t handle = NULL ;
301- s_master_init (& test_param_lists [i ], & handle );
366+ s_master_init (& test_param_lists [i ], & handle , NULL );
302367
303368 esp_err_t ret ;
304369 int offset = 0 ;
0 commit comments