104 lines
2.2 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "LetterShell.h"
#include "shell.h"
#define WR_BUFFER_SIZE 512
/* 1. 创建shell对象开辟shell缓冲区 */
Shell Host; //Shell实例化
char HostBuffer[WR_BUFFER_SIZE]; //读写缓冲区
uint32_t HostId; //串口号
/**
* @brief Shell写函数
* @param ComId 串口号ch 数据
* @retval void
* @note void
* @example void
*/
signed short ShellWrite(char* ch, unsigned short Len)
{
UsartSendStr(HostId, (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)
{
HostId = ComId;
//初始化串口
UsartStdConfig(ComId, baud);
//设置串口回调函数
IntCbReg(TTY_COM_IRQN, LetterShellIrqFunc);
//设置中断等级
IntSetLevel(TTY_COM_IRQN,1,1);
//注册写函数
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",VERSION);
return 0;
}
/**
* @brief DO控制
* @param chnl 通道号 val状态值
* @retval void
* @note void
* @example void
*/
void doSet(uint8_t chnl, uint8_t val)
{
IoCtl(IO_TYPE_DO, chnl, val);
}
/**
* @brief DO控制反转
* @param chnl 通道号
* @retval void
* @note void
* @example void
*/
void doToggle(uint8_t chnl)
{
IoCtlToggleDo(chnl);
}
//打印版本号
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), version, version, version);
//控制DO
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), doSet, doSet, doSet);
//反转DO
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), doToggle, doToggle, doToggle);