#pragma once

// Predefined Constants for Device Index
#define diNONE 0xFFFFFFFF  // "-1"
#define diFIRST 0xFFFFFFFE // "-2" First board
#define diONLY 0xFFFFFFFD  // "-3" One and only board

// Watchdog Function Constants
#define WDG_ACTION_IGNORE 0
#define WDG_ACTION_DISABLE 1
#define WDG_ACTION_SOFT_RESTART 2
#define WDG_ACTION_MOSTLY_SOFT_RESTART 4
#define PCI_WDG_CSM_RATE 2.08333
#define P104_WDG_CSM_RATE 2.08333
#define ISA_WDG_CSM_RATE 0.894886

// BAR constants
#define BAR0 0x80
#define BAR1 0x81
#define BAR2 0x82
#define BAR3 0x83
#define BAR4 0x84
#define BAR5 0x85

// DAC Range Constants
#define rcNO_CHANGE 0xFFFFFFFF
#define rcUNIPOLAR10 0x30313055  // "U010"
#define rcUNIPOLAR5 0x35303055   // "U005"
#define rcBIPOLAR10 0x3031E142   // "Bħ10"
#define rcBIPOLAR5 0x3530E142    // "Bħ05"
#define rcBIPOLAR2_5 0xBD32E142  // "Bħ2½"
#define rcCURRENT420 0x30323449  // "I420"
#define rcCURRENT020 0x30323049  // "I020"
#define rcCURRENT024 0x34323049  // "I024"
#define rcCODE0 0
#define rcCODE1 1
#define rcCODE2 2
#define rcCODE3 3
#define rcCODE4 4
#define rcCODE5 5
#define rcCODE6 6
#define rcCODE7 7
#define rcCODE8 8
#define rcCODE9 9
#define rcCODE10 10

// Additional Constants
#define bUPDATE 1
#define bSIMULTANEOUS 1
#define bRESTRICTED 1

#ifdef __cplusplus
extern "C" {
#endif

__declspec(dllimport) signed long GetNumCards(void);
__declspec(dllimport) unsigned long QueryCardInfo(long CardNum, unsigned long *pDeviceID, unsigned long *pBase, unsigned long *pNameSize, unsigned char *pName);
__declspec(dllimport) unsigned long QueryBARBase(long CardNum, unsigned long BARIndex, unsigned long *pBase);
__declspec(dllimport) unsigned long WaitForIRQ(long CardNum);
__declspec(dllimport) unsigned long AbortRequest(long CardNum);
__declspec(dllimport) unsigned long CloseCard(long CardNum);
__declspec(dllimport) unsigned long COSWaitForIRQ(long CardNum, unsigned long PPIs, void *pData);
__declspec(dllimport) unsigned long SetCOSScheme(long CardNum, unsigned long COSScheme);
__declspec(dllimport) unsigned long PollForIRQ(long CardNum);
__declspec(dllimport) unsigned long WDGInit(long CardNum);
__declspec(dllimport) unsigned long WDGHandleIRQ(long CardNum, unsigned long Action);
__declspec(dllimport) double WDGSetTimeout(long CardNum, double Milliseconds, double MHzClockRate);
__declspec(dllimport) double WDGSetResetDuration(long CardNum, double Milliseconds, double MHzClockRate);
__declspec(dllimport) unsigned long WDGPet(long CardNum);
__declspec(dllimport) double WDGReadTemp(long CardNum);
__declspec(dllimport) unsigned long WDGReadStatus(long CardNum);
__declspec(dllimport) unsigned long WDGStart(long CardNum);
__declspec(dllimport) unsigned long WDGStop(long CardNum);
__declspec(dllimport) unsigned long EmergencyReboot(void);


__declspec(dllimport) unsigned short RelInPortB      (long CardNum, unsigned long Port);
__declspec(dllimport) unsigned short RelOutPortB     (long CardNum, unsigned long Port, unsigned char Value);
__declspec(dllimport) unsigned char InBAR8(long CardNum, unsigned char BAR, unsigned long Offset);
__declspec(dllimport) unsigned char OutBAR8(long CardNum, unsigned char BAR, unsigned long Offset, unsigned char Value);
__declspec(dllimport) unsigned long  RelINSB         (long CardNum, unsigned long Offset, unsigned long Count, unsigned char * pBuf);

__declspec(dllimport) unsigned short RelInPort       (long CardNum, unsigned long Port);
__declspec(dllimport) unsigned short RelOutPort      (long CardNum, unsigned long Port, unsigned short Value);
__declspec(dllimport) unsigned short InBAR16(long CardNum, unsigned char BAR, unsigned long Offset);
__declspec(dllimport) unsigned short OutBAR16(long CardNum, unsigned char BAR, unsigned long Offset, unsigned short Value);
__declspec(dllimport) unsigned long  RelINSW         (long CardNum, unsigned long Offset, unsigned long Count, unsigned short * pBuf);

__declspec(dllimport) unsigned long  RelInPortL      (long CardNum, unsigned long Port);
__declspec(dllimport) unsigned short RelOutPortL     (long CardNum, unsigned long Port, unsigned long Value);
__declspec(dllimport) unsigned long InBAR32(long CardNum, unsigned char BAR, unsigned long Offset);
__declspec(dllimport) unsigned long OutBAR32(long CardNum, unsigned char BAR, unsigned long Offset, unsigned long Value);
__declspec(dllimport) unsigned long  RelINSL         (long CardNum, unsigned long Offset, unsigned long Count, unsigned long  * pBuf);
__declspec(dllimport) unsigned long  RelInPortDWord  (long CardNum, unsigned long Port);
__declspec(dllimport) unsigned short RelOutPortDWord (long CardNum, unsigned long Port, unsigned long Value);

__declspec(dllimport) unsigned short InPortB         (              unsigned long Port);
__declspec(dllimport) unsigned short OutPortB        (              unsigned long Port, unsigned char Value);
__declspec(dllimport) unsigned long  INSB            (              unsigned long Addr, unsigned long Count, unsigned char * pBuf);

__declspec(dllimport) unsigned short InPort          (              unsigned long Port);
__declspec(dllimport) unsigned short OutPort         (              unsigned long Port, unsigned short Value);
__declspec(dllimport) unsigned long  INSW            (              unsigned long Addr, unsigned long Count, unsigned short * pBuf);

__declspec(dllimport) unsigned long  InPortL         (              unsigned long Port);
__declspec(dllimport) unsigned short OutPortL        (              unsigned long Port, unsigned long Value);
__declspec(dllimport) unsigned long  INSL            (              unsigned long Addr, unsigned long Count, unsigned long  * pBuf);
__declspec(dllimport) unsigned long  InPortDWord     (              unsigned long Port);
__declspec(dllimport) unsigned short OutPortDWord    (              unsigned long Port, unsigned long Value);

__declspec(dllimport) unsigned long DAC_GetNumDacs(long CardNum, unsigned * numDacs);
__declspec(dllimport) unsigned long DAC_GetMaxCounts(long CardNum, unsigned long * maxCounts);
__declspec(dllimport) unsigned long DAC_Output(long CardNum, unsigned short iDac, double Value);
__declspec(dllimport) unsigned long DAC_Outputs(long CardNum, unsigned short NumValues, double * Values);
__declspec(dllimport) unsigned long DAC_SetRange(long CardNum, unsigned short iDac, unsigned long RangeCode);
__declspec(dllimport) unsigned long DAC_SetRanges(long CardNum, unsigned short numRangeCodes, unsigned long * RangeCodes);
__declspec(dllimport) unsigned long DAC_GetRange(long CardNum, unsigned short iDac, unsigned long * RangeCode);
__declspec(dllimport) unsigned long DAC_GetRanges(long CardNum, unsigned show *pNumRangeCodes, unsigned long * RangeCodes);
__declspec(dllimport) unsigned long DAC_ValueFromCounts(long CardNum, unsigned short iDac, unsigned long Counts, double *Value);
__declspec(dllimport) unsigned long DAC_OutputCount(long CardNum, unsigned short iDac, unsigned long Counts);
__declspec(dllimport) unsigned long DAC_OutputCounts(long CardNum, unsigned short numCounts, unsigned long *Counts);
__declspec(dllimport) unsigned long DAC_ReloadCalibrationData(long CardNum);
__declspec(dllimport) unsigned long DAC_EnableCalibration(long CardNum, unsigned short Enable /* 1 | 0 */);
__declspec(dllimport) unsigned long DAC_GetCalibrationData(long CardNum, unsigned short * pBufLength, void *pBuf);
__declspec(dllimport) unsigned long DAC_WriteCalibrationData(long CardNum, unsigned short * pBufLength, void * pBuf, bToEEPROM unsigned short);
__declspec(dllimport) unsigned long DAC_ConfigureSimultaneousMode(long CardNum, long bSimultaneous, long bUpdate);
__declspec(dllimport) unsigned long DAC_ConfigureVoltageRestrictMode(long CardNum, long bRestricted);

__declspec(dllimport) unsigned long DIF_ConfigurePulseClock(long CardNum, double* clockHz);
__declspec(dllimport) unsigned long DIF_Measure(long CardNum, uint32_t iBit, double* loSide, double* hiSide, double* dutyCycle, double* frequency);
__declspec(dllimport) unsigned long DIF_Generate(long CardNum, uint32_t iBit, double activeSide, double inactiveSide, uint16_t pulseCount);
__declspec(dllimport) unsigned long DIF_ConfigureGeneration(long CardNum, uint32_t iBit, double activeSide, double inactiveSide, uint16_t pulseCount);
__declspec(dllimport) unsigned long DIF_ConfigureCounting(long CardNum, uint32_t iBit, bool countFalling, bool countRising);
__declspec(dllimport) unsigned long DIF_Count(long CardNum, uint32_t iBit, uint32_t* count);
__declspec(dllimport) unsigned long DIF_CountOverflowIRQEnable(long CardNum, uint32_t iBit, bool enabled);
__declspec(dllimport) unsigned long DIF_IRQEdgeEnable(long CardNum, uint32_t iBit, bool fallingIRQ, bool risingIRQ);


#ifdef __cplusplus
}
#endif
