/*==================[external functions definition]==========================*/ void StartOs_Arch(void) { uint8f loopi; /* init every task */ for( loopi = 0; loopi < TASKS_COUNT; loopi++) { /* init stack */ ResetStack(loopi); /* set entry point */ SetEntryPoint(loopi); } /* initialize singals handler */ signal(SIGALRM,OsInterruptHandler); signal(SIGUSR1,OsInterruptHandler); signal(SIGTERM,OsInterruptHandler); /* shared memory for interrupts */ OSEK_InterruptFlags = mmap(NULL, sizeof(8), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); /* init Thread Terminate flag */ Os_Terminate_Flag = false; if(0 != pthread_create(&Os_Thread_Timer, NULL, HWTimerThread, (void*)0)) { printf("Error creating OS Thread timer!\n"); exit(-1); } #if 0 printf("Process ID: %d\n", getpid()); #endif /* All these is done in a similar way in StartOS.c, Is it code to be deleted? */ #if 0 /* enable interrupts */ InterruptState = 1; /* enable HWTimer0, interrupt 4 */ InterruptMask = ~(1 << 4); #if (defined HWCOUNTER1) /* enable HWTimer0, interrupt 5 */ InterruptMask &= ~(1 << 5); #endif #endif SaveOsStack(); }
/*==================[external functions definition]==========================*/ void StartOS ( AppModeType Mode ) { /* \req OSEK_SYS_3.25 The system service void ** StartOS ( AppModeType Mode ) shall be defined */ /* \req OSEK_SYS_3.25.1 This system service shall starts the operating ** system */ uint8f loopi; IntSecure_Start(); /* save the aplication mode */ ApplicationMode = Mode; /* StartOs_Arch */ StartOs_Arch(); /* init every task */ for( loopi = 0; loopi < TASKS_COUNT; loopi++) { /* \req OSEK_SYS_3.1.2-2/3 The operating system shall ensure that the task ** code is being executed from the first statement. */ SetEntryPoint(loopi); /* set task entry point */ } /* set sys context */ SetActualContext(CONTEXT_SYS); /* set actual task to invalid task */ SetRunningTask(INVALID_TASK); /* add to ready the corresponding tasks for this * Application Mode */ for (loopi = 0; loopi < AutoStart[Mode].TotalTasks; loopi++) { /* activate task */ ActivateTask(AutoStart[Mode].TasksRef[loopi]); } for (loopi = 0; loopi < ALARM_AUTOSTART_COUNT; loopi++) { if (AutoStartAlarm[loopi].Mode == Mode) { (void)SetRelAlarm(AutoStartAlarm[loopi].Alarm, AutoStartAlarm[loopi].AlarmTime, AutoStartAlarm[loopi].AlarmCycleTime); } } #if (HOOK_STARTUPHOOK == OSEK_ENABLE) StartupHook(); #endif IntSecure_End(); /* enable all OS interrupts */ EnableOSInterrupts(); /* enable interrupts */ EnableInterrupts(); /* call Scheduler */ (void)Schedule(); /* this function shall never return */ while(1); }