?? os_cpu.c
字號:
/*
*********************************************************************************************************
* minOS 0.01v
* The Real-Time OS Kernel
* All Rights Reserved
* File : OS_CPU.C
* 作者 : 21icbbs網友 LM7556 ,2004年7月 by : LM7556 , China , 2004-2004
*
*********************************************************************************************************
*/
#define OS_CPU_GLOBALS
#include "OS_Includes.h"
//#pragma interrupt_handler OSTickISR:8 //uses Timer0 for time ticks.
//;CPU specific definitions
#define C51_CRYSTAL_FREQ 4000000ul
//;Determine the reload values for timer 0 this is automated by the next macro
#define T0_RELOAD C51_CRYSTAL_FREQ / OS_TICKS_PER_SEC / 1024
#define T0_TCNT0 (256 - (T0_RELOAD & 0xff))
//Initial OS Timer for time ticks --- 初始化時間節拍定時器。
void InitOSTimer(void)
{
TIMSK |= (1<<1); // set T0IE0
TCCR0 = 0x05; // CTC0=CK/1024
TCNT0 = T0_TCNT0; // (256 - (T0_RELOAD & 0xff))
SREG |= (1<<7); // SEI
}
//建立一個任務(Create a Task)。
//Inport : tFunc --- function address , tStk --- stack bottom , prio --- Priority .
void OSTaskCreate (void (*tFunc)(void) , OS_STK *tStk, INT8U prio)
{
OSTCB[prio].OSTaskStatus = OS_TASK_Rdy;
OSTCB[prio].OSStkTop = (INT16U)tStk-1 /* Initial value when main was called */
-12 /* reserve for to save R0-R5 , R26-R31 registers */
-sizeof(INT16U) /* The PC value to be loaded */
;
*--tStk = (INT16U const)tFunc & 0xff; /* Save low byte of task function address */
*--tStk = (INT16U const)tFunc / 0x100; /* Save high byte of task function address */
}
static unsigned int SaveSP; //用于保存需恢復的SP,在OSTickISR或用戶中斷結束做任務切換時,恢復SP.
//context switch interrupt --- 軟中斷任務切換
void OSCtxSw(void)
{
//asm("in %0, %1" : "=r" (value) : "I" (PORTD) : );
asm("PUSH R31");
asm("PUSH R30");
asm("PUSH R29");
asm("PUSH R28");
asm("PUSH R27");
asm("PUSH R26");
asm("PUSH R0");
asm("PUSH R1");
asm("PUSH R2");
asm("PUSH R3");
asm("PUSH R4");
asm("PUSH R5");
asm("IN R31,0x3d");
asm("STS SaveSP,R31");
asm("IN R31,0x3e");
asm("STS SaveSP+1,R31");
OSTCB[OS_TASK_CrtPrio].OSStkTop = SaveSP; //Save the current task top.
OS_TASK_CrtPrio=OS_TASK_HighPri;
// Load context from the stack
SaveSP = OSTCB[OS_TASK_CrtPrio].OSStkTop; //load the high priority task task top.
asm("CLI");
asm("LDS R31,SaveSP");
asm("OUT 0x3d,R31");
asm("LDS R31,SaveSP+1");
asm("OUT 0x3e,R31");
asm("SEI");
asm("POP R5");
asm("POP R4");
asm("POP R3");
asm("POP R2");
asm("POP R1");
asm("POP R0");
asm("POP R26");
asm("POP R27");
asm("POP R28");
asm("POP R29");
asm("POP R30");
asm("POP R31");
}
//OS Time Tick Interrupt,OS 時鐘節拍中斷.
INTERRUPT(SIG_OVERFLOW0)
{
TCNT0 = T0_TCNT0; // (256 - (T0_RELOAD & 0xff))
#if OS_TICK_HOOK_EN>0
// AppTickHook(); //Hook file for a time tick --- 用戶每個時間節拍的鉤子函數
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -