?? 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:建立能支持浮點的任務數,空閑任務將被去除因為它一
點浮點也不會算。
2、OS_FP_STORAGE_SIZE:即使80x86浮點運算單元只需要108字節去保存浮點運算
內容,但是我分配128字節,作為進一步擴展
*********************************************************************************************************
*/
#define OS_NTASKS_FP (OS_MAX_TASKS + OS_N_SYS_TASKS - 1)//OS_N_SYS_TASKS 為系統統計任務
#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. */
//指向內存分割區掌握FPU存儲空間的指針。我用了32位保證在32位上是對齊模式
//它是一個指針,指向此建立的分區,靜態變量,用戶程序不能訪問
static INT32U OSFPPart[OS_NTASKS_FP][OS_FP_STORAGE_SIZE / sizeof(INT32U)];
//OS_NTASKS_FP為支持浮點的任務數,OS_FP_STORAGE_SIZE是浮點存儲空間
//OSFPPart[][]是實際的分區,保存了所有任務的FPU寄存器內容。至少要為它
//提供(OS_MAX_TASK+1)*128字節的RAM,因為它是靜態,所以用戶不能訪問
/*$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().
*********************************************************************************************************
*/
/*
*********************************************************************************************************
初始化浮點指針支持
描述:這個函數初始化需要支持任務轉換浮點寄存器的內存分割區。
必須在調用OSInit()后再調用
參數:無
返回:無
備注:1、支持浮點指針的任務必須由OSTaskCreateExt()建立
2、在80x86 FPU中,要108字節去保存FPU內容,我準備用128字節去作為進
一步擴展。也用了INT32U去保證在32位邊界線上對齊
3、在此函數中,你用OSTaskStatHook()又需要浮點運算操作情況下,我想改變
它的選項。這只應用于OS_TaskStat() 用 OSTaskCreateExt().建立的情況。
*********************************************************************************************************
*/
void OSFPInit (void)//浮點處理單元初始化
{
INT8U err;
#if OS_TASK_STAT_EN && OS_TASK_CREATE_EXT_EN//允許統計任務和浮點建立任務
OS_TCB *ptcb;//任務控制塊
void *pblk;
#endif
OSFPPartPtr = OSMemCreate(&OSFPPart[0][0], OS_NTASKS_FP, OS_FP_STORAGE_SIZE, &err);
//OSFPInit()將此分區信息告訴ucosII,OSMemCreate函數把一個內存分區分成多塊,
//每塊128B,并將這些塊鏈成單向鏈表,當需要一個內存保存FPU寄存器時,
//只須調用OSMemGet()函數
#if OS_TASK_STAT_EN && OS_TASK_CREATE_EXT_EN /* CHANGE 'OPTIONS' for OS_TaskStat() */
//允許統計任務和浮點建立任務,改變OS_TaskStat() 的選項
ptcb = OSTCBPrioTbl[OS_STAT_PRIO];
//改變OS_TaskStat()屬性,使之能進行浮點運算,這樣做是為了使用戶
//可以通過OS_TaskStatHook()來擴展OS_TaskStat()函數的功能,使之可以做浮點運算。
//在此,OSFPInit()得到統計任務的任務控制塊的指針。
ptcb->OSTCBOpt |= OS_TASK_OPT_SAVE_FP; /* Allow floating-point support for Statistic task */
//指明是需要保存和恢復浮點寄存器的,因為系統默認為0
pblk = OSMemGet(OSFPPartPtr, &err); /* Get storage for FPU registers */
//得到一個緩沖區,用于在統計任務OS_TaskStat()掛起時,保存該任務的浮點
//寄存器內容。
if (pblk != (void *)0) { /* Did we get a memory block? */
//檢查得到的緩沖區是否合法
ptcb->OSTCBExtPtr = pblk; /* Yes, Link to task's TCB */
//合法,保存在OS_TCB的擴展變量,OSTCBExtPtr中的指針指向
//保存FPU的存儲區
OSFPSave(pblk); /* Save the FPU registers in block */
//將FPU寄存器當前內容保存在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.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
系統初始化開始接口函數
描述:在 OSInit()開始的時候由OSInit()調用
*********************************************************************************************************
*/
#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.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
系統初始化結束接口函數
描述:在OSInit()結束的時候由OSInit()調用
備注:調用此函數時要關中斷
此函數調用了OSFPInit(),它負責設置保留的內存分區,該內存分區
用來保存各任務的浮點寄存器
*********************************************************************************************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void OSInitHookEnd (void)
{
OSFPInit();//它負責設置保留的內存分區,該內存分區
//用來保存各任務的浮點寄存器
}
#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().
*********************************************************************************************************
*/
/*
*********************************************************************************************************
任務建立接口函數
描述:任務建立的時候調用
參數:ptcb:將要建立任務的任務控制塊指針
備注:1、調用的時候中斷要關閉
2、當我們要在OSTaskStatHook()中作計算的時候我打算改變
它的屬性使之能夠浮點運算
*********************************************************************************************************
*/
#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 */
//任務是否需要支持浮點
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 */
//合法,加到任務TCB單向鏈表
OSFPSave(pblk); /* Save the FPU registers in block */
//將FPU寄存器當前內容保存在pblk指向的地方。這一過程中,FPU包含
//了什么內容不重要,重要的是,FPU寄存器包含了有效數值
}
}
}
#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.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
任務刪除接口函數
描述:當一個任務刪除時這個函數被調用
參數:ptcb:將要建立任務的任務控制塊指針
備注:1、調用的時候中斷要關閉
2、OSTaskDel()通過調用OSTaskDelHook()函數擴展其功能,
因為在建立任務時,分配了一個內存塊,用于保存浮點寄存器的內容
所以在任務刪除時,需要釋放該內存塊。
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -