Exemple #1
0
//----------------------------------------------------------------------------
int tn_queue_ireceive(TN_DQUE * dque,void ** data_ptr)
{
   TN_INTSAVE_DATA_INT
   int rc;
   CDLL_QUEUE * que;
   TN_TCB * task;

#if TN_CHECK_PARAM
   if(dque == NULL || data_ptr == NULL)
      return  TERR_WRONG_PARAM;
   if(dque->id_dque != TN_ID_DATAQUEUE)
      return TERR_NOEXS;
#endif

   TN_CHECK_INT_CONTEXT

   tn_idisable_interrupt();

   rc = dque_fifo_read(dque,data_ptr);
   if(rc == TERR_NO_ERR)  //-- There was entry(s) in data queue
   {
      if(!is_queue_empty(&(dque->wait_send_list)))
      {
         que  = queue_remove_head(&(dque->wait_send_list));
         task = get_task_by_tsk_queue(que);

         dque_fifo_write(dque,task->data_elem); //-- Put to data FIFO

         if(task_wait_complete(task))
         {
            tn_ienable_interrupt();
            return TERR_NO_ERR;
         }
      }
   }
   else //-- data FIFO is empty
   {
      if(!is_queue_empty(&(dque->wait_send_list)))
      {
         que  = queue_remove_head(&(dque->wait_send_list));
         task =  get_task_by_tsk_queue(que);

        *data_ptr = task->data_elem; //-- Return to caller

         if(task_wait_complete(task))
         {
            tn_ienable_interrupt();
            return TERR_NO_ERR;
         }
         rc = TERR_NO_ERR;
      }
      else
      {
         rc = TERR_TIMEOUT;
      }
   }

   tn_ienable_interrupt();

   return rc;
}
Exemple #2
0
/**
 *
 * @param dque
 * @param data_ptr
 *
 * @return TN_RETVAL
 */
TN_RETVAL tnnc_queue_ireceive (TN_DQUE_S *dque, void **data_ptr)
{
    TN_UWORD      tn_save_status_reg TN_UNUSED;
    TN_RETVAL           rc;
    CDLL_QUEUE_S *que;
    TN_TCB_S     *task;
/*
    Not check parameter error

    if (dque == TN_NULL || data_ptr == TN_NULL)
        return  TERR_WRONG_PARAM;
*/
    if (dque->id_dque != TN_ID_DATAQUEUE)
        return TERR_NOEXS;

    if (tn_is_non_sys_int_context())
    {
        return TERR_WCONTEXT;
    }

    tn_idisable_interrupt();

    rc = dque_fifo_read(dque,data_ptr);

    if (rc == TERR_NO_ERR)
    {
        if (!is_queue_empty(&(dque->wait_send_list)))
        {
            que  = queue_remove_head(&(dque->wait_send_list));
            task = get_task_by_tsk_queue(que);

            dque_fifo_write(dque,task->data_elem);

            if (task_wait_complete(task, TN_FALSE))
            {
                tn_context_switch_request = TN_TRUE;
                tn_ienable_interrupt();
                return TERR_NO_ERR;
            }
        }
    }
    else
    {
        if (!is_queue_empty(&(dque->wait_send_list)))
        {
            que  = queue_remove_head(&(dque->wait_send_list));
            task =  get_task_by_tsk_queue(que);

            *data_ptr = task->data_elem;

            if (task_wait_complete(task, TN_FALSE))
            {
                tn_context_switch_request = TN_TRUE;
                tn_ienable_interrupt();
                return TERR_NO_ERR;
            }
            rc = TERR_NO_ERR;
        }
        else
        {
            rc = TERR_TIMEOUT;
        }
    }

    tn_ienable_interrupt();
    return rc;
}
Exemple #3
0
//----------------------------------------------------------------------------
int tn_queue_receive(TN_DQUE * dque,void ** data_ptr,unsigned long timeout)
{
   TN_INTSAVE_DATA
   int rc; //-- return code
   CDLL_QUEUE * que;
   TN_TCB * task;

#if TN_CHECK_PARAM
   if(dque == NULL || timeout == 0 || data_ptr == NULL)
      return  TERR_WRONG_PARAM;
   if(dque->id_dque != TN_ID_DATAQUEUE)
      return TERR_NOEXS;
#endif

   TN_CHECK_NON_INT_CONTEXT

   tn_disable_interrupt();

   rc = dque_fifo_read(dque,data_ptr);
   if(rc == TERR_NO_ERR)  //-- There was entry(s) in data queue
   {
      if(!is_queue_empty(&(dque->wait_send_list)))
      {
         que  = queue_remove_head(&(dque->wait_send_list));
         task = get_task_by_tsk_queue(que);

         dque_fifo_write(dque,task->data_elem); //-- Put to data FIFO

         if(task_wait_complete(task))
         {
            tn_enable_interrupt();
            tn_switch_context();
            return TERR_NO_ERR;
         }
      }
   }
   else //-- data FIFO is empty
   {
      if(!is_queue_empty(&(dque->wait_send_list)))
      {
         que  = queue_remove_head(&(dque->wait_send_list));
         task = get_task_by_tsk_queue(que);

         *data_ptr = task->data_elem; //-- Return to caller

         if(task_wait_complete(task))
         {
            tn_enable_interrupt();
            tn_switch_context();
            return TERR_NO_ERR;
         }
         rc = TERR_NO_ERR;
      }
      else //-- wait_send_list is empty
      {
         task_curr_to_wait_action(&(dque->wait_receive_list),
                                     TSK_WAIT_REASON_DQUE_WRECEIVE,timeout);
         tn_enable_interrupt();
         tn_switch_context();

         //-- When returns to this point, in the data_elem have to be valid value

         *data_ptr = tn_curr_run_task->data_elem; //-- Return to caller

         return tn_curr_run_task->task_wait_rc;
      }
   }

   tn_enable_interrupt();

   return rc;
}
Exemple #4
0
/**
 *
 * @param dque
 * @param data_ptr
 * @param timeout
 *
 * @return TN_RETVAL
 */
TN_RETVAL tnnc_queue_receive (TN_DQUE_S * dque, void **data_ptr, TN_TIMEOUT timeout)
{
    TN_UWORD      tn_save_status_reg TN_UNUSED;     /* for SR save */
    TN_RETVAL           rc;
    CDLL_QUEUE_S *que;
    TN_TCB_S     *task;

/*
    Not check parameter error

    if (dque == TN_NULL || timeout == 0 || data_ptr == TN_NULL)
        return  TERR_WRONG_PARAM;
*/
    if (dque->id_dque != TN_ID_DATAQUEUE)
        return TERR_NOEXS;

    if (tn_is_non_task_context())
    {
        return TERR_WCONTEXT;
    }

    tn_disable_interrupt();

    rc = dque_fifo_read(dque,data_ptr);

    if (rc == TERR_NO_ERR)
    {
        if (!is_queue_empty(&(dque->wait_send_list)))
        {
            que  = queue_remove_head(&(dque->wait_send_list));
            task = get_task_by_tsk_queue(que);

            dque_fifo_write(dque,task->data_elem);

            if (task_wait_complete(task, TN_FALSE))
            {
                tn_enable_interrupt();
                tn_switch_context();
                return TERR_NO_ERR;
            }
        }
    }
    else
    {
        if (!is_queue_empty(&(dque->wait_send_list)))
        {
            que  = queue_remove_head(&(dque->wait_send_list));
            task = get_task_by_tsk_queue(que);

            *data_ptr = task->data_elem;

            if (task_wait_complete(task, TN_FALSE))
            {
                tn_enable_interrupt();
                tn_switch_context();
                return TERR_NO_ERR;
            }

            rc = TERR_NO_ERR;
        }
        else
        {
            task_curr_to_wait_action(&(dque->wait_receive_list), TSK_WAIT_REASON_DQUE_WRECEIVE, timeout);
            tn_enable_interrupt();
            tn_switch_context();

            /* When return to this point,in data_elem have to be  valid value */
            *data_ptr = tn_curr_run_task->data_elem;
            return tn_curr_run_task->task_wait_rc;
        }
    }

    tn_enable_interrupt();
    return rc;
}