📄 ucos_ii.h
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-2005, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* File : uCOS_II.H
* By : Jean J. Labrosse
* Version : V2.80
*********************************************************************************************************
*/
#ifndef OS_uCOS_II_H
#define OS_uCOS_II_H
/*
*********************************************************************************************************
* uC/OS-II VERSION NUMBER
*********************************************************************************************************
*/
#define OS_VERSION 280u /* Version of uC/OS-II (Vx.yy mult. by 100) */
/*
*********************************************************************************************************
* INCLUDE HEADER FILES
*********************************************************************************************************
*/
#include <os_cpu.h>
#include <os_cfg.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
*********************************************************************************************************
* MISCELLANEOUS
*********************************************************************************************************
*/
#ifdef OS_GLOBALS
#define OS_EXT
#else
#define OS_EXT extern
#endif
#ifndef FALSE
#define FALSE 0u
#endif
#ifndef TRUE
#define TRUE 1u
#endif
#define OS_ASCII_NUL (INT8U)0
#define OS_PRIO_SELF 0xFFu /* Indicate SELF priority */
#if OS_TASK_STAT_EN > 0
#define OS_N_SYS_TASKS 2u /* Number of system tasks */
#else
#define OS_N_SYS_TASKS 1u
#endif
#define OS_STAT_PRIO (OS_LOWEST_PRIO - 1) /* Statistic task priority */
#define OS_IDLE_PRIO (OS_LOWEST_PRIO) /* IDLE task priority */
#if OS_LOWEST_PRIO <= 63
#define OS_EVENT_TBL_SIZE ((OS_LOWEST_PRIO) / 8 + 1) /* Size of event table */
#define OS_RDY_TBL_SIZE ((OS_LOWEST_PRIO) / 8 + 1) /* Size of ready table */
#else
#define OS_EVENT_TBL_SIZE ((OS_LOWEST_PRIO) / 16 + 1) /* Size of event table */
#define OS_RDY_TBL_SIZE ((OS_LOWEST_PRIO) / 16 + 1) /* Size of ready table */
#endif
#define OS_TASK_IDLE_ID 65535u /* I.D. numbers for Idle and Stat tasks */
#define OS_TASK_STAT_ID 65534u
#define OS_EVENT_EN (((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0) || (OS_SEM_EN > 0) || (OS_MUTEX_EN > 0))
/*$PAGE*/
/*
*********************************************************************************************************
* TASK STATUS (Bit definition for OSTCBStat)
*********************************************************************************************************
*/
#define OS_STAT_RDY 0x00u /* Ready to run */
#define OS_STAT_SEM 0x01u /* Pending on semaphore */
#define OS_STAT_MBOX 0x02u /* Pending on mailbox */
#define OS_STAT_Q 0x04u /* Pending on queue */
#define OS_STAT_SUSPEND 0x08u /* Task is suspended */
#define OS_STAT_MUTEX 0x10u /* Pending on mutual exclusion semaphore */
#define OS_STAT_FLAG 0x20u /* Pending on event flag group */
#define OS_STAT_PEND_ANY (OS_STAT_SEM | OS_STAT_MBOX | OS_STAT_Q | OS_STAT_MUTEX | OS_STAT_FLAG)
/*
*********************************************************************************************************
* OS_EVENT types
*********************************************************************************************************
*/
#define OS_EVENT_TYPE_UNUSED 0u
#define OS_EVENT_TYPE_MBOX 1u
#define OS_EVENT_TYPE_Q 2u
#define OS_EVENT_TYPE_SEM 3u
#define OS_EVENT_TYPE_MUTEX 4u
#define OS_EVENT_TYPE_FLAG 5u
/*
*********************************************************************************************************
* EVENT FLAGS
*********************************************************************************************************
*/
#define OS_FLAG_WAIT_CLR_ALL 0u /* Wait for ALL the bits specified to be CLR (i.e. 0) */
#define OS_FLAG_WAIT_CLR_AND 0u
#define OS_FLAG_WAIT_CLR_ANY 1u /* Wait for ANY of the bits specified to be CLR (i.e. 0) */
#define OS_FLAG_WAIT_CLR_OR 1u
#define OS_FLAG_WAIT_SET_ALL 2u /* Wait for ALL the bits specified to be SET (i.e. 1) */
#define OS_FLAG_WAIT_SET_AND 2u
#define OS_FLAG_WAIT_SET_ANY 3u /* Wait for ANY of the bits specified to be SET (i.e. 1) */
#define OS_FLAG_WAIT_SET_OR 3u
#define OS_FLAG_CONSUME 0x80u /* Consume the flags if condition(s) satisfied */
#define OS_FLAG_CLR 0u
#define OS_FLAG_SET 1u
/*
*********************************************************************************************************
* Values for OSTickStepState
*
* Note(s): This feature is used by uC/OS-View.
*********************************************************************************************************
*/
#if OS_TICK_STEP_EN > 0
#define OS_TICK_STEP_DIS 0u /* Stepping is disabled, tick runs as mormal */
#define OS_TICK_STEP_WAIT 1u /* Waiting for uC/OS-View to set OSTickStepState to _ONCE */
#define OS_TICK_STEP_ONCE 2u /* Process tick once and wait for next cmd from uC/OS-View */
#endif
/*
*********************************************************************************************************
* Possible values for 'opt' argument of OSSemDel(), OSMboxDel(), OSQDel() and OSMutexDel()
*********************************************************************************************************
*/
#define OS_DEL_NO_PEND 0u
#define OS_DEL_ALWAYS 1u
/*
*********************************************************************************************************
* OS???PostOpt() OPTIONS
*
* These #defines are used to establish the options for OSMboxPostOpt() and OSQPostOpt().
*********************************************************************************************************
*/
#define OS_POST_OPT_NONE 0x00u /* NO option selected */
#define OS_POST_OPT_BROADCAST 0x01u /* Broadcast message to ALL tasks waiting */
#define OS_POST_OPT_FRONT 0x02u /* Post to highest priority task waiting */
/*
*********************************************************************************************************
* TASK OPTIONS (see OSTaskCreateExt())
*********************************************************************************************************
*/
#define OS_TASK_OPT_NONE 0x0000u /* NO option selected */
#define OS_TASK_OPT_STK_CHK 0x0001u /* Enable stack checking for the task */
#define OS_TASK_OPT_STK_CLR 0x0002u /* Clear the stack when the task is create */
#define OS_TASK_OPT_SAVE_FP 0x0004u /* Save the contents of any floating-point registers */
/*
*********************************************************************************************************
* ERROR CODES
*********************************************************************************************************
*/
#define OS_NO_ERR 0u
#define OS_ERR_EVENT_TYPE 1u
#define OS_ERR_PEND_ISR 2u
#define OS_ERR_POST_NULL_PTR 3u
#define OS_ERR_PEVENT_NULL 4u
#define OS_ERR_POST_ISR 5u
#define OS_ERR_QUERY_ISR 6u
#define OS_ERR_INVALID_OPT 7u
#define OS_ERR_TASK_WAITING 8u
#define OS_ERR_PDATA_NULL 9u
#define OS_TIMEOUT 10u
#define OS_TASK_NOT_EXIST 11u
#define OS_ERR_EVENT_NAME_TOO_LONG 12u
#define OS_ERR_FLAG_NAME_TOO_LONG 13u
#define OS_ERR_TASK_NAME_TOO_LONG 14u
#define OS_ERR_PNAME_NULL 15u
#define OS_ERR_TASK_CREATE_ISR 16u
#define OS_MBOX_FULL 20u
#define OS_Q_FULL 30u
#define OS_Q_EMPTY 31u
#define OS_PRIO_EXIST 40u
#define OS_PRIO_ERR 41u
#define OS_PRIO_INVALID 42u
#define OS_SEM_OVF 50u
#define OS_TASK_DEL_ERR 60u
#define OS_TASK_DEL_IDLE 61u
#define OS_TASK_DEL_REQ 62u
#define OS_TASK_DEL_ISR 63u
#define OS_NO_MORE_TCB 70u
#define OS_TIME_NOT_DLY 80u
#define OS_TIME_INVALID_MINUTES 81u
#define OS_TIME_INVALID_SECONDS 82u
#define OS_TIME_INVALID_MILLI 83u
#define OS_TIME_ZERO_DLY 84u
#define OS_TASK_SUSPEND_PRIO 90u
#define OS_TASK_SUSPEND_IDLE 91u
#define OS_TASK_RESUME_PRIO 100u
#define OS_TASK_NOT_SUSPENDED 101u
#define OS_MEM_INVALID_PART 110u
#define OS_MEM_INVALID_BLKS 111u
#define OS_MEM_INVALID_SIZE 112u
#define OS_MEM_NO_FREE_BLKS 113u
#define OS_MEM_FULL 114u
#define OS_MEM_INVALID_PBLK 115u
#define OS_MEM_INVALID_PMEM 116u
#define OS_MEM_INVALID_PDATA 117u
#define OS_MEM_INVALID_ADDR 118u
#define OS_MEM_NAME_TOO_LONG 119u
#define OS_ERR_NOT_MUTEX_OWNER 120u
#define OS_TASK_OPT_ERR 130u
#define OS_ERR_DEL_ISR 140u
#define OS_ERR_CREATE_ISR 141u
#define OS_FLAG_INVALID_PGRP 150u
#define OS_FLAG_ERR_WAIT_TYPE 151u
#define OS_FLAG_ERR_NOT_RDY 152u
#define OS_FLAG_INVALID_OPT 153u
#define OS_FLAG_GRP_DEPLETED 154u
#define OS_ERR_PIP_LOWER 160u
/*$PAGE*/
/*
*********************************************************************************************************
* EVENT CONTROL BLOCK
*********************************************************************************************************
*/
#if OS_EVENT_EN && (OS_MAX_EVENTS > 0)
typedef struct os_event {
INT8U OSEventType; /* Type of event control block (see OS_EVENT_TYPE_xxxx) */
void *OSEventPtr; /* Pointer to message or queue structure */
INT16U OSEventCnt; /* Semaphore Count (not used if other EVENT type) */
#if OS_LOWEST_PRIO <= 63
INT8U OSEventGrp; /* Group corresponding to tasks waiting for event to occur */
INT8U OSEventTbl[OS_EVENT_TBL_SIZE]; /* List of tasks waiting for event to occur */
#else
INT16U OSEventGrp; /* Group corresponding to tasks waiting for event to occur */
INT16U OSEventTbl[OS_EVENT_TBL_SIZE]; /* List of tasks waiting for event to occur */
#endif
#if OS_EVENT_NAME_SIZE > 1
INT8U OSEventName[OS_EVENT_NAME_SIZE];
#endif
} OS_EVENT;
#endif
/*
*********************************************************************************************************
* EVENT FLAGS CONTROL BLOCK
*********************************************************************************************************
*/
#if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
#if OS_FLAGS_NBITS == 8 /* Determine the size of OS_FLAGS (8, 16 or 32 bits) */
typedef INT8U OS_FLAGS;
#endif
#if OS_FLAGS_NBITS == 16
typedef INT16U OS_FLAGS;
#endif
#if OS_FLAGS_NBITS == 32
typedef INT32U OS_FLAGS;
#endif
typedef struct os_flag_grp { /* Event Flag Group */
INT8U OSFlagType; /* Should be set to OS_EVENT_TYPE_FLAG */
void *OSFlagWaitList; /* Pointer to first NODE of task waiting on event flag */
OS_FLAGS OSFlagFlags; /* 8, 16 or 32 bit flags */
#if OS_FLAG_NAME_SIZE > 1
INT8U OSFlagName[OS_FLAG_NAME_SIZE];
#endif
} OS_FLAG_GRP;
typedef struct os_flag_node { /* Event Flag Wait List Node */
void *OSFlagNodeNext; /* Pointer to next NODE in wait list */
void *OSFlagNodePrev; /* Pointer to previous NODE in wait list */
void *OSFlagNodeTCB; /* Pointer to TCB of waiting task */
void *OSFlagNodeFlagGrp; /* Pointer to Event Flag Group */
OS_FLAGS OSFlagNodeFlags; /* Event flag to wait on */
INT8U OSFlagNodeWaitType; /* Type of wait: */
/* OS_FLAG_WAIT_AND */
/* OS_FLAG_WAIT_ALL */
/* OS_FLAG_WAIT_OR */
/* OS_FLAG_WAIT_ANY */
} OS_FLAG_NODE;
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* MESSAGE MAILBOX DATA
*********************************************************************************************************
*/
#if OS_MBOX_EN > 0
typedef struct os_mbox_data {
void *OSMsg; /* Pointer to message in mailbox */
#if OS_LOWEST_PRIO <= 63
INT8U OSEventTbl[OS_EVENT_TBL_SIZE]; /* List of tasks waiting for event to occur */
INT8U OSEventGrp; /* Group corresponding to tasks waiting for event to occur */
#else
INT16U OSEventTbl[OS_EVENT_TBL_SIZE]; /* List of tasks waiting for event to occur */
INT16U OSEventGrp; /* Group corresponding to tasks waiting for event to occur */
#endif
} OS_MBOX_DATA;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -