Lines Matching +full:max +full:- +full:msgs
4 * SPDX-License-Identifier: Apache-2.0
8 #include <zephyr/dt-bindings/i2c/i2c.h>
37 struct i2c_msg *msgs, in i2c_nrfx_twim_transfer() argument
40 struct i2c_nrfx_twim_data *dev_data = dev->data; in i2c_nrfx_twim_transfer()
41 const struct i2c_nrfx_twim_common_config *dev_config = dev->config; in i2c_nrfx_twim_transfer()
43 uint8_t *msg_buf = dev_config->msg_buf; in i2c_nrfx_twim_transfer()
45 uint16_t msg_buf_size = dev_config->msg_buf_size; in i2c_nrfx_twim_transfer()
49 k_sem_take(&dev_data->transfer_sync, K_FOREVER); in i2c_nrfx_twim_transfer()
52 k_sem_take(&dev_data->completion_sync, K_NO_WAIT); in i2c_nrfx_twim_transfer()
57 if (I2C_MSG_ADDR_10_BITS & msgs[i].flags) { in i2c_nrfx_twim_transfer()
58 ret = -ENOTSUP; in i2c_nrfx_twim_transfer()
62 bool dma_accessible = nrf_dma_accessible_check(&dev_config->twim, msgs[i].buf); in i2c_nrfx_twim_transfer()
65 * - it is not the last fragment in i2c_nrfx_twim_transfer()
66 * - it does not end a bus transaction in i2c_nrfx_twim_transfer()
67 * - the next fragment does not start a bus transaction in i2c_nrfx_twim_transfer()
68 * - the direction of the next fragment is the same as this one in i2c_nrfx_twim_transfer()
71 && !(msgs[i].flags & I2C_MSG_STOP) in i2c_nrfx_twim_transfer()
72 && !(msgs[i + 1].flags & I2C_MSG_RESTART) in i2c_nrfx_twim_transfer()
73 && ((msgs[i].flags & I2C_MSG_READ) in i2c_nrfx_twim_transfer()
74 == (msgs[i + 1].flags & I2C_MSG_READ)); in i2c_nrfx_twim_transfer()
82 if ((msg_buf_used + msgs[i].len) > msg_buf_size) { in i2c_nrfx_twim_transfer()
86 "Adjust the zephyr,concat-buf-size or " in i2c_nrfx_twim_transfer()
87 "zephyr,flash-buf-max-size property " in i2c_nrfx_twim_transfer()
90 msg_buf_used, msgs[i].len, in i2c_nrfx_twim_transfer()
91 msg_buf_size, dev->name); in i2c_nrfx_twim_transfer()
92 ret = -ENOSPC; in i2c_nrfx_twim_transfer()
95 if (!(msgs[i].flags & I2C_MSG_READ)) { in i2c_nrfx_twim_transfer()
97 msgs[i].buf, in i2c_nrfx_twim_transfer()
98 msgs[i].len); in i2c_nrfx_twim_transfer()
100 msg_buf_used += msgs[i].len; in i2c_nrfx_twim_transfer()
108 buf = msgs[i].buf; in i2c_nrfx_twim_transfer()
109 buf_len = msgs[i].len; in i2c_nrfx_twim_transfer()
114 ret = i2c_nrfx_twim_msg_transfer(dev, msgs[i].flags, buf, buf_len, addr); in i2c_nrfx_twim_transfer()
119 ret = k_sem_take(&dev_data->completion_sync, in i2c_nrfx_twim_transfer()
139 ret = -EIO; in i2c_nrfx_twim_transfer()
143 if (dev_data->res != NRFX_SUCCESS) { in i2c_nrfx_twim_transfer()
144 ret = -EIO; in i2c_nrfx_twim_transfer()
151 if ((msgs[i].flags & I2C_MSG_READ) && (buf == msg_buf)) { in i2c_nrfx_twim_transfer()
154 while (msg_buf_used >= msgs[j].len) { in i2c_nrfx_twim_transfer()
155 msg_buf_used -= msgs[j].len; in i2c_nrfx_twim_transfer()
156 memcpy(msgs[j].buf, in i2c_nrfx_twim_transfer()
158 msgs[j].len); in i2c_nrfx_twim_transfer()
159 j--; in i2c_nrfx_twim_transfer()
169 k_sem_give(&dev_data->transfer_sync); in i2c_nrfx_twim_transfer()
177 struct i2c_nrfx_twim_data *dev_data = dev->data; in event_handler()
179 switch (p_event->type) { in event_handler()
181 dev_data->res = NRFX_SUCCESS; in event_handler()
184 dev_data->res = NRFX_ERROR_DRV_TWI_ERR_ANACK; in event_handler()
187 dev_data->res = NRFX_ERROR_DRV_TWI_ERR_DNACK; in event_handler()
190 dev_data->res = NRFX_ERROR_INTERNAL; in event_handler()
194 k_sem_give(&dev_data->completion_sync); in event_handler()
199 struct i2c_nrfx_twim_data *data = dev->data; in i2c_nrfx_twim_init()
201 k_sem_init(&data->transfer_sync, 1, 1); in i2c_nrfx_twim_init()
202 k_sem_init(&data->completion_sync, 0, 1); in i2c_nrfx_twim_init()
227 #define MSG_BUF_SIZE(idx) MAX(CONCAT_BUF_SIZE(idx), FLASH_BUF_MAX_SIZE(idx))