first commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#include "LedTest.h"
|
||||
|
||||
/* OS相关 */
|
||||
#define TASK_STACK_SIZE 128 //任务栈大小
|
||||
|
||||
/* OS相关 */
|
||||
TX_THREAD LedCtlTaskTCB; //LED控制任务句柄
|
||||
static uint8_t TaskStack[TASK_STACK_SIZE]; //任务栈空间
|
||||
|
||||
void LedCtlTask(ULONG thread_input);
|
||||
|
||||
/**
|
||||
* @brief LED控制任务初始化
|
||||
* @param Level任务优先级 Preemption抢占阈值
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
void LedCtlTaskInit(uint8_t Level,uint8_t Preemption)
|
||||
{
|
||||
tx_thread_create(&LedCtlTaskTCB, /* 任务句柄 */
|
||||
"LedCtlTask", /* 任务名称 */
|
||||
LedCtlTask, /* 任务入口函数 */
|
||||
0, /* 任务参数 */
|
||||
TaskStack, /* 任务栈起始地址 */
|
||||
TASK_STACK_SIZE, /* 任务堆栈大小 */
|
||||
Level, /* 优先级 */
|
||||
Preemption, /* 抢占阈值 */
|
||||
TX_NO_TIME_SLICE, /* 不使用时间片轮转 */
|
||||
TX_AUTO_START); /* 自动启动线程 */
|
||||
}
|
||||
/**
|
||||
* @brief LED控制任务
|
||||
* @param ThreadXInput 任务参数
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
void LedCtlTask(ULONG ThreadXInput)
|
||||
{
|
||||
(void)ThreadXInput;
|
||||
|
||||
while (true)
|
||||
{
|
||||
LedToggle(LED0);
|
||||
LedToggle(LED1);
|
||||
tx_thread_sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#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);
|
||||
@@ -0,0 +1,42 @@
|
||||
/* MCU INCLUDE */
|
||||
#include "stm32f10x.h"
|
||||
/* BSP INCLUDE */
|
||||
#include "Bsp.h"
|
||||
/* APP INLCUDE */
|
||||
#include "LedTest.h"
|
||||
|
||||
/**
|
||||
* @brief ThreadX操作系统入口函数
|
||||
* @param FirstUnusedMemory OS相关
|
||||
* @retval void
|
||||
* @note 此函数应该将所有OS相关的初始化放到这里
|
||||
* @example void
|
||||
*/
|
||||
void ThreadXTaskInit(void* FirstUnusedMemory)
|
||||
{
|
||||
/* 优先级31,抢占10 */
|
||||
LedCtlTaskInit(31,10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief C程序主函数
|
||||
* @param void
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
//bsp初始化
|
||||
BspConfigInit();
|
||||
|
||||
/* Start ThreadX */
|
||||
tx_kernel_enter();
|
||||
|
||||
while (true)
|
||||
{
|
||||
//程序运行到这里说明OS调度运行失败
|
||||
printf("OS Start Error !\n");
|
||||
DelayMs(1000);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user