@@ -66,40 +66,49 @@ const struct gpio_dt_spec mosi_pin = GPIO_DT_SPEC_GET_OR(DT_PATH(zephyr_user), m
66
66
********************
67
67
*/
68
68
69
- #if CONFIG_NOCACHE_MEMORY
69
+ #ifdef CONFIG_NOCACHE_MEMORY
70
70
#define __NOCACHE __attribute__((__section__(".nocache")))
71
71
#elif defined(CONFIG_DT_DEFINED_NOCACHE )
72
72
#define __NOCACHE __attribute__((__section__(CONFIG_DT_DEFINED_NOCACHE_NAME)))
73
73
#else /* CONFIG_NOCACHE_MEMORY */
74
74
#define __NOCACHE
75
+ #if CONFIG_DCACHE_LINE_SIZE != 0
76
+ #define __BUF_ALIGN __aligned(CONFIG_DCACHE_LINE_SIZE)
77
+ #else
78
+ #define __BUF_ALIGN __aligned(DT_PROP_OR(DT_PATH(cpus, cpu_0), d_cache_line_size, 32))
79
+ #endif
75
80
#endif /* CONFIG_NOCACHE_MEMORY */
76
81
82
+ #ifndef __BUF_ALIGN
83
+ #define __BUF_ALIGN __aligned(32)
84
+ #endif
85
+
77
86
#define BUF_SIZE 18
78
87
static const char tx_data [BUF_SIZE ] = "0123456789abcdef-\0" ;
79
- static __aligned ( 32 ) char buffer_tx [BUF_SIZE ] __NOCACHE ;
80
- static __aligned ( 32 ) char buffer_rx [BUF_SIZE ] __NOCACHE ;
88
+ static __BUF_ALIGN char buffer_tx [BUF_SIZE ] __NOCACHE ;
89
+ static __BUF_ALIGN char buffer_rx [BUF_SIZE ] __NOCACHE ;
81
90
82
91
#define BUF2_SIZE 36
83
92
static const char tx2_data [BUF2_SIZE ] = "Thequickbrownfoxjumpsoverthelazydog\0" ;
84
- static __aligned ( 32 ) char buffer2_tx [BUF2_SIZE ] __NOCACHE ;
85
- static __aligned ( 32 ) char buffer2_rx [BUF2_SIZE ] __NOCACHE ;
93
+ static __BUF_ALIGN char buffer2_tx [BUF2_SIZE ] __NOCACHE ;
94
+ static __BUF_ALIGN char buffer2_rx [BUF2_SIZE ] __NOCACHE ;
86
95
87
96
#define BUF3_SIZE CONFIG_SPI_LARGE_BUFFER_SIZE
88
97
static const char large_tx_data [BUF3_SIZE ] = "Thequickbrownfoxjumpsoverthelazydog\0" ;
89
- static __aligned ( 32 ) char large_buffer_tx [BUF3_SIZE ] __NOCACHE ;
90
- static __aligned ( 32 ) char large_buffer_rx [BUF3_SIZE ] __NOCACHE ;
98
+ static __BUF_ALIGN char large_buffer_tx [BUF3_SIZE ] __NOCACHE ;
99
+ static __BUF_ALIGN char large_buffer_rx [BUF3_SIZE ] __NOCACHE ;
91
100
92
101
#define BUFWIDE_SIZE 12
93
102
static const uint16_t tx_data_16 [] = {0x1234 , 0x5678 , 0x9ABC , 0xDEF0 ,
94
103
0xFF00 , 0x00FF , 0xAAAA , 0x5555 ,
95
104
0xF0F0 , 0x0F0F , 0xA5A5 , 0x5A5A };
96
- static __aligned ( 32 ) uint16_t buffer_tx_16 [BUFWIDE_SIZE ] __NOCACHE ;
97
- static __aligned ( 32 ) uint16_t buffer_rx_16 [BUFWIDE_SIZE ] __NOCACHE ;
105
+ static __BUF_ALIGN uint16_t buffer_tx_16 [BUFWIDE_SIZE ] __NOCACHE ;
106
+ static __BUF_ALIGN uint16_t buffer_rx_16 [BUFWIDE_SIZE ] __NOCACHE ;
98
107
static const uint32_t tx_data_32 [] = {0x12345678 , 0x56781234 , 0x9ABCDEF0 , 0xDEF09ABC ,
99
108
0xFFFF0000 , 0x0000FFFF , 0x00FF00FF , 0xFF00FF00 ,
100
109
0xAAAA5555 , 0x5555AAAA , 0xAA55AA55 , 0x55AA55AA };
101
- static __aligned ( 32 ) uint32_t buffer_tx_32 [BUFWIDE_SIZE ] __NOCACHE ;
102
- static __aligned ( 32 ) uint32_t buffer_rx_32 [BUFWIDE_SIZE ] __NOCACHE ;
110
+ static __BUF_ALIGN uint32_t buffer_tx_32 [BUFWIDE_SIZE ] __NOCACHE ;
111
+ static __BUF_ALIGN uint32_t buffer_rx_32 [BUFWIDE_SIZE ] __NOCACHE ;
103
112
104
113
/*
105
114
********************
@@ -667,7 +676,7 @@ ZTEST(spi_loopback, test_spi_word_size_9)
667
676
{
668
677
struct spi_dt_spec * spec = loopback_specs [spec_idx ];
669
678
670
- static __aligned ( 32 ) uint16_t tx_data_9 [BUFWIDE_SIZE ];
679
+ static __BUF_ALIGN uint16_t tx_data_9 [BUFWIDE_SIZE ];
671
680
672
681
for (int i = 0 ; i < BUFWIDE_SIZE ; i ++ ) {
673
682
tx_data_9 [i ] = tx_data_16 [i ] & 0x1FF ;
@@ -691,7 +700,7 @@ ZTEST(spi_loopback, test_spi_word_size_24)
691
700
{
692
701
struct spi_dt_spec * spec = loopback_specs [spec_idx ];
693
702
694
- static __aligned ( 32 ) uint32_t tx_data_24 [BUFWIDE_SIZE ];
703
+ static __BUF_ALIGN uint32_t tx_data_24 [BUFWIDE_SIZE ];
695
704
696
705
for (int i = 0 ; i < BUFWIDE_SIZE ; i ++ ) {
697
706
tx_data_24 [i ] = tx_data_32 [i ] & 0xFFFFFF ;
@@ -717,8 +726,8 @@ static struct k_thread thread[3];
717
726
static K_SEM_DEFINE (thread_sem , 0 , 3 ) ;
718
727
static K_SEM_DEFINE (sync_sem , 0 , 1 ) ;
719
728
720
- static uint8_t __aligned ( 32 ) tx_buffer [3 ][32 ] __NOCACHE ;
721
- static uint8_t __aligned ( 32 ) rx_buffer [3 ][32 ] __NOCACHE ;
729
+ static uint8_t __BUF_ALIGN tx_buffer [3 ][32 ] __NOCACHE ;
730
+ static uint8_t __BUF_ALIGN rx_buffer [3 ][32 ] __NOCACHE ;
722
731
723
732
atomic_t thread_test_fails ;
724
733
0 commit comments