参考网址:
letter-shell | 一个功能强大的嵌入式shell_Mculover666的博客(嵌入式)-CSDN博客_letter shell
实例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include "shell.h" #include "uart.h" #include "shell_port.h"
Shell shell; char shell_buffer[512];
short userShellWrite(char *data, unsigned short len) { for(int i = 0;i<len;i++) { UART_WriteByte(HW_UART0, data[i]); } return len; }
void User_Shell_Init(void) { shell.write = userShellWrite; shellInit(&shell, shell_buffer, 512); }
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| #ifndef _SHELL_PORT_H_ #define _SHELL_PORT_H_
#include "shell.h"
extern Shell shell;
void User_Shell_Init(void);
#endif
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| #include "gpio.h" #include "common.h" #include "uart.h" #include "cpuidy.h" #include "shell_port.h" uint16_t recv_buf = 0;
int test(int i, char ch, char *str) { printf("input int: %d, char: %c, string: %s\r\n", i, ch, str); return 0; }
static void UART_RX_ISR(uint16_t byteReceived) { recv_buf = byteReceived; shellHandler(&shell, recv_buf); } int main(void) { DelayInit(); uint32_t instance = GPIO_QuickInit(HW_GPIOE, 0, kGPIO_Mode_OPP); UART_QuickInit(UART0_RX_PA01_TX_PA02, 115200); UART_CallbackRxInstall(HW_UART0, UART_RX_ISR); UART_ITDMAConfig(HW_UART0, kUART_IT_Rx, true); User_Shell_Init(); while(1) { GPIO_ToggleBit(HW_GPIOE, 0); DelayMs(500); } }
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), test, test, test);
|