/************************************************************************/
/* Copyright 200-2012 MBARI						*/
/************************************************************************/
/* Summary  : Definitions for BEDS controller using Persistor CF2	*/
/* Filename : beds.h							*/
/* Author   : Robert Herlien (rah)					*/
/* Project  : Benthic Event Detection System (BEDS)			*/
/* Revision : 1.0							*/
/* Created  : 04/16/2012						*/
/*									    */
/* 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:						*/
/* 16apr2012 rah - created from OASIS oasis.h				*/
/************************************************************************/

#ifndef INCbedsh
#define INCbedsh	1

#include <mbariTypes.h>
#include <mbariConst.h>

#define DEBUG			// Comment this out to turn off debug msgs
#ifdef DEBUG
#define DBG(X)	X		// Example: DBG( printf("Hello world\n") )
#else
#define DBG(X)			// Nothing
#endif

//#define DEBUG_MODEM
//#define MODEM_ON_TPU		/* define to run acoustic modem from TPU port*/
//#define DEBUG_I2C		/* define to debug I2C I/O		*/
//#define DEBUG_PKT_SEND	/* define to debug pkt send on Teapot app*/
//#define DEBUG_UMPL		/* define to signal when in umplOnTimer */
//#define DEBUG_TIME
//#define DEBUG_CONTINUE_DATA	/* TRUE to continue watch and event files*/
//#define DEBUG_CONFIG


#define NumberOf(arr)		((sizeof(arr) / sizeof(arr[0])))

#define Offset(ptr_type,field)	((Nat32)&(((ptr_type)0)->field))
#define OffsetOf(s_type,field)	Offset(s_type *,field)
#define deblank(s)		while(isspace(*s)) ((s)++)
#define _to_upper(_c)		(isalpha(_c) ? (_c) & 0x5f : (_c))

  
/****************************************/
/* Miscellaneous typedefs and defines	*/
/****************************************/

/* Error Codes */
typedef short int	Errno;		/* Error number return code	    */
#ifndef uint
typedef unsigned int	uint;
#endif

#ifndef ERROR			/* ERROR and OK defined in <const.h>	    */
#define ERROR		(-1)	/* ERROR return code, same as <const.h>	    */
#define OK		0	/* OK return code, same as <const.h>	    */
#endif

#define TMOUT		(-2)	/* User timeout				*/

typedef enum				/************************************/
{					/* Enum for wakeup from LPStop	    */
    WakeNone = 0,			/* Invalid, init'd to this before wake*/
    WakeTmout,				/* Timeout from 10 ms ticker	    */
    WakeIRQ2,				/* External /IRQ2 pin		    */
    WakeIRQ5,				/* External /IRQ5 pin		    */
    WakeIRQ7,				/* External /IRQ7 pin		    */
    WakeConsoleChar,			/* Character from console port	    */
    WakeTick				/* 10 ms ticker			    */
} WhatWokeUs;				/************************************/


/* Declarations of various function pointers	*/
typedef void	vsFunc(short);	
typedef vsFunc	*vsfptr;
typedef short	svFunc(void);
typedef svFunc	*svfptr;
typedef short	ssFunc(short);
typedef ssFunc	*ssfptr;

/* Defeats Errno definitions in errno-base.h, which conflict with those in _cfx_errors.h*/
/* We do this for any source file that includes beds.h, which tends to be the files	*/
/* that we've written.  The standard Invensense files won't include beds.h		*/
#define _ASM_GENERIC_ERRNO_BASE_H

/* Additional error codes not in _cfx_errors.h.  Numbers start where _cfx_errors stops	*/
#define	ESRCH		 37	/* No such process */
#define	EINTR		 38	/* Interrupted system call */
#define	E2BIG		 39	/* Argument list too long */
#define	ENOEXEC		 40	/* Exec format error */
#define	ECHILD		 41	/* No child processes */

#endif	/* INCbedsh */
