⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ucos.h

📁 ucos 在 Intel 196 单片机上的移植
💻 H
字号:
/*
******************************************************************************
*                                  uCOS
*           Microcomputer Real-Time Multitasking Operating System
*                           SYSTEM DECLARATIONS
*
*        (c) Copyright 1992, Jean J. Labrosse, Plantation, FL
*                       All Rights Reserved
*
*
* File : UCOS.H
* By   : Jean J. Labrosse
******************************************************************************
*/
#include    "ucoscfg.h"                /* Aplication specific configuration */
/*
******************************************************************************
*                              uCOS CONFIGURATION
******************************************************************************
*/

#define OS_MAX_TASKS  20    /* Maximum number of tasks in your application   */
#define OS_MAX_EVENTS 15 /*Max # of event control blocks in your application */
#define OS_MAX_QS     1  /*Max # of queue control blocks in your application */

#define OS_IDLE_TASK_STK_SIZE  200          /* Idle task stack size (BYTEs) */

#define OS_USE_ACK 1 /* Can be used with OSMboxPend or OSEventPend to force 
                        a mail message ack by using OSMailAck */
#define OS_DONT_USE_ACK 0
#define NULL 0

/*
******************************************************************************
*                              uCOS ERROR CODES
******************************************************************************
*/

#define OS_NO_ERR            0         /* ERROR CODES */
#define OS_TIMEOUT          10
#define OS_MBOX_FULL        20
#define OS_Q_FULL           30
#define OS_PRIO_EXIST       40
#define OS_PRIO_ERR         41
#define OS_SEM_ERR          50
#define OS_SEM_OVF          51
#define OS_TASK_DEL_ERR     60
#define OS_TASK_DEL_IDLE    61
#define OS_NO_MORE_TCB      70

/*$PAGE*/
/*
******************************************************************************
*                             EVENT CONTROL BLOCK
******************************************************************************
*/

typedef struct os_event {
    BYTE  OSEventGrp;/*Group corresponding to tasks waiting for event to occur*/
    BYTE  OSEventTbl[8];         /* List of tasks waiting for event to occur */
    SWORD OSEventCnt;             /* Count of used when event is a semaphore */
    void  *OSEventPtr;              /* Pointer to message or queue structure */
    BYTE  OSMailFullLink; /* Links the sender of mail with the mailbox to be
                                               awakened when mailbox not full*/
    BYTE  OSMailAckLink; /* Links the sender of mail with the mailbox for ack
                                                    so messages dont overrun */
} OS_EVENT;


/*
******************************************************************************
*                          uCOS TASK CONTROL BLOCK
******************************************************************************
*/

typedef struct os_tcb {
    void * OSTCBStkPtr;                   /* Pointer to current top of stack */
    BYTE OSTCBStat;                                           /* Task status */
    BYTE OSTCBPrio;            /* Task priority (0 == highest, 63 == lowest) */
    WORD OSTCBDly;  /* Nbr ticks to delay task or, timeout waiting for event */
    BYTE OSTCBX; /* Bit position in group  corresponding to task priority (0..7) */
    BYTE OSTCBY;    /* Index into ready table corresponding to task priority */
    BYTE OSTCBBitX;        /* Bit mask to access bit position in ready table */
    BYTE OSTCBBitY;        /* Bit mask to access bit position in ready group */
    OS_EVENT *OSTCBEventPtr;               /* Pointer to event control block */
    OS_EVENT *OSTCBEvent2Ptr;/*T/R*//* Pointer to event control block used for multi events */
    struct os_tcb *OSTCBNext;     /* Pointer to next     TCB in the TCB list */
    struct os_tcb *OSTCBPrev;     /* Pointer to previous TCB in the TCB list */
} OS_TCB;


/*
******************************************************************************
*                             QUEUE CONTROL BLOCK
******************************************************************************
*/

typedef struct os_q {
    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 */
    BYTE OSQSize;     /* Size of queue (maximum number of entries) */
    BYTE OSQEntries;  /* Current number of entries in the queue */
} OS_Q;

/*$PAGE*/
/*
******************************************************************************
*                            uCOS GLOBAL VARIABLES
******************************************************************************
*/

                                 /* SYSTEM VARIABLES */
#if USE_DEBUG
extern WORD     OSCtxSwCtr;      /* Counter of number of context switches */
extern LONG     OSIdleCtr;       /* Idle counter */
#endif /*USE_DEBUG*/
extern BOOLEAN   OSRunning;      /* Flag indicating that kernel is running */
extern OS_TCB   *OSTCBCur;       /* Pointer to currently running TCB */
extern OS_TCB   *OSTCBHighRdy;   /* Pointer to highest priority TCB ready to run */
extern OS_TCB   *OSTCBPrioTbl[]; /* Table of pointers to all created TCBs */

/*
******************************************************************************
*                          uCOS FUNCTION PROTOTYPES
******************************************************************************
*/

void OSInit(void);
void OSStart(void);
void OSStartHighRdy(void);
void OSSched(void);
void OSSchedLock(void);
void OSSchedUnlock(void);
BYTE OSTCBInit(BYTE p, void  *stk);

BYTE OSTaskCreate(void ( *task)(void *pd), void *pdata, void *pstk, BYTE prio);
BYTE OSTaskDel(BYTE p);

#if USE_CHG_PRIORITY
BYTE OSTaskChangePrio(BYTE oldp, BYTE newp);
#endif /*USE_CHG_PRIORITY*/

void OSIntEnter(void);
void OSIntExit(void);

void OSIntCtxSw(void);
void OSCtxSw(void);

void OSTimeDly(WORD ticks);
void OSTimeTick(void);
void OSTimeSet(LONG ticks);
LONG OSTimeGet(void);

#if USE_SEMA
OS_EVENT *OSSemCreate(SWORD value);
BYTE OSSemPost(OS_EVENT *pevent);
void OSSemPend(OS_EVENT *pevent, WORD timeout, BYTE *err);
void OSSetSema(OS_EVENT *pevent, SWORD value);/*T/R*/
#endif /*USE_SEMA*/

#if USE_MAIL
OS_EVENT *OSMboxCreate(void *msg);
/* This CAN NOT be used from an ISR */
void OSMboxPost(OS_EVENT *pmail, void *msg, BYTE p, BYTE useAck);
/* pmail is pointer to mailbox */
/* msg is pointer to message to be sent */
/* p is priority of the sender ( this is only used when using ack ) */
/* useAck is to indicate the use of acking a mail message */
/*BYTE OSMboxPost(OS_EVENT *pevent, void *msg);*/
void *OSMboxPend(OS_EVENT *pevent, WORD timeout, BYTE *err);
void *OSMboxAccept(OS_EVENT *pmail);
void OSMailAck(OS_EVENT *pmail);/*T/R*/
#endif /*USE_MAIL*/

#if USE_QUEUE
OS_EVENT *OSQCreate(void **start, BYTE size);
BYTE OSQPost(OS_EVENT *pevent, void *msg);
void *OSQPend(OS_EVENT *pevent, WORD timeout, BYTE *err);
#endif /*USE_QUEUE*/

#if USE_MULTI_EVENTS
void *OSEventPend(OS_EVENT *psema,OS_EVENT *pmail,WORD timeout,BYTE *err);/*T/R*/
#endif /*USE_MULTI_EVENTS*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -