/************************************************************************/
/* Copyright 2002 MBARI							*/
/************************************************************************/
/* Summary  : Definitions for Multitasking library for Persistor CF2	*/
/* Filename : task.h							*/
/* Author   : Robert Herlien (rah)					*/
/* Project  : OASIS Mooring Replacement (OASIS3)			*/
/* Revision: 0.1							*/
/* Created  : 10/14/2002						*/
/*									    */
/* MBARI provides this documentation and code "as is", with no warranty,    */
/* express or implied, of its quality or consistency. It is provided without*/
/* support and without obligation on the part of the Monterey Bay Aquarium  */
/* Research Institute to assist in its use, correction, modification, or    */
/* enhancement. This information should not be published or distributed to  */
/* third parties without specific written permission from MBARI.            */
/*									    */
/************************************************************************/
/* Modification History:						*/
/* 10oct2002 rah - created from OASIS io.h				*/
/************************************************************************/

/************************************************************************/
/* You must include mbariTypes.h and oasis.h before this file		*/
/************************************************************************/

#ifndef INCtaskLibh
#define INCtaskLibh	1

#define STKSIZE		2048		/* Default task stack size	    */


/****************************************/
/* Type definitions for Task Library	*/
/****************************************/

typedef void		(*FuncPtr)();	/* Function pointer		    */

#define NULLTASK	((TaskDesc *)0)
#define NULLFUNC	((FuncPtr)0)

typedef enum				/************************************/
{					/* Task State type		    */
    RUNNING = 0,			/* The single running task	    */
    READY,				/* Ready, but not running	    */
    PENDING,				/* Pending on a semaphore	    */
    DELAY				/* Waiting for delay()		    */
}TaskState;				/************************************/
    
typedef struct task_desc		/************************************/
{					/* Task Descriptor STRUCTURE	    */
    Node	td_link;		/* For linked lists		    */
    char	*td_name;		/* Task name			    */
    TaskState	td_state;		/* Task state			    */
    SemID	td_sem;			/* Semaphore we're waiting on	    */
    Int16	td_delay;		/* Delay count			    */
    FuncPtr	*td_stack;		/* Base of task stack		    */
    FuncPtr	*td_sp;			/* Task current stack pointer	    */
    Driver	*td_drvr;		/* Driver ptr			    */
    Nat16	td_serport;		/* Serial port owned by this task   */
    Word	td_sermode;		/* Serial setup mode		    */
    Int16	td_serchar;		/* Last serial output char	    */
} TaskDesc;				/************************************/


/****************************************/
/* Function Declarations		*/
/****************************************/

TaskDesc *task_init( Void );
TaskDesc *task_get( Void );
Void	 task_exit( Void );
Void	 task_delay( Int16 count );
Void	 delay_secs( Nat16 secs );
Void	 dispatch( Void );

#endif	/* INCtaskLibh */
