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

📄 knl.h

📁 SEED的VPM642测试程序-板级支持库
💻 H
字号:
/*
 *  Copyright 2003 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  
 */
/* "@(#) DSP/BIOS 4.90.270 12-18-03 (barracuda-o04)" */
/*
 *  ======== knl.h ========
 *
 */


#ifndef KNL_
#define KNL_

#include <atm.h>
#include <fxn.h>
#include <que.h>
#include <stdarg.h>
#include <sts.h>
#include <swi.h>

#ifdef __cplusplus
extern "C" {
#endif

#define KNL_IDLEPRI (0)	    /* idle task priority (should not block) */
#define KNL_MINPRI  (1)	    /* minimum task priority */
#define KNL_MAXPRI  (15)    /* maximum task priority */

/*
 * Warning! KNL_SWIMASK and KNL_CURMASK must match their counterparts in knl.hti
 */
#define KNL_SWIMASK (0x1)   /* priority mask of KNL_swi */
#define KNL_CURMASK (0x2)   /* SWI_D_curmask value when inside the kernel */

#define KNL_RUNASYNC	(0)
#define KNL_RUNSYNC	(1)

#define KNL_RUNNING	(0)
#define KNL_READY	(1)
#define KNL_BLOCKED	(2)
#define KNL_TERMINATED	(3)

#define KNL_MAXARGS (8)

typedef struct KNL_Obj KNL_Obj;
typedef struct KNL_Obj *KNL_Handle;

struct KNL_Obj {
    QUE_Elem	ready;          /* ready/semaphore queue elem */
    QUE_Elem	alarm;          /* alarm queue elem */
    QUE_Elem	setpri;         /* set priority queue elem */
    QUE_Handle	queue;          /* task's ready queue */
    Int		priority;       /* task priority */
    Uns		mask;           /* 1 << priority */
    Ptr		sp;             /* current stack pointer */
    Uns		timeout;        /* timeout value */
    Int		mode;           /* KNL_BLOCKED, KNL_READY,... */
    /*
     *  This STS Object is used to measure the time from when the task is
     *  made ready, until the function TSK_deltatime() is called.  When the
     *  task is made ready, the STS object is "set" to the current time.
     */  
    STS_Obj     *sts;
    Bool	signalled;      /* pending task waken up by sem or timeout */
};

/*
 *  This struct overlays the fields in a KNL_Obj struct.
 *  It is used by KNL_tick() and SEM_pend() to find the timeout
 *  values for tasks on the alarm queue.
 */
typedef struct KNL_AObj KNL_AObj;
struct KNL_AObj {
    QUE_Elem	alarm;
    QUE_Elem	setpri;
    QUE_Handle	queue;
    Int		priority;
    Uns		mask;
    Ptr		sp;
    Uns		timeout;
    Int		mode;
    STS_Obj	*sts;
    Bool	signalled;
};

typedef struct KNL_Job *KNL_JobHandle;
typedef Void (*KNL_Fxn)(KNL_JobHandle);

typedef struct KNL_Job {
    QUE_Obj	wListElem;	/* KNL_wList queue */
    Int		wCount;		/* number of posts when on KNL_wList */
    KNL_Fxn	fxn;		/* function that services the job */
} KNL_Job;

/* Can be modified from an ISR and must be declared as volatile */
extern volatile Bool KNL_wFlag;		/* defined in knl.c */

#define KNL_NUMQUEUES ((KNL_MAXPRI + 5))

extern QUE_Obj KNL_queues[KNL_NUMQUEUES];

/* Can be modified from an ISR and must be declared as volatile */
extern volatile QUE_Handle KNL_wList;	/* defined in knl.c */
extern QUE_Handle KNL_alarm;
extern QUE_Handle KNL_setpri;
extern QUE_Handle KNL_inactive;
extern QUE_Handle KNL_priority;

extern Uns KNL_set;

extern KNL_Obj KNL_dummy;
extern KNL_Handle KNL_curtask;
extern KNL_Handle KNL_prevtask;

extern volatile Uns KNL_curtime;

extern SWI_Obj *KNL_swiptr;

extern QUE_Handle KNL_curqueue;
extern QUE_Handle KNL_maxqueue;

extern Fxn KNL_tswitchfxn;
extern Fxn KNL_tcreatefxn;
extern Fxn KNL_tdeletefxn;
extern Fxn KNL_treadyfxn;
extern Fxn KNL_idlefxn;

/*
 *  ======== KNL_block ========
 */
#define KNL_block()\
    QUE_dequeue(KNL_curqueue);\
    KNL_curtask->mode = KNL_BLOCKED;\
    if (QUE_empty(KNL_curqueue)) {\
	KNL_set &= ~(KNL_curtask->mask);\
    }\
    KNL_curqueue = NULL;\
    KNL_maxqueue = &KNL_priority[KNL_max()]

/*
 *  ======== KNL_busy ========
 *  The KNL_busy() macro returns TRUE if the SWI scheduler is blocked or if
 *  SWI_D_curmask > KNL_SWIMASK, when an SWI is the current process or we're
 *  already inside the scheduler. Thus, KNL_busy prevents us from entering the
 *  scheduler when inside an ISR, an SWI, or the kernel itself.
 */
#define KNL_busy()	((SWI_D_lock > -1) || (SWI_D_curmask > KNL_SWIMASK))

/*
 *  ======== KNL_init ========
 */
#define KNL_init	FXN_F_nop

/*
 *  ======== KNL_yield ========
 */
#define KNL_yield()\
    QUE_enqueue(KNL_curqueue, QUE_dequeue(KNL_curqueue));

extern Void KNL_enter(void);
extern Void KNL_exit(void);
extern Void KNL_idle(void);
extern Int KNL_max(void);
extern Void KNL_ready(KNL_Handle task);
#ifdef _55_
extern Ptr KNL_start(Ptr userStack, Ptr systemStack, Fxn fxn, va_list argv, Fxn exit, Fxn entry);
#else
extern Ptr KNL_start(Ptr stack, Fxn fxn, va_list argv, Fxn exit, Fxn entry);
#endif
extern Void KNL_switch(Ptr *oldsp, Ptr *newsp);
extern Void KNL_post(KNL_JobHandle job);
extern Void KNL_ipost(KNL_JobHandle job);

#ifdef __cplusplus
}
#endif /* extern "C" */

#endif /*KNL_*/

⌨️ 快捷键说明

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