/** * * @param dque * @param data_ptr * @param timeout * * @return TN_RETVAL */ TN_RETVAL tnnc_queue_send (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) 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(); if (!is_queue_empty(&(dque->wait_receive_list))) { que = queue_remove_head(&(dque->wait_receive_list)); task = get_task_by_tsk_queue(que); task->data_elem = data_ptr; if (task_wait_complete(task, TN_FALSE)) { tn_enable_interrupt(); tn_switch_context(); return TERR_NO_ERR; } rc = TERR_NO_ERR; } else { rc = dque_fifo_write(dque,data_ptr); if (rc != TERR_NO_ERR) { tn_curr_run_task->data_elem = data_ptr; task_curr_to_wait_action(&(dque->wait_send_list), TSK_WAIT_REASON_DQUE_WSEND, timeout); tn_enable_interrupt(); tn_switch_context(); return tn_curr_run_task->task_wait_rc; } } tn_enable_interrupt(); return rc; }
//---------------------------------------------------------------------------- int tn_queue_send(TN_DQUE * dque, void * data_ptr, unsigned long timeout) { TN_INTSAVE_DATA int rc; CDLL_QUEUE * que; TN_TCB * task; #if TN_CHECK_PARAM if(dque == NULL || timeout == 0) return TERR_WRONG_PARAM; if(dque->id_dque != TN_ID_DATAQUEUE) return TERR_NOEXS; #endif TN_CHECK_NON_INT_CONTEXT tn_disable_interrupt(); //-- there are task(s) in the data queue's wait_receive list if(!is_queue_empty(&(dque->wait_receive_list))) { que = queue_remove_head(&(dque->wait_receive_list)); task = get_task_by_tsk_queue(que); task->data_elem = data_ptr; if(task_wait_complete(task)) { tn_enable_interrupt(); tn_switch_context(); return TERR_NO_ERR; } rc = TERR_NO_ERR; } else //-- the data queue's wait_receive list is empty { rc = dque_fifo_write(dque,data_ptr); if(rc != TERR_NO_ERR) //-- No free entries in the data queue { tn_curr_run_task->data_elem = data_ptr; //-- Store data_ptr task_curr_to_wait_action(&(dque->wait_send_list), TSK_WAIT_REASON_DQUE_WSEND, timeout); tn_enable_interrupt(); tn_switch_context(); return tn_curr_run_task->task_wait_rc; } } tn_enable_interrupt(); return rc; }
/** * * @param dque * @param data_ptr * * @return TN_RETVAL */ TN_RETVAL tnnc_queue_isend_polling (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) 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(); if (!is_queue_empty(&(dque->wait_receive_list))) { que = queue_remove_head(&(dque->wait_receive_list)); task = get_task_by_tsk_queue(que); task->data_elem = data_ptr; 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 = dque_fifo_write(dque,data_ptr); if (rc != TERR_NO_ERR) { rc = TERR_TIMEOUT; } } tn_ienable_interrupt(); return rc; }
//---------------------------------------------------------------------------- int tn_queue_isend_polling(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) return TERR_WRONG_PARAM; if(dque->id_dque != TN_ID_DATAQUEUE) return TERR_NOEXS; #endif TN_CHECK_INT_CONTEXT tn_idisable_interrupt(); //-- there are task(s) in the data queue's wait_receive list if(!is_queue_empty(&(dque->wait_receive_list))) { que = queue_remove_head(&(dque->wait_receive_list)); task = get_task_by_tsk_queue(que); task->data_elem = data_ptr; if(task_wait_complete(task)) { tn_ienable_interrupt(); return TERR_NO_ERR; } rc = TERR_NO_ERR; } else //-- the data queue's wait_receive list is empty { rc = dque_fifo_write(dque,data_ptr); if(rc != TERR_NO_ERR) //-- No free entries in data queue rc = TERR_TIMEOUT; //-- Just convert errorcode } tn_ienable_interrupt(); return rc; }
//---------------------------------------------------------------------------- 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; }
//---------------------------------------------------------------------------- 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; }