modbus: move serial line config outside context

Move serial line config outside context.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
Johann Fischer 2021-03-03 14:58:39 +01:00 committed by Carles Cufí
commit b132ab556c
3 changed files with 145 additions and 113 deletions

View file

@ -34,13 +34,21 @@ DT_INST_FOREACH_STATUS_OKAY(MB_RTU_DEFINE_GPIO_CFGS)
COND_CODE_1(DT_INST_NODE_HAS_PROP(n, d), \
(&d##_cfg_##n), (NULL))
#define MODBUS_DT_GET_DEV(n) { \
.iface_name = DT_INST_LABEL(n), \
#define MODBUS_DT_GET_SERIAL_DEV(n) { \
.dev_name = DT_INST_BUS_LABEL(n), \
.de = MB_RTU_ASSIGN_GPIO_CFG(n, de_gpios), \
.re = MB_RTU_ASSIGN_GPIO_CFG(n, re_gpios), \
},
static struct modbus_serial_config modbus_serial_cfg[] = {
DT_INST_FOREACH_STATUS_OKAY(MODBUS_DT_GET_SERIAL_DEV)
};
#define MODBUS_DT_GET_DEV(n) { \
.iface_name = DT_INST_LABEL(n), \
.cfg = &modbus_serial_cfg[n], \
},
static struct modbus_context mb_ctx_tbl[] = {
DT_INST_FOREACH_STATUS_OKAY(MODBUS_DT_GET_DEV)
};
@ -156,9 +164,6 @@ static struct modbus_context *mb_cfg_iface(const uint8_t iface,
ctx->mbs_user_cb = NULL;
k_mutex_init(&ctx->iface_lock);
ctx->uart_buf_ctr = 0;
ctx->uart_buf_ptr = &ctx->uart_buf[0];
k_sem_init(&ctx->client_wait_sem, 0, 1);
k_work_init(&ctx->server_work, modbus_rx_handler);