Lines Matching refs:cfg

34 	struct modbus_serial_config *cfg = ctx->cfg;  in modbus_serial_tx_on()  local
36 if (cfg->de != NULL) { in modbus_serial_tx_on()
37 gpio_pin_set(cfg->de->port, cfg->de->pin, 1); in modbus_serial_tx_on()
40 uart_irq_tx_enable(cfg->dev); in modbus_serial_tx_on()
45 struct modbus_serial_config *cfg = ctx->cfg; in modbus_serial_tx_off() local
47 uart_irq_tx_disable(cfg->dev); in modbus_serial_tx_off()
48 if (cfg->de != NULL) { in modbus_serial_tx_off()
49 gpio_pin_set(cfg->de->port, cfg->de->pin, 0); in modbus_serial_tx_off()
55 struct modbus_serial_config *cfg = ctx->cfg; in modbus_serial_rx_on() local
57 if (cfg->re != NULL) { in modbus_serial_rx_on()
58 gpio_pin_set(cfg->re->port, cfg->re->pin, 1); in modbus_serial_rx_on()
61 uart_irq_rx_enable(cfg->dev); in modbus_serial_rx_on()
66 struct modbus_serial_config *cfg = ctx->cfg; in modbus_serial_rx_off() local
68 uart_irq_rx_disable(cfg->dev); in modbus_serial_rx_off()
69 if (cfg->re != NULL) { in modbus_serial_rx_off()
70 gpio_pin_set(cfg->re->port, cfg->re->pin, 0); in modbus_serial_rx_off()
101 struct modbus_serial_config *cfg = ctx->cfg; in modbus_ascii_rx_adu() local
108 rx_size = cfg->uart_buf_ctr; in modbus_ascii_rx_adu()
121 if ((cfg->uart_buf[0] != MODBUS_ASCII_START_FRAME_CHAR) || in modbus_ascii_rx_adu()
122 (cfg->uart_buf[rx_size - 2] != MODBUS_ASCII_END_FRAME_CHAR1) || in modbus_ascii_rx_adu()
123 (cfg->uart_buf[rx_size - 1] != MODBUS_ASCII_END_FRAME_CHAR2)) { in modbus_ascii_rx_adu()
131 pmsg = &cfg->uart_buf[1]; in modbus_ascii_rx_adu()
161 calc_lrc = modbus_ascii_get_lrc(&cfg->uart_buf[1], in modbus_ascii_rx_adu()
162 (cfg->uart_buf_ctr - 5) / 2); in modbus_ascii_rx_adu()
187 struct modbus_serial_config *cfg = ctx->cfg; in modbus_ascii_tx_adu() local
193 cfg->uart_buf[0] = MODBUS_ASCII_START_FRAME_CHAR; in modbus_ascii_tx_adu()
196 pbuf = &cfg->uart_buf[1]; in modbus_ascii_tx_adu()
215 lrc = modbus_ascii_get_lrc(&cfg->uart_buf[1], (tx_bytes - 1) / 2); in modbus_ascii_tx_adu()
224 cfg->uart_buf_ctr = tx_bytes; in modbus_ascii_tx_adu()
225 cfg->uart_buf_ptr = &cfg->uart_buf[0]; in modbus_ascii_tx_adu()
245 struct modbus_serial_config *cfg = ctx->cfg; in modbus_rtu_rx_adu() local
251 if ((cfg->uart_buf_ctr < MODBUS_RTU_MIN_MSG_SIZE) || in modbus_rtu_rx_adu()
252 (cfg->uart_buf_ctr > CONFIG_MODBUS_BUFFER_SIZE)) { in modbus_rtu_rx_adu()
257 ctx->rx_adu.unit_id = cfg->uart_buf[0]; in modbus_rtu_rx_adu()
258 ctx->rx_adu.fc = cfg->uart_buf[1]; in modbus_rtu_rx_adu()
259 data_ptr = &cfg->uart_buf[2]; in modbus_rtu_rx_adu()
261 ctx->rx_adu.length = cfg->uart_buf_ctr - 4; in modbus_rtu_rx_adu()
263 crc_idx = cfg->uart_buf_ctr - sizeof(uint16_t); in modbus_rtu_rx_adu()
267 ctx->rx_adu.crc = sys_get_le16(&cfg->uart_buf[crc_idx]); in modbus_rtu_rx_adu()
269 calc_crc = crc16_ansi(&cfg->uart_buf[0], in modbus_rtu_rx_adu()
270 cfg->uart_buf_ctr - sizeof(ctx->rx_adu.crc)); in modbus_rtu_rx_adu()
282 struct modbus_serial_config *cfg = ctx->cfg; in rtu_tx_adu() local
286 cfg->uart_buf[0] = ctx->tx_adu.unit_id; in rtu_tx_adu()
287 cfg->uart_buf[1] = ctx->tx_adu.fc; in rtu_tx_adu()
289 data_ptr = &cfg->uart_buf[2]; in rtu_tx_adu()
293 ctx->tx_adu.crc = crc16_ansi(&cfg->uart_buf[0], ctx->tx_adu.length + 2); in rtu_tx_adu()
295 &cfg->uart_buf[ctx->tx_adu.length + 2]); in rtu_tx_adu()
298 cfg->uart_buf_ctr = tx_bytes; in rtu_tx_adu()
299 cfg->uart_buf_ptr = &cfg->uart_buf[0]; in rtu_tx_adu()
301 LOG_HEXDUMP_DBG(cfg->uart_buf, cfg->uart_buf_ctr, "uart_buf"); in rtu_tx_adu()
313 struct modbus_serial_config *cfg = ctx->cfg; in cb_handler_rx() local
319 if (uart_fifo_read(cfg->dev, &c, 1) != 1) { in cb_handler_rx()
326 cfg->uart_buf_ptr = &cfg->uart_buf[0]; in cb_handler_rx()
327 cfg->uart_buf_ctr = 0; in cb_handler_rx()
330 if (cfg->uart_buf_ctr < CONFIG_MODBUS_BUFFER_SIZE) { in cb_handler_rx()
331 *cfg->uart_buf_ptr++ = c; in cb_handler_rx()
332 cfg->uart_buf_ctr++; in cb_handler_rx()
342 if (cfg->uart_buf_ctr == CONFIG_MODBUS_BUFFER_SIZE) { in cb_handler_rx()
349 k_timer_start(&cfg->rtu_timer, in cb_handler_rx()
350 K_USEC(cfg->rtu_timeout), K_NO_WAIT); in cb_handler_rx()
352 n = uart_fifo_read(cfg->dev, cfg->uart_buf_ptr, in cb_handler_rx()
354 cfg->uart_buf_ctr)); in cb_handler_rx()
356 cfg->uart_buf_ptr += n; in cb_handler_rx()
357 cfg->uart_buf_ctr += n; in cb_handler_rx()
363 struct modbus_serial_config *cfg = ctx->cfg; in cb_handler_tx() local
366 if (cfg->uart_buf_ctr > 0) { in cb_handler_tx()
367 n = uart_fifo_fill(cfg->dev, cfg->uart_buf_ptr, in cb_handler_tx()
368 cfg->uart_buf_ctr); in cb_handler_tx()
369 cfg->uart_buf_ctr -= n; in cb_handler_tx()
370 cfg->uart_buf_ptr += n; in cb_handler_tx()
378 if (uart_irq_tx_complete(cfg->dev)) { in cb_handler_tx()
380 cfg->uart_buf_ptr = &cfg->uart_buf[0]; in cb_handler_tx()
424 struct modbus_serial_config *cfg = ctx->cfg; in configure_gpio() local
426 if (cfg->de != NULL) { in configure_gpio()
427 if (!device_is_ready(cfg->de->port)) { in configure_gpio()
431 if (gpio_pin_configure_dt(cfg->de, GPIO_OUTPUT_INACTIVE)) { in configure_gpio()
437 if (cfg->re != NULL) { in configure_gpio()
438 if (!device_is_ready(cfg->re->port)) { in configure_gpio()
442 if (gpio_pin_configure_dt(cfg->re, GPIO_OUTPUT_INACTIVE)) { in configure_gpio()
453 struct modbus_serial_config *cfg = ctx->cfg; in configure_uart() local
494 if (uart_configure(cfg->dev, &uart_cfg) != 0) { in configure_uart()
514 struct modbus_serial_config *cfg = ctx->cfg; in modbus_serial_rx_adu() local
533 cfg->uart_buf_ctr = 0; in modbus_serial_rx_adu()
534 cfg->uart_buf_ptr = &cfg->uart_buf[0]; in modbus_serial_rx_adu()
560 struct modbus_serial_config *cfg = ctx->cfg; in modbus_serial_init() local
573 if (!device_is_ready(cfg->dev)) { in modbus_serial_init()
574 LOG_ERR("Bus device %s is not ready", cfg->dev->name); in modbus_serial_init()
585 cfg->rtu_timeout = (numof_bits * if_delay_max) / in modbus_serial_init()
588 cfg->rtu_timeout = (numof_bits * if_delay_max) / 38400; in modbus_serial_init()
595 cfg->uart_buf_ctr = 0; in modbus_serial_init()
596 cfg->uart_buf_ptr = &cfg->uart_buf[0]; in modbus_serial_init()
598 uart_irq_callback_user_data_set(cfg->dev, uart_cb_handler, ctx); in modbus_serial_init()
599 k_timer_init(&cfg->rtu_timer, rtu_tmr_handler, NULL); in modbus_serial_init()
600 k_timer_user_data_set(&cfg->rtu_timer, ctx); in modbus_serial_init()
603 LOG_INF("RTU timeout %u us", cfg->rtu_timeout); in modbus_serial_init()
612 k_timer_stop(&ctx->cfg->rtu_timer); in modbus_serial_disable()