Lines Matching +full:divider +full:- +full:int +full:- +full:5
2 * SPDX-License-Identifier: Apache-2.0
58 struct sy1xx_uart_config *config = (struct sy1xx_uart_config *)dev->config; in sy1xx_uart_configure()
60 if (uart_cfg->baudrate == 0) { in sy1xx_uart_configure()
61 return -1; in sy1xx_uart_configure()
66 * and then will restart from 0, so we must give div - 1 as in sy1xx_uart_configure()
67 * divider in sy1xx_uart_configure()
69 uint32_t divider = sy1xx_soc_get_peripheral_clock() / uart_cfg->baudrate - 1; in sy1xx_uart_configure() local
72 * [31:16]: clock divider (from SoC clock) in sy1xx_uart_configure()
77 * [2:1]: bits 00 = 5 bits in sy1xx_uart_configure()
85 volatile uint32_t setup = 0x0306 | uart_cfg->parity; in sy1xx_uart_configure()
87 setup |= ((divider) << 16); in sy1xx_uart_configure()
88 SY1XX_UDMA_WRITE_REG(config->base, SY1XX_UDMA_SETUP_REG, setup); in sy1xx_uart_configure()
104 * - < 0: Error
105 * - 0: OK
106 * - > 0: Busy
110 struct sy1xx_uart_config *config = (struct sy1xx_uart_config *)dev->config; in sy1xx_uart_read()
111 struct sy1xx_uart_data *data = (struct sy1xx_uart_data *)dev->data; in sy1xx_uart_read()
114 return -1; in sy1xx_uart_read()
117 uint32_t max_read_size = request->data_len; in sy1xx_uart_read()
119 request->data_len = 0; in sy1xx_uart_read()
122 return -3; in sy1xx_uart_read()
128 int32_t remaining_bytes = SY1XX_UDMA_READ_REG(config->base, SY1XX_UDMA_RX_SIZE_REG); in sy1xx_uart_read()
129 int32_t bytes_transferred = (DEVICE_MAX_BUFFER_SIZE - remaining_bytes); in sy1xx_uart_read()
136 request->data[i] = data->read[i]; in sy1xx_uart_read()
140 request->data_len = bytes_transferred; in sy1xx_uart_read()
143 SY1XX_UDMA_CANCEL_RX(config->base); in sy1xx_uart_read()
146 SY1XX_UDMA_START_RX(config->base, (int32_t)data->read, DEVICE_MAX_BUFFER_SIZE, 0); in sy1xx_uart_read()
161 * - < 0: Error
162 * - 0: OK
163 * - > 0: Busy
167 struct sy1xx_uart_config *config = (struct sy1xx_uart_config *)dev->config; in sy1xx_uart_write()
168 struct sy1xx_uart_data *data = (struct sy1xx_uart_data *)dev->data; in sy1xx_uart_write()
171 return -1; in sy1xx_uart_write()
174 if (request->data_len == 0) { in sy1xx_uart_write()
175 return -1; in sy1xx_uart_write()
178 if (request->data_len > DEVICE_MAX_BUFFER_SIZE) { in sy1xx_uart_write()
180 return -2; in sy1xx_uart_write()
183 if (0 == SY1XX_UDMA_IS_FINISHED_TX(config->base)) { in sy1xx_uart_write()
188 uint32_t remaining_bytes = SY1XX_UDMA_GET_REMAINING_TX(config->base); in sy1xx_uart_write()
191 SY1XX_UDMA_CANCEL_TX(config->base); in sy1xx_uart_write()
192 return -3; in sy1xx_uart_write()
196 for (uint32_t i = 0; i < request->data_len; i++) { in sy1xx_uart_write()
197 data->write[i] = request->data[i]; in sy1xx_uart_write()
201 SY1XX_UDMA_START_TX(config->base, (uint32_t)data->write, request->data_len, 0); in sy1xx_uart_write()
210 static int sy1xx_uart_poll_in(const struct device *dev, unsigned char *c) in sy1xx_uart_poll_in()
221 return -1; in sy1xx_uart_poll_in()
241 static int sy1xx_uart_err_check(const struct device *dev) in sy1xx_uart_err_check()
243 int err = 0; in sy1xx_uart_err_check()
248 static int sy1xx_uart_init(const struct device *dev) in sy1xx_uart_init()
250 struct sy1xx_uart_config *config = (struct sy1xx_uart_config *)dev->config; in sy1xx_uart_init()
251 struct sy1xx_uart_data *data = (struct sy1xx_uart_data *)dev->data; in sy1xx_uart_init()
254 data->write[i] = 0xa5; in sy1xx_uart_init()
255 data->read[i] = 0xb4; in sy1xx_uart_init()
259 sy1xx_udma_enable_clock(SY1XX_UDMA_MODULE_UART, config->inst); in sy1xx_uart_init()
283 SY1XX_PAD_CONFIG_ADDR_UART + (config->inst * 4 + 0)); in sy1xx_uart_init()
291 SY1XX_UDMA_CANCEL_RX(config->base); in sy1xx_uart_init()
292 SY1XX_UDMA_CANCEL_TX(config->base); in sy1xx_uart_init()