Skip to content

Commit b19be52

Browse files
Hau Hoquytranpzz
authored andcommitted
drivers: serial: Update serial driver to support RX26T
- Update serial driver for RX26T support. This MCU using grp interrupt feature (not supported yet), so need to add some marcos to enable support. - Change the struct st_sci0 to use a common sci iodefine struct as st_sci Signed-off-by: Hau Ho <[email protected]> Signed-off-by: Phi Tran <[email protected]>
1 parent 7e8303d commit b19be52

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

drivers/serial/uart_renesas_rx_sci.c

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Renesas Electronics Corporation
2+
* Copyright (c) 2024-2025 Renesas Electronics Corporation
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -14,9 +14,12 @@
1414
#include <zephyr/spinlock.h>
1515

1616
#include "r_sci_rx_if.h"
17+
#include "iodefine_sci.h"
1718

1819
#if CONFIG_SOC_SERIES_RX130
1920
#include "r_sci_rx130_private.h"
21+
#elif CONFIG_SOC_SERIES_RX26T
22+
#include "r_sci_rx26t_private.h"
2023
#else
2124
#error Unknown SOC, not (yet) supported.
2225
#endif
@@ -68,7 +71,7 @@ struct uart_rx_sci_data {
6871

6972
static int uart_rx_sci_poll_in(const struct device *dev, unsigned char *c)
7073
{
71-
volatile struct st_sci0 *sci = (struct st_sci0 *)DEV_BASE(dev);
74+
volatile struct st_sci *sci = (struct st_sci *)DEV_BASE(dev);
7275

7376
if (IS_ENABLED(CONFIG_UART_ASYNC_API) && sci->SCR.BIT.RIE) {
7477
return -EBUSY;
@@ -86,7 +89,7 @@ static int uart_rx_sci_poll_in(const struct device *dev, unsigned char *c)
8689

8790
static void uart_rx_sci_poll_out(const struct device *dev, unsigned char c)
8891
{
89-
volatile struct st_sci0 *sci = (struct st_sci0 *)DEV_BASE(dev);
92+
volatile struct st_sci *sci = (struct st_sci *)DEV_BASE(dev);
9093

9194
while (sci->SSR.BIT.TEND == 0U) {
9295
}
@@ -96,7 +99,7 @@ static void uart_rx_sci_poll_out(const struct device *dev, unsigned char c)
9699

97100
static int uart_rx_err_check(const struct device *dev)
98101
{
99-
volatile struct st_sci0 *sci = (struct st_sci0 *)DEV_BASE(dev);
102+
volatile struct st_sci *sci = (struct st_sci *)DEV_BASE(dev);
100103

101104
const uint32_t status = sci->SSR.BYTE;
102105
int errors = 0;
@@ -227,7 +230,7 @@ static int uart_rx_config_get(const struct device *dev, struct uart_config *cfg)
227230

228231
static int uart_rx_fifo_fill(const struct device *dev, const uint8_t *tx_data, int size)
229232
{
230-
volatile struct st_sci0 *sci = (struct st_sci0 *)DEV_BASE(dev);
233+
volatile struct st_sci *sci = (struct st_sci *)DEV_BASE(dev);
231234
uint8_t num_tx = 0U;
232235

233236
if (size > 0 && sci->SSR.BIT.TDRE) {
@@ -240,7 +243,7 @@ static int uart_rx_fifo_fill(const struct device *dev, const uint8_t *tx_data, i
240243

241244
static int uart_rx_fifo_read(const struct device *dev, uint8_t *rx_data, const int size)
242245
{
243-
volatile struct st_sci0 *sci = (struct st_sci0 *)DEV_BASE(dev);
246+
volatile struct st_sci *sci = (struct st_sci *)DEV_BASE(dev);
244247
uint8_t num_rx = 0U;
245248

246249
if (size > 0 && sci->SSR.BIT.RDRF) {
@@ -254,7 +257,7 @@ static int uart_rx_fifo_read(const struct device *dev, uint8_t *rx_data, const i
254257
static void uart_rx_irq_tx_enable(const struct device *dev)
255258
{
256259
struct uart_rx_sci_data *data = dev->data;
257-
volatile struct st_sci0 *sci = (struct st_sci0 *)DEV_BASE(dev);
260+
volatile struct st_sci *sci = (struct st_sci *)DEV_BASE(dev);
258261

259262
sci->SCR.BYTE |= (BIT(R_SCI_SCR_TIE_Pos) | BIT(R_SCI_SCR_TEIE_Pos));
260263
irq_enable(data->tei_irq);
@@ -274,44 +277,44 @@ static void uart_rx_irq_tx_enable(const struct device *dev)
274277
static void uart_rx_irq_tx_disable(const struct device *dev)
275278
{
276279
struct uart_rx_sci_data *data = dev->data;
277-
volatile struct st_sci0 *sci = (struct st_sci0 *)DEV_BASE(dev);
280+
volatile struct st_sci *sci = (struct st_sci *)DEV_BASE(dev);
278281

279282
sci->SCR.BYTE &= ~(BIT(R_SCI_SCR_TIE_Pos) | BIT(R_SCI_SCR_TEIE_Pos));
280283
irq_disable(data->tei_irq);
281284
}
282285

283286
static int uart_rx_irq_tx_ready(const struct device *dev)
284287
{
285-
volatile struct st_sci0 *sci = (struct st_sci0 *)DEV_BASE(dev);
288+
volatile struct st_sci *sci = (struct st_sci *)DEV_BASE(dev);
286289

287290
return (sci->SCR.BIT.TIE == 1U) &&
288291
(sci->SSR.BYTE & (BIT(R_SCI_SSR_TDRE_Pos) | BIT(R_SCI_SSR_TEND_Pos)));
289292
}
290293

291294
static int uart_rx_irq_tx_complete(const struct device *dev)
292295
{
293-
volatile struct st_sci0 *sci = (struct st_sci0 *)DEV_BASE(dev);
296+
volatile struct st_sci *sci = (struct st_sci *)DEV_BASE(dev);
294297

295298
return (sci->SCR.BIT.TEIE == 1U) && (sci->SSR.BYTE & BIT(R_SCI_SSR_TEND_Pos));
296299
}
297300

298301
static void uart_rx_irq_rx_enable(const struct device *dev)
299302
{
300-
volatile struct st_sci0 *sci = (struct st_sci0 *)DEV_BASE(dev);
303+
volatile struct st_sci *sci = (struct st_sci *)DEV_BASE(dev);
301304

302305
sci->SCR.BIT.RIE = 1U;
303306
}
304307

305308
static void uart_rx_irq_rx_disable(const struct device *dev)
306309
{
307-
volatile struct st_sci0 *sci = (struct st_sci0 *)DEV_BASE(dev);
310+
volatile struct st_sci *sci = (struct st_sci *)DEV_BASE(dev);
308311

309312
sci->SCR.BIT.RIE = 0U;
310313
}
311314

312315
static int uart_rx_irq_rx_ready(const struct device *dev)
313316
{
314-
volatile struct st_sci0 *sci = (struct st_sci0 *)DEV_BASE(dev);
317+
volatile struct st_sci *sci = (struct st_sci *)DEV_BASE(dev);
315318

316319
return (sci->SCR.BIT.RIE == 1U) && ((sci->SSR.BYTE & BIT(R_SCI_SSR_RDRF_Pos)));
317320
}
@@ -332,7 +335,7 @@ static void uart_rx_irq_err_disable(const struct device *dev)
332335

333336
static int uart_rx_irq_is_pending(const struct device *dev)
334337
{
335-
volatile struct st_sci0 *sci = (struct st_sci0 *)DEV_BASE(dev);
338+
volatile struct st_sci *sci = (struct st_sci *)DEV_BASE(dev);
336339
bool tx_pending = false;
337340
bool rx_pending = false;
338341

@@ -439,7 +442,9 @@ static void uart_rx_sci_txi_isr(const struct device *dev)
439442
data->user_cb(dev, data->user_cb_data);
440443
}
441444
}
445+
#endif
442446

447+
#ifndef CONFIG_SOC_SERIES_RX26T
443448
static void uart_rx_sci_tei_isr(const struct device *dev)
444449
{
445450
struct uart_rx_sci_data *data = dev->data;
@@ -459,7 +464,16 @@ static void uart_rx_sci_eri_isr(const struct device *dev)
459464
}
460465
#endif
461466

467+
#if defined(CONFIG_SOC_SERIES_RX26T)
468+
#define UART_RX_SCI_CONFIG_INIT(index)
469+
#else
470+
#define UART_RX_SCI_CONFIG_INIT(index) \
471+
.tei_irq = DT_IRQ_BY_NAME(DT_INST_PARENT(index), tei, irq), \
472+
.eri_irq = DT_IRQ_BY_NAME(DT_INST_PARENT(index), eri, irq),
473+
#endif
474+
462475
#if CONFIG_UART_INTERRUPT_DRIVEN || CONFIG_UART_ASYNC_API
476+
#ifndef CONFIG_SOC_SERIES_RX26T
463477
#define UART_RX_SCI_IRQ_INIT(index) \
464478
do { \
465479
IRQ_CONNECT(DT_IRQ_BY_NAME(DT_INST_PARENT(index), rxi, irq), \
@@ -480,9 +494,19 @@ static void uart_rx_sci_eri_isr(const struct device *dev)
480494
irq_enable(DT_IRQ_BY_NAME(DT_INST_PARENT(index), eri, irq)); \
481495
} while (0)
482496
#else
483-
#define UART_RX_SCI_IRQ_INIT(index)
497+
#define UART_RX_SCI_IRQ_INIT(index) \
498+
do { \
499+
IRQ_CONNECT(DT_IRQ_BY_NAME(DT_INST_PARENT(index), rxi, irq), \
500+
DT_IRQ_BY_NAME(DT_INST_PARENT(index), rxi, priority), \
501+
uart_rx_sci_rxi_isr, DEVICE_DT_INST_GET(index), 0); \
502+
IRQ_CONNECT(DT_IRQ_BY_NAME(DT_INST_PARENT(index), txi, irq), \
503+
DT_IRQ_BY_NAME(DT_INST_PARENT(index), txi, priority), \
504+
uart_rx_sci_txi_isr, DEVICE_DT_INST_GET(index), 0); \
505+
irq_enable(DT_IRQ_BY_NAME(DT_INST_PARENT(index), rxi, irq)); \
506+
irq_enable(DT_IRQ_BY_NAME(DT_INST_PARENT(index), txi, irq)); \
507+
} while (0)
508+
#endif
484509
#endif
485-
486510

487511
#define UART_RX_INIT(index) \
488512
PINCTRL_DT_DEFINE(DT_INST_PARENT(index)); \
@@ -506,9 +530,7 @@ static void uart_rx_sci_eri_isr(const struct device *dev)
506530
}, \
507531
.rxi_irq = DT_IRQ_BY_NAME(DT_INST_PARENT(index), rxi, irq), \
508532
.txi_irq = DT_IRQ_BY_NAME(DT_INST_PARENT(index), txi, irq), \
509-
.tei_irq = DT_IRQ_BY_NAME(DT_INST_PARENT(index), tei, irq), \
510-
.eri_irq = DT_IRQ_BY_NAME(DT_INST_PARENT(index), eri, irq), \
511-
}; \
533+
UART_RX_SCI_CONFIG_INIT(index)}; \
512534
\
513535
static int uart_rx_init_##index(const struct device *dev) \
514536
{ \

0 commit comments

Comments
 (0)