/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
* MESSAGE QUEUE MANAGEMENT
*
* (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
* All Rights Reserved
*
* V2.00
*
* File : OS_Q.C
* By : Jean J. Labrosse
*********************************************************************************************************
*/
#ifndef OS_MASTER_FILE
#include "includes.h"
#endif
#if OS_Q_EN && (OS_MAX_QS >= 2)
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
typedef struct os_q { /* QUEUE CONTROL BLOCK */
struct os_q *OSQPtr; /* Link to next queue control block in list of free blocks */
void **OSQStart; /* Pointer to start of queue data */
void **OSQEnd; /* Pointer to end of queue data */
void **OSQIn; /* Pointer to where next message will be inserted in the Q */
void **OSQOut; /* Pointer to where next message will be extracted from the Q */
INT16U OSQSize; /* Size of queue (maximum number of entries) */
INT16U OSQEntries; /* Current number of entries in the queue */
} OS_Q;
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
static OS_Q *OSQFreeList; /* Pointer to list of free QUEUE control blocks */
static OS_Q OSQTbl[OS_MAX_QS]; /* Table of QUEUE control blocks */
/*$PAGE*/
/*
*********************************************************************************************************
* ACCEPT MESSAGE FROM QUEUE
*
* Description: This function checks the queue to see if a message is available. Unlike OSQPend(),
* OSQAccept() does not suspend the calling task if a message is not available.
*
* Arguments : pevent is a pointer to the event control block
*
* Returns : != (void *)0 is the message in the queue if one is available. The message is removed
* from the so the next time OSQAccept() is called, the queue will contain
* one less entry.
* == (void *)0 if the queue is empty
* if you passed an invalid event type
*********************************************************************************************************
*/
void *OSQAccept (OS_EVENT *pevent)
{
void *msg;
OS_Q *pq;
OS_ENTER_CRITICAL();
if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type */
OS_EXIT_CRITICAL();
return ((void *)0);
}
pq = pevent->OSEventPtr; /* Point at queue control block */
if (pq->OSQEntries != 0) { /* See if any messages in the queue */
msg = *pq->OSQOut++; /* Yes, extract oldest message from the queue */
pq->OSQEntries--; /* Update the number of entries in the queue */
if (pq->OSQOut == pq->OSQEnd) { /* Wrap OUT pointer if we are at the end of the queue */
pq->OSQOut = pq->OSQStart;
}
} else {
msg = (void *)0; /* Queue is empty */
}
OS_EXIT_CRITICAL();
return (msg); /* Return message received (or NULL) */
}
/*$PAGE*/
/*
*********************************************************************************************************
* CREATE A MESSAGE QUEUE
*
* Description: This function creates a message queue if free event control blocks are available.
*
* Arguments : start is a pointer to the base address of the message queue storage area. The
* storage area MUST be declared as an array of pointers to 'void' as follows
*
* void *MessageStorage[size]
*
* size is the number of elements in the storage area
*
* Returns : != (void *)0 is a pointer to the event control clock (OS_EVENT) associated with the
* created queue
* == (void *)0 if no event control blocks were available
*********************************************************************************************************
*/
OS_EVENT *OSQCreate (void **start, INT16U size)
{
OS_EVENT *pevent;
OS_Q *pq;
OS_ENTER_CRITICAL();
pevent = OSEventFreeList; /* Get next free event control block */
if (OSEventFreeList != (OS_EVENT *)0) { /* See if pool of free ECB pool was empty */
OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
}
OS_EXIT_CRITICAL();
if (pevent != (OS_EVENT *)0) { /* See if we have an event control block */
OS_ENTER_CRITICAL(); /* Get a free queue control block */
pq = OSQFreeList;
if (OSQFreeList != (OS_Q *)0) {
OSQFreeList = OSQFreeList->OSQPtr;
}
OS_EXIT_CRITICAL();
if (pq != (OS_Q *)0) { /* See if we were able to get a queue control block */
pq->OSQStart = start; /* Yes, initialize the queue */
pq->OSQEnd = &start[size];
pq->OSQIn = start;
pq->OSQOut = start;
pq->OSQSize = size;
pq->OSQEntries = 0;
pevent->OSEventType = OS_EVENT_TYPE_Q;
pevent->OSEventPtr = pq;
OSEventWaitListInit(pevent);
} else { /* No, since we couldn't get a queue control block */
OS_ENTER_CRITICAL(); /* Return event control block on error */
pevent->OSEventPtr = (void *)OSEventFreeList;
OSEventFreeList = pevent;
OS_EXIT_CRITICAL();
pevent = (OS_EVENT *)0;
}
}
return (pevent);
}
/*$PAGE*/
/*
*********************************************************************************************************
* FLUSH QUEUE
*
* Description : This function is used to flush the contents of the message queue.
*
* Arguments : none
*
* Returns : OS_NO_ERR upon success
* OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue
*********************************************************************************************************
*/
INT8U OSQFlush (OS_EVENT *pevent)
{
OS_Q *pq;
OS_ENTER_CRITICAL();
if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type */
OS_EXIT_C
没有合适的资源?快使用搜索试试~ 我知道了~
COS-II_MSP430F2013程序
共24个文件
c:10个
h:4个
wsdt:1个
需积分: 9 10 下载量 6 浏览量
2010-08-20
10:53:02
上传
评论
收藏 36KB RAR 举报
温馨提示
本文是在网上搜集到的有关MSP430F2013单片机的程序,供初学者一起分享一下,顺便赚点辛苦费,嘿嘿
资源推荐
资源详情
资源评论
收起资源包目录
101259366uCOS-II_MSP430F2013.rar (24个子文件)
uCOS-II_MSP430F2013
uCOS-II.dep 4KB
OS_CPU_C.c 9KB
settings
uCOS-II.dbgdt 5KB
uCOS-II.cspy.bat 2KB
uCOS-II.wsdt 3KB
uCOS-II.dni 1KB
OS_CFG.h 3KB
Includes.h 661B
uCOS_II.H 18KB
uCOS-II.ewp 43KB
uCOS-II.eww 161B
uCOS-II.ewd 12KB
OS_CORE.C 20KB
OS_MEM.C 11KB
OS_MBOX.c 7KB
OS_Q.C 20KB
OS_TASK.c 14KB
OS_CPU.H 5KB
OS_CPU_A.asm 12KB
OS_SEM.c 6KB
Application.c 2KB
uCOS_II.C 938B
OS_TIME.c 2KB
www.pudn.com.txt 218B
共 24 条
- 1
资源评论
happyjane77
- 粉丝: 4
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功