/****************************************************************************
 *  F i l e   D a t a                                                        
 *  $Id: HV_INFN.c,v 1.1.1.1 2006/04/25 09:00:20 kusanagi Exp $
 *  $Revision: 1.1.1.1 $
 *  $Date: 2006/04/25 09:00:20 $
 *  $RCSfile: HV_INFN.c,v $
 *                                                                           
 ****************************************************************************
 *  S W   D e v e l o p m e n t   E n v i r o n m e n t                      
 *                                                                           
 *  $Author: kusanagi $
 *               :                                                           
 ****************************************************************************
 *  U p d a t i n g                                                          

 *  $Log: HV_INFN.c,v $
 *  Revision 1.1.1.1  2006/04/25 09:00:20  kusanagi
 *  These program extract in an XML format the info contained into the ROOT files generated by YODA from the PAMELA data. To visualize the XML files in a more human readable format a collection of XSL files are given in the Data subfolder.
 *
 *  Revision 1.3  2005/02/21 08:58:29  sebastiani
 *  all log comments completed
 *
 *  Revision 1.2  2004/08/27 13:30:39  alfarano
 *  cvs header
 *
 *  Revision 1.1  2003/10/03 16:12:26  faber
 *  *** empty log message ***
 *
 *                                                                           
 *****************************************************************************/
/*============================= Include File ================================*/


#include <src/INFN/LU_SourceFileID_INFN.h>
#define __FILEID__ _HV_INFN__c

#include <src/INFN/PRH_ParamHandler_INFN.h>
#include <src/INFN/LU_LogUtility_INFN.h>
#include <src/INFN/PRH_ParamHandler_INFN_auto.h>
LU_DECL_MASK();

#include <src/INFN/CM_Common_INFN.h>
#include <src/INFN/KHB_Driver_INFN.h>
#include <src/INFN/HK_Manager_INFN.h>
#include <src/INFN/HV_INFN.h>


/*============================ Global define ================================*/


/*============================== global types  ==============================*/





/*=========================== Structure define ==============================*/


/*============================ Enumerate define =============================*/


status_code HV_Init() 
{
  return CM_RC_SUCCESSFUL;
}

status_code HV_Initialization() 
{
  return CM_RC_SUCCESSFUL;
}

status_code HV_Write(BYTE channel, BYTE value)
{
  status_code status;
  UINT16 write_value,outbuf;

  if (channel <=  HV_MAX_CHANNEL)
    {
      write_value = (1 << 15) | (1 << 14) | ((UINT16)channel << 10) | ((UINT16)value << 7) | ((UINT16)channel << 3) | value;
      
      status = HK_KHB_Cmd2FE(KHB_POWER_SUPPLY,1,1,&write_value,&outbuf,HV_BOARD_TIMEOUT);
      
      if (status = CM_RC_SUCCESSFUL)
	{
	  // TBD check CC 
	}
    }
  else 
    status = CM_RC_INVALID_ID;
  /*@LOG HV_Write trace - status */
  LU_INFN_LOG (LU_DEBUG_TRACE, LU_MASK(__FILEID__), __FILEID__, __LINE__, status);    
  return status;
}
