Lines Matching +full:divider +full:- +full:int +full:- +full:5

4  * SPDX-License-Identifier: Apache-2.0
22 ((const struct uart_b91_config *)dev->config)->uart_addr)
38 #define UART_STOP_BIT_2 BIT(5)
111 return (uart->bufcnt & FLD_UART_TX_BUF_CNT) >> FLD_UART_TX_BUF_CNT_OFFSET; in uart_b91_get_tx_bufcnt()
117 return (uart->bufcnt & FLD_UART_RX_BUF_CNT) >> FLD_UART_RX_BUF_CNT_OFFSET; in uart_b91_get_rx_bufcnt()
123 uint32_t i = 5; in uart_b91_is_prime()
131 for (i = 5; i * i < n; i += 6) { in uart_b91_is_prime()
142 uint16_t *divider, uint8_t *bwpc) in uart_b91_cal_div_and_bwpc() argument
151 primeDec = 10 * pclk / baudrate - 10 * primeInt; in uart_b91_cal_div_and_bwpc()
155 } else if (primeDec > 5) { in uart_b91_cal_div_and_bwpc()
158 primeInt -= 1; in uart_b91_cal_div_and_bwpc()
163 D_intdec[i - 3] = (10 * primeInt) / (i + 1); in uart_b91_cal_div_and_bwpc()
164 D_dec[i - 3] = D_intdec[i - 3] - 10 * (D_intdec[i - 3] / 10); in uart_b91_cal_div_and_bwpc()
165 D_int[i - 3] = D_intdec[i - 3] / 10; in uart_b91_cal_div_and_bwpc()
183 if ((D_dec[position_min] < 5) && (D_dec[position_max] >= 5)) { in uart_b91_cal_div_and_bwpc()
184 if (D_dec[position_min] < (10 - D_dec[position_max])) { in uart_b91_cal_div_and_bwpc()
186 *divider = D_int[position_min] - 1; in uart_b91_cal_div_and_bwpc()
189 *divider = D_int[position_max]; in uart_b91_cal_div_and_bwpc()
191 } else if ((D_dec[position_min] < 5) && (D_dec[position_max] < 5)) { in uart_b91_cal_div_and_bwpc()
193 *divider = D_int[position_min] - 1; in uart_b91_cal_div_and_bwpc()
196 *divider = D_int[position_max]; in uart_b91_cal_div_and_bwpc()
201 static void uart_b91_init(volatile struct uart_b91_t *uart, uint16_t divider, in uart_b91_init() argument
205 divider = divider | FLD_UART_CLK_DIV_EN; in uart_b91_init()
206 uart->ctrl0 = bwpc; in uart_b91_init()
207 uart->clk_div = divider; in uart_b91_init()
212 uart->ctrl1 |= FLD_UART_PARITY_ENABLE; in uart_b91_init()
216 uart->ctrl1 &= (~FLD_UART_PARITY_POLARITY); in uart_b91_init()
219 uart->ctrl1 |= FLD_UART_PARITY_POLARITY; in uart_b91_init()
222 uart->ctrl1 &= (~FLD_UART_PARITY_ENABLE); /* disable parity function */ in uart_b91_init()
226 uart->ctrl1 &= (~FLD_UART_STOP_SEL); in uart_b91_init()
227 uart->ctrl1 |= stop_bit; in uart_b91_init()
236 struct uart_b91_data *data = dev->data; in uart_b91_irq_handler()
238 if (data->callback != NULL) { in uart_b91_irq_handler()
239 data->callback(dev, data->cb_data); in uart_b91_irq_handler()
246 static int uart_b91_configure(const struct device *dev, in uart_b91_configure()
249 struct uart_b91_data *data = dev->data; in uart_b91_configure()
250 uint16_t divider; in uart_b91_configure() local
258 if (cfg->parity == UART_CFG_PARITY_NONE) { in uart_b91_configure()
260 } else if (cfg->parity == UART_CFG_PARITY_ODD) { in uart_b91_configure()
262 } else if (cfg->parity == UART_CFG_PARITY_EVEN) { in uart_b91_configure()
265 return -ENOTSUP; in uart_b91_configure()
269 if (cfg->stop_bits == UART_CFG_STOP_BITS_1) { in uart_b91_configure()
271 } else if (cfg->stop_bits == UART_CFG_STOP_BITS_1_5) { in uart_b91_configure()
273 } else if (cfg->stop_bits == UART_CFG_STOP_BITS_2) { in uart_b91_configure()
276 return -ENOTSUP; in uart_b91_configure()
280 if (cfg->flow_ctrl != UART_CFG_FLOW_CTRL_NONE) { in uart_b91_configure()
281 return -ENOTSUP; in uart_b91_configure()
285 uart_b91_cal_div_and_bwpc(cfg->baudrate, sys_clk.pclk * 1000 * 1000, &divider, &bwpc); in uart_b91_configure()
286 uart_b91_init(uart, divider, bwpc, parity, stop_bits); in uart_b91_configure()
289 data->cfg = *cfg; in uart_b91_configure()
295 static int uart_b91_config_get(const struct device *dev, in uart_b91_config_get()
298 struct uart_b91_data *data = dev->data; in uart_b91_config_get()
300 *cfg = data->cfg; in uart_b91_config_get()
307 static int uart_b91_driver_init(const struct device *dev) in uart_b91_driver_init()
309 int status = 0; in uart_b91_driver_init()
310 uint16_t divider = 0u; in uart_b91_driver_init() local
313 const struct uart_b91_config *cfg = dev->config; in uart_b91_driver_init()
314 struct uart_b91_data *data = dev->data; in uart_b91_driver_init()
317 uart->status |= UART_RX_RESET_BIT | UART_TX_RESET_BIT; in uart_b91_driver_init()
318 data->rx_byte_index = 0; in uart_b91_driver_init()
319 data->tx_byte_index = 0; in uart_b91_driver_init()
322 status = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); in uart_b91_driver_init()
327 uart_b91_cal_div_and_bwpc(cfg->baud_rate, sys_clk.pclk * 1000 * 1000, &divider, &bwpc); in uart_b91_driver_init()
328 uart_b91_init(uart, divider, bwpc, UART_PARITY_NONE, UART_STOP_BIT_1); in uart_b91_driver_init()
331 cfg->pirq_connect(); in uart_b91_driver_init()
341 struct uart_b91_data *data = dev->data; in uart_b91_poll_out()
346 uart->data_buf[data->tx_byte_index] = c; in uart_b91_poll_out()
347 data->tx_byte_index = (data->tx_byte_index + 1) % ARRAY_SIZE(uart->data_buf); in uart_b91_poll_out()
351 static int uart_b91_poll_in(const struct device *dev, unsigned char *c) in uart_b91_poll_in()
354 struct uart_b91_data *data = dev->data; in uart_b91_poll_in()
357 return -1; in uart_b91_poll_in()
360 *c = uart->data_buf[data->rx_byte_index]; in uart_b91_poll_in()
361 data->rx_byte_index = (data->rx_byte_index + 1) % ARRAY_SIZE(uart->data_buf); in uart_b91_poll_in()
367 static int uart_b91_err_check(const struct device *dev) in uart_b91_err_check()
371 return ((uart->status & UART_RX_ERR_STATUS) != 0) ? 1 : 0; in uart_b91_err_check()
377 static int uart_b91_fifo_fill(const struct device *dev, in uart_b91_fifo_fill()
379 int size) in uart_b91_fifo_fill()
381 int i = 0; in uart_b91_fifo_fill()
400 static int uart_b91_fifo_read(const struct device *dev, in uart_b91_fifo_read()
402 const int size) in uart_b91_fifo_read()
404 int rx_count; in uart_b91_fifo_read()
423 uart->ctrl3 = (uart->ctrl3 & (~FLD_UART_TX_IRQ_TRIQ_LEV)) | in uart_b91_irq_tx_enable()
425 uart->ctrl0 |= UART_TX_IRQ_MASK; in uart_b91_irq_tx_enable()
433 uart->ctrl0 &= ~UART_TX_IRQ_MASK; in uart_b91_irq_tx_disable()
437 static int uart_b91_irq_tx_ready(const struct device *dev) in uart_b91_irq_tx_ready()
442 ((uart->ctrl0 & UART_TX_IRQ_MASK) != 0)) ? 1 : 0; in uart_b91_irq_tx_ready()
446 static int uart_b91_irq_tx_complete(const struct device *dev) in uart_b91_irq_tx_complete()
458 uart->ctrl3 = (uart->ctrl3 & (~FLD_UART_RX_IRQ_TRIQ_LEV)) | in uart_b91_irq_rx_enable()
460 uart->ctrl0 |= UART_RX_IRQ_MASK; in uart_b91_irq_rx_enable()
468 uart->ctrl0 &= ~UART_RX_IRQ_MASK; in uart_b91_irq_rx_disable()
472 static int uart_b91_irq_rx_ready(const struct device *dev) in uart_b91_irq_rx_ready()
484 uart->rxtimeout |= UART_ERR_IRQ_MASK; in uart_b91_irq_err_enable()
492 uart->rxtimeout &= ~UART_ERR_IRQ_MASK; in uart_b91_irq_err_disable()
496 static int uart_b91_irq_is_pending(const struct device *dev) in uart_b91_irq_is_pending()
500 return ((uart->status & UART_IRQ_STATUS) != 0) ? 1 : 0; in uart_b91_irq_is_pending()
504 static int uart_b91_irq_update(const struct device *dev) in uart_b91_irq_update()
517 struct uart_b91_data *data = dev->data; in uart_b91_irq_callback_set()
519 data->callback = cb; in uart_b91_irq_callback_set()
520 data->cb_data = cb_data; in uart_b91_irq_callback_set()