예제 #1
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;
}
예제 #2
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;
}
예제 #3
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;
}
예제 #4
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;
}
예제 #5
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;
}