78 lines
1.7 KiB
C
78 lines
1.7 KiB
C
#include "LetterShell.h"
|
||
#include "shell.h"
|
||
|
||
#define WR_BUFFER_SIZE 512
|
||
|
||
/* 1. 创建shell对象,开辟shell缓冲区 */
|
||
Shell Host; //Shell实例化
|
||
char HostBuffer[WR_BUFFER_SIZE]; //读写缓冲区
|
||
uint32_t TtyComId; //串口号
|
||
|
||
/**
|
||
* @brief Shell写函数
|
||
* @param ComId 串口号,ch 数据
|
||
* @retval void
|
||
* @note void
|
||
* @example void
|
||
*/
|
||
signed short ShellWrite(char* ch, unsigned short Len)
|
||
{
|
||
UsartSendStr(TtyComId, (uint8_t* )ch,Len);
|
||
return Len;
|
||
}
|
||
/**
|
||
* @brief Shell读函数 - 中断回调实现
|
||
* @param Vector 中断向量号
|
||
* @retval void
|
||
* @note void
|
||
* @example void
|
||
*/
|
||
void LetterShellIrqFunc(uint32_t Vector)
|
||
{
|
||
uint8_t ch = 0x00;
|
||
ch = UsartReceiveChar(Vector);
|
||
|
||
shellHandler(&Host, ch);
|
||
}
|
||
|
||
|
||
/**
|
||
* @brief 初始化Shell
|
||
* @param ComId 串口号,baud 波特率
|
||
* @retval void
|
||
* @note void
|
||
* @example void
|
||
*/
|
||
void LetterShellInit(uint32_t ComId, uint32_t baud)
|
||
{
|
||
TtyComId = ComId;
|
||
|
||
//初始化串口
|
||
UsartStdConfig(ComId, baud);
|
||
//设置串口回调函数
|
||
InterruptRegist(TTY_COM_IRQN, LetterShellIrqFunc);
|
||
//设置中断等级
|
||
InterruptSetLevel(TTY_COM_IRQN,3,3);
|
||
//注册写函数
|
||
Host.write = ShellWrite;
|
||
|
||
shellInit(&Host, HostBuffer, WR_BUFFER_SIZE);
|
||
}
|
||
|
||
/**
|
||
* @brief 打印版本号
|
||
* @param void
|
||
* @retval void
|
||
* @note void
|
||
* @example void
|
||
*/
|
||
int version(void)
|
||
{
|
||
printf("硬件版本:%s\r\n",HARDWARE_VERSION);
|
||
printf("软件版本:%s\r\n",SOFTWARE_VERSION);
|
||
return 0;
|
||
}
|
||
|
||
//打印版本号
|
||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), version, version, version);
|