?? os_cpu_c.c
字號:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* 80x86 Specific code
* LARGE MEMORY MODEL WITH FLOATING-POINT
* Borland C/C++ V4.51
*
*
* File : OS_CPU_C.C
* By : Jean J. Labrosse
*********************************************************************************************************
*/
#define OS_CPU_GLOBALS
#include "includes.h"
/*$PAGE*/
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*
* Note(s) : 1) OS_NTASKS_FP establishes the number of tasks capable of supporting floating-point. One
* task is removed for the idle task because it doesn't do floating-point at all.
* 2) OS_FP_STORAGE_SIZE currently allocates 128 bytes of storage even though the 80x86 FPU
* only require 108 bytes to save the FPU context. I decided to allocate 128 bytes for
* future expansion.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
局部常量
備注:1、OS_NTASKS_FP:建立能支持浮點(diǎn)的任務(wù)數(shù),空閑任務(wù)將被去除因?yàn)樗? 點(diǎn)浮點(diǎn)也不會(huì)算。
2、OS_FP_STORAGE_SIZE:即使80x86浮點(diǎn)運(yùn)算單元只需要108字節(jié)去保存浮點(diǎn)運(yùn)算
內(nèi)容,但是我分配128字節(jié),作為進(jìn)一步擴(kuò)展
*********************************************************************************************************
*/
#define OS_NTASKS_FP (OS_MAX_TASKS + OS_N_SYS_TASKS - 1)//OS_N_SYS_TASKS 為系統(tǒng)統(tǒng)計(jì)任務(wù)
#define OS_FP_STORAGE_SIZE 128
/*
*********************************************************************************************************
* LOCAL VARIABLES
*********************************************************************************************************
*/
//局部變量
static OS_MEM *OSFPPartPtr; /* Pointer to memory partition holding FPU storage areas */
/* I used INT32U to ensure that storage is aligned on a ... */
/* ... 32-bit boundary. */
//指向內(nèi)存分割區(qū)掌握FPU存儲空間的指針。我用了32位保證在32位上是對齊模式
//它是一個(gè)指針,指向此建立的分區(qū),靜態(tài)變量,用戶程序不能訪問
static INT32U OSFPPart[OS_NTASKS_FP][OS_FP_STORAGE_SIZE / sizeof(INT32U)];
//OS_NTASKS_FP為支持浮點(diǎn)的任務(wù)數(shù),OS_FP_STORAGE_SIZE是浮點(diǎn)存儲空間
//OSFPPart[][]是實(shí)際的分區(qū),保存了所有任務(wù)的FPU寄存器內(nèi)容。至少要為它
//提供(OS_MAX_TASK+1)*128字節(jié)的RAM,因?yàn)樗庆o態(tài),所以用戶不能訪問
/*$PAGE*/
/*
*********************************************************************************************************
* INITIALIZE FP SUPPORT
*
* Description: This function is called to initialize the memory partition needed to support context
* switching the Floating-Point registers. This function MUST be called AFTER calling
* OSInit().
*
* Arguments : none
*
* Returns : none
*
* Note(s) : 1) Tasks that are to use FP support MUST be created with OSTaskCreateExt().
* 2) For the 80x86 FPU, 108 bytes are required to save the FPU context. I decided to
* allocate 128 bytes for future expansion. Also, I used INT32U to ensure that storage
* is aligned on a 32-bit boundary.
* 3) I decided to 'change' the 'Options' attribute for the statistic task in case you
* use OSTaskStatHook() and need to perform floating-point operations in this function.
* This only applies if OS_TaskStat() was created with OSTaskCreateExt().
*********************************************************************************************************
*/
/*
*********************************************************************************************************
初始化浮點(diǎn)指針支持
描述:這個(gè)函數(shù)初始化需要支持任務(wù)轉(zhuǎn)換浮點(diǎn)寄存器的內(nèi)存分割區(qū)。
必須在調(diào)用OSInit()后再調(diào)用
參數(shù):無
返回:無
備注:1、支持浮點(diǎn)指針的任務(wù)必須由OSTaskCreateExt()建立
2、在80x86 FPU中,要108字節(jié)去保存FPU內(nèi)容,我準(zhǔn)備用128字節(jié)去作為進(jìn)
一步擴(kuò)展。也用了INT32U去保證在32位邊界線上對齊
3、在此函數(shù)中,你用OSTaskStatHook()又需要浮點(diǎn)運(yùn)算操作情況下,我想改變
它的選項(xiàng)。這只應(yīng)用于OS_TaskStat() 用 OSTaskCreateExt().建立的情況。
*********************************************************************************************************
*/
void OSFPInit (void)//浮點(diǎn)處理單元初始化
{
INT8U err;
#if OS_TASK_STAT_EN && OS_TASK_CREATE_EXT_EN//允許統(tǒng)計(jì)任務(wù)和浮點(diǎn)建立任務(wù)
OS_TCB *ptcb;//任務(wù)控制塊
void *pblk;
#endif
OSFPPartPtr = OSMemCreate(&OSFPPart[0][0], OS_NTASKS_FP, OS_FP_STORAGE_SIZE, &err);
//OSFPInit()將此分區(qū)信息告訴ucosII,OSMemCreate函數(shù)把一個(gè)內(nèi)存分區(qū)分成多塊,
//每塊128B,并將這些塊鏈成單向鏈表,當(dāng)需要一個(gè)內(nèi)存保存FPU寄存器時(shí),
//只須調(diào)用OSMemGet()函數(shù)
#if OS_TASK_STAT_EN && OS_TASK_CREATE_EXT_EN /* CHANGE 'OPTIONS' for OS_TaskStat() */
//允許統(tǒng)計(jì)任務(wù)和浮點(diǎn)建立任務(wù),改變OS_TaskStat() 的選項(xiàng)
ptcb = OSTCBPrioTbl[OS_STAT_PRIO];
//改變OS_TaskStat()屬性,使之能進(jìn)行浮點(diǎn)運(yùn)算,這樣做是為了使用戶
//可以通過OS_TaskStatHook()來擴(kuò)展OS_TaskStat()函數(shù)的功能,使之可以做浮點(diǎn)運(yùn)算。
//在此,OSFPInit()得到統(tǒng)計(jì)任務(wù)的任務(wù)控制塊的指針。
ptcb->OSTCBOpt |= OS_TASK_OPT_SAVE_FP; /* Allow floating-point support for Statistic task */
//指明是需要保存和恢復(fù)浮點(diǎn)寄存器的,因?yàn)橄到y(tǒng)默認(rèn)為0
pblk = OSMemGet(OSFPPartPtr, &err); /* Get storage for FPU registers */
//得到一個(gè)緩沖區(qū),用于在統(tǒng)計(jì)任務(wù)OS_TaskStat()掛起時(shí),保存該任務(wù)的浮點(diǎn)
//寄存器內(nèi)容。
if (pblk != (void *)0) { /* Did we get a memory block? */
//檢查得到的緩沖區(qū)是否合法
ptcb->OSTCBExtPtr = pblk; /* Yes, Link to task's TCB */
//合法,保存在OS_TCB的擴(kuò)展變量,OSTCBExtPtr中的指針指向
//保存FPU的存儲區(qū)
OSFPSave(pblk); /* Save the FPU registers in block */
//將FPU寄存器當(dāng)前內(nèi)容保存在pblk指向的地方。
}
#endif
}
/*$PAGE*/
/*
*********************************************************************************************************
* 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.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
系統(tǒng)初始化開始接口函數(shù)
描述:在 OSInit()開始的時(shí)候由OSInit()調(diào)用
*********************************************************************************************************
*/
#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.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
系統(tǒng)初始化結(jié)束接口函數(shù)
描述:在OSInit()結(jié)束的時(shí)候由OSInit()調(diào)用
備注:調(diào)用此函數(shù)時(shí)要關(guān)中斷
此函數(shù)調(diào)用了OSFPInit(),它負(fù)責(zé)設(shè)置保留的內(nèi)存分區(qū),該內(nèi)存分區(qū)
用來保存各任務(wù)的浮點(diǎn)寄存器
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void OSInitHookEnd (void)
{
OSFPInit();//它負(fù)責(zé)設(shè)置保留的內(nèi)存分區(qū),該內(nèi)存分區(qū)
//用來保存各任務(wù)的浮點(diǎn)寄存器
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* 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.
* 2) I decided to change the options on the statistic task to allow for floating-point in
* case you decide to do math. in OSTaskStatHook().
*********************************************************************************************************
*/
/*
*********************************************************************************************************
任務(wù)建立接口函數(shù)
描述:任務(wù)建立的時(shí)候調(diào)用
參數(shù):ptcb:將要建立任務(wù)的任務(wù)控制塊指針
備注:1、調(diào)用的時(shí)候中斷要關(guān)閉
2、當(dāng)我們要在OSTaskStatHook()中作計(jì)算的時(shí)候我打算改變
它的屬性使之能夠浮點(diǎn)運(yùn)算
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0
void OSTaskCreateHook (OS_TCB *ptcb)
{
INT8U err;
void *pblk;
if (ptcb->OSTCBOpt & OS_TASK_OPT_SAVE_FP) { /* See if task needs FP support */
//任務(wù)是否需要支持浮點(diǎn)
pblk = OSMemGet(OSFPPartPtr, &err); /* Yes, Get storage for FPU registers */
//需要的話,得到存儲FPU寄存器的存儲空間
if (pblk != (void *)0) { /* Did we get a memory block? */
//得到的空間是否合法
ptcb->OSTCBExtPtr = pblk; /* Yes, Link to task's TCB */
//合法,加到任務(wù)TCB單向鏈表
OSFPSave(pblk); /* Save the FPU registers in block */
//將FPU寄存器當(dāng)前內(nèi)容保存在pblk指向的地方。這一過程中,F(xiàn)PU包含
//了什么內(nèi)容不重要,重要的是,F(xiàn)PU寄存器包含了有效數(shù)值
}
}
}
#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.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
任務(wù)刪除接口函數(shù)
描述:當(dāng)一個(gè)任務(wù)刪除時(shí)這個(gè)函數(shù)被調(diào)用
參數(shù):ptcb:將要建立任務(wù)的任務(wù)控制塊指針
備注:1、調(diào)用的時(shí)候中斷要關(guān)閉
2、OSTaskDel()通過調(diào)用OSTaskDelHook()函數(shù)擴(kuò)展其功能,
因?yàn)樵诮⑷蝿?wù)時(shí),分配了一個(gè)內(nèi)存塊,用于保存浮點(diǎn)寄存器的內(nèi)容
所以在任務(wù)刪除時(shí),需要釋放該內(nèi)存塊。
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -