/****************************************************************************/
/* Copyright 2014 MBARI                                                     */
/* MBARI Proprietary Information. All rights reserved.                      */
/* Written 30jan2014, Robert Herlien (rah)				    */
/****************************************************************************/

#include <stdio.h>
#include "misc.h"
#include "gf.h"
#include "dig_io.h"
#include "adc.h"
#include "config.h"
#include "sys_timer.h"
#include "p24Fxxxx.h"
#include "GenericTypeDefs.h"
#include "mb.h"
#include <string.h>

extern ConfigData configData;

void miscInit(void)
{
}

UINT miscRegRead(UINT address)
{
    UINT val;

    switch(address)
    {
      case SERIAL_NUM:
	  return(configData.serialNum);

      case SOFTWARE_REV:
	  return((SW_REV_HIGH << 8) | (SW_REV_LOW & 0xff));

      case SYS_STATUS:
	  return(digGetSysStatus());

      case H2O_SENSE:
	  val = H2O_SENSE_01 ? 1 : 0;
	  if (H2O_SENSE_02)
	      val |= 2;
	  return(val);

      default:
	  if ((address >= GF_START) && (address <= GF_END))
	      return(gfRegRead(address));
    }
    return(0);
}

eMBErrorCode	miscRegWrite(UINT address, UINT val)
{
    if ((address >= GF_START) && (address <= GF_END))
	return(gfRegWrite(address, val));

    return(MB_ENOREG);
}

