2 Star 6 Fork 3

稀风/KOS

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app4.c 3.63 KB
一键复制 编辑 原始数据 按行查看 历史
#include <app.h>
#include <print.h>
APP_INFO appInfo[MAX_APP_NUM] = {0};
U16 appNum = 0;
E_RET AppRegister(APP_FUNC pFunc, U08* stackAddr, U16 stackSize, U08* name, E_APP_PRI priority)
{
if(appNum >= MAX_APP_NUM)
return E_ERR;
appInfo[appNum].pfunc = pFunc;
appInfo[appNum].stackAddr = stackAddr;
appInfo[appNum].stackSize = stackSize;
appInfo[appNum].name = name;
appInfo[appNum].priority = priority;
appNum++;
return E_OK;
}
/******************************************************************************
* 函数名称: static void TaskIdleFunc(void)
* 功能说明: 空闲任务
* 输入参数: 无
* 输出参数: 无
* 函数返回: 无
* 其它说明: 无
******************************************************************************/
#define IDLE_STACK_SIZE 512
static U08 taskIdle_stack[IDLE_STACK_SIZE]; // 空闲任务私有栈
static void TaskIdleFunc(void) // 空闲任务执行函数
{
// while(1);
static U32 count = 0;
while(1)
{
if(count++ % 100000 == 0)
{
static U32 j = 0;
asm volatile("cli");
SetCursorPos(0, 14);
printk("TASK Idle: %d\n", j++);
asm volatile("sti");
}
}
}
U08 taskA_stack[512]; // 任务私有栈
void TaskAFunc(void) // 任务执行函数
{
static U32 count = 0;
// U32* p = (U32*)0xB666; // 这个地址在内核范围内
// *p = 0x12345678; // 尝试改动内核数据
// printk(">>>>: %x\n", *p); // 查看是否修改成功
while(1)
{
if(count++ % 10000 == 0)
{
static U32 j = 0;
asm volatile("cli");
SetCursorPos(0, 6);
printk("TASK A: %d\n", j++);
asm volatile("sti");
}
}
}
U08 taskB_stack[512]; // 任务私有栈
void TaskBFunc(void) // 任务执行函数
{
static U32 count = 0;
while(1)
{
if(count++ % 10000 == 0)
{
static U32 j = 0;
asm volatile("cli");
SetCursorPos(0, 8);
printk("TASK B: %d\n", j++);
asm volatile("sti");
}
}
}
U08 taskC_stack[512]; // 任务私有栈
void TaskCFunc(void) // 任务执行函数
{
static U32 count = 0;
while(1)
{
if(count++ % 10000 == 0)
{
static U32 j = 0;
asm volatile("cli");
SetCursorPos(0, 10);
printk("TASK C: %d\n", j++);
asm volatile("sti");
}
}
}
U08 taskD_stack[512]; // 任务私有栈
void TaskDFunc(void) // 任务执行函数
{
static U32 count = 0;
while(1)
{
if(count++ % 10000 == 0)
{
static U32 j = 0;
asm volatile("cli");
SetCursorPos(0, 12);
printk("TASK D: %d\n", j++);
asm volatile("sti");
}
}
}
void AppInit(void)
{
SetCursorPos(0, 3); // 设置光标位置: (0, 3)
SetFontColor(E_FONT_WHITE); // 设置打印字体颜色: 白色
printk("AppInit\n");
AppRegister(TaskAFunc, taskA_stack, 512, "TASK A", E_APP_PRI5);
AppRegister(TaskBFunc, taskB_stack, 512, "TASK B", E_APP_PRI7);
AppRegister(TaskCFunc, taskC_stack, 512, "TASK C", E_APP_PRI9);
AppRegister(TaskDFunc, taskD_stack, 512, "TASK D", E_APP_PRI11);
// 把应用数据放入共享内存 0xA800 处
*((volatile U32*)0xA800) = (U32)appInfo;
*((volatile U32*)0xA804) = appNum;
*((volatile U32*)0xA808) = (U32)taskIdle_stack;
*((volatile U32*)0xA80C) = IDLE_STACK_SIZE;
*((volatile U32*)0xA810) = (U32)TaskIdleFunc;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/thin-wind/KOS.git
git@gitee.com:thin-wind/KOS.git
thin-wind
KOS
KOS
main

搜索帮助