📄 os_cpu_c.c
字号:
/****************************************Copyright (c)***************************************************
;**
;** 公 司
;** 部 门
;**
;** http://www.xxxx.com
;**
;**--------------文件信息--------------------------------------------------------------------------------
;** 文 件 名: OS_CPU_C.C
;** 创 建 人: 罗辉联
;** 创建日期: 2006年6月10日
;** 描 述: UCOS需用用户修改C代码部分
;**
;**--------------历史版本--------------------------------------------------------------------------------
;** 创 建 人: 罗辉联
;** 技术顾问: 楼东武 浙江大学信电系 (高级工程师)
;** 张美玉 浙江工业大学软件学院 (教授)
;** 邹洪波 浙江大学自动化系 (博士)
;** 钟 曦 北京中星威电子有限公司 (工程师)
;**
;** 版 本: V1.0
;** 日 期: 2006年6月10日
;** 描 述: 原始版本
;**
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
#define OS_CPU_GLOBALS
#include "ucos_ii.h"
#define OS_VIEW_MODULE 0
#if OS_VIEW_MODULE > 0
#include <OS_VIEWc.H>
#include <OS_VIEW.H>
#endif
#define ARM_MODE_ARM 0x00000000
#define ARM_MODE_THUMB 0x00000020
#ifdef __thumb
#define ARM_SVC_MODE (0x00000013L + ARM_MODE_THUMB)
#else
#define ARM_SVC_MODE (0x00000013L + ARM_MODE_ARM)
#endif
/*
*********************************************************************************************************
* 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_CPU_HOOKS_EN > 0 && 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_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void OSInitHookEnd (void)
{
#if OS_CPU_INT_DIS_MEAS_EN > 0
OS_CPU_IntDisMeasInit();
#endif
}
#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.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskCreateHook (OS_TCB *ptcb)
{
#if OS_VIEW_MODULE > 0
OSView_TaskCreateHook(ptcb);
#else
ptcb = ptcb; /* Prevent compiler warning */
#endif
}
#endif
/*
*********************************************************************************************************
* 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.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskDelHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent compiler warning */
}
#endif
/*
*********************************************************************************************************
* 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.
*
* Arguments : none
*
* Note(s) : 1) Interrupts are enabled during this call.
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION >= 251
void OSTaskIdleHook (void)
{
}
#endif
/*
*********************************************************************************************************
* 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
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskStatHook (void)
{
}
#endif
/*********************************************************************************************************
;** 函数名称: OSTaskStkInit
;** 功能描述: 任务堆栈初始化代码,本函数调用失败会使OS系统崩溃
;**
;** 参 数: task : 任务开始执行的地址
;** pdata :传递给任务的参数
;** ptos :任务的堆栈开始位置
;** opt :附加参数,当前版本对于本函数无用,具体意义参见OSTaskCreateExt()的opt参数
;**
;** 返 回 值: 栈顶指针位置
;**
;** 作 者: 罗辉联
;** 日 期: 2006年6月10日
;**-------------------------------------------------------------------------------------------------------
;** 修 改 人:
;** 日 期:
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
OS_STK *OSTaskStkInit (void (*task)(void *p_arg), void *p_arg, OS_STK *ptos, INT16U opt)
{
OS_STK *stk;
opt = opt; /* 'opt' 没有使用。作用是避免编译器警告 */
stk = ptos; /* 获取堆栈指针 */
*(stk) = (OS_STK)task; /* 建立任务环境,ADS1.2使用满递减堆栈 */
*(--stk) = (INT32U)0x14141414L; /* R14 (LR) */
*(--stk) = (INT32U)0x12121212L; /* R12 */
*(--stk) = (INT32U)0x11111111L; /* R11 */
*(--stk) = (INT32U)0x10101010L; /* R10 */
*(--stk) = (INT32U)0x09090909L; /* R9 */
*(--stk) = (INT32U)0x08080808L; /* R8 */
*(--stk) = (INT32U)0x07070707L; /* R7 */
*(--stk) = (INT32U)0x06060606L; /* R6 */
*(--stk) = (INT32U)0x05050505L; /* R5 */
*(--stk) = (INT32U)0x04040404L; /* R4 */
*(--stk) = (INT32U)0x03030303L; /* R3 */
*(--stk) = (INT32U)0x02020202L; /* R2 */
*(--stk) = (INT32U)0x01010101L; /* R1 */
*(--stk) = (INT32U)p_arg; /* R0 : 第一个参数使用R0传递 */
*(--stk) = (INT32U)ARM_SVC_MODE; /* CPSR 允许 IRQ, FIQ 中断 */
return (stk);
}
/*
*********************************************************************************************************
* 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).
*********************************************************************************************************
*/
#if (OS_CPU_HOOKS_EN > 0) && (OS_TASK_SW_HOOK_EN > 0)
void OSTaskSwHook (void)
{
#if OS_VIEW_MODULE > 0
OSView_TaskSwHook();
#endif
}
#endif
/*
*********************************************************************************************************
* OS_TCBInit() HOOK
*
* Description: This function is called by OS_TCBInit() 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_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void OSTCBInitHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent Compiler warning */
}
#endif
/*
*********************************************************************************************************
* TICK HOOK
*
* Description: This function is called every tick.
*
* Arguments : none
*
* Note(s) : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if (OS_CPU_HOOKS_EN > 0) && (OS_TIME_TICK_HOOK_EN > 0)
void OSTimeTickHook (void)
{
#if OS_VIEW_MODULE > 0
OSView_TickHook();
#endif
}
#endif
/*
*********************************************************************************************************
* INTERRUPT DISABLE TIME MEASUREMENT, START
*********************************************************************************************************
*/
#if OS_CPU_INT_DIS_MEAS_EN > 0
void OS_CPU_IntDisMeasInit (void)
{
OS_CPU_IntDisMeasNestingCtr = 0;
OS_CPU_IntDisMeasCntsEnter = 0;
OS_CPU_IntDisMeasCntsExit = 0;
OS_CPU_IntDisMeasCntsMax = 0;
OS_CPU_IntDisMeasCntsDelta = 0;
OS_CPU_IntDisMeasCntsOvrhd = 0;
OS_CPU_IntDisMeasStart(); /* Measure the overhead of the functions */
OS_CPU_IntDisMeasStop();
OS_CPU_IntDisMeasCntsOvrhd = OS_CPU_IntDisMeasCntsDelta;
}
void OS_CPU_IntDisMeasStart (void)
{
OS_CPU_IntDisMeasNestingCtr++;
if (OS_CPU_IntDisMeasNestingCtr == 1) { /* Only measure at the first nested level */
OS_CPU_IntDisMeasCntsEnter = OS_CPU_IntDisMeasTmrRd();
}
}
void OS_CPU_IntDisMeasStop (void)
{
OS_CPU_IntDisMeasNestingCtr--; /* Decrement nesting ctr */
if (OS_CPU_IntDisMeasNestingCtr == 0) {
OS_CPU_IntDisMeasCntsExit = OS_CPU_IntDisMeasTmrRd();
OS_CPU_IntDisMeasCntsDelta = OS_CPU_IntDisMeasCntsExit - OS_CPU_IntDisMeasCntsEnter;
if (OS_CPU_IntDisMeasCntsDelta > OS_CPU_IntDisMeasCntsOvrhd) { /* Ensure overhead < delta */
OS_CPU_IntDisMeasCntsDelta -= OS_CPU_IntDisMeasCntsOvrhd;
} else {
OS_CPU_IntDisMeasCntsDelta = OS_CPU_IntDisMeasCntsOvrhd;
}
if (OS_CPU_IntDisMeasCntsDelta > OS_CPU_IntDisMeasCntsMax) { /* Track MAXIMUM */
OS_CPU_IntDisMeasCntsMax = OS_CPU_IntDisMeasCntsDelta;
}
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -