Пример #1
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;
}
Пример #2
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;
}