
#ifndef API_H
#define API_H

#define AllArgs ...


#ifdef __cplusplus
extern "C" {
#endif

#pragma pack (push,1)   


#ifdef linux

	#ifdef __LP64__
	
		#define __cdecl
	#else
	
		#define __cdecl   __attribute__((cdecl))
	#endif
	

#endif

#ifdef  _X86_

//	#pragma message "32-bit"
	#define KTAPI_32

#elif  _M_IX86

//	#pragma message "32-bit"
	#define KTAPI_32

#elif defined(__i386__)

//	#pragma message "32-bit"
	#define KTAPI_32
	
#elif defined(__x86_64__)
//	#pragma message "64-bit"
	#define KTAPI_64
#elif  _M_AMD64
//	#pragma message "64-bit"
	#define KTAPI_64

#else
	#error "Can't detect 32/64 compile"
#endif


extern char OS_String[0x100];

extern int  ( __cdecl *KT_API_Proc)(int Function, AllArgs );
extern void (__cdecl *Proc_DebugOut)(char * Text);

typedef int  ( __cdecl *_KT_API_Proc)(int Function, AllArgs );

typedef enum
{

_API_cbe_MEM_Allocate=0,
_API_cbe_MEM_Free,

_API_cbe_MSG,

_API_cbe_Phys_MEM_Map,
_API_cbe_Phys_MEM_Unmap,

_API_cbe_IO_Block,

_API_cbe_Microsecond_Delay,
_API_cbe_CPUID,
_API_cbe_Write_MSR,
_API_cbe_Read_MSR,

}_API_CallBackEnum;

typedef enum
{
_API_iob_END=0,

_API_iob_ADD=1,
_API_iob_AND=2,
_API_iob_OR=3,
_API_iob_XOR=4,
_API_iob_SHL=5,     // <<
_API_iob_SHR=6,     // >>


_API_iob_Set_Port_Pointer=7,
_API_iob_Set_Data_Pointer=8,
_API_iob_Set_Data=9,


_API_iob_Copy=10,

_API_iob_IO_Read_Byte=11,
_API_iob_IO_Read_Word=12,
_API_iob_IO_Read_Dword=13,

_API_iob_IO_Write_Byte=14,
_API_iob_IO_Write_Word=15,
_API_iob_IO_Write_Dword=16,


_API_iob_IO_Delay=17,



}_API_IO_Block_Command;

typedef struct
{
unsigned int Command;
unsigned int Data;
}_API_IO_Struct;


typedef struct
{
unsigned int _EAX;
unsigned int _EBX;
unsigned int _ECX;
unsigned int _EDX;
}_API_ASM_REGS_Struct;


typedef struct
{
unsigned long long Function;
unsigned long long Arg1;
unsigned long long Arg2;
unsigned long long Return;

}_API_Callback;

/*
typedef struct
{
unsigned __int64 Function;
unsigned __int64 Arg1;
unsigned __int64 Arg2;
unsigned __int64 Return;

}_API_Callback;
*/

typedef struct
{
unsigned int Magic[2];
unsigned int Size;
unsigned int PSize;
unsigned int VersionMajor;
unsigned int VersionMinor;
unsigned int Build;
unsigned int Type;
unsigned int Entry;
}_API_;

extern _API_ * KT_API;


typedef enum
{
_API_fe_Init=0,
_API_fe_Deinit,
_API_fe_GetFunction,
}_API_FunctionsEnum;

typedef enum
{
_API_se_OK=1,
_API_se_Error=0,
}_API_StatusEnum;

extern void * Internal_API;

extern unsigned int KTAPI_Location;


#define sfNewest 0x00	//	Check BIOS and disk for the newest version and load it. 
#define sfBIOS 0x01		//	Only load driver from BIOS.
#define sfDISK 0x02		//	Only load driver from DISK.
#define sfInternal 0x03

int KT_API_Init(_API_ * API);


#ifndef _lib_

int KT_API_GetFunction(char * Name,void *pFunction);

int KT_API_Open(int sf);

int KT_API_Close(void);

#else

int _KT_API_GetFunction(char * Name,void *pFunction);

int _KT_API_Open(int sf);

int _KT_API_Close(void);


#endif // _lib_


//----------------------------------------------


typedef struct
{
unsigned char Magicscan[4];
unsigned char Infosize;
unsigned char Boardinfo;
unsigned short BIOSmjr;
unsigned short BIOSmnr;
unsigned char Reserved;
unsigned char S_N[4];
unsigned char P_N[4];
}TIntegratedInfoHeader,*pTIntegratedInfoHeader;


typedef struct _HWMON
{
   float VCORE;
   float VCOREb;
   float VCC2_5;
   float VCC3;
   float VCC5;
   float V12;
   float SB3;
   float V_12;
   float SB5;
   float VBATT;
   float CPUTemp;
   float FAN;
   float BoardTemp;
   float Reserved1;
   float Reserved2;
   float Reserved3;
   float Reserved4;
   float Reserved5;
   float Reserved6;

} HWMON;
              
              
                    
                    


#define Manual_Mode 0x00
#define Thermal_Cruise_Mode 0x01
#define Fan_Speed_Cruise_Mode 0x02

typedef int (__cdecl *tKT_API_Open)(int sf);
typedef int (__cdecl *tKT_API_Close)(void);
typedef int (__cdecl *tGet_KT_API)(_API_ * * ptr);
typedef int (__cdecl *tKT_API_Get_OS_String)(char **Text);


typedef int (__cdecl *tInternalTest)(void);


typedef int (__cdecl *tReadMonitor)(HWMON *);

typedef int (__cdecl *tReadBoardHeader)(void * Buffer);

typedef int (__cdecl *tGetBoardName)(char * * Name);

typedef int (__cdecl *tGetSerialNumber)(char * * Number);
typedef int (__cdecl *tGetPartNumber)(char * * Number);

typedef int (__cdecl *tSetFanSpeed)(unsigned int Speed);
typedef int (__cdecl *tSelectFanTempTacChannel)(unsigned char Channel);
typedef int (__cdecl *tSetFanTarget)(unsigned int uiStt);
typedef int (__cdecl *tSetFanMode)(unsigned char ucSfm);

typedef int (__cdecl *tStartThermalCruise)(void);

typedef int (__cdecl *tGetIntruderStatus)(unsigned int *Status);

typedef int (__cdecl *tClrIntruderStatus)(void);


typedef int (__cdecl *tSmBus_RecvByte)(unsigned char ucDevAddr,unsigned char *ucpData);
typedef int (__cdecl *tSmBus_ReadByte)(unsigned char ucDevAddr,unsigned char ucCommandCode,unsigned char * ucpData);
typedef int (__cdecl *tSmBus_ReadWord)(unsigned char ucDevAddr,unsigned char ucCommandCode,unsigned short *uspData);
typedef int (__cdecl *tSmBus_ReadBlock)(unsigned char ucDevAddr,unsigned char ucCommandCode,unsigned char * ucpByteCnt,unsigned char *ucpDataBuf);
typedef int (__cdecl *tSmBus_ReadBytes)(unsigned char ucDevAddr,unsigned char ucCommandCode,unsigned int uiByteCnt,unsigned char *ucpDataBuf);

typedef int (__cdecl *tSmBus_SendByte)(unsigned char ucDevAddr,unsigned char ucCommandCode);
typedef int (__cdecl *tSmBus_WriteByte)(unsigned char ucDevAddr,unsigned char ucCommandCode,unsigned char usData);
typedef int (__cdecl *tSmBus_WriteWord)(unsigned char ucDevAddr,unsigned char ucCommandCode,unsigned short usData);
typedef int (__cdecl *tSmBus_WriteBlock)(unsigned char ucDevAddr,unsigned char ucCommandCode,unsigned char ucByteCnt,unsigned char *ucpDataBuf);
                                                                                                                        
typedef int (__cdecl *tSmBus_PorcessCall)(unsigned char ucDevAddr,unsigned char ucCommandCode,unsigned short *uspData);



typedef int (__cdecl *tSetClrGPIO)(unsigned char GPIO,int SetClr);

typedef int (__cdecl *tReadGPIO)(unsigned char GPIO,unsigned char *Data);
typedef int (__cdecl *tWriteGPIO)(unsigned char GPIO,unsigned char Data);

typedef int (__cdecl *tReadGPIOEvent)(unsigned char *Data);

typedef int (__cdecl *tSetGPIODir)(unsigned char GPIO);


typedef int (__cdecl *tGetMac)(unsigned char nMac,void * Buffer);  

typedef int (__cdecl *tSetWDTimer)(unsigned char Time);
typedef int (__cdecl *tSetWDTimerInterval)(unsigned char VAL);

typedef int (__cdecl *tEnableWD)(void);
typedef int (__cdecl *tDisableWD)(void);

typedef int (__cdecl *tSetBKLControl)(unsigned int Freq,unsigned int Duty);
typedef int (__cdecl *tSetCPUThrottle)(unsigned char DUTY);




#define _sec   0x01
#define _min   0x02

#define C12_PROCENT_THROTTLE  0x12
#define C25_PROCENT_THROTTLE  0x14
#define C37_PROCENT_THROTTLE  0x16
#define C50_PROCENT_THROTTLE  0x18
#define C62_PROCENT_THROTTLE  0x1A
#define C75_PROCENT_THROTTLE  0x1C
#define C87_PROCENT_THROTTLE  0x1E
#define C100_PROCENT_THROTTLE 0x10
#define DISABLE_THROTTLE      0x00

typedef enum
{         
_HWM_Last=0x0000,	
_HWM_VCORE=0x0001,
_HWM_VCOREb=0x0002,
_HWM_VCC2_5=0x0003,
_HWM_VCC3=0x0004,
_HWM_VCC5=0x0005,
_HWM_V12=0x0006,
_HWM_SB3=0x0007,
_HWM_V_12=0x0008,
_HWM_SB5=0x0009,
_HWM_VBATT=0x000a,
_HWM_VCC1_2=0x000b,
_HWM_VCC1_8=0x000c,
_HWM_VIN=0x000d,
_HWM_VCC1_5=0x000e, 
_HWM_VCC_DDR=0x000f, 
_HWM_VCC1_05=0x0010,
_HWM_AUX=0x0011,
_HWM_CPU_PWR=0x0012,


_HWM_CPU_Temp=0x1001,
_HWM_System_Temp=0x1002,
_HWM_FC_Temp=0x1003,

_HWM_CPU_Fan=0x2001,
_HWM_System_Fan=0x2002,
_HWM_FC_Fan=0x2003,
_HWM_FC_Fan2=0x2004,


_HWM_CPU_Power=0x3001,
                    
_HWM_Type_Mask=0xf000,
_HWM_Type_Voltage=0x0000,
_HWM_Type_Temperature=0x1000,
_HWM_Type_Fan=0x2000,
_HWM_Type_Power=0x3000,
                    
}_HWM_ID;

#pragma pack (8)   

typedef struct
{             
_HWM_ID ID;
float Value;
char * Name;	
}_HWM_Item,*_pHWM_Item;

#pragma pack(pop)   

typedef int (__cdecl *tReadHWMonitorItems)(_pHWM_Item * Items);
typedef int (__cdecl *tGetHWMonitorItem)(_HWM_ID ID,float * Value);


typedef int (__cdecl *tGetGPIOConfig)(unsigned int Index,unsigned int * Config);
typedef int (__cdecl *tSetGPIOConfig)(unsigned int Index,unsigned int Config);

typedef int (__cdecl *tGetGPIOValue)(unsigned int Index,unsigned int * Value);
typedef int (__cdecl *tSetGPIOValue)(unsigned int Index,unsigned int Value);

typedef int (__cdecl *tGetGPIOCap)(unsigned int Index,unsigned int * Value);

typedef enum
{
eGPIO_Input		=	0x0000,
eGPIO_Output	=	0x0001,
eGPIO_PWM		=	0x0002,
eGPIO_ADC		=	0x0003,
eGPIO_DAC		=	0x0004,
eGPIO_Timer		=	0x0005,
eGPIO_Invalid	=	0x00ff,
eGPIO_TypeMask	=	0x00ff,

// Flags
eGPIO_Pullup	=	0x0100,
eGPIO_Pulldown	=	0x0200,
eGPIO_FlagMask	=	0xffffff00

}eGPIO_Config;

typedef enum
{
eGPIO_Cap_Input		=	0x0001,
eGPIO_Cap_Output	=	0x0002,
eGPIO_Cap_PWM		=	0x0004,
eGPIO_Cap_ADC		=	0x0008,
eGPIO_Cap_DAC		=	0x0010,
eGPIO_Cap_Timer		=	0x0020,

eGPIO_Cap_Pullup	=	0x0100,
eGPIO_Cap_Pulldown	=	0x0200,

}eGPIO_Caps;

#ifdef __cplusplus
}
#endif

#endif //API_H


