static int cmd_init(int argc, char **argv) { int dev, res; uint32_t baud; if (argc < 3) { printf("usage: %s <dev> <baudrate>\n", argv[0]); return 1; } /* parse parameters */ dev = parse_dev(argv[1]); if (dev < 0) { return 1; } baud = (uint32_t)atoi(argv[2]); /* initialize UART */ res = uart_init(UART_DEV(dev), baud, rx_cb, (void *)dev); if (res == -1) { printf("Error: Given baudrate (%u) not possible\n", (unsigned int)baud); return 1; } else if (res < -1) { puts("Error: Unable to initialize UART device\n"); return 1; } printf("Successfully initialized UART_DEV(%i)\n", dev); return 0; }
static int parse_uart(char *arg) { unsigned uart = atoi(arg); if (uart >= UART_NUMOF) { printf("Error: Invalid UART_DEV device specified (%u).\n", uart); return -1; } else if (UART_DEV(uart) == UART_STDIO_DEV) { printf("Error: The selected UART_DEV(%u) is used for the shell!\n", uart); return -2; } return uart; }
static int init(int argc, char **argv) { (void)argc; (void)argv; if (argc < 3) { printf("Usage: %s <uart> <baudrate>\n", argv[0]); return 1; } uint8_t uart = atoi(argv[1]); uint32_t baudrate = atoi(argv[2]); at_dev_init(&at_dev, UART_DEV(uart), baudrate, buf, sizeof(buf)); return 0; }
static int cmd_send(int argc, char **argv) { int dev; if (argc < 3) { printf("usage: %s <dev> <data (string)>\n", argv[0]); return 1; } /* parse parameters */ dev = parse_dev(argv[1]); if (dev < 0) { return 1; } printf("UART_DEV(%i) TX: %s\n", dev, argv[2]); uart_write(UART_DEV(dev), (uint8_t *)argv[2], strlen(argv[2]) + 1); return 0; }
void UART_5_ISR(void) { irq_handler(UART_DEV(5)); }
void UART_4_ISR(void) { irq_handler(UART_DEV(4)); }
void UART_3_ISR(void) { irq_handler(UART_DEV(3)); }
void UART_2_ISR(void) { irq_handler(UART_DEV(2)); }
void UART_1_ISR(void) { irq_handler(UART_DEV(1)); }
void UART_0_ISR(void) { irq_handler(UART_DEV(0)); }