Skip to content

Commit 965e5b4

Browse files
[nrf fromlist] drivers: i2c: nrfx_twim_rtio: fix dma buf section attr
The buffer used for the TWIM DMA needs to be allocated to the section provided with the memory-regions dt prop. The macros for doing this where malformed. This commit fixes and cleans up the macros. Upstream PR #: 85565 Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent 234efe4 commit 965e5b4

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

drivers/i2c/i2c_nrfx_twim_rtio.c

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <zephyr/drivers/pinctrl.h>
1616
#include <soc.h>
1717
#include <nrfx_twim.h>
18+
#include <zephyr/linker/devicetree_regions.h>
1819

1920
#include "i2c_nrfx_twim_common.h"
2021

@@ -174,6 +175,31 @@ int i2c_nrfx_twim_rtio_init(const struct device *dev)
174175
COND_CODE_0(CONCAT_BUF_SIZE(idx), (COND_CODE_0(FLASH_BUF_MAX_SIZE(idx), (0), (1))), (1))
175176
#define MSG_BUF_SIZE(idx) MAX(CONCAT_BUF_SIZE(idx), FLASH_BUF_MAX_SIZE(idx))
176177

178+
#define MSG_BUF_HAS_MEMORY_REGIONS(idx) \
179+
DT_NODE_HAS_PROP(I2C(idx), memory_regions)
180+
181+
#define MSG_BUF_LINKER_REGION_NAME(idx) \
182+
LINKER_DT_NODE_REGION_NAME(DT_PHANDLE(I2C(idx), memory_regions))
183+
184+
#define MSG_BUF_ATTR_SECTION(idx) \
185+
__attribute__((__section__(MSG_BUF_LINKER_REGION_NAME(idx))))
186+
187+
#define MSG_BUF_ATTR(idx) \
188+
COND_CODE_1( \
189+
MSG_BUF_HAS_MEMORY_REGIONS(idx), \
190+
(MSG_BUF_ATTR_SECTION(idx)), \
191+
() \
192+
)
193+
194+
#define MSG_BUF_SYM(idx) \
195+
_CONCAT_3(twim_, idx, _msg_buf)
196+
197+
#define MSG_BUF_DEFINE(idx) \
198+
static uint8_t MSG_BUF_SYM(idx)[MSG_BUF_SIZE(idx)] MSG_BUF_ATTR(idx)
199+
200+
#define MAX_TRANSFER_SIZE(idx) \
201+
BIT_MASK(DT_PROP(I2C(idx), easydma_maxcnt_bits))
202+
177203
#define I2C_NRFX_TWIM_RTIO_DEVICE(idx) \
178204
NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(I2C(idx)); \
179205
BUILD_ASSERT(I2C_FREQUENCY(idx) != I2C_NRFX_TWIM_INVALID_FREQUENCY, \
@@ -183,9 +209,7 @@ int i2c_nrfx_twim_rtio_init(const struct device *dev)
183209
IRQ_CONNECT(DT_IRQN(I2C(idx)), DT_IRQ(I2C(idx), priority), nrfx_isr, \
184210
nrfx_twim_##idx##_irq_handler, 0); \
185211
} \
186-
IF_ENABLED( \
187-
USES_MSG_BUF(idx), \
188-
(static uint8_t twim_##idx##_msg_buf[MSG_BUF_SIZE(idx)] I2C_MEMORY_SECTION(idx);)) \
212+
IF_ENABLED(USES_MSG_BUF(idx), (MSG_BUF_DEFINE(idx);)) \
189213
I2C_RTIO_DEFINE(_i2c##idx##_twim_rtio, \
190214
DT_INST_PROP_OR(n, sq_size, CONFIG_I2C_RTIO_SQ_SIZE), \
191215
DT_INST_PROP_OR(n, cq_size, CONFIG_I2C_RTIO_CQ_SIZE)); \
@@ -204,22 +228,15 @@ int i2c_nrfx_twim_rtio_init(const struct device *dev)
204228
.msg_buf_size = MSG_BUF_SIZE(idx), \
205229
.irq_connect = irq_connect##idx, \
206230
.pcfg = PINCTRL_DT_DEV_CONFIG_GET(I2C(idx)), \
207-
IF_ENABLED(USES_MSG_BUF(idx), (.msg_buf = twim_##idx##_msg_buf,)) \
208-
.max_transfer_size = \
209-
BIT_MASK(DT_PROP(I2C(idx), easydma_maxcnt_bits)), \
231+
IF_ENABLED(USES_MSG_BUF(idx), (.msg_buf = MSG_BUF_SYM(idx),)) \
232+
.max_transfer_size = MAX_TRANSFER_SIZE(idx), \
210233
}, \
211234
.ctx = &_i2c##idx##_twim_rtio, \
212235
}; \
213236
PM_DEVICE_DT_DEFINE(I2C(idx), twim_nrfx_pm_action, PM_DEVICE_ISR_SAFE); \
214237
I2C_DEVICE_DT_DEFINE(I2C(idx), i2c_nrfx_twim_rtio_init, PM_DEVICE_DT_GET(I2C(idx)), NULL, \
215238
&twim_##idx##z_config, POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \
216-
&i2c_nrfx_twim_driver_api)
217-
218-
#define I2C_MEMORY_SECTION(idx) \
219-
COND_CODE_1(I2C_HAS_PROP(idx, memory_regions), \
220-
(__attribute__((__section__( \
221-
LINKER_DT_NODE_REGION_NAME(DT_PHANDLE(I2C(idx), memory_regions)))))), \
222-
())
239+
&i2c_nrfx_twim_driver_api);
223240

224241
#ifdef CONFIG_HAS_HW_NRF_TWIM0
225242
I2C_NRFX_TWIM_RTIO_DEVICE(0);

0 commit comments

Comments
 (0)