📄 os_cpu_c.c
字号:
/*---------------------------------------------------------------------------
//
// FILE : $Workfile: Os_cpu_c.c $
//
// ORIGINATOR : Martin Rodier
// CREATION DATE : March, 7 2002
// REVISION : 1.10
// PURPOSE : This uC/OS-II port is intended for Infineon Technologies and ST10R167
// C16x Extended Architecture Micro Controller Targets (C167CR-LM)
// PART OF : uC/OS-II version 2.00
// COMPILE WITH : KEIL C166/ST10 V4.20 Ansi C Compiler
//
//---------------------------------------------------------------------------
// uC/OS-II
// The Real-Time Kernel
// Infineon C16x/C167CR
// Extended Architecture Specific Code
// HLARGE MEMORY MODEL
//---------------------------------------------------------------------------
//
// Revision history:
//
// $Log: /.../UCOS-II/C167/Os_cpu_c.c $
*
* 5 3/07/02 3:49p Mrodier
* Revised Version of the port that include a copy of the interrupting
* task PSW to fix the problem of the multiplication when the interrupted
* task had a multiplication in progress and the interrupting task do not
* return to it.
*
* Addition into OSTaskBuildStk of the PSW at position -2E of the task
* stack to let the interrupting task memorize the state of PSW into the
* task stack.
*
* 4 6/13/01 10:42a Mrodier
* Revised to final version as relased in uCOSII port
//
//-------------------------------------------------------------------------
*/
#define OS_CPU_GLOBALS
#include "includes.h"
#include <intrins.h>
#pragma SRC
/*
*********************************************************************************************************
* INITIALISE A TASK'S STACK
*
* Description: This function is called by either OSTaskCreate() or OSTaskCreateExt() to initialise the
* stack frame of the task being created. This function is highly processor specific.
*
* Arguments : task is a pointer to the task code
*
* pdata is a pointer to a user supplied data area that will be passed to the task
* when the task first executes.
*
* ptos is a pointer to the top of stack. It is assumed that 'ptos' points to
* a 'free' entry on the task stack. If OS_STK_GROWTH is set to 1 then
* 'ptos' will contain the HIGHEST valid address of the stack. Similarly, if
* OS_STK_GROWTH is set to 0, the 'ptos' will contains the LOWEST valid address
* of the stack.
*
* opt specifies options that can be used to alter the behavior of OSTaskStkInit().
*
* TASK STACK AREA (High Memory)
* +14 TASK DATA PARAMETER SEGMENT pointer of task
* +12 TASK DATA PARAMETER OFFSET pointer of task
* +10 SEGMENT of task code address
* +0E OFFSET of task code address
* +0C SP of System stack of task
* +0A USER STACK OFFSET POINTER (R0) of task
* +08 USER STACK PAGE POINTER (DPP2) of task
* +06 PSW of task
* +04 OFFSET of task return address (IP)
* +02 SEGMENT of task return address (CSP)
* 0 (Low Memory)
*
* Returns : Always returns the location of the new top-of-stack' once the processor registers have
* been placed on the stack in the proper order.
*
* Note(s) : Interrupts are enabled when your task starts executing. You can change this by setting the
* PSW to 0x0800 instead. In this case, interrupts would be disabled upon task startup. The
* application code would be responsible for enabling interrupts at the beginning of the task
* code. You will need to modify OSTaskIdle() and OSTaskStat() so that they enable
* interrupts. Failure to do this will make your system crash!
*
*********************************************************************************************************
*/
OS_STK *OSTaskStkInit (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT16U opt)
{
INT16U *stk;
INT32U usr;
INT16U page;
INT16U offset;
INT16U data_seg;
INT16U data_sof;
opt = opt; /* 'opt' is not used, prevent warning */
data_seg = (INT16U)((INT32U)pdata >> 16);
data_sof = ((INT16U) pdata & 0xFFFF);
stk = (INT16U *)ptos; /* Load stack pointer */
*stk-- = data_seg; /* TASK DATA PARAMETER SEGMENT pointer of task */
*stk-- = data_sof; /* TASK DATA PARAMETER OFFSET pointer of task */
*stk-- = (INT16U)((INT32U)task >> 16); /* Task segment start address */
*stk-- = ((INT16U)task & 0xFFFF); /* Task offset start address */
*stk-- = (INT16U)0xFC00; /* Task SP of System stack of task */
usr = (INT32U)stk; /* Keep a copy of STACK OFFSET POINTER location */
offset = (INT16U)((((usr) & 0x3FFF) - 0x0A) | 0x4000); /* First adress of stack offset pointer of the task */
*stk-- = offset; /* Task user stack offset R0 */
page = (INT16U)(usr >> 0x000E); /* Task user stack page DPP2 */
*stk-- = page; /* Task user stack page DPP2 */
*stk-- = (INT16U)0x0800; /* Task PSW = Interrupt enabled */
*stk-- = ((INT16U)task & 0xFFFF); /* Task offset return address */
*stk-- = (INT16U)((INT32U)task >> 16); /* Task segment return address */
OSTaskBuildStk(page, offset, data_seg, data_sof);
return ((OS_STK *)stk);
}
/*$PAGE*/
#if OS_CPU_HOOKS_EN
/*
*********************************************************************************************************
* 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)
{
}
/*
*********************************************************************************************************
* TICK HOOK
*
* Description: This function is called every tick.
*
* Arguments : none
*
* Note(s) : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
void OSTimeTickHook (void)
{}
/*
*********************************************************************************************************
*
*Description :Those function is added by donghegang
*
*Notes :There are not those function at the version before 200.
*
*********************************************************************************************************
*/
void OSInitHookBegin(void)
{}
void OSInitHookEnd(void)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -