📄 os_cpu_c.c
字号:
void OSTickISR(unsigned int a,unsigned int b,unsigned long c,unsigned long d,unsigned long e)
{
// if(!FlagEn)
// return; //如果当前中断被屏蔽则返回
SuspendThread(mainhandle); //中止主线程的运行,模拟中断产生.但没有保存寄存器
GetThreadContext(mainhandle, &Context); //得到主线程上下文,为切换任务做准备
OSIntNesting++;
if (OSIntNesting == 1) {
OSTCBCur->OSTCBStkPtr = (OS_STK *)Context.Esp; //保存当前esp
}
OSTimeTick(); //ucos内部定时
OSIntExit(); //由于不能使用中断返回指令,所以此函数是要返回的
ResumeThread(mainhandle); //模拟中断返回,主线程得以继续执行
}
#endif
/*$PAGE*/
#if OS_CPU_HOOKS_EN
/*
*********************************************************************************************************
* OS INITIALIZATION HOOK
* (BEGINNING)
*
* Description: This function is called by OSInit() at the beginning of OSInit().
*
* Arguments : none
*
* Note(s) : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_VERSION > 203
void OSInitHookBegin (void)
{
}
#endif
/*
*********************************************************************************************************
* OS INITIALIZATION HOOK
* (END)
*
* Description: This function is called by OSInit() at the end of OSInit().
*
* Arguments : none
*
* Note(s) : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_VERSION > 203
void OSInitHookEnd (void)
{
}
#endif
/*
*********************************************************************************************************
* TASK CREATION HOOK
*
* Description: This function is called when a task is created.
*
* Arguments : ptcb is a pointer to the task control block of the task being created.
*
* Note(s) : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
void OSTaskCreateHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent compiler warning */
}
/*
*********************************************************************************************************
* TASK DELETION HOOK
*
* Description: This function is called when a task is deleted.
*
* Arguments : ptcb is a pointer to the task control block of the task being deleted.
*
* Note(s) : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
void OSTaskDelHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent compiler warning */
}
/*
*********************************************************************************************************
* TASK SWITCH HOOK
*
* Description: This function is called when a task switch is performed. This allows you to perform other
* operations during a context switch.
*
* Arguments : none
*
* Note(s) : 1) Interrupts are disabled during this call.
* 2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
* will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
* task being switched out (i.e. the preempted task).
*********************************************************************************************************
*/
void OSTaskSwHook (void)
{
}
/*
*********************************************************************************************************
* STATISTIC TASK HOOK
*
* Description: This function is called every second by uC/OS-II's statistics task. This allows your
* application to add functionality to the statistics task.
*
* Arguments : none
*********************************************************************************************************
*/
void OSTaskStatHook (void)
{
}
/*
*********************************************************************************************************
* OSTCBInit() HOOK
*
* Description: This function is called by OSTCBInit() after setting up most of the TCB.
*
* Arguments : ptcb is a pointer to the TCB of the task being created.
*
* Note(s) : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_VERSION > 203
void OSTCBInitHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent Compiler warning */
}
#endif
/*
*********************************************************************************************************
* TICK HOOK
*
* Description: This function is called every tick.打印定时信息
changed by 文佳 Email:ganganwen@163.com
*
* Arguments : none
*
* Note(s) : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
void OSTimeTickHook (void)
{
// _log(" tasktick\n");
}
/*
*********************************************************************************************************
* IDLE TASK HOOK
*
* Description: This function is called by the idle task. This hook has been added to allow you to do
* such things as STOP the CPU to conserve power.changed by 文佳 Email:ganganwen@163.com
*
* Arguments : none
*
* Note(s) : 1) Interrupts are enabled during this call.
*********************************************************************************************************
*/
#if OS_VERSION >= 251
void OSTaskIdleHook (void)
{
//Sleep(1); //这里一定要加上一个短短的延迟,要不会出现错误,
//具体原因我也不太清楚,不过加上这个的好处是多的,
//使得整个程序占有很少的cpu
}
#endif
/*
*********************************************************************************************************
*
* 安装中断服务程序
*
*
*********************************************************************************************************
*/
void install_isr_service(void (*isr)(void))
{
unsigned int count;
int tip;
//注册入口函数
install_isr(isr);
//设置时钟中断
get_cp0_count(count);
tip = TIME_PERIC - (0xffffffff - count);
if(tip < 0)//no wrap
{
set_cp0_compare(count + TIME_PERIC);
}
else //wrap
{
set_cp0_compare(tip);
}
}
/*
*********************************************************************************************************
*
* 中断服务程序
*
* 进入此处,应该使得 ra 指向被中断的任务处
*********************************************************************************************************
*/
void isr_service_wrap(void)
{
unsigned int cause; //避免使用堆栈变量
unsigned int count;
int tip;
//中断原因
get_cp0_cause(cause);
//clear interrupt
set_cp0_cause(cause);
//告诉OS,进入了中断处理程序
//OSIntEnter();
OSIntNesting++;
printf("into isr\n");
if(cause & CAUSE_TIMER)
{
//重新设置时钟中断
get_cp0_count(count);
tip = TIME_PERIC - (0xffffffff - count);
if(tip < 0)//no wrap
{
set_cp0_compare(count + TIME_PERIC);
}
else //wrap
{
set_cp0_compare(tip);
}
OSTimeTick();
}
OSIntExit();
printf("out isr\n");
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -