
// 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 LM87_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 
// LM87_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 LM87_EXPORTS
#define LM87_API __declspec(dllexport)
#else
#define LM87_API __declspec(dllimport)
#endif

#include <windows.h>

/*******************************************************************************
*
* function type definition for callback routine required for Lm87RegisterAlert()
*
*/ 
typedef VOID (*ftNotifyFunc)(UCHAR SmbAddr, UCHAR IrqStatus1, UCHAR IrqStatus2);

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

LM87_API DWORD Lm87Init(
 						   UCHAR  SmbAddr	/* SMBus address */
						);

/*******************************************************************************
*
* LM87SmbDeInit - deinitialize the LM87 device
*
* This routine initializes the LM87 device
*
* PARAMETERS: This routine requires the following parameter
*
* SmbAddr		valid LM87 SM bus address
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*			other							see definition of DeviceIoControl(),
*                                           CancleIo(), CloseHandle()
*/

LM87_API DWORD Lm87DeInit(
 						   UCHAR  SmbAddr	/* SMBus address */
						);

/*******************************************************************************
*
* Lm87GetAlertEvents - gets alarm notification configuration of LM87 device
*
* This routine returns settings of alertable events
* NOTE: Use interrupt mask register bits out of lm87_hw.h to evaluate contents 
*       of event parameters. Set bits inside event parameters represents active
*       alerts.
*
* PARAMETERS: This routine requires the following parameter
*
* UCHAR SmbAddr				must be set to a valid LM87 SM bus address
* PUCHAR pEvents1			ptr to location to store first 8 events
* PUCHAR pEvents2			ptr to location to store second 8 events
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											ToBeInformed not valid
*			ERROR_NOT_READY					device not initialized
*			ERROR_IO_DEVICE					SMbus not accessable
*			other							see definition of DeviceIoControl()
*
*/

LM87_API DWORD Lm87GetAlertEvents(
	UCHAR  SmbAddr,		/* SMBus address */
	PUCHAR pEvents1,	/* first event register */
	PUCHAR pEvents2		/* second event register */
);

/*******************************************************************************
*
* Lm87SetAlertEvents - sets alarm notification configuration of LM87 device
*
* This routine configures alertable events
*
* NOTE: Use interrupt mask register bits out of lm87_hw.h file to define
*       events to be alerted. All events set inside event parameters are
*       enabled for alert watch!!!!
*
* PARAMETERS: This routine requires the following parameter
*
* UCHAR SmbAddr			must be set to a valid LM87 SM bus address
* UCHAR Events1			first 8 events
* UCHAR Events2			second 8 events
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											ToBeInformed not valid
*			ERROR_NOT_READY					device not initialized
*			ERROR_IO_DEVICE					SMbus not accessable
*			other							see definition of DeviceIoControl()
*
*/

LM87_API DWORD Lm87SetAlertEvents(
	UCHAR  SmbAddr,		/* SMBus address */
	UCHAR Events1,		/* first event register */
	UCHAR Events2		/* second event register */
);

/*******************************************************************************
*
* Lm87RegisterAlert - register to alarm notification list
*
* This routine enables the ALERT interrupt

* PARAMETERS: This routine requires the following parameter
*
* UCHAR SmbAddr					must be set to a valid LM87 SM bus address
* ftNotifyFunc ToBeInformed		ptr to a callback function to be called in case
*								of alert from this device
*								refer to definition of ftNotifyFunc
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											ToBeInformed not valid
*			ERROR_NOT_READY					device not initialized
*			ERROR_IO_DEVICE					SMbus not accessable
*			other							see definition of DeviceIoControl()
*
*/

LM87_API DWORD Lm87RegisterAlert(
	UCHAR  SmbAddr,				/* SMBus address */
	ftNotifyFunc ToBeInformed	/* callback function */
);

/*******************************************************************************
*
* Lm87DeRegisterAlert - deregister from alert notification list
*
* The device is prevented from generating alerts and afterwards it is removed
* from alert notification list
*
* PARAMETERS: This routine requires the following parameter
*
* UCHAR SmbAddr			must be set to a valid LM87 SM bus address
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*			ERROR_NOT_READY					device not initialized
*			ERROR_IO_DEVICE					SMbus not accessable
*			other							see definition of DeviceIoControl()
*
*/

LM87_API DWORD Lm87DeRegisterAlert(
	UCHAR  SmbAddr	/* SMBus address */
);

/*******************************************************************************
*
* LM87DacGet - get the DAC output value
*
* This routine gets the DAC output value.
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM87 SM bus address
* Value			ptr to location to store digital value of output voltage
*
* NOTE: Calculate the output voltage with 'voltage = <Value> * 9.80 mV'
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											value out of range
*			ERROR_IO_DEVICE					SMbus not accessable
*/

LM87_API DWORD Lm87DacGet (
						   UCHAR  SmbAddr,	/* SMBus address */
						   PUCHAR  Value	/* value to set */
);

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

LM87_API DWORD Lm87DacSet (
						   UCHAR  SmbAddr,	/* SMBus address */
						   UCHAR  Value		/* value to set */
);

/*******************************************************************************
*
* LM87FanCountGet - 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 LM87 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 * 1e+6 / (<pCount> * <divisor>)'
* 
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*											invalid fan 
*/

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

/*******************************************************************************
*
* LM87FanDivisorGet - 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 LM87 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 LM87_hw.h
*/

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

/*******************************************************************************
*
* LM87FanDivisorSet - 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 LM87 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 LM87_hw.h
*/

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

/*******************************************************************************
*
* lm87FanLimitGet - 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 LM87 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 * 1e+6 / (<pLimit> * <divisor>)'
*
*/

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

/*******************************************************************************
*
* lm87FanLimitSet - 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 LM87 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 * 1e+6 / RPM * <divisor>'
*/

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

/*******************************************************************************
*
* lm87StatusGet - get the LM87 interrupt status registers
*
* This routine gets the interrupt status registers of the LM87, which indicate
* whether a WATCHDOG limit is exceeded.
*
* PARAMETERS: This routine requires the following parameters
*
* SmbAddr		valid LM87 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     | |  LM87_ISR1_2V5               | | LM87_ISR2_12V
*             | |  LM87_ISR1_VCC1              | | LM87_ISR2_VCC2
*             | |  LM87_ISR1_3V3               | | 
*             | |  LM87_ISR1_5V                | |
* temperature | |  LM87_ISR1_INT_TEMP          | | LM87_ISR2_CI
*             | |  LM87_ISR1_RMT_TEMP          | | LM87_ISR2_TLOW
* fan speed   | |  LM87_ISR1_FAN1              | | LM87_ISR2_D1
*             | |  LM87_ISR1_FAN2              | | LM87_ISR2_D2
*
*/

LM87_API DWORD Lm87StatusGet (
							UCHAR  SmbAddr,		/* LM87 SMBus address */
							PUCHAR pIrqStatus1,	/* value read from the interrupt status register 1 */
							PUCHAR pIrqStatus2	/* value read from the interrupt status register 2 */
						);

/*******************************************************************************
*
* lm87TempGet - get the LM87 internal/remote temperature
*
* This routine gets internal/remote temperature of the LM87. 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 LM87 SM bus address
* TempLocation	must either be set to LM87_TEMP_INT or LM87_TEMP_RMT
* pTemperature	ptr to location where the temperature value will be stored
*
* RETURNS:	OK
*			ERROR_INVALID_PARAMETER			invalid SM bus address
*/

LM87_API DWORD Lm87TempGet (
								UCHAR  SmbAddr,		/* SMBus address */
								UCHAR  TempLocation, /* internal or remote temperature measurement */
								PCHAR pTemperature	/* location to store the temperature */
								);

/*******************************************************************************
*
* lm87TempLimitGet - get the limit for the LM87 internal/remote temperature
*
* This routine reads the limit for the LM87 internal/remote 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 LM87 SM bus address
* TempLocation	must either be set to LM87_TEMP_INT or LM87_TEMP_RMT
* 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
* lm87_hw.h
*/

LM87_API DWORD Lm87TempLimitGet (
								UCHAR  SmbAddr,		/* SMBus address */
								UCHAR  TempLocation, /* internal or remote temperature measurement */
								UCHAR  Setpoint,	/* desired limit */
								PCHAR  pLimit		/* location to store the limit */
								);

/*******************************************************************************
*
* lm87TempLimitSet - set the limit for the LM87 internal/remote temperature
*
* This routine sets the limit for the LM87 internal/remote 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 LM87 SM bus address
* TempLocation	must either be set to LM87_TEMP_INT or LM87_TEMP_RMT
* 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
* lm87_hw.h
*
* RETURNS: OK, or ERROR
*
*/

LM87_API DWORD Lm87TempLimitSet (
								UCHAR  SmbAddr,		/* SMBus address */
								UCHAR  TempLocation, /* internal or remote temperature measurement */
								UCHAR  setpoint,	/* desired setpoint */
								CHAR   limit		/* limit to set */
								);

/*******************************************************************************
*
* lm87VidGet - 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 LM87 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
*/

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

/*******************************************************************************
*
* lm87VoltGet - 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 LM87 SM bus address
* Sensor		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 <Sensor> refer to definitions for voltage handling inside
* lm87_hw.h
*/

LM87_API DWORD Lm87VoltGet (
								UCHAR  SmbAddr,		/* SMBus address */
								UCHAR  Sensor,		/* desired voltage sensor */
								PUCHAR pVoltage		/* location to store the voltage */
								);

/*******************************************************************************
*
* lm87VoltLimitGet - 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 LM87 SM bus address
* Sensor		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
* lm87_hw.h
* NOTE: For settings of Sensor refer to definitions for voltage handling inside
* lm87_hw.h
*/

LM87_API DWORD Lm87VoltLimitGet (
								UCHAR  SmbAddr,		/* SMBus address */
								UCHAR  Sensor,		/* desired voltage sensor*/
								UCHAR  Threshold,	/* desired threshold */
								PUCHAR pLimit		/* location to store the limit */
								);

/*******************************************************************************
*
* lm87VoltLimitSet - 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 LM87 SM bus address
* Sensor		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 <Sensor> 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
* lm87_hw.h
* NOTE: For settings of Sensor refer to definitions for voltage handling inside
* lm87_hw.h
*/

LM87_API DWORD Lm87VoltLimitSet (
								UCHAR  SmbAddr,		/* SMBus address */
								UCHAR  Sensor,		/* desired voltage */
								UCHAR  Threshold,	/* desired threshold */
								CHAR  Limit		/* limit to set */
								);

#ifdef __cplusplus
}
#endif

