Skip to content

Commit

Permalink
imxrt: implement uart ioctl to set baudrate
Browse files Browse the repository at this point in the history
JIRA: RTOS-848
  • Loading branch information
Gerard Swiderski authored and gerard5 committed Jun 25, 2024
1 parent 7ff36b5 commit 7789882
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions devices/devs.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#define DEVS_ITER_STOP ((const dev_t *)-1)

#define DEV_CONTROL_SETBAUD 1

/* clang-format off */
enum { dev_isMappable = 0, dev_isNotMappable };
/* clang-format on */
Expand Down
32 changes: 32 additions & 0 deletions devices/uart-imxrt106x/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,37 @@ static int uart_init(unsigned int minor)
}


static int uart_control(unsigned int minor, int cmd, void *args)
{
u32 reg;
uart_t *uart;

uart = uart_getInstance(minor);
if (uart == NULL) {
return -EINVAL;
}

switch (cmd) {
case DEV_CONTROL_SETBAUD:
/* Set baudrate */
reg = *(uart->base + baudr) & ~((0x1f << 24) | (1 << 17) | 0x1fff);
*(uart->base + baudr) = reg | calculate_baudrate(*(int *)args);

/* Set 8 bit and no parity mode */
*(uart->base + ctrlr) &= ~0x117;

/* One stop bit */
*(uart->base + baudr) &= ~(1 << 13);
return EOK;

default:
break;
}

return -ENOSYS;
}


__attribute__((constructor)) static void uart_reg(void)
{
static const dev_ops_t opsUartIMXRT106X = {
Expand All @@ -632,6 +663,7 @@ __attribute__((constructor)) static void uart_reg(void)
.erase = NULL,
.sync = uart_sync,
.map = uart_map,
.control = uart_control,
};

static const dev_t devUartIMXRT106X = {
Expand Down
32 changes: 32 additions & 0 deletions devices/uart-imxrt117x/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,37 @@ static int uart_init(unsigned int minor)
}


static int uart_control(unsigned int minor, int cmd, void *args)
{
u32 reg;
uart_t *uart;

uart = uart_getInstance(minor);
if (uart == NULL) {
return -EINVAL;
}

switch (cmd) {
case DEV_CONTROL_SETBAUD:
/* Set baudrate */
reg = *(uart->base + baudr) & ~((0x1f << 24) | (1 << 17) | 0xfff);
*(uart->base + baudr) = reg | calculate_baudrate(*(int *)args);

/* Set 8 bit and no parity mode */
*(uart->base + ctrlr) &= ~0x117;

/* One stop bit */
*(uart->base + baudr) &= ~(1 << 13);
return EOK;

default:
break;
}

return -ENOSYS;
}


__attribute__((constructor)) static void uart_reg(void)
{
static const dev_ops_t opsUartIMXRT117X = {
Expand All @@ -663,6 +694,7 @@ __attribute__((constructor)) static void uart_reg(void)
.erase = NULL,
.sync = uart_sync,
.map = uart_map,
.control = uart_control,
};

static const dev_t devUartIMXRT117X = {
Expand Down

0 comments on commit 7789882

Please sign in to comment.