📄 os.c
字号:
unsigned char OSEKOSoldAllCCRcounter = 0;
unsigned char OSEKOSoldAllCCR = 0;
# ifdef __BANKED__
unsigned char OSEKOShc12Startpage;
# endif
# ifdef __BANKED__
const unsigned char OSEKOShc12config = 1;
# else
const unsigned char OSEKOShc12config = 0;
# endif
unsigned short *OSEKOShc12Stackstart;
unsigned short OSEKOShc12Startfunction;
void OSEKOSAsmDispatch(OSEKOSPrioType);
void OSEKOSAsmIDispatch(void);
# ifdef INCLUDE_OSEKTIME
void OSEKOSUserMain(void)
# else
# ifdef __COSMIC__
# ifdef OSEKOS_RELOCATE_NONBANKED
# pragma section (non_banked)
# endif
@near void main(void)
# else
void main(void)
# endif
# endif
{
# ifdef __HIWARE__
asm SEI;
OSEKOS_COV(486);
# endif
# ifdef __COSMIC__
_asm("sei\n");
OSEKOS_COV(487);
# endif
OSEKOSSystem();
}
# ifdef __COSMIC__
# pragma section ()
# endif
# ifdef __HIWARE__
#pragma NO_EXIT
#pragma NO_FRAME
void OSEKOSAsmDispatch(OSEKOSPrioType prio)
{
if(OSEKOStermregie == 0)
{
OSEKOS_COV(489);
asm {
LDX OSEKOSrbptr ; load pointer to rbptr in X
PULB
LDAA OSEKOSoldCCR ; get old CCR
PSHA ; push old CCR on stack.
STS 0,X ; store the stack pointer in [X]
PSHB
}
}
# endif
# ifdef __COSMIC__
# asm
# ifdef __BANKED__
f_OSEKOSAsmDispatch:
# else
_OSEKOSAsmDispatch:
# endif
tfr d,y
clrb
cmpb _OSEKOStermregie
bne continue
ldx _OSEKOSrbptr
ldaa _OSEKOSoldCCR
psha
sts 0,x
continue:
tfr y,d
# ifdef __BANKED__
call f_OSEKOSAsmDispatchFinal
rtc
# else
jmp _OSEKOSAsmDispatchFinal
# endif
# endasm
# ifdef __BANKED__
@far void OSEKOSAsmDispatchFinal(OSEKOSPrioType prio)
# else
void OSEKOSAsmDispatchFinal(OSEKOSPrioType prio)
# endif
{
# endif
OSEKOStermregie = 0;
OSEKOStidact = OSEKOSpliste[OSEKOSrunprio=prio];
OSEKOS_traceTrigger();
OSEKOSrbptr = &OSEKOSrbliste[OSEKOStaskRbIndex[OSEKOStidact]];
OSEKOStaskStatus[OSEKOStidact] = ((OSEKOStaskStatus[OSEKOStidact] & ~TSTATBITS) | RUNNING);
if ( OSEKOStaskStatus[OSEKOStidact] & INTSTART )
{
OSEKOS_COV(493);
OSEKOStaskStatus[OSEKOStidact] ^= INTSTART;
# ifdef __HIWARE__
asm
{
LDX OSEKOSrbptr
LDS 0,X
# ifdef __BANKED__
}
POP_PPAGE
asm
{
# endif
RTI
}
# endif
# ifdef __COSMIC__
# ifdef __BANKED__
_asm ("ldx _OSEKOSrbptr\n");
_asm ("lds 0,x\n");
POP_PPAGE
_asm ("rti\n");
# else
_asm ("ldx _OSEKOSrbptr\n");
_asm ("lds 0,x\n");
_asm ("rti\n");
# endif
# endif
}
if ( OSEKOStaskStatus[OSEKOStidact] & SETSTART )
{
OSEKOS_COV(494);
OSEKOSGetInternalResourceFast();
OSEKOStaskStatus[OSEKOStidact] ^= SETSTART;
OSEKOShc12Stackstart = (unsigned short *)OSEKOStaskStack[OSEKOStidact];
# ifdef __HIWARE__
OSEKOShc12Startfunction = *((unsigned short *)(&OSEKOStaskStartAddress[OSEKOStidact]));
# ifdef __BANKED__
OSEKOShc12Startpage = (unsigned char)(((unsigned long)(OSEKOStaskStartAddress[OSEKOStidact]))&0xff);
# endif
# endif
# ifdef __COSMIC__
# ifdef __BANKED__
OSEKOShc12Startfunction = *(((unsigned short *)&OSEKOStaskStartAddressBanked[OSEKOStidact]));
OSEKOShc12Startpage = (((unsigned char *)&OSEKOStaskStartAddressBanked[OSEKOStidact])[2]);
# else
OSEKOShc12Startfunction = *((unsigned short *)(&OSEKOStaskStartAddress[OSEKOStidact]));
# endif
# endif
OSEKOSoldCCR = 0x0;
# ifdef __HIWARE__
asm
{
LDX OSEKOShc12Stackstart
TXS
LDD OSEKOShc12Startfunction
PSHD
# ifdef __BANKED__
LDAA OSEKOShc12Startpage
PSHA
CLI
RTC
# else
CLI
RTS
# endif
}
# endif
# ifdef __COSMIC__
_asm("ldx _OSEKOShc12Stackstart\n");
_asm("txs\n");
_asm("ldd _OSEKOShc12Startfunction\n");
_asm("pshd\n");
# ifdef __BANKED__
_asm("ldaa _OSEKOShc12Startpage\n");
_asm("psha\n");
_asm("cli\n");
_asm("rtc\n");
# endif
_asm("cli\n");
_asm("rts\n");
# endif
}
# ifdef __HIWARE__
asm
{
LDX OSEKOSrbptr
LDS 0,X
NOP
PULB
STAB OSEKOSoldCCR ; restore old CCR
# ifdef __BANKED__
RTC
# else
RTS
# endif
}
# endif
# ifdef __COSMIC__
_asm("ldx _OSEKOSrbptr\n");
_asm("lds 0,x\n");
_asm("nop\n");
_asm("pulb\n");
_asm("stab _OSEKOSoldCCR\n");
# ifdef __BANKED__
_asm("rtc\n");
# else
_asm("rts\n");
# endif
# endif
OSEKOShc12Startfunction = (unsigned short)(&OSEKOShc12config);
}
# ifdef __HIWARE__
# endif
void OSEKOSAsmIDispatch(void)
{
if (OSEKOStaskStatus[OSEKOStidact]&NPRTASK){
OSEKOS_COV(495);
return;
}
if (OSEKOSkernel){
OSEKOS_COV(496);
return;
}
if (OSEKOSneuregie == 1)
{
OSEKOS_COV(497);
OSEKOSrunprio = OSEKOShighPrio;
}
else
{
OSEKOS_COV(498);
for(OSEKOSrunprio = PMAX;OSEKOSpliste[OSEKOSrunprio] >= ATMAX; OSEKOSrunprio--)
;
if (OSEKOStidact==OSEKOSpliste[OSEKOSrunprio]){
OSEKOS_COV(501);
return;
}
OSEKOShighPrio = OSEKOSrunprio;
}
OSEKOSneuregie = 0;
OSEKOStaskStatus[OSEKOStidact] ^= ((READY^RUNNING) | INTSTART);
*OSEKOSrbptr = OSEKOSisrInterruptedTaskStackPointer;
OSEKOS_COV(505);
OSEKOStidact = OSEKOSpliste[OSEKOSrunprio];
OSEKOS_traceTrigger();
OSEKOSrbptr = &OSEKOSrbliste[OSEKOStaskRbIndex[OSEKOStidact]];
OSEKOStaskStatus[OSEKOStidact] = ((OSEKOStaskStatus[OSEKOStidact] & ~TSTATBITS) | RUNNING);
if ( OSEKOStaskStatus[OSEKOStidact] & SETSTART )
{
OSEKOS_COV(507);
OSEKOSGetInternalResourceFast();
OSEKOStaskStatus[OSEKOStidact] ^= SETSTART;
OSEKOShc12Stackstart = (unsigned short *)OSEKOStaskStack[OSEKOStidact];
# ifdef __HIWARE__
OSEKOShc12Startfunction = *((unsigned short *)(&OSEKOStaskStartAddress[OSEKOStidact]));
# ifdef __BANKED__
OSEKOShc12Startpage = (unsigned char)(((unsigned long)(OSEKOStaskStartAddress[OSEKOStidact]))&0xff);
# endif
# endif
# ifdef __COSMIC__
# ifdef __BANKED__
OSEKOShc12Startfunction = *(((unsigned short *)&OSEKOStaskStartAddressBanked[OSEKOStidact]));
OSEKOShc12Startpage = (((unsigned char *)&OSEKOStaskStartAddressBanked[OSEKOStidact])[2]);
# else
OSEKOShc12Startfunction = *((unsigned short *)(&OSEKOStaskStartAddress[OSEKOStidact]));
# endif
# endif
# ifdef __HIWARE__
asm {
LDX OSEKOShc12Stackstart
TXS
LDD OSEKOShc12Startfunction
PSHD
# ifdef __BANKED__
LDAA OSEKOShc12Startpage
PSHA
CLI
RTC
# else
CLI
RTS
# endif
}
# endif
# ifdef __COSMIC__
_asm("ldx _OSEKOShc12Stackstart\n");
_asm("txs\n");
_asm("ldd _OSEKOShc12Startfunction\n");
_asm("pshd\n");
# ifdef __BANKED__
_asm("ldaa _OSEKOShc12Startpage\n");
_asm("psha\n");
_asm("cli\n");
_asm("rtc\n");
# endif
_asm("cli\n");
_asm("rts\n");
# endif
}
# ifdef __HIWARE__
asm
{
LDX OSEKOSrbptr
LDS 0,X
NOP
PULB
STAB OSEKOSoldCCR ; restore old CCR
# ifdef __BANKED__
RTC
# else
RTS
# endif
}
# endif
# ifdef __COSMIC__
_asm("ldx _OSEKOSrbptr\n");
_asm("lds 0,x\n");
_asm("nop\n");
_asm("pulb\n");
_asm("stab _OSEKOSoldCCR\n");
# ifdef __BANKED__
_asm("rtc\n");
# else
_asm("rts\n");
# endif
# endif
}
void OSEKOSDisable(void)
{
# ifdef __HIWARE__
asm
{
TFR CCR,D
SEI
STAB OSEKOSoldCCR
}
# endif
# ifdef __COSMIC__
_asm("tfr ccr,d\n");
_asm("sei\n");
_asm("stab _OSEKOSoldCCR\n");
# endif
}
void OSEKOSEnable(void)
{
# ifdef __HIWARE__
asm
{
LDAB OSEKOSoldCCR
EXG CCR,B
}
# endif
# ifdef __COSMIC__
_asm("ldab _OSEKOSoldCCR\n");
_asm("exg ccr,b\n");
# endif
}
# ifdef __HIWARE__
# pragma INLINE
unsigned char OSEKOSgetCCR()
{
asm TFR CCR,B;
}
# pragma INLINE
static void setCCR(unsigned char A)
{
asm TFR B,CCR;
}
# endif
# ifdef __COSMIC__
#define setCCR(A) _asm("tfr b,ccr\n",A)
# endif
void OSEKOSSuspendOSInterrupts()
{
unsigned char old = OSEKOSgetCCR();
# ifdef __HIWARE__
asm SEI;
# endif
# ifdef __COSMIC__
_asm("sei\n");
# endif
if (OSEKOSoldAllCCRcounter == 0){
OSEKOS_COV(508);
OSEKOSoldAllCCR = old;
}
OSEKOSoldAllCCRcounter++;
}
void OSEKOSResumeOSInterrupts()
{
if (--OSEKOSoldAllCCRcounter == 0){
OSEKOS_COV(509);
setCCR(OSEKOSoldAllCCR);
}
}
void OSEKOScheckSuspendResumeNesting(void)
{
if(OSEKOSoldAllCCRcounter!=0){
OSEKOSShutdownOS(E_OS_SYS_CODE);
}
}
void OSEKOSStartupEnable(void)
{
# ifdef __HIWARE__
asm
{
TFR CCR,D
ANDB #0xEF
STAB OSEKOSoldCCR
}
# endif
# ifdef __COSMIC__
_asm("tfr ccr,d\n");
_asm("andb #$ef\n");
_asm("stab _OSEKOSoldCCR");
# endif
}
/*
SizeInformation:
================
Type BitsPerUnit UnitSize
----------------------------------
Variables 8 75
Constants 8 77
Stack 8 198
VectorTable 8 126
Variables_extra 8 0
*/
/* 6faf3391764039ab4ceb43cdea8608b1 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -