#include "resets.h" #include "gpio.h" #include "uart.h" #include "stdio.h" #include "string.h" #include "mem.h" #include "shell.h" #define LED_PIN (25) int main(void) { reset_unreset_blocks_wait(RESETS_BLOCK_IO_BANK0 | RESETS_BLOCK_UART0 | RESETS_BLOCK_TIMER); gpio_init(0, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_DRIVE_4MA); /* UART_TX pin */ gpio_init(1, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_SCHMITT | GPIO_PAD_IE | GPIO_PAD_OD); /* UART_RX pin */ uart_init(uart0_hw, 6 * 1000 * 1000, UART_DATABITS_8 | UART_PARITY_NONE | UART_STOPBITS_1); printf("shell example\r\n"); kmem_init((void *)0x20030000, 64 * 1024); shell_init(); gpio_init(LED_PIN, GPIO_FUNC_NULL | GPIO_OVER_OUT_LOW | GPIO_OVER_OE_ENABLE | GPIO_PULL_DOWN | GPIO_DRIVE_4MA); /* LED pin */ while(1) { int c = uart_get_char(uart0_hw); if (c >= 0) { shell_handler((char)c); } } return 0; } void shell_test(int argc, char **argv) { printf("shell test, argc=%d:\r\n", argc); for (int i = 0; i < argc; i++) { printf("argv[%d] = %s\r\n", i, argv[i]); } printf("\r\n"); } SHELL_CMD_EXPORT_ALIAS(shell_test, test, shell test.); void shell_led(int argc, char **argv) { if (argc != 2) { printf("Usage: led on/off\r\n"); return; } if (strlen(argv[1]) == 3 && argv[1][0] == 'o' && argv[1][1] == 'f' && argv[1][2] == 'f') { gpio_clear(LED_PIN); } else if (strlen(argv[1]) == 2 && argv[1][0] == 'o' && argv[1][1] == 'n') { gpio_set(LED_PIN); } else { printf("Usage: led on/off\r\n"); return; } } SHELL_CMD_EXPORT_ALIAS(shell_led, led, shell led.);