Ejemplo n.º 1
0
/* Cortex-M0 core of LPC4337 uses RIT Timer for periodic IRQ */
void RIT_IRQHandler(void)
{
   if(Chip_RIT_GetIntStatus(LPC_RITIMER) == SET)
   {
      /* Store the calling context in a variable. */
      ContextType actualContext = GetCallingContext();

      /* Set ISR2 context. */
      SetActualContext(CONTEXT_ISR2);

#if (ALARMS_COUNT != 0)

      /* Counter increment. */
      static CounterIncrementType CounterIncrement = 1; /* TODO remove me. */

      (void)CounterIncrement; /* This avoids a compiler warning because the variable is not being used. */

      /*
       * Enter critical section.
       * */
      IntSecure_Start();

      /*
       * The the RTOS counter increment handler.
       * */
      CounterIncrement = IncrementCounter(0, 1 /* CounterIncrement */); /* TODO FIXME */

      /*
       * Exit the critical section.
       * */
      IntSecure_End();

#endif /* #if (ALARMS_COUNT != 0) */

      /* reset context */
      SetActualContext(actualContext);

#if (NON_PREEMPTIVE == OSEK_DISABLE)

      /*
       * Check if the currently active task is preemptive;
       * if it is, call schedule().
       * */

      if ( ( CONTEXT_TASK == actualContext ) &&
            ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) )
      {
         /* This shall force a call to the scheduler. */
         PostIsr2_Arch(isr);
      }

#endif /* #if (NON_PREEMPTIVE == OSEK_DISABLE) */

      Chip_RIT_ClearInt(LPC_RITIMER);

      NVIC_ClearPendingIRQ(RITIMER_IRQn);
   }
}
Ejemplo n.º 2
0
/* Periodic Interrupt Timer, included in all Cortex-M4 processors */
void SysTick_Handler(void)
{
#if (ALARMS_COUNT != 0)
	/* to save the context during the interrupt */
	ContextType context;
	/* counter increment */
	static CounterIncrementType CounterIncrement = 1;
   (void)CounterIncrement; /* TODO remove me */

	/* increment the disable interrupt conter to avoid enable the interrupts */
	IntSecure_Start();

	/* save actual context */
	context = GetCallingContext();

	/* set context to CONTEXT_DBG */
	SetActualContext(CONTEXT_DBG);

	/* call counter interrupt handler */
	CounterIncrement = IncrementCounter(0, 1 /* CounterIncrement */); /* TODO FIXME */

	/* interrupt has to be called first after so many CounterIncrement */
	/* SetCounterTime(CounterIncrement); */ /* TODO FIXME */

	/* set context back */
	SetActualContext(context);

	/* set the disable interrupt counter back */
	IntSecure_End();

#endif /* #if (ALARMS_COUNT != 0) */

	/* clear timer interrupt flag */
	//not necessary for Cortex-M3
	//ClearTimerInterrupt_Cpu();

#if 0 /* TODO */
#if (NON_PREEMPTIVE == DISABLE)
		/* check if interrupt a Task Context */
		if ( GetCallingContext() ==  CONTEXT_TASK )
		{
			if ( TasksConst[GetRunningTask()].ConstFlags.Preemtive )
			{
				/* \req TODO Rescheduling shall take place only if interrupt a
				 * preemptable task. */
				(void)Schedule();
			}
		}
#endif /* #if (NON_PREEMPTIVE == ENABLE) */
#endif
}
Ejemplo n.º 3
0
/* Periodic Interrupt Timer, included in all Cortex-M4 processors */
void SysTick_Handler(void)
{
   /* store the calling context in a variable */
   ContextType actualContext = GetCallingContext();
   /* set isr 2 context */
   SetActualContext(CONTEXT_ISR2);

#if (ALARMS_COUNT != 0)
   /* counter increment */
   static CounterIncrementType CounterIncrement = 1;
   (void)CounterIncrement; /* TODO remove me */

   /* increment the disable interrupt conter to avoid enable the interrupts */
   IntSecure_Start();

   /* call counter interrupt handler */
   CounterIncrement = IncrementCounter(0, 1 /* CounterIncrement */); /* TODO FIXME */

   /* set the disable interrupt counter back */
   IntSecure_End();

#endif /* #if (ALARMS_COUNT != 0) */

   /* reset context */
   SetActualContext(actualContext);

#if (NON_PREEMPTIVE == OSEK_DISABLE)
   /* check if the actual task is preemptive */
   if ( ( CONTEXT_TASK == actualContext ) &&
        ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) )
   {
      /* indicate that the scheduler will be called from isr2 */
//      OSEK_ISR2_SchedulerCall = 1;
      OSEK_ISR2_SchedulerCall++;

      /* this shall force a call to the scheduler */
      PostIsr2_Arch(isr);
   }
#endif /* #if (NON_PREEMPTIVE == OSEK_DISABLE) */
}
Ejemplo n.º 4
0
/*==================[external functions definition]==========================*/
void OSEK_ISR2_ISRtec(void)
{
   /* store the calling context in a variable */
   ContextType actualContext = GetCallingContext();
   /* set isr 2 context */
   SetActualContext(CONTEXT_ISR2);

   /* trigger isr 2 */
   OSEK_ISR_ISRtec();

   /* reset context */
   SetActualContext(actualContext);

#if (NON_PREEMPTIVE == OSEK_DISABLE)
   /* check if the actual task is preemptive */
   if ( ( CONTEXT_TASK == actualContext ) &&
        ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) )
   {
      /* this shall force a call to the scheduler */
      PostIsr2_Arch(isr);
   }
#endif /* #if (NON_PREEMPTIVE == OSEK_ENABLE) */
}
Ejemplo n.º 5
0
extern StatusType Schedule
(
   void
)
#endif
{
   /* \req OSEK_SYS_3.4 The system service StatusType Schedule ( void ) shall
    ** be defined */

   /* \req OSEK_SYS_3.4.4 Possible return values in Standard mode is E_OK */
   StatusType ret = E_OK;
   TaskType nextTask;
   TaskType actualTask;
#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)
   ContextType actualContext;
#endif

   IntSecure_Start();

   /* get actual running task */
   actualTask = GetRunningTask();

   /* \req OSEK_SYS_3.3.5 Extra possible return values in Extended mode are E_OS
    ** CALLEVEL, E_OS_RESOURCE  */
#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)

   /* get actual context */
   actualContext = GetCallingContext();

   /* if called from scheduler no checks shall be performed */
   if (FALSE == PerformChecks)
   {
      /* no checks shall be performed */
   }
   else if ( ( CONTEXT_TASK != actualContext ) &&
        ( CONTEXT_SYS != actualContext ) )
   {
      /* \req OSEK_SYS_3.3.5 Extra possible return values in Extended mode
       ** are E_OS_CALLEVEL, E_OS_RESOURCE */
      ret = E_OS_CALLEVEL;
   }
   else if ( ( INVALID_TASK != actualTask ) &&
             ( CONTEXT_TASK == actualContext ) )
   {
      if ( TasksVar[actualTask].Resources != 0 )
      {
         /* \req OSEK_SYS_3.3.5 Extra possible return values in Extended mode
          ** are E_OS_CALLEVEL, E_OS_RESOURCE */
         ret = E_OS_RESOURCE;
      }
   }
   else
   {
      /* nothing to check Runngin Task is invalid */
   }

   if (ret == E_OK)
#endif
   {
      /* get next task */
      nextTask = GetNextTask();

      /* while until one or boths are not more invalid tasks */
      while ( ( actualTask == INVALID_TASK ) &&
            ( nextTask == INVALID_TASK) )
      {
         IntSecure_End();

         /* macro used to indicate the processor that we are in idle time */
         osekpause();

         IntSecure_Start();

         /* get next task */
         nextTask = GetNextTask();
      };

      /* if the actual task is invalid */
      if ( actualTask == INVALID_TASK )
      {
         /* set task state to running */
         TasksVar[nextTask].Flags.State = TASK_ST_RUNNING;

         /* set as running task */
         SetRunningTask(nextTask);

         /* set actual context task */
         SetActualContext(CONTEXT_TASK);

         IntSecure_End();

#if (HOOK_PRETASKHOOK == OSEK_ENABLE)
         PreTaskHook();
#endif /* #if (HOOK_PRETASKHOOK == OSEK_ENABLE) */

         /* jmp tp the next task */
         JmpTask(nextTask);
      }
      else
      {
         /* check priorities */
         /* \req OSEK_SYS_3.4.1 If a task with a lower or equal priority than the
          ** ceiling priority of the internal resource and higher priority than
          ** the priority of the calling task is ready */
         if ( TasksConst[nextTask].StaticPriority > TasksVar[actualTask].ActualPriority )
         {

#if (HOOK_POSTTASKHOOK == OSEK_ENABLE)
            PostTaskHook();
#endif /* #if (HOOK_POSTTASKHOOK == OSEK_ENABLE) */

            /* \req OSEK_SYS_3.4.1.1 the internal resource of the task shall be
             ** released */
            ReleaseInternalResources();

            /* \req OSEK_SYS_3.4.1.2 the current task is put into the ready state */
            TasksVar[actualTask].Flags.State = TASK_ST_READY;

            /* set the new task to running */
            TasksVar[nextTask].Flags.State = TASK_ST_RUNNING;

            /* set as running task */
            SetRunningTask(nextTask);

            /* set actual context task */
            SetActualContext(CONTEXT_TASK);

            IntSecure_End();

#if (HOOK_PRETASKHOOK == OSEK_ENABLE)
            PreTaskHook();
#endif /* #if (HOOK_PRETASKHOOK == OSEK_ENABLE) */

            /* \req OSEK_SYS_3.4.1.3 its context is saved */
            /* \req OSEK_SYS_3.4.1.4 and the higher-priority task is executed */
            CallTask(actualTask, nextTask);
         }
         else
         {
            IntSecure_End();

            /* \req OSEK_SYS_3.4.2 Otherwise the calling task is continued */
         }
      }
   }
#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)
   else
   {
      IntSecure_End();
   }
#endif /* #if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) */

#if (HOOK_ERRORHOOK == OSEK_ENABLE)
   /* \req OSEK_ERR_1.3-4/xx The ErrorHook hook routine shall be called if a
    ** system service returns a StatusType value not equal to E_OK.*/
   /* \req OSEK_ERR_1.3.1-4/xx The hook routine ErrorHook is not called if a
    ** system service is called from the ErrorHook itself. */
   if ( ( ret != E_OK ) && (ErrorHookRunning != 1))
   {
      SetError_Api(OSServiceId_Schedule);
      SetError_Ret(ret);
      SetError_Msg("Schedule Task returns != than E_OK");
      SetError_ErrorHook();
   }
#endif

   return ret;
}
Ejemplo n.º 6
0
/*==================[external functions definition]==========================*/
   StatusType ActivateTask
(
 TaskType TaskID
 )
{
   /* \req OSEK_SYS_3.1 The system service StatusType
    * ActivateTask ( TaskType TaskID ) shall be defined. */

   /* \req OSEK_SYS_3.1.3 The service may be called from interrupt category 2
    * level and from task level. */
   /* nothing to do for this req. */

   /* \req OSEK_SYS_3.1.7-1/3 Possible return values in Standard mode are E_OK or E_OS_LIMIT */
   StatusType ret = E_OK;

#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)
   /* check if the task id is valid */
   if ( TaskID >= TASKS_COUNT )
   {
      /* if an invalid task id return E_OS_ID */
      /* \req OSEK_SYS_3.1.5-1/3 If other than E_OK is returned the activation
       * is ignored */
      /* \req OSEK_SYS_3.1.8 Added possible return values in Extended mode is
       * E_OS_ID */
      ret = E_OS_ID;
   }
   else
#endif
   {
      IntSecure_Start();

      /* check if the task is susspended */
      /* \req OSEK_SYS_3.1.1-1/2 The task TaskID shall be transferred from the
       * suspended state into the ready state. */
      if ( TasksVar[TaskID].Flags.State == TASK_ST_SUSPENDED )
      {
         /* increment activation counter */
         TasksVar[TaskID].Activations++;
         /* if the task was suspended set it to ready */
         /* OSEK_SYS_3.1.1-2/2 The task TaskID shall be transferred from the
          * suspended state into the ready state.*/
         TasksVar[TaskID].Flags.State = TASK_ST_READY;
         /* clear all events */
         /* \req OSEK_SYS_3.1.6 When an extended task is transferred from
          * suspended state into ready state all its events are cleared. */
         TasksVar[TaskID].Events = 0;
         /* add the task to the ready list */
         AddReady(TaskID);
      }
      else
      {
         /* task is not suspended */

         /* check if the task is a extended task */
         if ( TasksConst[TaskID].ConstFlags.Extended )
         {
            /* return E_OS_LIMIT */
            /* \req OSEK_SYS_3.1.5-2/3 If other than E_OK is returned the activation
             * is ignored */
            /* \req OSEK_SYS_3.1.7-2/3 Possible return values in Standard mode are
             * E_OK or E_OS_LIMIT */
            ret = E_OS_LIMIT;
         }
         else
         {
            /* check if more activations are allowed */
            if ( TasksVar[TaskID].Activations < TasksConst[TaskID].MaxActivations )
            {
               /* increment activation counter */
               TasksVar[TaskID].Activations++;
               /* add the task to the ready list */
               AddReady(TaskID);
            }
            else
            {
               /* maximal activation reached, return E_OS_LIMIT */
               /* \req OSEK_SYS_3.1.5-3/3 If other than E_OK is returned the
                * activation is ignored */
               /* \req OSEK_SYS_3.1.7-3/3 Possible return values in Standard mode are
                * E_OK or E_OS_LIMIT */
               ret = E_OS_LIMIT;
            }
         }
      }

      IntSecure_End();

#if (NON_PREEMPTIVE == OSEK_DISABLE)
      /* check if called from a Task Context */
      if ( GetCallingContext() ==  CONTEXT_TASK )
      {
         if ( ( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) &&
               ( ret == E_OK )	)
         {
            /* This is needed to avoid Schedule to perform standard checks
             * which are done when normally called from the application
             * the actual context has to be task so is not need to store it */
            SetActualContext(CONTEXT_SYS);

            /* \req OSEK_SYS_3.1.4 Rescheduling shall take place only if called from a
             * preemptable task. */
            (void)Schedule();

            /* restore the old context */
            SetActualContext(CONTEXT_TASK);
         }
      }
#endif /* #if (NON_PREEMPTIVE == OSEK_DISABLE) */
   }


#if (HOOK_ERRORHOOK == OSEK_ENABLE)
   /* \req OSEK_ERR_1.3-1/xx The ErrorHook hook routine shall be called if a
    * system service returns a StatusType value not equal to E_OK.*/
   /* \req OSEK_ERR_1.3.1-1/xx The hook routine ErrorHook is not called if a
    * system service is called from the ErrorHook itself. */
   if ( ( ret != E_OK ) && (ErrorHookRunning != 1U))
   {
      SetError_Api(OSServiceId_ActivateTask);
      SetError_Param1(TaskID);
      SetError_Ret(ret);
      SetError_Msg("ActivateTask returns != than E_OK");
      SetError_ErrorHook();
   }
#endif

   return ret;
}
Ejemplo n.º 7
0
/*==================[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);
}