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

📄 os.h

📁 ucos on sa1200 from ixp1200 EB
💻 H
字号:
/*
* File:    ucos.h
*
* uC/OS Real-time multitasking kernel for the ARM processor.
*
* Created by Jean J. Labrosse. 
* ARM port by Marco Graziano (marcog@crl.com).
*
*/

#ifndef OS_H
#define OS_H

/* Unsigned integer */
typedef unsigned int uint;

/* Register type */
typedef volatile unsigned int ureg;

/* Unsigned characters */
typedef unsigned char byte;

/* Pointer to function with no arguments returning int */
/* typedef int (*PFI)(void); */ /* Due to name conflict */

/* Pointer to function with no arguments returning void */
typedef void (*PFV)(void);

/* Pointer to function with a pointer argument returning void */
typedef void (*PTV)(void*);

/* Pointer to function with a pointer to char argument returning void */
typedef void (*PFC)(char*);

/* make both C compiler error and C++ compiler warning go away */
#ifdef __cplusplus
#define IGNORE
#else
#define IGNORE ignore 
#endif

/* used in boolean fields */
#define UCOS_TRUE    0x1 
#define UCOS_FALSE   0x0

/* idle task stack size (words) */
#define OS_IDLE_STK_SIZE    0x400

#define OS_TICKS_PER_SEC    100

/* constants */
#define SVC32MODE   0x13
#define OS_INT_MAX     0x7FFFFFFF

#define NO_CONSOLE  0
#define USE_CONSOLE 1

/* task status */
#define OS_STAT_RDY     0   /* ready to run */
#define OS_STAT_SEM     1   /* suspended on semaphore */
#define OS_STAT_MBOX    2   /* suspended on mailbox */
#define OS_STAT_Q       3   /* suspended on queue */
#define OS_STAT_SLEEP   4   /* suspended on timer */

/* special int pattern for stack boundary check */
#define MAGIC_WORD0 0xa5a5a5a5
#define MAGIC_WORD1 0x5a5a5a5a
#define MAGIC_WORD2 0x12345678
#define MAGIC_WORD3 0x87654321

#define ENTER_CRITICAL() (unsigned int)SAr_DisableInt()
#define EXIT_CRITICAL(intFlags) SAr_EnableInt(intFlags)

/*
* uC/OS configuration
*/
#define OS_MAX_TASKS    64  /* max number of tasks in an application */
#define OS_MAX_EVENTS   192 /* max number of events */
#define OS_MAX_QS       64  /* max number of queues */
#define OS_LO_PRIO      63  /* lowest priority */

/*
* Error codes
*/
#define OS_NO_ERR           0
#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

/*
* Event control block.
*/
typedef struct os_event {
    uint OSEventGrp;
    uint OSEventTbl[8];
    int OSEventCnt;
    void *OSEventPtr;
} OS_EVENT;

/*
* Task control block.
*/
typedef struct os_tcb {
    void *OSTCBStkPtr;
    uint OSTCBStat;
    uint OSTCBPrio;
    uint OSTCBDly;
    uint OSTCBX;
    uint OSTCBY;
    uint OSTCBBitX;
    uint OSTCBBitY;
    OS_EVENT *OSTCBEventPtr;
    void *OSTCBStkTop;
    void *OSTCBStkBottom;
    struct os_tcb *OSTCBNext;
    struct os_tcb *OSTCBPrev;
} OS_TCB;

/*
* Queue control block.
*/
typedef struct os_q {
    struct os_q *OSQPtr;
    void **OSQStart;
    void **OSQEnd;
    void **OSQIn;
    void **OSQOut;
    uint OSQSize;
    uint OSQEntries;
} OS_Q;


/*
* Global variables.
*/
extern uint     OSCtxSwCtr;         /* context switches counter */
extern uint     OSIdleCtr;          /* idle counter */
extern uint     OSRunning;          /* kernel running flag */
extern uint     OSLockNesting;
extern uint     OSTime;
extern uint     taskReSched;
extern uint     const OSUnMapTbl[];
extern OS_TCB   *OSTCBCur;          /* current running TCB pointer */
extern OS_TCB   *OSTCBHighRdy;      /* highest priority TCB ready to run */
extern OS_TCB   *OSTCBPrioTbl[];    /* table of pointers to created TCBs */
extern OS_TCB   *OSTCBList;


/*
* Function prototypes.
*/
#ifdef __cplusplus
extern "C" {
#endif
    
    void OSInit(void);              /* initialize uC/OS */
    void OSStart(void);             /* start multitasking */
    
    void OSSchedLock(void);         /* prevent rescheduling */
    void OSSchedUnlock(void);       /* allow rescheduling */
    
    int OSTaskCreate(void(*)(void *), void *, void *, uint, uint);
    int OSTaskDel(uint);
    int OSTaskChangePrio(uint, uint);
    void OSSched(void);
    
    void OSTimeTick(void);          /* time tick */
    void OSTimeDly(uint);           /* delay a task */
    void OSTimeSet(uint);           /* set system time */
    uint OSTimeGet(void);           /* get system time */
    
    OS_EVENT *OSSemCreate(int);     /* create a semaphore */
    uint OSSemPost(OS_EVENT *);     /* signal semaphore */
    void OSSemPend(OS_EVENT *, uint, uint *);   /* wait semaphore */
    
    OS_EVENT *OSMboxCreate(void *);             /* create mailbox */
    uint OSMboxPost(OS_EVENT *, void *);        /* post message */
    void *OSMboxPend(OS_EVENT *, uint, uint *); /* pend for message */
    
    OS_EVENT *OSQCreate(void **, uint);         /* create a queue */
    uint OSQPost(OS_EVENT *, void *);           /* post a message */
    void *OSQPend(OS_EVENT *, uint, uint *);    /* pend for message */
    
    void rootTask(void*);
    void ucosStart(PFV userInit_in, unsigned int useConsole_in);

	void sysMemVirtSize
     (
     unsigned int* sys,
     unsigned int* sys_all,
     unsigned int* sdram,
     unsigned int* sram,
     unsigned int* flash
     ); // get memory sizes
    
#ifdef __cplusplus
}
#endif

/*
* Command Line Console
*/

#define MAXNAME 20

typedef struct {
    const char* name;
    void (*func)(char*);
    const char* help;
    int size;
} ConsoleCommand;

#ifdef __cplusplus
extern "C" {
#endif
    
    void consoleTask(void*);
    void doCommand(char* cmdLine);
    void help(char*);
    void i(char*);
    void ti(char*);
    void r(char*);
    void n(char*);
    void m(char*);
    void list(char* param);
    int getParam(char** str, unsigned int* value);
    int getStringParam(char** str, char* subString);
    void consoleConnect(ConsoleCommand* userCommand);
    
    // uC/OS debug tools
    //
    void uCOS_ShowAllTasks(void);
    void uCOS_ShowAllTasks2(void);
    void uCOS_ShowTaskTCB(OS_TCB* tcb);
    void uCOS_ShowAllTaskDetail(void);
    void uCOS_ShowAllTaskDetail2(void);
    void uCOS_ShowTaskDetail(unsigned int tid);
    void uCOS_ShowTaskDetailByTCB(OS_TCB* tcb);
    void uCOS_ShowEvent(OS_EVENT* pevent);
    
#ifdef __cplusplus
}
#endif

#endif /* OS_H */

/* end of file */

⌨️ 快捷键说明

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