#ifndef _MOTIONQUEUE_H_
#define _MOTIONQUEUE_H_

/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1991 by John E. Lloyd and Vincent Hayward.	    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

/*---------------------------------------------------------------------------
 *
 * DESCRIPTION:	Structure and parameter definitions for the RCCL 
 *		motion queue.
 * 
 * AUTHOR/DATE:	John Lloyd, 1986
 *
 * MODIFICATION HISTORY:
 *
 *--------------------------------------------------------------------------*/

#include "../h/cdefs.h"

#define MAX_MQ_ENTRIES	0x100	/* Max. no. of queue entires */
#define MQ_BUF_SIZE	0x8000	/* Total space for queue entries */

typedef struct {
	/* Describes that address and size of a particular entry
	   within the queue. 
	 */
	char *addr;
	int size;
} MQ_ENTRY;

typedef struct {
	char buf[MQ_BUF_SIZE];	/* circular buffer for request packets */
	char *bufAddr;		/* value of buf seen by planning task */
	char *headAddress;	/* next availble address in buffer */

	MQ_ENTRY entries[MAX_MQ_ENTRIES]; /* circ. list of queue entries */
	int head;		/* index for next put request */
	int tail;		/* index for next get request */
	int spaceReserved;	/* queue insert space has been reserved */
} MOTION_QUEUE;

/* Macros speed up the process of testing the queue and getting
   items from it:
*/

/* Returns true if something is on the queue */
#define test_queue(mq)	(mq->head != mq->tail)

/* Get address of next packet on the queue, but don't free space */
#define get_queue(mq)	\
  ((MOTION_REQUEST *)(mq->entries[mq->tail].addr + (mq->buf - mq->bufAddr)))

/* Remove a packet from the queue (freeing up the space)
   This can be done very quickly if MAX_MQ_ENTRIES is a power of two
*/
#if (MAX_MQ_ENTRIES & (MAX_MQ_ENTRIES-1)) == 0
#define free_queue(mq)	(mq->tail = (mq->tail+1) & (MAX_MQ_ENTRIES-1))
#else
#define free_queue(mq)	(mq->tail = (mq->tail+1) % MAX_MQ_ENTRIES)
#endif

#endif
