/*[CR]*************************************************************************

  Copyright (c) 2001 - 2003 by PEP Modular Computers GmbH

  All Rights reserved.

*/
/*[FH]*************************************************************************
  FILE:     LM81.h
  MODULE:   LM81
  CMM ID:   $ID$
  CONTENTS: API interface for LM81 ACPI hardware monitor library.
*/


// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the LM81_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// LM81_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.

#ifdef __cplusplus
extern "C" {
#endif

#ifdef LM81_EXPORTS
#define LM81_API __declspec(dllexport)
#else
#define LM81_API __declspec(dllimport)
#endif

/*******************************************************************************
*
* lm81SmbInit - initialize the LM81 ACPI hardware monitor library
*
* This routine initializes the LM81 library and attaches the device to the
* SMBus host controller of the carrier board.
*
* PARAMETERS: This routine requires the following parameter
*
* SmbAddr		valid LM81 SM bus address
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*			ERROR_GEN_FAILURE				LM81 system management init failed
*			ERROR_IO_DEVICE					SMbus not accessable
*			other							see definition of CreateFile()
*/

LM81_API DWORD Lm81Init(
 						   UCHAR  SmbAddr	/* SMBus address */
						);

/*******************************************************************************
*
* lm81SmbDeInit - deinitialize the LM81 device
*
* This routine initializes the LM81 device
*
* PARAMETERS: This routine requires the following parameter
*
* SmbAddr		valid LM81 SM bus address
*
* RETURNS: nothing
*/

LM81_API DWORD Lm81DeInit(
 						   UCHAR  SmbAddr	/* SMBus address */
						);

/*******************************************************************************
*
* lm81DacSet - set the DAC output value
*
* This routine sets the DAC output value.
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM81 SM bus address
* Value			digital value of output voltage
*
* NOTE: Calculate the output voltage with 'voltage = <Value> * 4.88 mV'
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											value out of range
*			ERROR_IO_DEVICE					SMbus not accessable
*/

LM81_API DWORD Lm81DacSet (
						   UCHAR  SmbAddr,	/* SMBus address */
						   UCHAR  Value	/* value to set */
);

/*******************************************************************************
*
* lm81FanCountGet - get the count measured for a FAN
*
* This routine gets the count measured either for FAN1 or for FAN2.
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM81 SM bus address
* Fan			fan number (refer to definitions for fan handling)
* pCount		ptr to location where the count value will be stored
*
* NOTE: Calculate the fan speed with 'RPM = 1.35 * 10e6 / <pCount> * <divisor>'
* 
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											invalid fan 
*/

LM81_API DWORD Lm81FanCountGet (
								UCHAR  SmbAddr,	/* SMBus address */
								UCHAR  Fan,		/* desired fan */
								PUCHAR pCount	/* location to store the count */
								);

/*******************************************************************************
*
* lm81FanDivisorGet - get the divisor for FAN speed measurement
*
* This routine gets the divisor for the FAN speed measurement either for FAN1
* or for FAN2.
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM81 SM bus address
* Fan			fan number (refer to definitions for fan handling)
* pDivisor		ptr to location where the divisor value will be stored
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											invalid fan 
*			ERROR_IO_DEVICE					SMbus not accessable
*
* NOTE: For more information about <pDivisor> settings refer to definitions
* for fan handling inside lm81_hw.h
*/

LM81_API DWORD Lm81FanDivisorGet (
								UCHAR  SmbAddr,	/* SMBus address */
								UCHAR  Fan,		/* desired fan */
								PUCHAR pDivisor	/* location to store the divisor */
								);

/*******************************************************************************
*
* lm81FanDivisorSet - set the divisor for FAN speed measurement
*
* This routine sets the divisor for the FAN speed measurement either for FAN1
* or for FAN2.
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM81 SM bus address
* Fan			fan number (refer to definitions for fan handling)
* Divisor		divisor value
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											invalid fan
*											invalid divisor
*			ERROR_IO_DEVICE					SMbus not accessable
*
* NOTE: For more information about <divisor> settings refer to definitions
* for fan handling inside lm81_hw.h
*/

LM81_API DWORD Lm81FanDivisorSet (
								UCHAR  SmbAddr,	/* SMBus address */
								UCHAR  Fan,		/* desired fan */
								UCHAR  Divisor	/* divisor to set */
								);

/*******************************************************************************
*
* lm81FanLimitGet - get the count limit for a FAN
*
* This routine gets the count limit either for FAN1 or for FAN2.
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM81 SM bus address
* Fan			fan number (refer to definitions for fan handling)
* pLimit		ptr to location where the fan limit value will be stored
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											invalid fan 
*			ERROR_IO_DEVICE					SMbus not accessable
*
*
* NOTE: Calculate the fan speed with 'RPM = 1.35 * 1e6 / <pLimit> * <divisor>'
*
*/

LM81_API DWORD Lm81FanLimitGet (
								UCHAR  SmbAddr,	/* SMBus address */
								UCHAR  fan,		/* desired fan */
								PUCHAR pLimit	/* location to store the limit */
								);

/*******************************************************************************
*
* lm81FanLimitSet - set the count limit for a FAN
*
* This routine sets the count limit either for FAN1 or for FAN2.
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM81 SM bus address
* Fan			fan number (refer to definitions for fan handling)
* Limit			fan limit (0-255)
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											invalid fan 
*			ERROR_IO_DEVICE					SMbus not accessable
*
* NOTE: Calculate the <limit> with '<limit> = 1.35 * 10e6 / RPM * <divisor>'
*/

LM81_API DWORD Lm81FanLimitSet (
								UCHAR  SmbAddr,	/* SMBus address */
								UCHAR  fan,		/* desired fan */
								UCHAR  limit	/* limit to set */
								);

/*******************************************************************************
*
* lm81StatusGet - get the LM81 interrupt status registers
*
* This routine gets the interrupt status registers of the LM81, which indicate
* whether a WATCHDOG limit is exceeded.
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM81 SM bus address
* pIrqStatus1	ptr to location where the content of the interrupt status 
*				register 1 will be stored
* pIrqStatus2	ptr to location where the content of the interrupt status
*				register 2 will be stored
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*			ERROR_IO_DEVICE					SMbus not accessable
*
* NOTE: The relation of WATCHDOG limits and interrupt status register bits is
* depicted in the table below.
* 
* limit       | |  interrupt status register 1 | | interrupt status register 2
* ------------|-|------------------------------|-|----------------------------
* voltage     | |  LM81_ISR1_V1                | | LM81_ISR2_V5
*             | |  LM81_ISR1_V2                | | LM81_ISR2_V6
*             | |  LM81_ISR1_V3                | |
*             | |  LM81_ISR1_V4                | |
* temperature | |  LM81_ISR1_TEMP1             | | LM81_ISR2_TLOW
* fan speed   | |  LM81_ISR1_FAN1              | |
*             | |  LM81_ISR1_FAN2              | |
*
*/

LM81_API DWORD Lm81StatusGet (
								UCHAR  SmbAddr,		/* LM81 SMBus address */
								PUCHAR pIrqStatus1,	/* value read from the interrupt status register 1 */
								PUCHAR pIrqStatus2	/* value read from the interrupt status register 2 */
							);

/*******************************************************************************
*
* lm81TempGet - get the LM81 local temperature
*
* This routine gets the local temperature of the LM81. The data format is 7 bits
* plus sign, with each bit corresponding to 1°C, in twos-complement format. 
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM81 SM bus address
* pTemperature	ptr to location where the temperature value will be stored
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*/

LM81_API DWORD Lm81TempGet (
								UCHAR  SmbAddr,		/* SMBus address */
								PCHAR pTemperature	/* location to store the temperature */
								);

/*******************************************************************************
*
* lm81TempLimitGet - get the limit for the LM81 local temperature
*
* This routine reads the limit for the LM81 local temperature. The data 
* format is 7 bits plus sign, with each bit corresponding to 1°C, in
* twos-complement format.
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM81 SM bus address
* Setpoint		desired limit ( upper or lower )
* pLimit		ptr to location where the limit value will be stored
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											invalid setpoint
*			ERROR_IO_DEVICE					SMbus not accessable
*
* NOTE: For settings of setpoint refer to defintions to select thresholds inside
* lm81_hw.h
*/

LM81_API DWORD Lm81TempLimitGet (
								UCHAR  SmbAddr,		/* SMBus address */
								UCHAR  Setpoint,	/* desired limit */
								PCHAR  pLimit		/* location to store the limit */
								);

/*******************************************************************************
*
* lm81TempLimitSet - set the limit for the LM81 local temperature
*
* This routine sets the limit for the LM81 local temperature. The data 
* format is 7 bits plus sign, with each bit corresponding to 1°C, in
* twos-complement format.
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM81 SM bus address
* Setpoint		desired limit ( upper or lower )
* Limit			limit value
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											invalid setpoint
*			ERROR_IO_DEVICE					SMbus not accessable
*
* NOTE: For settings of setpoint refer to defintions to select thresholds inside
* lm81_hw.h
*
* RETURNS: OK, or ERROR
*
*/

LM81_API DWORD Lm81TempLimitSet (
								UCHAR  SmbAddr,		/* SMBus address */
								UCHAR  setpoint,	/* desired setpoint */
								CHAR   limit		/* limit to set */
								);

/*******************************************************************************
*
* lm81VidGet - get the CPU operation voltage
*
* This routine gets the CPU operating voltage determined by the VID (voltage
* identifier) pins.
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM81 SM bus address
* pVid			ptr to the location where the VID pin status will be stored
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*			ERROR_IO_DEVICE					SMbus not accessable
*/

LM81_API DWORD Lm81VidGet (
								UCHAR  SmbAddr,		/* SMBus address */
								UCHAR* pVid			/* location to store the VID pin status */
								);

/*******************************************************************************
*
* lm81VoltGet - get the measured power supply voltage
*
* This routine gets the voltage measured at one of the six analog input pins.
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM81 SM bus address
* Voltage		desired voltage sensor
* pVoltage		ptr to the location where the voltage value will be stored
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											invalid Voltage sensor
*
* NOTE: For the relation of <voltage> to the voltages measured on the different
* PEP carrier boards please refer to the overall description of the library. A
* digital reading can be converted to a voltage by simply multiplying the
* decimal value of the reading by the LSB size.
* For settings of <Voltage> refer to definitions for voltage handling inside
* lm81_hw.h
*/

LM81_API DWORD Lm81VoltGet (
								UCHAR  SmbAddr,		/* SMBus address */
								UCHAR  Voltage,		/* desired voltage sensor */
								PUCHAR pVoltage		/* location to store the voltage */
								);

/*******************************************************************************
*
* lm81VoltLimitGet - get the high limit for a power supply voltage
*
* This routine gets the WATCHDOG limit for a voltage measured at one of the six
* analog input pins.
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM81 SM bus address
* Voltage		desired voltage sensor
* Threshold		desired threshold
* pLimit		ptr to location where the limit value will be stored
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											invalid Voltage sensor
*											invalid threshold
*			ERROR_IO_DEVICE					SMbus not accessable
*
* NOTE: For the relation of <voltage> to the voltages measured on the different
* PEP carrier boards please refer to the overall description of the library. A
* digital reading can be converted to a voltage by simply multiplying the
* decimal value of the reading by the LSB size.
* NOTE: For settings of threshold refer to defintions to select thresholds inside
* lm81_hw.h
* NOTE: For settings of voltage refer to definitions for voltage handling inside
* lm81_hw.h
*/

LM81_API DWORD Lm81VoltLimitGet (
								UCHAR  SmbAddr,		/* SMBus address */
								UCHAR  Voltage,		/* desired voltage sensor*/
								UCHAR  Threshold,	/* desired threshold */
								PUCHAR pLimit		/* location to store the limit */
								);

/*******************************************************************************
*
* lm81VoltLimitSet - set the high limit for a power supply voltage
*
* This routine sets the WATCHDOG limit for a voltage measured at one of the six
* analog input pins.
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM81 SM bus address
* Voltage		desired voltage sensor
* Threshold		desired threshold
* Limit			limit value
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											invalid Voltage sensor
*											invalid threshold
*											invalid limit
*			ERROR_IO_DEVICE					SMbus not accessable
*
* NOTE: For the relation of <voltage> to the voltages measured on the different
* PEP carrier boards please refer to the overall description of the library. A 
* <limit> value can be calculated by simply dividing the decimal voltage value
* by the LSB size.
* NOTE: For settings of threshold refer to defintions to select thresholds inside
* lm81_hw.h
* NOTE: For settings of voltage refer to definitions for voltage handling inside
* lm81_hw.h
*/

LM81_API DWORD Lm81VoltLimitSet (
								UCHAR  SmbAddr,		/* SMBus address */
								UCHAR  Voltage,		/* desired voltage */
								UCHAR  Threshold,	/* desired threshold */
								CHAR  Limit		/* limit to set */
								);


#ifdef __cplusplus
}
#endif

