/****************************************************/
/*                                                  */
/*      SSX.H - things needed to use SSX            */
/*      (stack swap executive)                      */
/*                                                  */
/*      By Tom Green and Dennis Cronin              */
/*      10/19/92                                    */
/*                                                  */
/****************************************************/

/* function pointer */
typedef void (*fptr)(void);

/* this is a wait_q structure */
typedef struct wait_q{
    void *task_ptr;
    int mesg_flg;
}wait_q;

/* SSX prototypes */
int ssx_init(void);
void ssx_run(void);
void ssx_stop(void);
int ssx_task_create(unsigned char task_pri,
                  unsigned char task_id,fptr task_ptr,
                  unsigned int stack_size,char *name);
void ssx_task_delay(long ticks);
int ssx_task_delete(unsigned char task_id);
unsigned char ssx_change_priority(unsigned char
                                   new_priority);
void ssx_wait(wait_q *wqptr);
int ssx_wait_with_alarm(wait_q *wqptr,long timeout);
int ssx_alert(wait_q *wqptr);
void ssx_clock_tick(void);
void ssx_set_time(long ticks);
long ssx_get_time(void);
void ssx_lock(void);
void ssx_unlock(void);
void ssx_switch(void);

/* SSX status codes */

#define SUCCESS                 0
/* task ID error */
#define TID_ERR                 1
/* message waiting error */
#define MW_ERR                  2
/* no TCBs error */
#define TCB_ERR                 3
/* could not allocate stack for task */
#define STACK_ERR               4
/* task timed out (wait_with_alarm)  */
#define TO_ERR                  5
/* error initializing SSX */
#define INIT_ERROR              6

/* initialize semaphore to having waiting message */
#define SET_SEMAPHORE(wqptr)    (wqptr)->mesg_flg=1; \
                                (wqptr)->task_ptr=NULL

/* 
 * initialize wait_q to NULL task_ptr and no
 * message waiting
 */
#define INIT_WAIT_Q(wqptr)      (wqptr)->mesg_flg=0; \
                                (wqptr)->task_ptr=NULL
