/************************************************************************/
/* Copyright 2002 MBARI													*/
/************************************************************************/
/* Summary	: Definitions for the OASIS3 I/O Bits						*/
/* Filename : io.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								*/
/************************************************************************/

#ifndef INCioh
#define INCioh	1

#include <serial.h>

/****************************************/
/* Miscellaneous typedefs and defines	*/
/****************************************/
#define CPU_CLOCK		16000L			/* Clock frequency = 16 MHz			*/

#define TICKS_PER_SECOND 100			/* Frequency of software time base	*/
#define TICK_INT_LEVEL	6				/* Interrupt level for ticker		*/
#define RTC_INT_LEVEL	2				/* Interrupt level for RTC			*/
#define SLEEP_51MS_TICKS 39				/* Sleep for 2 seconds at a time	*/

#define RTC_TICKS_PER_O3_TICK (40000/TICKS_PER_SECOND)
#define RTC_TICKS_PER_SECOND   40000
#define RTC_TICKS_PER_MS	  (RTC_TICKS_PER_SECOND/1000)

#define WAIT_FOREVER	INT32_MAX

#define PHYS_PWR_PORTS	8				/* 8 physical power ports			*/
#define isPhysPwr(virt) (virt && (virt < PHYS_PWR_PORTS))

#define NAD_PORTS		8				/* Number of A/D ports				*/
#define AD_SCALE		(2.5/4096.0)	/* Scale factor for A/D cnts->volts */

#define RELAY_DELAY		4				/* Relays spec'd at 3 and 15 ms		*/
										/* This is conservative at 30-40 ms */

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

Nat32	ioGetTick(Void);
Void	ioPingWatchdog(Void);
Void	ioSetHeartbeat(MBool onoff);
Void	io_power(DWord pwrbits);
Void	io_pwron(Nat32 pwrnum);
Void	io_pwroff(Nat32 pwrnum);
DWord	ioGetPwrVec(Void);
Nat16	io_atod(Nat16 channel);
Void	io_AtoDPwrOn(Nat16 channel);
Void	io_AtoDPwrOff(Void);
Void	io_serRelay(Nat16 virtPort, MBool onoff);
Void	io_serEnable(Nat16 physPort, CommsMode mode);
Void	io_setWakeupBit(Nat16 bitNum, MBool onoff);
Void	io_setWakeupByte(Nat16 bitvec);
Nat16	io_getWakeupBits(Void);
Void	io_init(Void);
Void	io_pwrup(Void);
WhatWokeUs io_pwrdown(Nat32 secs);

#endif	/* INCioh */
