📄 tx_qs.c
字号:
/**************************************************************************/
/* */
/* Copyright (c) 1996-2000 by Express Logic Inc. */
/* */
/* This software is copyrighted by and is the sole property of Express */
/* Logic, Inc. All rights, title, ownership, or other interests */
/* in the software remain the property of Express Logic, Inc. This */
/* software may only be used in accordance with the corresponding */
/* license agreement. Any unauthorized use, duplication, transmission, */
/* distribution, or disclosure of this software is expressly forbidden. */
/* */
/* This Copyright notice may not be removed or modified without prior */
/* written consent of Express Logic, Inc. */
/* */
/* Express Logic, Inc. reserves the right to modify this software */
/* without notice. */
/* */
/* Express Logic, Inc. */
/* 11440 West Bernardo Court info@expresslogic.com */
/* Suite 366 http://www.expresslogic.com */
/* San Diego, CA 92127 */
/* */
/**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** ThreadX Component */
/** */
/** Queue (QUE) */
/** */
/**************************************************************************/
/**************************************************************************/
#define TX_SOURCE_CODE
/* Include necessary system files. */
#include "tx_api.h"
#include "tx_thr.h"
#include "tx_tim.h"
#include "tx_que.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_queue_send PORTABLE C */
/* 3.0f */
/* AUTHOR */
/* */
/* William E. Lamie, Express Logic, Inc. */
/* */
/* DESCRIPTION */
/* */
/* This function places a message into the specified queue. If there */
/* is no room in the queue, this function waits according to the */
/* option specified. */
/* */
/* INPUT */
/* */
/* queue_ptr Pointer to queue control block */
/* source_ptr Pointer to message source */
/* wait_option Suspension option */
/* */
/* OUTPUT */
/* */
/* status Completion status */
/* */
/* CALLS */
/* */
/* _tx_timer_activate Activate timer routine */
/* _tx_timer_deactivate Deactivate timer routine */
/* _tx_thread_resume Resume thread routine */
/* _tx_thread_suspend Suspend thread routine */
/* _tx_thread_system_return Return to system routine */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 12-31-1996 William E. Lamie Initial Version 3.0 */
/* 07-04-1997 William E. Lamie Modified message copy logic */
/* to avoid casting structure */
/* pointers, which causes */
/* compiler warnings in some */
/* development tools, */
/* resulting in version 3.0a. */
/* 11-11-1997 William E. Lamie Modified comment(s), */
/* resulting in version 3.0b. */
/* 03-01-1998 William E. Lamie Optimized post RESTORE */
/* processing, resulting in */
/* version 3.0d. */
/* 01-01-1999 William E. Lamie Modified comment(s), */
/* resulting in version 3.0e. */
/* 11-01-1999 William E. Lamie Modified comment(s), */
/* added logic to track events,*/
/* resulting in version 3.0f. */
/* */
/**************************************************************************/
UINT _tx_queue_send(TX_QUEUE *queue_ptr, VOID *source_ptr, ULONG wait_option)
{
TX_INTERRUPT_SAVE_AREA
REG_1 UINT status; /* Return status */
REG_2 TX_THREAD *thread_ptr; /* Working thread pointer */
REG_3 ULONG *source; /* Source pointer */
REG_4 ULONG *destination; /* Destination pointer */
/* Disable interrupts to place message in the queue. */
TX_DISABLE
/* Log this kernel call. */
TX_EL_QUEUE_SEND_INSERT
/* Determine if there is room in the queue. */
if (queue_ptr -> tx_queue_available_storage)
{
/* Now determine if there is a thread waiting for a message. */
if (!queue_ptr -> tx_queue_suspension_list)
{
/* No thread suspended while waiting for a message from
this queue. */
/* Simply place the message in the queue. */
/* Reduce the amount of available storage. */
queue_ptr -> tx_queue_available_storage--;
/* Increase the enqueued count. */
queue_ptr -> tx_queue_enqueued++;
/* Setup source and destination pointers. */
source = (ULONG *) source_ptr;
destination = (ULONG *) queue_ptr -> tx_queue_write;
/* Copy the message into the queue. */
if (queue_ptr -> tx_queue_message_size == TX_1_ULONG)
{
/* Copy single longword message into the queue. */
*destination = *source;
}
else if (queue_ptr -> tx_queue_message_size == TX_2_ULONG)
{
/* Copy double longword message into the queue. */
*destination++ = *source++;
*destination = *source;
}
else if (queue_ptr -> tx_queue_message_size == TX_4_ULONG)
{
/* Copy a four longword message into the queue. */
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination = *source;
}
else if (queue_ptr -> tx_queue_message_size == TX_8_ULONG)
{
/* Copy an eight longword message into the queue. */
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination = *source;
}
else
{
/* Copy a sixteen longword message into the queue. */
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination++ = *source++;
*destination = *source;
}
/* Adjust the write pointer. */
queue_ptr -> tx_queue_write =
queue_ptr -> tx_queue_write + queue_ptr -> tx_queue_message_size;
/* Determine if we are at the end. */
if (queue_ptr -> tx_queue_write >= queue_ptr -> tx_queue_end)
/* Yes, wrap around to the beginning. */
queue_ptr -> tx_queue_write = queue_ptr -> tx_queue_start;
/* Set status to success. */
status = TX_SUCCESS;
}
else
{
/* Thread suspended waiting for a message. Remove it and copy this message
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -