@@ -56,17 +56,20 @@ TEST_CASE("DW_GDMA M2M Test: Contiguous Mode", "[DW_GDMA]")
5656 TEST_ASSERT_NOT_NULL (done_sem );
5757
5858 printf ("prepare the source and destination buffers\r\n" );
59- uint8_t * src_buf = heap_caps_aligned_calloc (64 , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
60- uint8_t * dst_buf = heap_caps_aligned_calloc (64 , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
59+ size_t sram_alignment = 0 ;
60+ TEST_ESP_OK (esp_cache_get_alignment (0 , & sram_alignment ));
61+ size_t alignment = MAX (sram_alignment , 8 );
62+ uint8_t * src_buf = heap_caps_aligned_calloc (alignment , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
63+ uint8_t * dst_buf = heap_caps_aligned_calloc (alignment , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
6164 TEST_ASSERT_NOT_NULL (src_buf );
6265 TEST_ASSERT_NOT_NULL (dst_buf );
6366 for (int i = 0 ; i < 256 ; i ++ ) {
6467 src_buf [i ] = i ;
6568 }
66- # if CONFIG_IDF_TARGET_ESP32P4
67- // do write-back for the source data because it's in the cache
68- TEST_ESP_OK (esp_cache_msync ((void * )src_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_C2M ));
69- #endif
69+ if ( sram_alignment ) {
70+ // do write-back for the source data because it's in the cache
71+ TEST_ESP_OK (esp_cache_msync ((void * )src_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_C2M ));
72+ }
7073
7174 printf ("allocate a channel for memory copy\r\n" );
7275 dw_gdma_channel_static_config_t static_config = {
@@ -117,10 +120,10 @@ TEST_CASE("DW_GDMA M2M Test: Contiguous Mode", "[DW_GDMA]")
117120 TEST_ASSERT_EQUAL (pdFALSE , xSemaphoreTake (done_sem , pdMS_TO_TICKS (100 )));
118121
119122 printf ("check the memory copy result\r\n" );
120- # if CONFIG_IDF_TARGET_ESP32P4
121- // the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
122- TEST_ESP_OK (esp_cache_msync ((void * )dst_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_M2C ));
123- #endif
123+ if ( sram_alignment ) {
124+ // the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
125+ TEST_ESP_OK (esp_cache_msync ((void * )dst_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_M2C ));
126+ }
124127 for (int i = 0 ; i < 256 ; i ++ ) {
125128 TEST_ASSERT_EQUAL_UINT8 (i , dst_buf [i ]);
126129 }
@@ -145,17 +148,20 @@ TEST_CASE("DW_GDMA M2M Test: Reload Mode", "[DW_GDMA]")
145148 TEST_ASSERT_NOT_NULL (done_sem );
146149
147150 printf ("prepare the source and destination buffers\r\n" );
148- uint8_t * src_buf = heap_caps_aligned_calloc (64 , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
149- uint8_t * dst_buf = heap_caps_aligned_calloc (64 , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
151+ size_t sram_alignment = 0 ;
152+ TEST_ESP_OK (esp_cache_get_alignment (0 , & sram_alignment ));
153+ size_t alignment = MAX (sram_alignment , 8 );
154+ uint8_t * src_buf = heap_caps_aligned_calloc (alignment , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
155+ uint8_t * dst_buf = heap_caps_aligned_calloc (alignment , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
150156 TEST_ASSERT_NOT_NULL (src_buf );
151157 TEST_ASSERT_NOT_NULL (dst_buf );
152158 for (int i = 0 ; i < 256 ; i ++ ) {
153159 src_buf [i ] = i ;
154160 }
155- # if CONFIG_IDF_TARGET_ESP32P4
156- // do write-back for the source data because it's in the cache
157- TEST_ESP_OK (esp_cache_msync ((void * )src_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_C2M ));
158- #endif
161+ if ( sram_alignment ) {
162+ // do write-back for the source data because it's in the cache
163+ TEST_ESP_OK (esp_cache_msync ((void * )src_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_C2M ));
164+ }
159165
160166 printf ("allocate a channel for memory copy\r\n" );
161167 dw_gdma_channel_static_config_t static_config = {
@@ -212,10 +218,10 @@ TEST_CASE("DW_GDMA M2M Test: Reload Mode", "[DW_GDMA]")
212218 TEST_ASSERT_EQUAL (pdTRUE , xSemaphoreTake (done_sem , pdMS_TO_TICKS (100 )));
213219
214220 printf ("check the memory copy result\r\n" );
215- # if CONFIG_IDF_TARGET_ESP32P4
216- // the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
217- TEST_ESP_OK (esp_cache_msync ((void * )dst_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_M2C ));
218- #endif
221+ if ( sram_alignment ) {
222+ // the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
223+ TEST_ESP_OK (esp_cache_msync ((void * )dst_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_M2C ));
224+ }
219225 for (int i = 0 ; i < 256 ; i ++ ) {
220226 TEST_ASSERT_EQUAL_UINT8 (i , dst_buf [i ]);
221227 }
@@ -264,17 +270,20 @@ TEST_CASE("DW_GDMA M2M Test: Shadow Mode", "[DW_GDMA]")
264270 TEST_ASSERT_NOT_NULL (done_sem );
265271
266272 printf ("prepare the source and destination buffers\r\n" );
267- uint8_t * src_buf = heap_caps_aligned_calloc (64 , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
268- uint8_t * dst_buf = heap_caps_aligned_calloc (64 , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
273+ size_t sram_alignment = 0 ;
274+ TEST_ESP_OK (esp_cache_get_alignment (0 , & sram_alignment ));
275+ size_t alignment = MAX (sram_alignment , 8 );
276+ uint8_t * src_buf = heap_caps_aligned_calloc (alignment , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
277+ uint8_t * dst_buf = heap_caps_aligned_calloc (alignment , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
269278 TEST_ASSERT_NOT_NULL (src_buf );
270279 TEST_ASSERT_NOT_NULL (dst_buf );
271280 for (int i = 0 ; i < 256 ; i ++ ) {
272281 src_buf [i ] = i ;
273282 }
274- # if CONFIG_IDF_TARGET_ESP32P4
275- // do write-back for the source data because it's in the cache
276- TEST_ESP_OK (esp_cache_msync ((void * )src_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_C2M ));
277- #endif
283+ if ( sram_alignment ) {
284+ // do write-back for the source data because it's in the cache
285+ TEST_ESP_OK (esp_cache_msync ((void * )src_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_C2M ));
286+ }
278287
279288 printf ("allocate a channel for memory copy\r\n" );
280289 dw_gdma_channel_static_config_t static_config = {
@@ -334,10 +343,10 @@ TEST_CASE("DW_GDMA M2M Test: Shadow Mode", "[DW_GDMA]")
334343 TEST_ASSERT_EQUAL_UINT8 (1 , user_data .count );
335344
336345 printf ("check the memory copy result\r\n" );
337- # if CONFIG_IDF_TARGET_ESP32P4
338- // the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
339- TEST_ESP_OK (esp_cache_msync ((void * )dst_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_M2C ));
340- #endif
346+ if ( sram_alignment ) {
347+ // the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
348+ TEST_ESP_OK (esp_cache_msync ((void * )dst_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_M2C ));
349+ }
341350 for (int i = 0 ; i < 256 ; i ++ ) {
342351 TEST_ASSERT_EQUAL_UINT8 (i , dst_buf [i ]);
343352 }
@@ -387,17 +396,20 @@ TEST_CASE("DW_GDMA M2M Test: Link-List Mode", "[DW_GDMA]")
387396 TEST_ASSERT_NOT_NULL (done_sem );
388397
389398 printf ("prepare the source and destination buffers\r\n" );
390- uint8_t * src_buf = heap_caps_aligned_calloc (64 , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
391- uint8_t * dst_buf = heap_caps_aligned_calloc (64 , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
399+ size_t sram_alignment = 0 ;
400+ TEST_ESP_OK (esp_cache_get_alignment (0 , & sram_alignment ));
401+ size_t alignment = MAX (sram_alignment , 8 );
402+ uint8_t * src_buf = heap_caps_aligned_calloc (alignment , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
403+ uint8_t * dst_buf = heap_caps_aligned_calloc (alignment , 1 , 256 , MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
392404 TEST_ASSERT_NOT_NULL (src_buf );
393405 TEST_ASSERT_NOT_NULL (dst_buf );
394406 for (int i = 0 ; i < 256 ; i ++ ) {
395407 src_buf [i ] = i ;
396408 }
397- # if CONFIG_IDF_TARGET_ESP32P4
398- // do write-back for the source data because it's in the cache
399- TEST_ESP_OK (esp_cache_msync ((void * )src_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_C2M ));
400- #endif
409+ if ( sram_alignment ) {
410+ // do write-back for the source data because it's in the cache
411+ TEST_ESP_OK (esp_cache_msync ((void * )src_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_C2M ));
412+ }
401413
402414 printf ("allocate a channel for memory copy\r\n" );
403415 dw_gdma_channel_static_config_t static_config = {
@@ -472,10 +484,10 @@ TEST_CASE("DW_GDMA M2M Test: Link-List Mode", "[DW_GDMA]")
472484 TEST_ASSERT_EQUAL (pdTRUE , xSemaphoreTake (done_sem , pdMS_TO_TICKS (1000 )));
473485
474486 printf ("check the memory copy result\r\n" );
475- # if CONFIG_IDF_TARGET_ESP32P4
476- // the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
477- TEST_ESP_OK (esp_cache_msync ((void * )dst_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_M2C ));
478- #endif
487+ if ( sram_alignment ) {
488+ // the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
489+ TEST_ESP_OK (esp_cache_msync ((void * )dst_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_M2C ));
490+ }
479491 for (int i = 0 ; i < 256 ; i ++ ) {
480492 TEST_ASSERT_EQUAL_UINT8 (i , dst_buf [i ]);
481493 }
@@ -504,10 +516,10 @@ TEST_CASE("DW_GDMA M2M Test: Link-List Mode", "[DW_GDMA]")
504516 TEST_ASSERT_EQUAL_UINT8 (1 , user_data .count );
505517
506518 printf ("check the memory copy result\r\n" );
507- # if CONFIG_IDF_TARGET_ESP32P4
508- // the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
509- TEST_ESP_OK (esp_cache_msync ((void * )dst_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_M2C ));
510- #endif
519+ if ( sram_alignment ) {
520+ // the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
521+ TEST_ESP_OK (esp_cache_msync ((void * )dst_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_M2C ));
522+ }
511523 for (int i = 0 ; i < 256 ; i ++ ) {
512524 TEST_ASSERT_EQUAL_UINT8 (i , dst_buf [i ]);
513525 }
@@ -536,10 +548,10 @@ TEST_CASE("DW_GDMA M2M Test: memory set with fixed address", "[DW_GDMA]")
536548 src_buf [i ] = 0 ;
537549 }
538550 src_buf [0 ] = 66 ;
539- # if CONFIG_IDF_TARGET_ESP32P4
540- // do write-back for the source data because it's in the cache
541- TEST_ESP_OK (esp_cache_msync ((void * )src_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_C2M ));
542- #endif
551+ if ( ext_mem_alignment ) {
552+ // do write-back for the source data because it's in the cache
553+ TEST_ESP_OK (esp_cache_msync ((void * )src_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_C2M ));
554+ }
543555
544556 printf ("allocate a channel for memory set\r\n" );
545557 dw_gdma_channel_static_config_t static_config = {
@@ -581,10 +593,10 @@ TEST_CASE("DW_GDMA M2M Test: memory set with fixed address", "[DW_GDMA]")
581593 vTaskDelay (pdMS_TO_TICKS (100 ));
582594
583595 printf ("check the memory set result\r\n" );
584- # if CONFIG_IDF_TARGET_ESP32P4
585- // the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
586- TEST_ESP_OK (esp_cache_msync ((void * )dst_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_M2C ));
587- #endif
596+ if ( int_mem_alignment ) {
597+ // the destination data are not reflected to the cache, so do an invalidate to ask the cache load new data
598+ TEST_ESP_OK (esp_cache_msync ((void * )dst_buf , 256 , ESP_CACHE_MSYNC_FLAG_DIR_M2C ));
599+ }
588600 for (int i = 0 ; i < 256 ; i ++ ) {
589601 TEST_ASSERT_EQUAL_UINT8 (66 , dst_buf [i ]);
590602 }
0 commit comments