?? os_cpu_c.c
字號:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-1999, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
*
* C167 Specific code
* LARGE MEMORY MODEL
*
* File : OS_CPU_C.C
* By : Jean J. Labrosse
* Michael Awosika
Karl Wannenmacher
*********************************************************************************************************
*/
#define OS_CPU_GLOBALS
#include "includes.h"
/*
*********************************************************************************************************
* 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().
*
* 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_pag;
INT16U data_pof;
opt = opt; /* 'opt' is not used, prevent warning */
data_pag = (INT16U)_pag(pdata);
data_pof = (INT16U)_pof(pdata);
stk = (INT16U *)ptos; /* Load stack pointer */
*stk-- = data_pag;
*stk-- = data_pof;
*stk-- = (INT16U)_seg(task); /* Task segment start address */
*stk-- = (INT16U)_sof(task); /* Task offset start address */
usr = (INT32U)stk;
offset = (INT16U)((((usr) & 0x3FFF) - 10) | 0x4000); /* Task user stack offset */
*stk-- = offset;
page = (INT16U)(usr >> 0x000E); /* Task user stack page */
*stk-- = page;
*stk-- = (INT16U)0x0800; /* Task PSW = Interrupts enabled */
*stk-- = (INT16U)_sof(task); /* Task offset return address */
*stk-- = (INT16U)_seg(task); /* Task segment return address */
OSTaskBuildStk(page, offset, data_pag, data_pof);
return ((OS_STK *)stk);
}
/*$PAGE*/
/*$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)
{
}
#endif
/*
*********************************************************************************************************
* BUILD A TASK'S STACK AREA
*
* Description: This function is called by OSTaskStkInit to initialise the
* stack frame of the task being created.
*
* Arguments : page is a pointer to the current task user stack page.
*
* offset is a pointer to the current task user stack offset.
*
* datapag is a pointer to a user supplied data area page when the task first executes.
*
* datapof is a pointer to a user supplied data area offset when the task first executes.
*
* Returns : None
*********************************************************************************************************
*/
void OSTaskBuildStk (INT16U page, INT16U offset, INT16U datapag, INT16U datapof)
{
#pragma asm(@1=page, @2=offset, @3=datapag, @4=datapof)
; ; SAVE USED REGISTERS
PUSH R1
PUSH R2
PUSH R3
PUSH R4
PUSH R10
PUSH DPP1
; ; LOAD INITIAL TASK STACK.
MOV R4,@2 ; Get pointer to Task Stack
MOV DPP1,@1 ; Task Stack DPP1:R4
MOV R2,@3 ; Page pointer to passed parameter
MOV R3,@4 ; Offset pointer to passed parameter
; ; ADJUST THE TASK USER OFFSET POINTER
ADD R4,#10 ; Point at user stack offset
MOV R1,[R4] ; Get initial user offset pointer
SUB R1,#2Ch ; adjust user offset pointer to save task registers
MOV [R4],R1 ; Save true user offset pointer
MOV R4,@2 ; Reload current stack pointer
; ; INITIALISE REGISTER VALUES
SUB R1,R1 ; Set R1 to zero
MOV R10,#01111h ; R1 initialised to 1111
MOV [-R4],R10
MOV R10,#02222h ; R2 initialised to 2222
MOV [-R4],R10
MOV R10,#03333h ; R3 initialised to 3333
MOV [-R4],R10
MOV R10,#04444h ; R4 initialised to 4444
MOV [-R4],R10
MOV R10,#05555h ; R5 initialised to 5555
MOV [-R4],R10
MOV R10,#06666h ; R6 initialised to 6666
MOV [-R4],R10
MOV R10,#07777h ; R7 initialised to 7777
MOV [-R4],R10
MOV R10,#08888h ; R8 initialised to 8888
MOV [-R4],R10
MOV R10,#09999h ; R9 initialised to 9999
MOV [-R4],R10
MOV R10,#0AAAAh ; R10 initialised to AAAA
MOV [-R4],R10
MOV R10,#0BBBBh ; R11 initialised to BBBB
MOV [-R4],R10
MOV R10,R3 ; R12 initialised to point @ POF of pdata
MOV [-R4],R10
MOV R10,R2 ; R13 initialised to point @ PAG of pdata
MOV [-R4],R10
MOV R10,#0EEEEh ; R14 initialised to EEEE
MOV [-R4],R10
MOV R10,#0FFFFh ; R15 initialised to FFFF
MOV [-R4],R10
MOV R10,CP ; Get the Context Pointer (CP)
MOV [-R4],R10 ; Put it on the user stack
MOV R10,DPP3 ; Get Data Page Pointer 3 (DPP3)
MOV [-R4],R10 ; Put it on the user stack
MOV R10,DPP2 ; Get Data Page Pointer 2 (DPP2)
MOV [-R4],R10 ; Put it on the user stack
MOV R10,DPP0 ; Get Data Page Pointer 0 (DPP0)
MOV [-R4],R10 ; Put it on the user stack
MOV [-R4],R1 ; Set Multiply/Divide Control (MDC)
MOV [-R4],R1 ; Set Multiply/Divide High (MDH)
MOV [-R4],R1 ; Set Multiply/Divide Low (MDL)
; ; RESTORE USED REGISTERS
POP DPP1
POP R10
POP R4
POP R3
POP R2
POP R1
#pragma endasm
}
/*$PAGE*/
/*
*********************************************************************************************************
* INITIALIZE SYSTEM TICK
*
* Description: This function is called to initialize and configure the system interrupt tick.
*
* Arguments : none
*********************************************************************************************************
*/
void OSTickISRInit (void)
{
IEN=1; // allg. Interrupt freigeben
T3CON=0x0; // Mode: Timer, Input Prescaler = 16 -> 26ms -> 38 times/sec,
T3IC=68; // Timer3 Prioritaet und Interrupt freigeben
T3R=1;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -