예제 #1
0
StatusType ClearEvent
(
   EventMaskType Mask
)
{
   /* \req OSEK_SYS_3.16 The system service StatusType
    * ClearEvent ( EventMaskType Mask ) shall be defined */

   /* \req OSEK_SYS_3.16.2 Possible return values in Standard mode is E_OK */
   StatusType ret = E_OK;

#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)
   if ( GetCallingContext() != CONTEXT_TASK )
   {
      /* \req OSEK_SYS_3.16.3-2/2 Extra possible return values in Extended
       * mode are E_OS_ACCESS, E_OS_CALLEVEL */
      ret = E_OS_CALLEVEL;
   }
   else if ( !TasksConst[GetRunningTask()].ConstFlags.Extended )
   {
      /* \req OSEK_SYS_3.16.3-1/2 Extra possible return values in Extended
       * mode are E_OS_ACCESS, E_OS_CALLEVEL */
      ret = E_OS_ACCESS;
   }
   else
#endif
   {
      /* enter to critical code */
      IntSecure_Start();

      /* \req OSEK_SYS_3.16.1 The events of the extended task calling ClearEvent
       * are cleared according to the event mask Mask */
      TasksVar[GetRunningTask()].Events &=
         (EventMaskType)~( Mask & TasksConst[GetRunningTask()].EventsMask );

      /* finish cirtical code */
      IntSecure_End();

   }

#if ( (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) && \
      (HOOK_ERRORHOOK == OSEK_ENABLE) )
   /* \req OSEK_ERR_1.3-9/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-9/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_ClearEvent);
      SetError_Param1(Mask);
      SetError_Ret(ret);
      SetError_Msg("ClearEvent returns != than E_OK");
      SetError_ErrorHook();
   }
#endif

   return ret;
}
예제 #2
0
/*******************************************************************************
**                                                                            **
** FUNC-NAME     :                                                            **
**                                                                            **
** DESCRIPTION   :                                                            **
**                                                                            **
** PRECONDITIONS :                                                            **
**                                                                            **
** PARAMETER     :                                                            **
**                                                                            **
** RETURN        :                                                            **
**                                                                            **
** REMARKS       :                                                            **
**                                                                            **
*******************************************************************************/
StatusType GetAlarmBase
(
	AlarmType AlarmID,
	AlarmBaseRefType Info
)
{
	/* \req OSEK_SYS_3.19 The system service StatusType
	 ** GetAlarmBase ( AlarmType AlarmID, AlarmBaseRefType Info )
	 ** shall be defined. */

	/* \req OSEK_SYS_3.19.2 Possible return values in Standard mode is E_OK */
	StatusType ret = E_OK;

	CounterType counter;

#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)
	/* check that the AlarmID is in range */
	if(AlarmID >= ALARMS_COUNT)
	{
		/* \req OSEK_SYS_3.19.: Extra possible return values in Extended mode
		 ** is E_OS_ID */
		ret = E_OS_ID;
	}
	else
#endif
	{
		/* get counter of this alarm */
		counter = AlarmsConst[AlarmID].Counter;

		/* \req OSEK_SYS_3.19.1 The system service GetAlarmBase reads the alarm base
		 ** characteristics. The return value Info is a structure in which the
		 ** information of data type AlarmBaseType is stored */
		Info->maxallowedvalue = CountersConst[counter].MaxAllowedValue;
		Info->ticksperbase = CountersConst[counter].TicksPerBase;
		Info->mincycle = CountersConst[counter].MinCycle;
	}

#if ( (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) && \
	 	(HOOK_ERRORHOOK == ENABLE) )
	/* \req OSEK_ERR_1.3-12/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-12/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_GetAlarmBase);
		SetError_Param1(AlarmID);
		SetError_Param2((uint32)Info);
		SetError_Ret(ret);
		SetError_Msg("GetAlarmBase returns != than E_OK");
		SetError_ErrorHook();
	}
#endif
	
	return ret;
}
예제 #3
0
/*******************************************************************************
**                                                                            **
** FUNC-NAME     :                                                            **
**                                                                            **
** DESCRIPTION   :                                                            **
**                                                                            **
** PRECONDITIONS :                                                            **
**                                                                            **
** PARAMETER     :                                                            **
**                                                                            **
** RETURN        :                                                            **
**                                                                            **
** REMARKS       :                                                            **
**                                                                            **
*******************************************************************************/
StatusType GetAlarm
(
	AlarmType AlarmID,
	TickRefType Tick
)
{
	/* \req OSEK_SYS_3.20 The system service StatusType
	 ** GetAlarm ( AlarmType AlarmID, TickRefType Tick) shall be defined */

	/* \req OSEK_SYS_3.20.2 Possible return values in Standard mode is E_OK */
	StatusType ret = E_OK;

#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)
	/* check if it handle of a valid AlarmID */
	if (AlarmID >= ALARMS_COUNT)
	{
		/* \req OSEK_SYS_3.20.3-1/2 Extra possible return values in Extended mode
		 ** are E_OS_NOFUNC, E_OS_ID */
		ret = E_OS_ID;
	}
	else
#endif /* #if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) */
	/* check if the alarm is running */
	if(AlarmsVar[AlarmID].AlarmState == 0)
	{
		/* \req OSEK_SYS_3.20.3-2/2 Extra possible return values in Extended mode
		 ** are E_OS_NOFUNC, E_OS_ID */
		ret = E_OS_NOFUNC;
	}
	else

	{
		/* \req OSEK_SYS_3.20.1 The system service GetAlarm shall return the
		 ** relative value in ticks before the alarm AlarmID expires */
		*Tick = AlarmsVar[AlarmID].AlarmTime;
	}

#if (HOOK_ERRORHOOK == ENABLE)
	/* \req OSEK_ERR_1.3-12/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-12/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_GetAlarm);
      SetError_Param1(AlarmID);
		SetError_Param2((uint32)Tick);
      SetError_Ret(ret);
      SetError_Msg("GetAlarm returns != than E_OK");
      SetError_ErrorHook();
   }
#endif /* #if (HOOK_ERRORHOOK == ENABLE) */
	
	return ret;
}
예제 #4
0
/*******************************************************************************
**                                                                            **
** FUNC-NAME     :                                                            **
**                                                                            **
** DESCRIPTION   :                                                            **
**                                                                            **
** PRECONDITIONS :                                                            **
**                                                                            **
** PARAMETER     :                                                            **
**                                                                            **
** RETURN        :                                                            **
**                                                                            **
** REMARKS       :                                                            **
**                                                                            **
*******************************************************************************/
StatusType CancelAlarm
(
	AlarmType AlarmID
)
{
	/* \req OSEK_SYS_3.23 The system service StatusType
	 ** CancelAlarm ( AlarmType AlarmID ) shall be defined */

	/* \req OSEK_SYS_3.23.2-1/2 Possible return values in Standard mode are
	 ** E_OK, E_OS_NOFUNC */
	StatusType ret = E_OK;

#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)	
	/* check if alarm id is in the valid range */
	if(AlarmID >= ALARMS_COUNT)
	{
		/* \req SEK_SYS_3.23.3: Extra possible return values in Extended mode ar
		 **  E_OS_ID */
		ret = E_OS_ID;
	}
	else
#endif
	if(AlarmsVar[AlarmID].AlarmState == 0)
	{
		/* \req OSEK_SYS_3.23.2-2/2 Possible return values in Standard mode are
		 ** E_OK, E_OS_NOFUNC */
		ret = E_OS_NOFUNC;
	}
	else
	{
		/* \req OSEK_SYS_3.23.1 The system service shall cancel the alarm AlarmID */
		AlarmsVar[AlarmID].AlarmState = 0;
	}

#if (HOOK_ERRORHOOK == ENABLE)
	/* \req OSEK_ERR_1.3-15/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-15/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_CancelAlarm);
		SetError_Param1(AlarmID);
		SetError_Ret(ret);
		SetError_Msg("CancelAlarm returns != than E_OK");
		SetError_ErrorHook();
	}
#endif
	
	return ret;
}
예제 #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;
}
예제 #6
0
파일: GetEvent.c 프로젝트: grtwall/my_osek
StatusType GetEvent
(
   TaskType TaskID,
   EventMaskRefType Event
)
{
   /* \req OSEK_SYS_3.17 The system service StatusType
    ** GetEvent ( TaskType TaskID, EventMaskRefType Event ) shall be defined*/

   /* \req OSEK_SYS_3.17.3 Possible return values in Standard mode is E_OK */
   StatusType ret = E_OK;

#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)
   if ( TaskID >= TASKS_COUNT )
   {
      /* \req OSEK_SYS_3.17.4-1/3 Extra possible return values in Extended mode are
       ** E_OS_ID, E_OS_ACCESS, E_OS_STATE */
      ret = E_OS_ID;
   }
   else if ( !TasksConst[TaskID].ConstFlags.Extended )
   {
      /* \req OSEK_SYS_3.17.4-2/3 Extra possible return values in Extended mode are
       ** E_OS_ID, E_OS_ACCESS, E_OS_STATE */
      ret = E_OS_ACCESS;
   }
   else if ( TasksVar[TaskID].Flags.State == TASK_ST_SUSPENDED )
   {
      /* \req OSEK_SYS_3.17.4-3/3 Extra possible return values in Extended mode are
       ** E_OS_ID, E_OS_ACCESS, E_OS_STATE */
      ret = E_OS_STATE;
   }
   else
#endif
   {
      /* \req OSEK_SYS_3.17.1 This service shall return the current state of
       ** all event bits of the task TaskID, not the events that the task is
       ** waiting for */
      /* \req OSEK_SYS_3.17.2 The current status of the event mask of task
       ** TaskID shall be copied to Event */
      *Event = TasksVar[TaskID].Events;
   }

#if ( (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) && \
      (HOOK_ERRORHOOK == OSEK_ENABLE) )
   /* \req OSEK_ERR_1.3-10/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-10/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_SetEvent);
      SetError_Param1(TaskID);
      SetError_Param2((unsigned int)Event);
      SetError_Ret(ret);
      SetError_Msg("ActivateTask returns != than E_OK");
      SetError_ErrorHook();
   }
#endif

   return ret;
}
예제 #7
0
/*******************************************************************************
**                                                                            **
** FUNC-NAME     :                                                            **
**                                                                            **
** DESCRIPTION   :                                                            **
**                                                                            **
** PRECONDITIONS :                                                            **
**                                                                            **
** PARAMETER     :                                                            **
**                                                                            **
** RETURN        :                                                            **
**                                                                            **
** REMARKS       :                                                            **
**                                                                            **
*******************************************************************************/
StatusType SetAbsAlarm
(
	AlarmType AlarmID,
	TickType Start,
	TickType Cycle
)
{
	/* \req OSEK_SYS_3.22 The system service StatusType
	 ** SetAbsAlarm ( AlarmType AlarmID, TickType Start, TickType Cycle )
	 ** shall be defined */

	/* \req OSEK_SYS_3.22.3-1/2 Possible return values in Standard mode are E_OK,
	 ** E_OS_STATE */
	StatusType ret = E_OK;

#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)
	/* check if the alarm id is in range */
	if(AlarmID >= ALARMS_COUNT)
	{
		/* \req OSEK_SYS_3.22.4-1/2 Extra possible return values in Extended mode
		 ** are E_OS_ID, E_OS_VALUE */
		ret = E_OS_ID;
	}
	/* check that increment and cycle are in range */
	else if( (Start > CountersConst[AlarmsConst[AlarmID].Counter].MaxAllowedValue) ||
				( ( Cycle != 0 ) &&
					( (Cycle > CountersConst[AlarmsConst[AlarmID].Counter].MaxAllowedValue) ||
						(Cycle < CountersConst[AlarmsConst[AlarmID].Counter].MinCycle) ) ) )
	{
		/* \req OSEK_SYS_3.22.4-2/2 Extra possible return values in Extended mode
		 ** are E_OS_ID, E_OS_VALUE */
		ret = E_OS_VALUE;
	}
	else
#endif
	/* check if the alarm is disable */
	if(AlarmsVar[AlarmID].AlarmState != 0)
   {
		/* \req OSEK_SYS_3.22.3-2/2 Possible return values in Standard mode are E_OK,
		 ** E_OS_STATE */
      ret = E_OS_STATE;
   }
	else
	{

		IntSecure_Start();

		/* enable alarm */
		AlarmsVar[AlarmID].AlarmState = 1;

		/* set abs alarm */
		AlarmsVar[AlarmID].AlarmTime = GetCounter(AlarmsConst[AlarmID].Counter) + Start;
		AlarmsVar[AlarmID].AlarmCycleTime = Cycle;

		IntSecure_End();
	}

#if (HOOK_ERRORHOOK == ENABLE)
	/* \req OSEK_ERR_1.3-14/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-14/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_SetAbsAlarm);
		SetError_Param1(AlarmID);
		SetError_Param2(Start);
		SetError_Param3(Cycle);
		SetError_Ret(ret);
		SetError_Msg("SetAbsAlarm returns != than E_OK");
		SetError_ErrorHook();
	}
#endif

	return ret;
}
StatusType ReleaseResource
(
   ResourceType ResID
)
{
   /* \req OSEK_SYS_3.13 The system service StatusType
    * ReleaseResource ( ResourceType ResID ) shall be defined */

   /* \req OSEK_SYS_3.14.2: Possible return values in Standard mode is
    * E_OK  */
   StatusType ret = E_OK;

#if (RESOURCES_COUNT != 0)
   uint8 loopi;
#endif /* #if (RESOURCES_COUNT != 0) */

   /* asign the static priority to the task */
   TaskPriorityType priority = TasksConst[GetRunningTask()].StaticPriority;

#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)
   if (
/* only if one or more resources were defined */
#if (RESOURCES_COUNT != 0)
        ( ResID >= RESOURCES_COUNT )
#endif /* #if (RESOURCES_COUNT != 0) */
#if ( (RESOURCES_COUNT != 0) && (NO_RES_SCHEDULER == OSEK_DISABLE) )
            &&
#endif /* #if ( (RESOURCES_COUNT != 0) && (NO_RES_SCHEDULER == OSEK_DISABLE) ) */
/* check RES_SCHEDULER only if used */
#if (NO_RES_SCHEDULER == OSEK_DISABLE)
        ( ResID != RES_SCHEDULER )
#endif /* #if (NO_RES_SCHEDULER == OSEK_DISABLE) */
      )
   {
      /* \req OSEK_SYS_3.14.3-1/2 Extra possible return values in Extended mode are
       * E_OS_ID, E_OS_NOFUNC, E_OS_ACCESS */
      ret = E_OS_ID;
   }
   else
#if (NO_RES_SCHEDULER == OSEK_DISABLE)
      if ( ResID != RES_SCHEDULER )
#endif /* #if (NO_RES_SCHEDULER == OSEK_DISABLE) */
   {
      if ( ( TasksVar[GetRunningTask()].Resources & ( 1 << ResID ) ) == 0 )
      {
         /* \req OSEK_SYS_3.14.3-2/2 Extra possible return values in Extended mode are
          ** E_OS_ID, E_OS_NOFUNC, E_OS_ACCESS */
         ret = E_OS_NOFUNC;
      }
   }
#if (NO_RES_SCHEDULER == OSEK_DISABLE)
   else
   {
      /* nothing to do */
   }
#endif /* #if (NO_RES_SCHEDULER == OSEK_DISABLE) */

   if ( ret == E_OK )
#endif /* #if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) */
   {
      IntSecure_Start();

#if (RESOURCES_COUNT != 0)
#if (NO_RES_SCHEDULER == OSEK_DISABLE)
      if ( ResID != RES_SCHEDULER )
#endif /* #if (NO_RES_SCHEDULER == OSEK_DISABLE) */
      {
         /* clear resource */
         TasksVar[GetRunningTask()].Resources &= ~( 1 << ResID );
      }

      for (loopi = 0; loopi < RESOURCES_COUNT; loopi++)
      {
         if ( TasksVar[GetRunningTask()].Resources & ( 1 << loopi ) )
         {
            if ( priority < ResourcesPriority[loopi] )
            {
               priority = ResourcesPriority[loopi];
            }
         }
      }
#endif /* #if (RESOURCES_COUNT != 0) */

      /* \req OSEK_SYS_3.14.1 ReleaseResource is the counterpart of GetResource
       * and serves to leave critical sections in the code that are assigned to
       * the resource referenced by ResID */
      TasksVar[GetRunningTask()].ActualPriority = priority;

      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 ) )
         {
            /* \req OSEK_SYS_3.14.4 Rescheduling shall take place only if called from a
             * preemptable task. */
            (void)Schedule();
         }
      }
#endif /* #if (NON_PREEMPTIVE == OSEK_DISABLE) */

   }

#if ( (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) && \
      (HOOK_ERRORHOOK == OSEK_ENABLE) )
   /* \req OSEK_ERR_1.3-7/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-7/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_ReleaseResource);
      SetError_Param1(ResID);
      SetError_Ret(ret);
      SetError_Msg("ReleaseResource returns != E_OK");
      SetError_ErrorHook();
   }
#endif

   return ret;
}
예제 #9
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;
}
예제 #10
0
StatusType GetResource
(
   ResourceType ResID
)
{
   /* \req OSEK_SYS_3.13 The system service StatusType
    * GetResource ( ResourceType ResID ) shall be defined */

   /* \req OSEK_SYS_3.13.2: Possible return values in Standard mode is E_OK */
   StatusType ret = E_OK;

#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)
   if (
/* only if one or more resources were defined */
#if (RESOURCES_COUNT != 0)
         ( ResID > RESOURCES_COUNT )
#endif /* (RESOURCES_COUNT != 0) */
#if ( (RESOURCES_COUNT != 0) && (NO_RES_SCHEDULER == OSEK_DISABLE) )
            &&
#endif /* #if ( (RESOURCES_COUNT != 0) && (NO_RES_SCHEDULER == OSEK_DISABLE) ) */
/* check RES_SCHEDULER only if used */
#if (NO_RES_SCHEDULER == OSEK_DISABLE)
         ( ResID != RES_SCHEDULER )
#endif /* #if (NO_RES_SCHEDULER == OSEK_DISABLE) */
      )
   {
      /* \req OSEK_SYS_3.13.3-1/2 Extra possible return values in Extended mode are
       * E_OS_ID, E_OS_ACCESS */
      ret = E_OS_ID;
   }
   else
#if (NO_RES_SCHEDULER == OSEK_DISABLE)
      if ( ResID != RES_SCHEDULER )
#endif /* #if (NO_RES_SCHEDULER == OSEK_DISABLE) */
   {
      if ( ( TasksVar[GetRunningTask()].Resources & ( 1 << ResID ) ) ||
           ( ( TasksConst[GetRunningTask()].ResourcesMask & ( 1 << ResID ) ) == 0 ) )
      {
         /* \req OSEK_SYS_3.13.3-2/2 Extra possible return values in Extended mode are
          * E_OS_ID, E_OS_ACCESS */
         ret = E_OS_ACCESS;
      }
   }
#if (NO_RES_SCHEDULER == OSEK_DISABLE)
   else
   {
      /* nothing to do */
   }
#endif /* #if (NO_RES_SCHEDULER == OSEK_DISABLE) */

   if ( ret == E_OK )
#endif /* #if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) */
   {
      IntSecure_Start();

/* check RES_SCHEDULER only if used */
#if (NO_RES_SCHEDULER == OSEK_DISABLE)
      if ( ResID == RES_SCHEDULER )
      {
         TasksVar[GetRunningTask()].ActualPriority = TASK_MAX_PRIORITY;
      }
#endif /* #if (NO_RES_SCHEDULER == OSEK_DISABLE) */
#if ( (RESOURCES_COUNT != 0) && (NO_RES_SCHEDULER == OSEK_DISABLE) )
      else
#endif /* #if ( (RESOURCES_COUNT != 0) && (NO_RES_SCHEDULER == OSEK_DISABLE) ) */

/* only if one or more resources were defined */
#if (RESOURCES_COUNT != 0)
      {
         /* \req OSEK_SYS_3.13.1 This call serves to enter critical sections in
          * the code that are assigned to the resource referenced by ResID */
         if ( TasksVar[GetRunningTask()].ActualPriority < ResourcesPriority[ResID])
         {
            TasksVar[GetRunningTask()].ActualPriority = ResourcesPriority[ResID];
         }

         /* mark resource as set */
         TasksVar[GetRunningTask()].Resources |= ( 1 << ResID );
      }
#endif /* #if (RESOURCES_COUNT != 0) */

      IntSecure_End();
   }

#if ( (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) && \
      (HOOK_ERRORHOOK == OSEK_ENABLE) )
   /* \req OSEK_ERR_1.3-6/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-6/xx The hook routine ErrorHook is not called if a
    * system service is called from the ErrorHook itself. */
   else if ( ( ErrorHookRunning != 1 ) )
   {
      SetError_Api(OSServiceId_GetResource);
      SetError_Param1(ResID);
      SetError_Ret(ret);
      SetError_Msg("GetResource returns != E_OK");
      SetError_ErrorHook();
   }
   else
   {
      /* nothing to do */
   }
#endif

   return ret;
}
예제 #11
0
StatusType SetEvent
(
   TaskType TaskID,
   EventMaskType Mask
)
{
   /* \req OSEK_SYS_3.15 The system service StatusType
    * SetEvent ( TaskType TaskID, EventMaskType Mask ) shall be defined */

   /* \req OSEK_SYS_3.15.2: Possible return values in Standard mode is E_OK */
   StatusType ret = E_OK;

#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)
   if ( TaskID >= TASKS_COUNT )
   {
      /* \req OSEK_SYS_3.15.3-1/3 Extra possible return values in Extended mode
       * are E_OS_ID, E_OS_ACCESS, E_OS_STATE */
      ret = E_OS_ID;
   }
   else if ( !TasksConst[TaskID].ConstFlags.Extended )
   {
      /* \req OSEK_SYS_3.15.3-2/3 Extra possible return values in Extended mode
       * are E_OS_ID, E_OS_ACCESS, E_OS_STATE */
      ret = E_OS_ACCESS;
   }
   else if ( TasksVar[TaskID].Flags.State == TASK_ST_SUSPENDED )
   {
      /* \req OSEK_SYS_3.15.3-3/3 Extra possible return values in Extended mode
       * are E_OS_ID, E_OS_ACCESS, E_OS_STATE */
      ret = E_OS_STATE;
   }
   else
#endif
   {
      /* enter to critical code */
      IntSecure_Start();

      /* the event shall be set only if the task is running ready or waiting */
      if ( ( TasksVar[TaskID].Flags.State == TASK_ST_RUNNING ) ||
           ( TasksVar[TaskID].Flags.State == TASK_ST_READY ) ||
           ( TasksVar[TaskID].Flags.State == TASK_ST_WAITING) )
      {
         /* set the events */
         /* \req OSEK_SYS_3.15.1-1/3 The events of task TaskID are set according to the
          * event mask Mask. Calling SetEvent causes the task TaskID to be
          * transferred to the ready state, if it was waiting for at least one
          * of the events specified in Mask */
         TasksVar[TaskID].Events |= ( Mask & TasksConst[TaskID].EventsMask );

         /* if the task is waiting and one waiting event occurrs set it to ready */
         if ( ( TasksVar[TaskID].Flags.State == TASK_ST_WAITING ) &&
              ( TasksVar[TaskID].EventsWait & TasksVar[TaskID].Events ) )
         {
            /* \req OSEK_SYS_3.15.1-2/3 The events of task TaskID are set according to the
             * event mask Mask. Calling SetEvent causes the task TaskID to be
             * transferred to the ready state, if it was waiting for at least one
             * of the events specified in Mask */
            AddReady(TaskID);

            /* \req OSEK_SYS_3.15.1-3/3 The events of task TaskID are set according to the
             * event mask Mask. Calling SetEvent causes the task TaskID to be
             * transferred to the ready state, if it was waiting for at least one
             * of the events specified in Mask */
            TasksVar[TaskID].Flags.State = TASK_ST_READY;

            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 ) )
               {
                  /* \req OSEK_SYS_3.15.4 Rescheduling shall take place only if called from a
                   * preemptable task. */
                  (void)Schedule();
               }
            }
#endif /* #if (NON_PREEMPTIVE == OSEK_DISABLE) */

         }
         else
         {
            IntSecure_End();
         }
      }
      else
      {
         IntSecure_End();
      }
   }


#if ( (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED) && \
      (HOOK_ERRORHOOK == OSEK_ENABLE) )
   /* \req OSEK_ERR_1.3-8/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-8/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_SetEvent);
      SetError_Param1(TaskID);
      SetError_Param2(Mask);
      SetError_Ret(ret);
      SetError_Msg("ActivateTask returns != than E_OK");
      SetError_ErrorHook();
   }
#endif

   return ret;
}