//This code was developed under the
//ComLab2 Pilot Project
//
//Author: Bostjan Murovec
//Email: bostjan@lie.fe.uni-lj.si
//       bostjan.murovec@fe.uni-lj.si
//

#ifndef eProDas_H
#define eProDas_H

#ifdef eProDasDLL_EXPORTS
#define eProDasDLL_API __declspec(dllexport)
#else
#define eProDasDLL_API __declspec(dllimport)
#endif
typedef __int64 LONGLONG;

///////////////////////////////////////////////////////
//            eProDas Device Type Codes              //
///////////////////////////////////////////////////////

const int eProDas_DeviceType_Platform                          =   0;
const int eProDas_DeviceType_SingleChip1                       =   1;
const int eProDas_DeviceType_SingleChip2                       =   2;
const int eProDas_DeviceType_MultiFunction1                    =   3;

const int eProDas_DeviceType_Unspecified                       = 255;

///////////////////////////////////////////////////////
//               eProDas Error Codes                 //
///////////////////////////////////////////////////////

const int eProDas_Error_SUCCESS                                =  +0;

const int eProDas_Error_FailedToOpenHandle                     =  -1;
const int eProDas_Error_HandleAlreadyOpen                      =  -2;
const int eProDas_Error_FailedToCloseHandle                    =  -3;

const int eProDas_Error_InvalidDeviceIdx                       =  -4;

const int eProDas_Error_WriteToUSBFailed                       =  -5;
const int eProDas_Error_ReadFromUSBFailed                      =  -6;
const int eProDas_Error_InternalError                          =  -7;

const int eProDas_Error_UnimplementedFunctionality             =  -8;

const int eProDas_Error_InvalidMemoryBlock                     =  -9;
const int eProDas_Error_WriteToDataEEPROMFailed                = -10;
const int eProDas_Error_WriteToProgramFLASHFailed              = -11;

const int eProDas_Error_InvalidDeviceTag                       = -12;

const int eProDas_Error_UpgradeFirmwarePhaseOneFailed          = -13;
const int eProDas_Error_UpgradeFirmwarePhaseTwoFailed          = -14;

const int eProDas_Error_OpenFileFailed                         = -15;
const int eProDas_Error_ReadFromFileFailed                     = -16;
const int eProDas_Error_InvalidFileFormat                      = -17;

const int eProDas_Error_FirmwareTooBig                         = -18;

const int eProDas_Error_InvalidPortIndex                       = -19;

const int eProDas_Error_InvalidNumberOfADChannels              = -20;
const int eProDas_Error_InvalidAcquisitionTimeCode             = -21;

const int eProDas_Error_InvalidADChannel                       = -22;

const int eProDas_Error_InvalidComparatorMode                  = -23;

const int eProDas_Error_InvalidReferenceValue                  = -24;

const int eProDas_Error_InvalidMode                            = -25;
const int eProDas_Error_InvalidPeriod                          = -26;
const int eProDas_Error_InvalidPrescaler                       = -27;
const int eProDas_Error_InvalidDutyCycle                       = -28;
const int eProDas_Error_InvalidActiveState                     = -29;
const int eProDas_Error_InvalidDelay                           = -30;
const int eProDas_Error_InvalidAutoShutDownSource              = -31;
const int eProDas_Error_InvalidAutoShutDownPinState            = -32;
const int eProDas_Error_TimerDisabled                          = -33;

const int eProDas_Error_BadMainDivider                         = -34;
const int eProDas_Error_BadExtendedDivider                     = -35;
const int eProDas_Error_ClockTooHigh                           = -36;
const int eProDas_Error_ClockTooLow                            = -37;
const int eProDas_Error_ClockNotPossible                       = -38;
const int eProDas_Error_ResourceInUse                          = -39;
const int eProDas_Error_PeriodicActionsNotActive               = -40;
const int eProDas_Error_NotEnoughSpace                         = -41;

const int eProDas_Error_InvalidParameter                       = -42;
const int eProDas_Error_PreviousValueOverwritten               = -43;
const int eProDas_Error_InvalidChainSize                       = -44;
const int eProDas_Error_InvalidPeriodicProgram                 = -45;
const int eProDas_Error_IN_PacketSizeNotMultipleOfOnePeriod    = -46;
const int eProDas_Error_OUT_PacketSizeNotMultipleOfOnePeriod   = -47;

const int eProDas_Error_WriteToCONFIGByteFailed                = -48;
const int eProDas_Error_InvalidPeriodicSequence                = -49;

const int eProDas_Error_ModuleNotActive                        = -50;

const int eProDas_Error_Invalid_IN_PeriodicPacketSize          = -51;
const int eProDas_Error_Invalid_OUT_PeriodicPacketSize         = -52;
const int eProDas_Error_PeriodicProgramTooLong                 = -53;

const int eProDas_Error_InvalidFileRegister                    = -54;
const int eProDas_Error_InvalidBitNumber                       = -55;
const int eProDas_Error_InvalidDisplacement                    = -56;
const int eProDas_Error_InvalidAddress                         = -57;
const int eProDas_Error_InvalidLiteral                         = -58;
const int eProDas_Error_InvalidFSR                             = -59;
const int eProDas_Error_InvalidPinIndex                        = -60;
const int eProDas_Error_DuplicateLabel                         = -61;
const int eProDas_Error_InvalidInstruction                     = -62;

const int eProDas_Error_DataCorruptionError                    = -63;
const int eProDas_Error_NotEnoughResources                     = -64;
const int eProDas_Error_EndOfBufferReached                     = -65;
const int eProDas_Error_InvalidDuringPeriodicActions           = -66;

///////////////////////////////////////////////////////
//                   Port indexes                    //
///////////////////////////////////////////////////////

const int eProDas_Index_PORTA      =     0;
const int eProDas_Index_PORTB      =     1;
const int eProDas_Index_PORTC      =     2;
const int eProDas_Index_PORTD      =     3;
const int eProDas_Index_PORTE      =     4;

///////////////////////////////////////////////////////
//                   Wait PinState                   //
///////////////////////////////////////////////////////

const int eProDas_WaitPin_Low       =     0;
const int eProDas_WaitPin_High      =     1;
const int eProDas_WaitPin_LowToHigh =     2;
const int eProDas_WaitPin_HighToLow =     3;

///////////////////////////////////////////////////////
//                   TRIS actions                    //
///////////////////////////////////////////////////////

const int eProDas_TRIS_Action_WriteALL    =      256;
const int eProDas_TRIS_Action_WriteOnes   =      512;
const int eProDas_TRIS_Action_WriteZeros  =     1024;
const int eProDas_TRIS_Action_ChangeOnes  =     2048;

///////////////////////////////////////////////////////
//              Pin Configuration Bits               //
///////////////////////////////////////////////////////

const int eProDas_Pin_Error         =         1; //any detected error in configuration of pin
const int eProDas_Pin_Unimplemented =         2; //pin does not physically exist
const int eProDas_Pin_Reserved      =         4; //pin is not available as a general purpose pin to the user
const int eProDas_Pin_DigitalOut    =         8; //set if pin is digital output
const int eProDas_Pin_Analog        =        16; //digital if this bit is cleared
const int eProDas_Pin_ADInput       =        32; //input to AD converter
const int eProDas_Pin_ADPlus        =        64; //plus reference voltage for AD converter
const int eProDas_Pin_ADMinus       =       128; //minus reference voltage for AD converter
const int eProDas_Pin_CompPlus      =       256; //noninverting input to analog comparator
const int eProDas_Pin_CompMinus     =       512; //inverting input to analog comparator
const int eProDas_Pin_CompOut       =      1024; //output of analog comparator
const int eProDas_Pin_RefPlus       =      2048; //plus reference voltage for comparator reference
const int eProDas_Pin_RefMinus      =      4096; //minus reference voltage for comparator reference
const int eProDas_Pin_RefOut        =      8192; //output of comparator reference
const int eProDas_Pin_TimerIn       =     16384; //timer input (clock source)
const int eProDas_Pin_PWMOut        =     32768; //PWM output pin
const int eProDas_Pin_SPIOut        =     65536; //SPI output pin
const int eProDas_Pin_SPIIn         =    131072; //SPI input pin
const int eProDas_Pin_SPIClk        =    262144; //SPI clock pin
const int eProDas_Pin_USARTOut      =    524288; //USART output pin
const int eProDas_Pin_USARTIn       =   1048576; //USART input

///////////////////////////////////////////////////////
//               Configuration Errors                //
///////////////////////////////////////////////////////

const int eProDas_ConfigError_Pins           =  1;
const int eProDas_ConfigError_ADChannels     =  2;
const int eProDas_ConfigError_ADChannel      =  4;
const int eProDas_ConfigError_Reference      =  8;
const int eProDas_ConfigError_Periodic       = 16;

///////////////////////////////////////////////////////
//       eProDas Periodic actions configuration      //
///////////////////////////////////////////////////////

const unsigned int eProDas_PeriodicStep_Clear         =  0;
const unsigned int eProDas_PeriodicStep_SetMode       =  1;
const unsigned int eProDas_PeriodicStep_Build         =  2;
const unsigned int eProDas_PeriodicStep_Analysis      =  3;
const unsigned int eProDas_PeriodicStep_Program       =  4;
const unsigned int eProDas_PeriodicStep_SetClock      =  5;
const unsigned int eProDas_PeriodicStep_Prepare       =  6;
const unsigned int eProDas_PeriodicStep_Run           =  7;

const unsigned int eProDas_PeriodicMode_None                 =  0;
const unsigned int eProDas_PeriodicMode_Out                  =  1;
const unsigned int eProDas_PeriodicMode_InAtStart            =  2;
const unsigned int eProDas_PeriodicMode_InAtEnd              =  3;
const unsigned int eProDas_PeriodicMode_BothAtStart          =  4;
const unsigned int eProDas_PeriodicMode_Synchronous          =  5;
const unsigned int eProDas_PeriodicMode_Out_InAtEnd          =  6;
const unsigned int eProDas_PeriodicMode_OutConst12           =  7;
const unsigned int eProDas_PeriodicMode_OutConst6_InAtStart  =  8;
const unsigned int eProDas_PeriodicMode_OutConst6_InAtEnd    =  9;
const unsigned int eProDas_PeriodicMode_OutConst8_InAtStart  = 10;
const unsigned int eProDas_PeriodicMode_OutConst8_InAtEnd    = 11;
const unsigned int eProDas_PeriodicMode_OutConst10_InAtStart = 12;
const unsigned int eProDas_PeriodicMode_OutConst10_InAtEnd   = 13;

///////////////////////////////////////////////////////
//               eProDas Reset Codes                 //
///////////////////////////////////////////////////////

const int eProDas_Reset_PowerOn                                =    0;
const int eProDas_Reset_BrownOut                               =    1;
const int eProDas_Reset_MCLR                                   =    2;
const int eProDas_Reset_MCLRIdleSleep                          =    3;
const int eProDas_Reset_WatchDog                               =    4;
const int eProDas_Reset_RESETInstruction                       =    5;
const int eProDas_Reset_StackOverflow                          =    6;
const int eProDas_Reset_StackUnderflow                         =    7;
const int eProDas_Reset_Unknown                                =  666;

///////////////////////////////////////////////////////
//        eProDas Configuration Octet Codes          //
///////////////////////////////////////////////////////

const int eProDas_CONFIG1L                                     =    0;
const int eProDas_CONFIG1H                                     =    1;
const int eProDas_CONFIG2L                                     =    2;
const int eProDas_CONFIG2H                                     =    3;
const int eProDas_CONFIG3H                                     =    5;
const int eProDas_CONFIG4L                                     =    6;
const int eProDas_CONFIG5L                                     =    8;
const int eProDas_CONFIG5H                                     =    9;
const int eProDas_CONFIG6L                                     =   10;
const int eProDas_CONFIG6H                                     =   11;
const int eProDas_CONFIG7L                                     =   12;
const int eProDas_CONFIG7H                                     =   13;
const int eProDas_DEVID1                                       =  254;
const int eProDas_DEVID2                                       =  255;

///////////////////////////////////////////////////////
//           LOW addresses of SFR Registers          //
///////////////////////////////////////////////////////

const unsigned char eProDas_lSFR_STATUS                = 0xD8;
const unsigned char eProDas_lSFR_WREG                  = 0xE8;

const unsigned char eProDas_lSFR_PORTA                 = 0x80;
const unsigned char eProDas_lSFR_PORTB                 = 0x81;
const unsigned char eProDas_lSFR_PORTC                 = 0x82;
const unsigned char eProDas_lSFR_PORTD                 = 0x83;
const unsigned char eProDas_lSFR_PORTE                 = 0x84;

const unsigned char eProDas_lSFR_LATA                  = 0x89;
const unsigned char eProDas_lSFR_LATB                  = 0x8A;
const unsigned char eProDas_lSFR_LATC                  = 0x8B;
const unsigned char eProDas_lSFR_LATD                  = 0x8C;
const unsigned char eProDas_lSFR_LATE                  = 0x8D;

const unsigned char eProDas_lSFR_TRISA                 = 0x92;
const unsigned char eProDas_lSFR_TRISB                 = 0x93;
const unsigned char eProDas_lSFR_TRISC                 = 0x94;
const unsigned char eProDas_lSFR_TRISD                 = 0x95;
const unsigned char eProDas_lSFR_TRISE                 = 0x96;

const unsigned char eProDas_lSFR_ADCON0                = 0xC2;
const unsigned char eProDas_lSFR_ADCON1                = 0xC1;
const unsigned char eProDas_lSFR_ADCON2                = 0xC0;

const unsigned char eProDas_lSFR_ADRESL                = 0xC3;
const unsigned char eProDas_lSFR_ADRESH                = 0xC4;

const unsigned char eProDas_lSFR_CMCON                 = 0xB4;
const unsigned char eProDas_lSFR_CVRCON                = 0xB5;

const unsigned char eProDas_lSFR_FSR0L                 = 0xE9;
const unsigned char eProDas_lSFR_FSR0H                 = 0xEA;
const unsigned char eProDas_lSFR_FSR1L                 = 0xE1;
const unsigned char eProDas_lSFR_FSR1H                 = 0xE2;
const unsigned char eProDas_lSFR_FSR2L                 = 0xD9;
const unsigned char eProDas_lSFR_FSR2H                 = 0xDA;

const unsigned char eProDas_lSFR_T0CON                 = 0xD5;
const unsigned char eProDas_lSFR_TMR0L                 = 0xD6;
const unsigned char eProDas_lSFR_TMR0H                 = 0xD7;

const unsigned char eProDas_lSFR_T1CON                 = 0xCD;
const unsigned char eProDas_lSFR_TMR1L                 = 0xCE;
const unsigned char eProDas_lSFR_TMR1H                 = 0xCF;

const unsigned char eProDas_lSFR_T2CON                 = 0xCA;
const unsigned char eProDas_lSFR_PR2                   = 0xCB;
const unsigned char eProDas_lSFR_TMR2                  = 0xCC;

const unsigned char eProDas_lSFR_T3CON                 = 0xB1;
const unsigned char eProDas_lSFR_TMR3L                 = 0xB2;
const unsigned char eProDas_lSFR_TMR3H                 = 0xB3;

const unsigned char eProDas_lSFR_CCP1CON               = 0xBD;
const unsigned char eProDas_lSFR_CCPR1L                = 0xBE;
const unsigned char eProDas_lSFR_CCPR1H                = 0xBF;
const unsigned char eProDas_lSFR_CCP2CON               = 0xBA;
const unsigned char eProDas_lSFR_CCPR2L                = 0xBB;
const unsigned char eProDas_lSFR_CCPR2H                = 0xBC;

const unsigned char eProDas_lSFR_ECCP1AS               = 0xB6;
const unsigned char eProDas_lSFR_ECCP1DEL              = 0xB7;

const unsigned char eProDas_lSFR_INTCON                = 0xF2;
const unsigned char eProDas_lSFR_INTCON2               = 0xF1;
const unsigned char eProDas_lSFR_INTCON3               = 0xF0;

const unsigned char eProDas_lSFR_PIE1                  = 0x9D;
const unsigned char eProDas_lSFR_PIR1                  = 0x9E;
const unsigned char eProDas_lSFR_IPR1                  = 0x9F;
const unsigned char eProDas_lSFR_PIE2                  = 0xA0;
const unsigned char eProDas_lSFR_PIR2                  = 0xA1;
const unsigned char eProDas_lSFR_IPR2                  = 0xA2;

const unsigned char eProDas_lSFR_SSPSTAT               = 0xC7;
const unsigned char eProDas_lSFR_SSPCON1               = 0xC6;
const unsigned char eProDas_lSFR_SSPCON2               = 0xC5;

const unsigned char eProDas_lSFR_TXSTA                 = 0xAC;
const unsigned char eProDas_lSFR_RCSTA                 = 0xAB;
const unsigned char eProDas_lSFR_BAUDCON               = 0xB8;
const unsigned char eProDas_lSFR_SPBRGH                = 0xB0;
const unsigned char eProDas_lSFR_SPBRG                 = 0xAF;

const unsigned char eProDas_lSFR_INDF0                 = 0xEF;
const unsigned char eProDas_lSFR_POSTINC0              = 0xEE;
const unsigned char eProDas_lSFR_POSTDEC0              = 0xED;
const unsigned char eProDas_lSFR_PREINC0               = 0xEC;
const unsigned char eProDas_lSFR_PLUSWO                = 0xEB;

const unsigned char eProDas_lSFR_INDF1                 = 0xE7;
const unsigned char eProDas_lSFR_POSTINC1              = 0xE6;
const unsigned char eProDas_lSFR_POSTDEC1              = 0xE5;
const unsigned char eProDas_lSFR_PREINC1               = 0xE4;
const unsigned char eProDas_lSFR_PLUSW1                = 0xE3;

const unsigned char eProDas_lSFR_INDF2                 = 0xDF;
const unsigned char eProDas_lSFR_POSTINC2              = 0xDE;
const unsigned char eProDas_lSFR_POSTDEC2              = 0xDD;
const unsigned char eProDas_lSFR_PREINC2               = 0xDC;
const unsigned char eProDas_lSFR_PLUSW2                = 0xDB;

const unsigned char eProDas_lSFR_UEP0                  = 0x70;
const unsigned char eProDas_lSFR_UEP1                  = 0x71;
const unsigned char eProDas_lSFR_UEP2                  = 0x72;
const unsigned char eProDas_lSFR_UEP3                  = 0x73;
const unsigned char eProDas_lSFR_UEP4                  = 0x74;
const unsigned char eProDas_lSFR_UEP5                  = 0x75;
const unsigned char eProDas_lSFR_UEP6                  = 0x76;
const unsigned char eProDas_lSFR_UEP7                  = 0x77;
const unsigned char eProDas_lSFR_UEP8                  = 0x78;
const unsigned char eProDas_lSFR_UEP9                  = 0x79;
const unsigned char eProDas_lSFR_UEP10                 = 0x7A;
const unsigned char eProDas_lSFR_UEP11                 = 0x7B;
const unsigned char eProDas_lSFR_UEP12                 = 0x7C;
const unsigned char eProDas_lSFR_UEP13                 = 0x7D;
const unsigned char eProDas_lSFR_UEP14                 = 0x7E;
const unsigned char eProDas_lSFR_UEP15                 = 0x7F;

const unsigned char eProDas_lSFR_UCFG                  = 0x6F;
const unsigned char eProDas_lSFR_UADDR                 = 0x6E;
const unsigned char eProDas_lSFR_UCON                  = 0x6D;
const unsigned char eProDas_lSFR_USTAT                 = 0x6C;
const unsigned char eProDas_lSFR_UEIE                  = 0x6B;
const unsigned char eProDas_lSFR_UEIR                  = 0x6A;
const unsigned char eProDas_lSFR_UIE                   = 0x69;
const unsigned char eProDas_lSFR_UIR                   = 0x68;
const unsigned char eProDas_lSFR_UFRMH                 = 0x67;
const unsigned char eProDas_lSFR_UFRML                 = 0x66;
const unsigned char eProDas_lSFR_SPPCON                = 0x65;
const unsigned char eProDas_lSFR_SPPEPS                = 0x64;
const unsigned char eProDas_lSFR_SPPCFG                = 0x63;
const unsigned char eProDas_lSFR_SPPDATA               = 0x62;

const unsigned char eProDas_lSFR_OSCTUNE               = 0x9B;

const unsigned char eProDas_lSFR_EEADR                 = 0xA9;
const unsigned char eProDas_lSFR_EEDATA                = 0xA8;
const unsigned char eProDas_lSFR_EECON2                = 0xA7;
const unsigned char eProDas_lSFR_EECON1                = 0xA6;

const unsigned char eProDas_lSFR_SSPADD                = 0xC8;
const unsigned char eProDas_lSFR_SSPBUF                = 0xC9;

const unsigned char eProDas_lSFR_RCON                  = 0xD0;
const unsigned char eProDas_lSFR_WDTCON                = 0xD1;
const unsigned char eProDas_lSFR_HLVDCON               = 0xD2;
const unsigned char eProDas_lSFR_OSCCON                = 0xD3;

const unsigned char eProDas_lSFR_TXREG                 = 0xAD;
const unsigned char eProDas_lSFR_RCREG                 = 0xAE;

const unsigned char eProDas_lSFR_BSR                   = 0xE0;

const unsigned char eProDas_lSFR_PRODL                 = 0xF3;
const unsigned char eProDas_lSFR_PRODH                 = 0xF4;

const unsigned char eProDas_lSFR_TABLAT                = 0xF5;
const unsigned char eProDas_lSFR_TBLPTRL               = 0xF6;
const unsigned char eProDas_lSFR_TBLPTRH               = 0xF7;
const unsigned char eProDas_lSFR_TBLPTRU               = 0xF8;

const unsigned char eProDas_lSFR_PCL                   = 0xF9;
const unsigned char eProDas_lSFR_PCLATH                = 0xFA;
const unsigned char eProDas_lSFR_PCLATU                = 0xFB;

const unsigned char eProDas_lSFR_STKPTR                = 0xFC;
const unsigned char eProDas_lSFR_TOSL                  = 0xFD;
const unsigned char eProDas_lSFR_TOSH                  = 0xFE;
const unsigned char eProDas_lSFR_TOSU                  = 0xFF;

///////////////////////////////////////////////////////
//        Conversion of codes into strings           //
///////////////////////////////////////////////////////

extern "C" {

  eProDasDLL_API char* eProDas_TypeString(int TypeCode);
  eProDasDLL_API char* eProDas_ErrorString(int ErrorCode);
  eProDasDLL_API void eProDas_PinCfgString(unsigned int PinConfig, unsigned int MinChars, char *StringBuffer);

  eProDasDLL_API char* eProDas_ResetString(int ResetCode);
  eProDasDLL_API void eProDas_ErrorFlagsString(int ErrorCode, char *ResultBuffer);

} //extern "C"

///////////////////////////////////////////////////////
//      eProDas Structures for Exchanging Data       //
///////////////////////////////////////////////////////

extern "C" {

  struct eProDasStruct_PeriodicClock {
    unsigned int MainDivider;
    unsigned int ExtendedDividerUsed;
    unsigned int ExtendedDivider;
    __int64 Period;
    double Frequency;
    double PeriodNanoSeconds;
    unsigned int PeriodMicroSeconds;
    unsigned int PeriodMiliSeconds;
    unsigned int PeriodSeconds;
    unsigned int PeriodMinutes;
    unsigned int PeriodHours;
    unsigned int PeriodDays;
    double FrequencyMantissa;
    int FrequencyExponent;
  }; //struct eProDasStruct_PeriodicClock



  struct eProDasStruct_PeriodicParameters {
    unsigned int DeviceIdx;
    unsigned int ConfigurationStep;

    unsigned int PacketMode;

    unsigned int Warnings;
    unsigned int Errors;
    unsigned int FatalErrors;

    unsigned int OnePeriodSize_IN_Packet;
    unsigned int OnePeriodSize_OUT_Packet;

    unsigned int ActualSize_IN_Packet;
    unsigned int ActualSize_OUT_Packet;

    unsigned int RequestedPeriodsForOne_IN_Packet;
    unsigned int RequestedPeriodsForOne_OUT_Packet;

    unsigned int ActualPeriodsForOne_IN_Packet;
    unsigned int ActualPeriodsForOne_OUT_Packet;

    unsigned int NumberOf_IN_Buffers;
    unsigned int NumberOf_OUT_Buffers;

    unsigned int Duration; //PIC's instruction cycles

    double MaxFrequency;

    double MaxFrequencyMantissa;
    int MaxFrequencyExponent;
    char MaxFrequencyPrefix;

    unsigned int MinMainDivider; //Minimal MainDivider when extended divider is not in use
    unsigned int MinMainDividerWithExt; //Minimal MainDivider when extended divider is used

    unsigned int DurationWithAD; //PIC's instruction cycles

    double MaxFrequencyWithAD;
    double MaxFrequencyMantissaWithAD;
    int MaxFrequencyExponentWithAD;
    char MaxFrequencyPrefixWithAD;

    unsigned int MinMainDividerWithAD; //Minimal MainDivider when extended divider is not in use
  }; //struct eProDasStruct_PeriodicParameters



  struct eProDasStruct_Configuration {
    unsigned int Errors; //0 = no error

    unsigned int Ports[5*8]; //0..7 = PortA, 8..15 = PortB, 16..23 = PortC, 24..31 = PortD, 32..39 = PortE

    unsigned int *PortA() { return Ports+0; }
    unsigned int *PortB() { return Ports+8; }
    unsigned int *PortC() { return Ports+16; }
    unsigned int *PortD() { return Ports+24; }
    unsigned int *PortE() { return Ports+32; }
    unsigned int InternalPullUpsEnabled;

    unsigned int NumberOfInternalADChannels; //0 = AD module is off
    unsigned int SelectedInternalADChannel; //0 = AD module is off
    unsigned int InternalADRefPlus; //0 = VDD, 1 = VrefPlus pin
    unsigned int InternalADRefMinus; //0 = VSS, 1 = VrefMinus pin
    unsigned int InternalADJustify; //0 = left justify, 1 = right justify
    unsigned int InternalADClock; //Hz
    unsigned int InternalADAcquisitionCode; //from 0 to 7
    unsigned int InternalADAcquisitionClocks; //Tad
    unsigned int InternalADAcquisitionTime; //micros

    unsigned int InternalComparatorsOn;
    unsigned int InternalComparatorsMode;
    unsigned int InternalComparator1On;
    unsigned int InternalComparator2On;
    unsigned int InternalComparator1Inv;
    unsigned int InternalComparator2Inv;
    unsigned int InternalComparatorInputSwitch;

    unsigned int InternalReferenceEnabled;
    unsigned int InternalReferenceValue;
    unsigned int InternalReferenceRange;
    unsigned int InternalReferenceSourceOnPin;
    unsigned int InternalReferenceOutputOnPin;

    unsigned int InternalTimer1On;
    unsigned int InternalTimer1Value;
    unsigned int InternalTimer1ExternalClockSource;
    unsigned int InternalTimer1ExternalClockSync;
    unsigned int InternalTimer1OscillatorEnable;
    unsigned int InternalTimer1Prescalar;
    unsigned int InternalTimer1IsDeviceClock;
    unsigned int InternalTimer1ReadWrite16Bit;

    unsigned int InternalTimer2On;
    unsigned int InternalTimer2Value;
    unsigned int InternalTimer2PeriodRegister;
    unsigned int InternalTimer2Prescalar;
    unsigned int InternalTimer2Postscalar;
    unsigned int InternalTimer2PeriodClocks;

    unsigned int InternalTimer3On;
    unsigned int InternalTimer3Value;
    unsigned int InternalTimer3ExternalClockSource;
    unsigned int InternalTimer3ExternalClockSync;
    unsigned int InternalTimer3Prescalar;
    unsigned int InternalTimer3ReadWrite16Bit;

    unsigned int InternalPWM1On;
    unsigned int InternalPWM1PeriodClocks;
    unsigned int InternalPWM1DutyCycleClocks;
    unsigned int InternalPWM1Mode;
    unsigned int InternalPWM1ActiveStateP1A;
    unsigned int InternalPWM1ActiveStateP1B;
    unsigned int InternalPWM1ActiveStateP1C;
    unsigned int InternalPWM1ActiveStateP1D;
    unsigned int InternalPWM1HalfBridgeDelay;
    unsigned int AutoShutDownSource;
    unsigned int AutoShutDownState;
    unsigned int InternalPWM1AutoShutdownStateP1A;
    unsigned int InternalPWM1AutoShutdownStateP1B;
    unsigned int InternalPWM1AutoShutdownStateP1C;
    unsigned int InternalPWM1AutoShutdownStateP1D;
    unsigned int InternalPWM1AutoRestart;

    unsigned int InternalPWM2On;
    unsigned int InternalPWM2PeriodClocks;
    unsigned int InternalPWM2DutyCycleClocks;
    unsigned int InternalPWM2MuxPin; //RC1 = 1, RB3 = 0

    unsigned int InternalSPIOn;
    unsigned int InternalSPIMode;
    unsigned int InternalSPI_IN_SampleAtTheEnd;
    unsigned int InternalSPITransmitOnActiveToIdle;
    unsigned int InternalSPIClockIdleStateHigh;
    unsigned int InternalSPIOutputDemanded;
    unsigned int InternalSPIInputDemanded;

    unsigned int InternalUSARTOn;
    unsigned int InternalUSARTBaudRate;
    unsigned int InternalUSARTTransmitEnabled;
    unsigned int InternalUSARTOutputDemanded;
    unsigned int InternalUSARTInputDemanded;
  }; //struct eProDasStruct_Configuration

  struct eProDasStruct_DiagnosticInfo {
    unsigned int DeviceType;
    unsigned int DeviceTag;

    unsigned int FirmwareVersionLow;
    unsigned int FirmwareVersionHigh;

    unsigned int DLLVersionLow;
    unsigned int DLLVersionHigh;

    unsigned int KernelVersionLow;
    unsigned int KernelVersionHigh;

    unsigned int ResetType;

    unsigned int USBAddress;

    unsigned int UpgradeReport;

    unsigned int DebugIDC;
    unsigned int LowVoltageProgramming;
    unsigned int PinMCLREnabled;
    unsigned int CCP2PinMux;

    unsigned int Errors;
  }; //struct eProDasStruct_GlobalInfo

} //extern "C"

///////////////////////////////////////////////////////
//                  textual utils                    //
///////////////////////////////////////////////////////

extern "C" {

char eProDas_Exponent2Prefix(int Exponent);
void eProDas_Double2HumanReadable(double &Number, int &Exponent);
void eProDas_Frequency2String(double Frequency, char *Result);
void eProDas_PrintFrequency(double Frequency);

} //extern "C"

///////////////////////////////////////////////////////
//       eProDas Data Acquisition commands           //
///////////////////////////////////////////////////////

extern "C" {

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Device handle
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_OpenHandle();
eProDasDLL_API void eProDas_CloseHandle();
eProDasDLL_API unsigned int eProDas_GetNumberOfDevices();

eProDasDLL_API unsigned int eProDas_GetMaxNumberOfDevices();

eProDasDLL_API int eProDas_SearchDevice(int Type, int Tag);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Operations on the whole eProDas device
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_Initialize(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_GetConfiguration(unsigned int DeviceIdx, eProDasStruct_Configuration &ConfigInfo);

eProDasDLL_API int eProDas_GetDeviceType(unsigned int DeviceIdx, unsigned int &DeviceType);
eProDasDLL_API int eProDas_SetDeviceType(unsigned int DeviceIdx, unsigned int DeviceType);

eProDasDLL_API int eProDas_GetDeviceTag(unsigned int DeviceIdx, unsigned int &DeviceTag);
eProDasDLL_API int eProDas_SetDeviceTag(unsigned int DeviceIdx, unsigned int DeviceTag);

eProDasDLL_API int eProDas_GetDeviceID(unsigned int DeviceIdx, char *Serial_ID_String);
eProDasDLL_API int eProDas_SetDeviceID(unsigned int DeviceIdx, char *Serial_ID_String);
eProDasDLL_API int eProDas_SetRandomDeviceID(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_ReadDiagnosticInfo(unsigned int DeviceIdx, eProDasStruct_DiagnosticInfo &Data, int ResetInfo);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Digital ports
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_ConfigurePort(unsigned int DeviceIdx, unsigned int Port, unsigned char NewTris, unsigned int Action);
eProDasDLL_API int eProDas_ConfigurePorts(unsigned int DeviceIdx, unsigned char *NewTrises, unsigned int *Actions);

eProDasDLL_API int eProDas_ConfigurePortUnsafe(unsigned int DeviceIdx, unsigned int Port, unsigned char NewTris);
eProDasDLL_API int eProDas_ConfigurePortsUnsafe(unsigned int DeviceIdx, unsigned char *NewTrises);

eProDasDLL_API int eProDas_ConfigureSelectedPortsUnsafe(unsigned int DeviceIdx, unsigned int PortFlags, unsigned char *NewTrises);

eProDasDLL_API int eProDas_XOR_PortsUnsafe(unsigned int DeviceIdx, unsigned char *XOR_Trises);
eProDasDLL_API int eProDas_XOR_SelectedPortsUnsafe(unsigned int DeviceIdx, unsigned int PortFlags, unsigned char *XOR_Trises);

eProDasDLL_API int eProDas_Configure_XOR_SelectedPortsUnsafe(unsigned int DeviceIdx, unsigned int WriteFlags, unsigned int XORFlags, unsigned char *New_XOR_Trises);

eProDasDLL_API int eProDas_ConfigurePinAsOutput(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin, unsigned int InitialState);
eProDasDLL_API int eProDas_ConfigurePinAsInput(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin);

eProDasDLL_API int eProDas_ConfigurePinAsOutputUnsafe(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin, unsigned int InitialState);
eProDasDLL_API int eProDas_ConfigurePinAsInputUnsafe(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin);

eProDasDLL_API int eProDas_ReadPort(unsigned int DeviceIdx, unsigned int Port, unsigned char &Value);
eProDasDLL_API int eProDas_ReadPorts(unsigned int DeviceIdx, unsigned char *Values);
eProDasDLL_API int eProDas_ReadSelectedPorts(unsigned int DeviceIdx, unsigned int PortFlags, unsigned char *Values);

eProDasDLL_API int eProDas_WritePort(unsigned int DeviceIdx, unsigned int Port, unsigned char NewValue);
eProDasDLL_API int eProDas_WritePorts(unsigned int DeviceIdx, unsigned char *NewValues);
eProDasDLL_API int eProDas_WriteSelectedPorts(unsigned int DeviceIdx, unsigned int PortFlags, unsigned char *NewValues);

eProDasDLL_API int eProDas_ReadWriteSelectedPorts(unsigned int DeviceIdx, unsigned int ReadFlags, unsigned int WriteFlags, unsigned char *ReadValues, unsigned char *WriteValues);

eProDasDLL_API int eProDas_AND_Port(unsigned int DeviceIdx, unsigned int Port, unsigned char AND_Value);
eProDasDLL_API int eProDas_OR_Port(unsigned int DeviceIdx, unsigned int Port, unsigned char OR_Value);
eProDasDLL_API int eProDas_XOR_Port(unsigned int DeviceIdx, unsigned int Port, unsigned char XOR_Value);
eProDasDLL_API int eProDas_XORXOR_Port(unsigned int DeviceIdx, unsigned int Port, unsigned char XORXOR_Value);

eProDasDLL_API int eProDas_AND_Ports(unsigned int DeviceIdx, unsigned char *AND_Values);
eProDasDLL_API int eProDas_OR_Ports(unsigned int DeviceIdx, unsigned char *OR_Values);
eProDasDLL_API int eProDas_XOR_Ports(unsigned int DeviceIdx, unsigned char *XOR_Values);
eProDasDLL_API int eProDas_XORXOR_Ports(unsigned int DeviceIdx, unsigned char *XORXOR_Values);

eProDasDLL_API int eProDas_XOR_SelectedPorts(unsigned int DeviceIdx, unsigned int PortFlags, unsigned char *XOR_Values);
eProDasDLL_API int eProDas_Read_XOR_SelectedPorts(unsigned int DeviceIdx, unsigned int ReadFlags, unsigned int XOR_Flags, unsigned char *ReadValues, unsigned char *XOR_Values);

eProDasDLL_API int eProDas_ROTL_Port(unsigned int DeviceIdx, unsigned int Port);
eProDasDLL_API int eProDas_ROTR_Port(unsigned int DeviceIdx, unsigned int Port);
eProDasDLL_API int eProDas_SHIFTL_Port(unsigned int DeviceIdx, unsigned int Port, unsigned int LSB_Value);
eProDasDLL_API int eProDas_SHIFTR_Port(unsigned int DeviceIdx, unsigned int Port, unsigned int MSB_Value);
eProDasDLL_API int eProDas_Complement_Port(unsigned int DeviceIdx, unsigned int Port);
eProDasDLL_API int eProDas_Negate_Port(unsigned int DeviceIdx, unsigned int Port);
eProDasDLL_API int eProDas_SwapNibbles_Port(unsigned int DeviceIdx, unsigned int Port);

eProDasDLL_API int eProDas_ADD_Port(unsigned int DeviceIdx, unsigned int Port, unsigned char ADD_Value);
eProDasDLL_API int eProDas_SUB_Port(unsigned int DeviceIdx, unsigned int Port, unsigned char SUB_Value);
eProDasDLL_API int eProDas_INC_Port(unsigned int DeviceIdx, unsigned int Port);
eProDasDLL_API int eProDas_DEC_Port(unsigned int DeviceIdx, unsigned int Port);

eProDasDLL_API int eProDas_SetPin(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin);
eProDasDLL_API int eProDas_ClearPin(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin);
eProDasDLL_API int eProDas_TogglePin(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin);
eProDasDLL_API int eProDas_TogglePinTwice(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin);

eProDasDLL_API int eProDas_GeneratePulses(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin, unsigned int NumberOfDelays, unsigned int *Delays);
eProDasDLL_API int eProDas_GenerateLongPulses(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin, unsigned int NumberOfDelays, unsigned int *Delays);

eProDasDLL_API int eProDas_WaitPortState(unsigned int DeviceIdx, unsigned int Port, unsigned int AND_Mask, unsigned int State);
eProDasDLL_API int eProDas_WaitPortTransition(unsigned int DeviceIdx, unsigned int Port, unsigned int AND_Mask, unsigned int State1, unsigned int State2);

eProDasDLL_API int eProDas_RepetitivelyWaitPortState(unsigned int DeviceIdx, unsigned int Repetitions, unsigned int Port, unsigned int AND_Mask, unsigned int State);
eProDasDLL_API int eProDas_RepetitivelyWaitPortTransition(unsigned int DeviceIdx, unsigned int Repetitions, unsigned int Port, unsigned int AND_Mask, unsigned int State1, unsigned int State2);

eProDasDLL_API int eProDas_WaitStablePortState(unsigned int DeviceIdx, unsigned int Repetitions, unsigned int Port, unsigned int AND_Mask, unsigned int &ReachedState);

eProDasDLL_API int eProDas_WaitPinState(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin, unsigned int State);
eProDasDLL_API int eProDas_WaitPinTransition(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin, unsigned int LowToHigh);

eProDasDLL_API int eProDas_RepetitivelyWaitPinState(unsigned int DeviceIdx, unsigned int Repetitions, unsigned int Port, unsigned int Pin, unsigned int State);
eProDasDLL_API int eProDas_RepetitivelyWaitPinTransition(unsigned int DeviceIdx, unsigned int Repetitions, unsigned int Port, unsigned int Pin, unsigned int LowToHigh);

eProDasDLL_API int eProDas_WaitStablePinState(unsigned int DeviceIdx, unsigned int Repetitions, unsigned int Port, unsigned int Pin, unsigned int &ReachedState);

eProDasDLL_API int eProDas_ADD_Port_BitMask(unsigned int DeviceIdx, unsigned int Port, unsigned int StartPin, unsigned int EndPin, unsigned int AddValue, unsigned int MatchValue, unsigned int ResetValue);
eProDasDLL_API int eProDas_ROT_Port_BitMask(unsigned int DeviceIdx, unsigned int Port, unsigned int StartPin, unsigned int EndPin);
eProDasDLL_API int eProDas_WritePort_BitMask(unsigned int DeviceIdx, unsigned int Port, unsigned int StartPin, unsigned int EndPin, unsigned char Value);

eProDasDLL_API int eProDas_ADD_Port_BitMask_TogglePin(unsigned int DeviceIdx, unsigned int Port, unsigned int StartPin, unsigned int EndPin, unsigned int AddValue, unsigned int MatchValue, unsigned int ResetValue, unsigned int TogglePort, unsigned int TogglePin);
eProDasDLL_API int eProDas_ROT_Port_BitMask_TogglePin(unsigned int DeviceIdx, unsigned int Port, unsigned int StartPin, unsigned int EndPin, unsigned int TogglePort, unsigned int TogglePin);
eProDasDLL_API int eProDas_WritePort_BitMask_TogglePin(unsigned int DeviceIdx, unsigned int Port, unsigned int StartPin, unsigned int EndPin, unsigned char Value, unsigned int TogglePort, unsigned int TogglePin);

eProDasDLL_API int eProDas_ConfigureInternalPullupResistors(unsigned int DeviceIdx, unsigned int Enable);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Internal AD converter
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_ConfigureInternalAD(unsigned int DeviceIdx, unsigned int NumberOfADPorts, unsigned int AcquisitionTimeCode, unsigned int VrefPlus, unsigned int VrefMinus);
eProDasDLL_API int eProDas_ConfigureInternalAD_Advanced(unsigned int DeviceIdx, unsigned int NumberOfADPorts, unsigned int AcquisitionTimeCode, unsigned int VrefPlus, unsigned int VrefMinus, unsigned int Justification, unsigned int FullAccuracy);

eProDasDLL_API int eProDas_AcquireInternalADChannel(unsigned int DeviceIdx, unsigned int ADPort);
eProDasDLL_API int eProDas_ReadInternalADChannel(unsigned int DeviceIdx, unsigned int &Result);
eProDasDLL_API int eProDas_AcquireAndReadInternalADChannel(unsigned int DeviceIdx, unsigned int ADPort, unsigned int &Result);
eProDasDLL_API int eProDas_ReadAndAcquireInternalADChannel(unsigned int DeviceIdx, unsigned int &Result, unsigned int ADPortToAcquireAfter);

eProDasDLL_API int eProDas_ReadSelectedInternalADChannels(unsigned int DeviceIdx, unsigned int ChannelFlags, unsigned int *Results);

eProDasDLL_API int eProDas_WaitInternalADAboveThreshold(unsigned int DeviceIdx, unsigned int Channel, unsigned int Threshold, unsigned int &Result);
eProDasDLL_API int eProDas_WaitInternalADBelowThreshold(unsigned int DeviceIdx, unsigned int Channel, unsigned int Threshold, unsigned int &Result);
eProDasDLL_API int eProDas_WaitInternalADBetweenThresholds(unsigned int DeviceIdx, unsigned int Channel, unsigned int LowThreshold, unsigned int HighThreshold, unsigned int &Result);
eProDasDLL_API int eProDas_WaitInternalADTransition(unsigned int DeviceIdx, unsigned int Channel, unsigned int Threshold, unsigned int LowToHigh, unsigned int &Result);

////////////////////////////////////////////////////////////////////////////////////////////////////////
// Internal voltage comparators and voltage reference
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_ConfigureInternalComparators(unsigned int DeviceIdx, unsigned int Mode, unsigned int InputSwitch, unsigned int Comp1Inv, unsigned int Comp2Inv);
eProDasDLL_API int eProDas_ReadInternalComparators(unsigned int DeviceIdx, unsigned char &Result);
eProDasDLL_API int eProDas_QueryInternalComparatorsChange(unsigned int DeviceIdx, unsigned int &Changed, unsigned int &Result);

eProDasDLL_API int eProDas_WaitInternalComparatorsState(unsigned int DeviceIdx, unsigned int MonitorComp1, unsigned int MonitorComp2, unsigned int State1, unsigned int State2);
eProDasDLL_API int eProDas_RepetitivelyWaitInternalComparatorsState(unsigned int DeviceIdx, unsigned int Repetitions, unsigned int MonitorComp1, unsigned int MonitorComp2, unsigned int State1, unsigned int State2);
eProDasDLL_API int eProDas_WaitStableInternalComparatorsState(unsigned int DeviceIdx, unsigned int Repetitions, unsigned int MonitorComp1, unsigned int MonitorComp2, unsigned char &Result);
eProDasDLL_API int eProDas_WaitInternalComparatorTransition(unsigned int DeviceIdx, unsigned int Comparator, unsigned int LowToHigh);
eProDasDLL_API int eProDas_RepetitivelyWaitInternalComparatorTransition(unsigned int DeviceIdx, unsigned int Repetitions, unsigned int Comparator, unsigned int LowToHigh);

eProDasDLL_API int eProDas_ConfigureInternalReference(unsigned int DeviceIdx, unsigned int Enabled, unsigned int Value, unsigned int Range, unsigned int SourceOnPin, unsigned int OutputOnPin);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Pulse-width modulation
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_ConfigureInternalPWM1(unsigned int DeviceIdx, int UnscaledPeriod, unsigned int Prescalar, unsigned int DutyCycle, unsigned int Mode, unsigned int ActiveState, unsigned int Delay, unsigned int AutoShutDownSource, unsigned int AutoShutDownPinState, unsigned int AutoRestart);
eProDasDLL_API int eProDas_TurnOffInternalPWM1(unsigned int DeviceIdx, unsigned int ConfigPin);
eProDasDLL_API int eProDas_GetInternalPWM1FullBridgeDirection(unsigned int DeviceIdx, unsigned int &Direction);
eProDasDLL_API int eProDas_ChangeInternalPWM1FullBridgeDirection(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_GetInternalPWM1AutoShutDownState(unsigned int DeviceIdx, unsigned int &State);
eProDasDLL_API int eProDas_ClearInternalPWM1AutoShutDownState(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_ConfigureInternalPWM2(unsigned int DeviceIdx, int UnscaledPeriod, unsigned int Prescalar, unsigned int DutyCycle, unsigned int ConfigPin);
eProDasDLL_API int eProDas_TurnOffInternalPWM2(unsigned int DeviceIdx, unsigned int ConfigPin);
eProDasDLL_API int eProDas_SetInternalPWM2OutputPin(unsigned int DeviceIdx, unsigned int OutputPin);
eProDasDLL_API int eProDas_SetInternalPWMDutyCycle(unsigned int DeviceIdx, int DutyCycle1, int DutyCycle2);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// SPI Serial interface
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_SetInternalSPI_MasterMode(unsigned int DeviceIdx, unsigned int IN_SampleAtTheEnd, unsigned int ClockIdleStateHigh, unsigned int ClockSpeed, unsigned int ClockPeriod, unsigned int ClockPrescaler, unsigned int CorrectFirstBit, unsigned int EnableInput, unsigned int EnableOutput);
eProDasDLL_API int eProDas_SetInternalSPI_MasterMode_CS(unsigned int DeviceIdx, unsigned int IN_SampleAtTheEnd, unsigned int ClockIdleStateHigh, unsigned int ClockSpeed, unsigned int ClockPeriod, unsigned int ClockPrescaler, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int ChipSelectState, unsigned int CorrectFirstBit, unsigned int EnableInput, unsigned int EnableOutput);

eProDasDLL_API int eProDas_SetInternalSPI_SlaveMode(unsigned int DeviceIdx, unsigned int TransmitOnActiveToIdle, unsigned int SlaveSelectEnable, unsigned int ClockIdleStateHigh, unsigned int EnableInput, unsigned int EnableOutput);

eProDasDLL_API int eProDas_TurnOffInternalSPI(unsigned int DeviceIdx, unsigned int ShutDownTimer2);

eProDasDLL_API int eProDas_Configure_SPI_Clock(unsigned int DeviceIdx, unsigned int IN_SampleAtTheEnd, unsigned int ClockIdleStateHigh, unsigned int ClockSpeed, unsigned int ClockPeriod, unsigned int ClockPrescaler, unsigned int CorrectFirstBit);

eProDasDLL_API int eProDas_MasterSPI_TransferByte(unsigned int DeviceIdx, unsigned char WriteByte, unsigned char &ReadByte);
eProDasDLL_API int eProDas_MasterSPI_TransferByteOUT(unsigned int DeviceIdx, unsigned char WriteByte);
eProDasDLL_API int eProDas_MasterSPI_TransferByteIN(unsigned int DeviceIdx, unsigned char &ReadByte);

eProDasDLL_API int eProDas_MasterSPI_TransferByteCS(unsigned int DeviceIdx, unsigned char WriteByte, unsigned char &ReadByte, unsigned int ChipSelectPort, unsigned int ChipSelectBit);
eProDasDLL_API int eProDas_MasterSPI_TransferByteOUT_CS(unsigned int DeviceIdx, unsigned char WriteByte, unsigned int ChipSelectPort, unsigned int ChipSelectBit);
eProDasDLL_API int eProDas_MasterSPI_TransferByteIN_CS(unsigned int DeviceIdx, unsigned char &ReadByte, unsigned int ChipSelectPort, unsigned int ChipSelectBit);

eProDasDLL_API int eProDas_MasterSPI_TransferByteTG(unsigned int DeviceIdx, unsigned char WriteByte, unsigned char &ReadByte, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int TogglePort, unsigned int ToggleBit);
eProDasDLL_API int eProDas_MasterSPI_TransferByteOUT_TG(unsigned int DeviceIdx, unsigned char WriteByte, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int TogglePort, unsigned int ToggleBit);
eProDasDLL_API int eProDas_MasterSPI_TransferByteIN_TG(unsigned int DeviceIdx, unsigned char &ReadByte, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int TogglePort, unsigned int ToggleBit);

eProDasDLL_API int eProDas_MasterSPI_TransferByteWS(unsigned int DeviceIdx, unsigned char WriteByte, unsigned char &ReadByte, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int WaitPort, unsigned int WaitPin, unsigned int WaitState);
eProDasDLL_API int eProDas_MasterSPI_TransferByteOUT_WS(unsigned int DeviceIdx, unsigned char WriteByte, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int WaitPort, unsigned int WaitPin, unsigned int WaitState);
eProDasDLL_API int eProDas_MasterSPI_TransferByteIN_WS(unsigned int DeviceIdx, unsigned char &ReadByte, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int WaitPort, unsigned int WaitPin, unsigned int WaitState);

eProDasDLL_API int eProDas_MasterSPI_TransferByteWS2(unsigned int DeviceIdx, unsigned char WriteByte, unsigned char &ReadByte, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int WaitPort, unsigned int WaitPin, unsigned int WaitState);
eProDasDLL_API int eProDas_MasterSPI_TransferByteOUT_WS2(unsigned int DeviceIdx, unsigned char WriteByte, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int WaitPort, unsigned int WaitPin, unsigned int WaitState);
eProDasDLL_API int eProDas_MasterSPI_TransferByteIN_WS2(unsigned int DeviceIdx, unsigned char &ReadByte, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int WaitPort, unsigned int WaitPin, unsigned int WaitState);

eProDasDLL_API int eProDas_MasterSPI_TransferArray(unsigned int DeviceIdx, unsigned char *WriteArray, unsigned char *ReadArray, unsigned int Length);
eProDasDLL_API int eProDas_MasterSPI_TransferArrayOUT(unsigned int DeviceIdx, unsigned char *WriteArray, unsigned int Length);
eProDasDLL_API int eProDas_MasterSPI_TransferArrayIN(unsigned int DeviceIdx, unsigned char *ReadArray, unsigned int Length);

eProDasDLL_API int eProDas_MasterSPI_TransferArrayCS(unsigned int DeviceIdx, unsigned char *WriteArray, unsigned char *ReadArray, unsigned int Length, unsigned int ChipSelectPort, unsigned int ChipSelectBit);
eProDasDLL_API int eProDas_MasterSPI_TransferArrayOUT_CS(unsigned int DeviceIdx, unsigned char *WriteArray, unsigned int Length, unsigned int ChipSelectPort, unsigned int ChipSelectBit);
eProDasDLL_API int eProDas_MasterSPI_TransferArrayIN_CS(unsigned int DeviceIdx, unsigned char *ReadArray, unsigned int Length, unsigned int ChipSelectPort, unsigned int ChipSelectBit);

eProDasDLL_API int eProDas_MasterSPI_TransferArrayTG(unsigned int DeviceIdx, unsigned char *WriteArray, unsigned char *ReadArray, unsigned int Length, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int TogglePort, unsigned int ToggleBit);
eProDasDLL_API int eProDas_MasterSPI_TransferArrayOUT_TG(unsigned int DeviceIdx, unsigned char *WriteArray, unsigned int Length, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int TogglePort, unsigned int ToggleBit);
eProDasDLL_API int eProDas_MasterSPI_TransferArrayIN_TG(unsigned int DeviceIdx, unsigned char *ReadArray, unsigned int Length, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int TogglePort, unsigned int ToggleBit);

eProDasDLL_API int eProDas_MasterSPI_TransferArrayWS(unsigned int DeviceIdx, unsigned char *WriteArray, unsigned char *ReadArray, unsigned int Length, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int WaitPort, unsigned int WaitPin, unsigned int WaitState);
eProDasDLL_API int eProDas_MasterSPI_TransferArrayOUT_WS(unsigned int DeviceIdx, unsigned char *WriteArray, unsigned int Length, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int WaitPort, unsigned int WaitPin, unsigned int WaitState);
eProDasDLL_API int eProDas_MasterSPI_TransferArrayIN_WS(unsigned int DeviceIdx, unsigned char *ReadArray, unsigned int Length, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int WaitPort, unsigned int WaitPin, unsigned int WaitState);

eProDasDLL_API int eProDas_MasterSPI_TransferArrayWS2(unsigned int DeviceIdx, unsigned char *WriteArray, unsigned char *ReadArray, unsigned int Length, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int WaitPort, unsigned int WaitPin, unsigned int WaitState);
eProDasDLL_API int eProDas_MasterSPI_TransferArrayOUT_WS2(unsigned int DeviceIdx, unsigned char *WriteArray, unsigned int Length, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int WaitPort, unsigned int WaitPin, unsigned int WaitState);
eProDasDLL_API int eProDas_MasterSPI_TransferArrayIN_WS2(unsigned int DeviceIdx, unsigned char *ReadArray, unsigned int Length, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int WaitPort, unsigned int WaitPin, unsigned int WaitState);

eProDasDLL_API int eProDas_StatusSPI(unsigned int DeviceIdx, unsigned int &BufferFull, unsigned int &WriteCollision, unsigned int &ReceiveOverflow);

///////////////// utilities: supporting SPI chips

eProDasDLL_API int eProDas_SetInternalSPI_MasterMode_MCP320x(unsigned int DeviceIdx, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int CorrectFirstBit);
eProDasDLL_API int eProDas_ReadExternalAD_MCP320x(unsigned int DeviceIdx, unsigned int Channel, unsigned int SingleEnded, unsigned int &Result, unsigned int ChipSelectPort, unsigned int ChipSelectBit);
eProDasDLL_API int eProDas_ReadExternalAD_MCP320x_All(unsigned int DeviceIdx, unsigned int SingleEnded, unsigned int *Results, unsigned int ChipSelectPort, unsigned int ChipSelectBit);
eProDasDLL_API int eProDas_ReadExternalAD_MCP320x_Selected(unsigned int DeviceIdx, unsigned int SingleEndedFlags, unsigned int DifferentialFlags, unsigned int *Results, unsigned int ChipSelectPort, unsigned int ChipSelectBit);
eProDasDLL_API int eProDas_Configure_SPI_Clock_MCP320x(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_SetInternalSPI_MasterMode_ADS7816(unsigned int DeviceIdx, unsigned int ChipSelectPort, unsigned int ChipSelectBit);
eProDasDLL_API int eProDas_ReadExternalAD_ADS7816(unsigned int DeviceIdx, unsigned int &Result, unsigned int ChipSelectPort, unsigned int ChipSelectBit);
eProDasDLL_API int eProDas_Configure_SPI_Clock_ADS7816(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_SetInternalSPI_MasterMode_DAC7611(unsigned int DeviceIdx, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int LoadPort, unsigned int LoadBit);
eProDasDLL_API int eProDas_WriteExternalDA_DAC7611(unsigned int DeviceIdx, unsigned int Value, unsigned int ChipSelectPort, unsigned int ChipSelectBit, unsigned int LoadPort, unsigned int LoadBit);
eProDasDLL_API int eProDas_Configure_SPI_Clock_DAC7611(unsigned int DeviceIdx);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// USART Serial interface
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_Config_USART_RS232(unsigned int DeviceIdx, unsigned int BaudRate, unsigned int EnableInput, unsigned int EnableOutput);
eProDasDLL_API int eProDas_TurnOff_USART(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_USART_SetBaudRateRaw(unsigned int DeviceIdx, unsigned int Divider, unsigned int HighSpeed);
eProDasDLL_API int eProDas_USART_SetBaudRate(unsigned int DeviceIdx, unsigned int BaudRate);
eProDasDLL_API int eProDas_USART_GetBaudRate(unsigned int DeviceIdx, unsigned int &BaudRate);

eProDasDLL_API int eProDas_USART_TransferByte(unsigned int DeviceIdx, unsigned char WriteByte, unsigned char &ReadByte);
eProDasDLL_API int eProDas_USART_TransferByteOUT(unsigned int DeviceIdx, unsigned char WriteByte);
eProDasDLL_API int eProDas_USART_TransferByteIN(unsigned int DeviceIdx, unsigned char &ReadByte);

eProDasDLL_API int eProDas_USART_TransferArray(unsigned int DeviceIdx, unsigned char *WriteArray, unsigned char *ReadArray, unsigned int Length);
eProDasDLL_API int eProDas_USART_TransferArrayOUT(unsigned int DeviceIdx, unsigned char *WriteArray, unsigned int Length);
eProDasDLL_API int eProDas_USART_TransferArrayIN(unsigned int DeviceIdx, unsigned char *ReadArray, unsigned int Length);

eProDasDLL_API int eProDas_USART_ClearReceptionBuffer(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_SwitchFrom_USART_To_SPI(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_SwitchFrom_SPI_To_USART(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_SwitchFrom_USART_To_SPI_TogglePinBefore(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin);
eProDasDLL_API int eProDas_SwitchFrom_USART_To_SPI_TogglePinAfter(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin);
eProDasDLL_API int eProDas_SwitchFrom_USART_To_SPI_TogglePinBeforeAfter(unsigned int DeviceIdx, unsigned int PortBefore, unsigned int PinBefore, unsigned int PortAfter, unsigned int PinAfter);

eProDasDLL_API int eProDas_SwitchFrom_SPI_To_USART_TogglePinBefore(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin);
eProDasDLL_API int eProDas_SwitchFrom_SPI_To_USART_TogglePinAfter(unsigned int DeviceIdx, unsigned int Port, unsigned int Pin);
eProDasDLL_API int eProDas_SwitchFrom_SPI_To_USART_TogglePinBeforeAfter(unsigned int DeviceIdx, unsigned int PortBefore, unsigned int PinBefore, unsigned int PortAfter, unsigned int PinAfter);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// RDTSC and other time related functions
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API void eProDas_Get_RDTSC_TickInformation(__int64 &TicksInMicroSec, __int64 &TicksInMiliSec, __int64 &TicksInSec);

eProDasDLL_API unsigned __int64 eProDas_ExecRDTSC();

eProDasDLL_API void eProDas_Sleep(unsigned int MiliSeconds); //wrapper function for Windows Sleep

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// time related measurements
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_MeasureDelay_HighRes(unsigned int DeviceIdx, unsigned int ExcitationPort, unsigned int ExcitationPin, unsigned int ConfigPins, unsigned int ActiveExcitationState, unsigned int ActiveDetectedState, unsigned int WaitForInactiveState, unsigned int StopExcitingAtStart, unsigned int TimeOut, unsigned __int64 &Delay_12MHz_Ticks);

eProDasDLL_API int eProDas_StartMeasureDelay_HighRes(unsigned int DeviceIdx, unsigned int ExcitationPort, unsigned int ExcitationPin, unsigned int ConfigPins, unsigned int ActiveExcitationState, unsigned int ActiveDetectedState, unsigned int WaitForInactiveState, unsigned int StopExcitingAtStart);
eProDasDLL_API int eProDas_MonitorMeasureDelay_HighRes(unsigned int DeviceIdx, unsigned int &MeasurementInProgress, unsigned int &MeasurementFinished, unsigned __int64 &Delay_12MHz_Ticks);
eProDasDLL_API int eProDas_StopMeasureDelay_HighRes(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_MeasureDelay_MidRes(unsigned int DeviceIdx, unsigned int ExcitationPort, unsigned int ExcitationPin, unsigned int MonitoringPort, unsigned int MonitoringPin, unsigned int ConfigPins, unsigned int ActiveExcitationState, unsigned int ActiveDetectedState, unsigned int WaitForInactiveState, unsigned int StopExcitingAtStart, unsigned int &Delay_12MHz_Ticks);

eProDasDLL_API int eProDas_MeasureDelay_LowRes(unsigned int DeviceIdx, unsigned int ExcitationPort, unsigned int ExcitationPin, unsigned int MonitoringPort, unsigned int MonitoringPin, unsigned int ConfigPins, unsigned int ActiveExcitationState, unsigned int ActiveDetectedState, unsigned int WaitForInactiveState, unsigned int StopExcitingAtStart, unsigned int TimeOut, unsigned __int64 &Delay_12MHz_Ticks);

eProDasDLL_API int eProDas_StartMeasureDelay_LowRes(unsigned int DeviceIdx, unsigned int ExcitationPort, unsigned int ExcitationPin, unsigned int MonitoringPort, unsigned int MonitoringPin, unsigned int ConfigPins, unsigned int ActiveExcitationState, unsigned int ActiveDetectedState, unsigned int WaitForInactiveState, unsigned int StopExcitingAtStart);
eProDasDLL_API int eProDas_MonitorMeasureDelay_LowRes(unsigned int DeviceIdx, unsigned int &MeasurementInProgress, unsigned int &MeasurementFinished, unsigned __int64 &Delay_12MHz_Ticks);
eProDasDLL_API int eProDas_StopMeasureDelay_LowRes(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_MeasureDelay_Vernier_MD_ULI_HighRes(unsigned int DeviceIdx, unsigned int ExcitationPort, unsigned int ExcitationPin, unsigned int ConfigPins, unsigned __int64 &Delay_12MHz_Ticks);
eProDasDLL_API int eProDas_MeasureDistance_Vernier_MD_ULI_HighRes(unsigned int DeviceIdx, unsigned int ExcitationPort, unsigned int ExcitationPin, unsigned int ConfigPins, double Speed_MetersPerSecond, double &Distance);

eProDasDLL_API int eProDas_MeasureDelay_Vernier_MD_ULI_MidRes(unsigned int DeviceIdx, unsigned int ExcitationPort, unsigned int ExcitationPin, unsigned int MonitoringPort, unsigned int MonitoringPin, unsigned int ConfigPins, unsigned int &Delay_12MHz_Ticks);
eProDasDLL_API int eProDas_MeasureDistance_Vernier_MD_ULI_MidRes(unsigned int DeviceIdx, unsigned int ExcitationPort, unsigned int ExcitationPin, unsigned int MonitoringPort, unsigned int MonitoringPin, unsigned int ConfigPins, double Speed_MetersPerSecond, double &Distance);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Periodic actions
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_GetPeriodicConfigurationStep(unsigned int DeviceIdx, unsigned int &Step);

eProDasDLL_API int eProDas_ClearPeriodicActions(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_SetPeriodicMode(unsigned int DeviceIdx, unsigned int Mode, unsigned int OUT_Periods, unsigned int IN_Periods, unsigned int Const_OUT_Length);

eProDasDLL_API int eProDas_AnalyzePeriodicActions(unsigned int DeviceIdx, unsigned int TextualReport, unsigned int Disassembly, unsigned int SaveToFile);
eProDasDLL_API int eProDas_GetParametersOfPeriodicActions(unsigned int DeviceIdx, eProDasStruct_PeriodicParameters &Data);

eProDasDLL_API int eProDas_GetSizeOfPeriodicTextualReport(unsigned int DeviceIdx, unsigned int &Size);
eProDasDLL_API int eProDas_GetPeriodicTextualReport(unsigned int DeviceIdx, char *Buffer);

eProDasDLL_API int eProDas_ProgramPeriodicActions(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_SetPeriodicClockRaw(unsigned int DeviceIdx, unsigned int MainDivider, unsigned int ExtendedDivider, unsigned int Forced);
eProDasDLL_API int eProDas_SetPeriodicClockFrequency(unsigned int DeviceIdx, unsigned int FrequencyHz, unsigned int Forced);
eProDasDLL_API int eProDas_SetPeriodicClockPeriod(unsigned int DeviceIdx, unsigned int MicroSeconds, unsigned int MiliSeconds, unsigned int Seconds, unsigned int Minutes, unsigned int Hours, unsigned int Forced);

eProDasDLL_API int eProDas_GetPeriodicClock(unsigned int DeviceIdx, eProDasStruct_PeriodicClock &Data);

eProDasDLL_API int eProDas_PreparePeriodicActions(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_StartPeriodicActions(unsigned int DeviceIdx, unsigned int RaisePriority);
eProDasDLL_API int eProDas_StopPeriodicActions(unsigned int DeviceIdx, unsigned int FinishSent, unsigned int FinishReceived, unsigned char *PostSendBuffer, unsigned int &SendViolations, unsigned int &ReceiveViolations);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Periodic transactions
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_FillConstBufferBeforeStart(unsigned int DeviceIdx, unsigned char *Data);

eProDasDLL_API int eProDas_SendPeriodicPacket(unsigned int DeviceIdx, unsigned char *Data);
eProDasDLL_API int eProDas_SendPeriodicPacket_Advance(unsigned int DeviceIdx, unsigned char *&Data);
eProDasDLL_API int eProDas_SendPeriodicPacket_AdvanceWithStop(unsigned int DeviceIdx, unsigned char *&Data, unsigned char *StopPtr, unsigned char *PostStopData);
eProDasDLL_API int eProDas_SendPeriodicPacket_Circulate(unsigned int DeviceIdx, unsigned char *&Data, unsigned char *StartPtr, unsigned char *StopPtr);
eProDasDLL_API int eProDas_SendPeriodicPacket_CirculateCount(unsigned int DeviceIdx, unsigned char *&Data, unsigned char *StartPtr, unsigned char *StopPtr, unsigned int &Counter);

eProDasDLL_API int eProDas_SendPeriodicPacket_AdvanceMany(unsigned int DeviceIdx, unsigned char *&Data);
eProDasDLL_API int eProDas_SendPeriodicPacket_AdvanceManyWithStop(unsigned int DeviceIdx, unsigned char *&Data, unsigned char *StopPtr, unsigned char *PostStopData);
eProDasDLL_API int eProDas_SendPeriodicPacket_CirculateMany(unsigned int DeviceIdx, unsigned char *&Data, unsigned char *StartPtr, unsigned char *StopPtr);
eProDasDLL_API int eProDas_SendPeriodicPacket_CirculateManyCount(unsigned int DeviceIdx, unsigned char *&Data, unsigned char *StartPtr, unsigned char *StopPtr, unsigned int &Counter);

eProDasDLL_API int eProDas_SendPeriodicPacket_AdvanceMany_FillBuffersBeforeStart(unsigned int DeviceIdx, unsigned char *&Data);

eProDasDLL_API int eProDas_ReceivePeriodicPacket(unsigned int DeviceIdx, unsigned char *Data);
eProDasDLL_API int eProDas_ReceivePeriodicPacket_Advance(unsigned int DeviceIdx, unsigned char *&Data);
eProDasDLL_API int eProDas_ReceivePeriodicPacket_AdvanceWithStop(unsigned int DeviceIdx, unsigned char *&Data, unsigned char *StopPtr);
eProDasDLL_API int eProDas_ReceivePeriodicPacket_Circulate(unsigned int DeviceIdx, unsigned char *&Data, unsigned char *StartPtr, unsigned char *StopPtr);
eProDasDLL_API int eProDas_ReceivePeriodicPacket_CirculateCount(unsigned int DeviceIdx, unsigned char *&Data, unsigned char *StartPtr, unsigned char *StopPtr, unsigned int &Counter);

eProDasDLL_API int eProDas_ReceivePeriodicPacket_AdvanceMany(unsigned int DeviceIdx, unsigned char *&Data);
eProDasDLL_API int eProDas_ReceivePeriodicPacket_AdvanceManyWithStop(unsigned int DeviceIdx, unsigned char *&Data, unsigned char *StopPtr);
eProDasDLL_API int eProDas_ReceivePeriodicPacket_CirculateMany(unsigned int DeviceIdx, unsigned char *&Data, unsigned char *StartPtr, unsigned char *StopPtr);
eProDasDLL_API int eProDas_ReceivePeriodicPacket_CirculateManyCount(unsigned int DeviceIdx, unsigned char *&Data, unsigned char *StartPtr, unsigned char *StopPtr, unsigned int &Counter);

eProDasDLL_API int eProDas_ReceivePeriodicPacket_AdvanceMany_FillBuffersBeforeStart(unsigned int DeviceIdx, unsigned char *&Data);

eProDasDLL_API int eProDas_UncompletedPeriodicSends(unsigned int DeviceIdx, unsigned int &UncompletedPeriodicSends);
eProDasDLL_API int eProDas_UncompletedPeriodicReceives(unsigned int DeviceIdx, unsigned int &UncompletedPeriodicReceives);

eProDasDLL_API int eProDas_WaitAnySendPeriodicTransaction(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_WaitAnyReceivePeriodicTransaction(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_WaitAnyPeriodicTransaction(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_WaitAnySendPeriodicTransactionWithTimeOut(unsigned int DeviceIdx, unsigned int MiliSeconds, unsigned int &TimeOut);
eProDasDLL_API int eProDas_WaitAnyReceivePeriodicTransactionWithTimeOut(unsigned int DeviceIdx, unsigned int MiliSeconds, unsigned int &TimeOut);
eProDasDLL_API int eProDas_WaitAnyPeriodicTransactionWithTimeOut(unsigned int DeviceIdx, unsigned int MiliSeconds, unsigned int &TimeOut);

eProDasDLL_API int eProDas_WaitAllSendPeriodicTransactions(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_WaitAllReceivePeriodicTransactions(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_WaitAllPeriodicTransactions(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_WaitAllSendPeriodicTransactionsWithTimeOut(unsigned int DeviceIdx, unsigned int MiliSeconds, unsigned int &TimeOut);
eProDasDLL_API int eProDas_WaitAllReceivePeriodicTransactionsWithTimeOut(unsigned int DeviceIdx, unsigned int MiliSeconds, unsigned int &TimeOut);
eProDasDLL_API int eProDas_WaitAllPeriodicTransactionsWithTimeOut(unsigned int DeviceIdx, unsigned int MiliSeconds, unsigned int &TimeOut);

eProDasDLL_API int eProDas_DoesNextPeriodicSendFail(unsigned int DeviceIdx, unsigned int &SendFails);
eProDasDLL_API int eProDas_DoesNextPeriodicReceiveFail(unsigned int DeviceIdx, unsigned int &ReceiveFails);
eProDasDLL_API int eProDas_DoesNextPeriodicSendReceiveFail(unsigned int DeviceIdx, unsigned int &SendFails, unsigned int &ReceiveFails);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Periodic commands
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_AddPeriodicAction_ReadPort(unsigned int DeviceIdx, unsigned int PortIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_ReadLatch(unsigned int DeviceIdx, unsigned int PortIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_ReadTris(unsigned int DeviceIdx, unsigned int PortIdx);

eProDasDLL_API int eProDas_AddPeriodicAction_WritePort(unsigned int DeviceIdx, unsigned int PortIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_WriteTris(unsigned int DeviceIdx, unsigned int PortIdx);

eProDasDLL_API int eProDas_AddPeriodicAction_WriteConst2Port(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int Const);
eProDasDLL_API int eProDas_AddPeriodicAction_WriteConst2Tris(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int Const);

eProDasDLL_API int eProDas_AddPeriodicAction_ClearPort(unsigned int DeviceIdx, unsigned int PortIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_SetPort(unsigned int DeviceIdx, unsigned int PortIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_ComplementPort(unsigned int DeviceIdx, unsigned int PortIdx);

eProDasDLL_API int eProDas_AddPeriodicAction_ClearPin(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int PinIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_SetPin(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int PinIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_TogglePin(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int PinIdx);

eProDasDLL_API int eProDas_AddPeriodicAction_AND_ConstWithPort(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int Const);
eProDasDLL_API int eProDas_AddPeriodicAction_OR_ConstWithPort(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int Const);
eProDasDLL_API int eProDas_AddPeriodicAction_XOR_ConstWithPort(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int Const);

eProDasDLL_API int eProDas_AddPeriodicAction_ConfigPortAsOutput(unsigned int DeviceIdx, unsigned int PortIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_ConfigPortAsInput(unsigned int DeviceIdx, unsigned int PortIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_TogglePortDirection(unsigned int DeviceIdx, unsigned int PortIdx);

eProDasDLL_API int eProDas_AddPeriodicAction_AND_ConstWithTris(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int Const);
eProDasDLL_API int eProDas_AddPeriodicAction_OR_ConstWithTris(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int Const);
eProDasDLL_API int eProDas_AddPeriodicAction_XOR_ConstWithTris(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int Const);

eProDasDLL_API int eProDas_AddPeriodicAction_ConfigPinAsOutput(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int PinIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_ConfigPinAsInput(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int PinIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_TogglePinDirection(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int PinIdx);

eProDasDLL_API int eProDas_AddPeriodicAction_IncrementPort(unsigned int DeviceIdx, unsigned int PortIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_IncrementSubPort(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int StartPin, unsigned int EndPin);
eProDasDLL_API int eProDas_AddPeriodicAction_IncrementSubPortWithReset(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int StartPin, unsigned int EndPin, unsigned int MatchValue, unsigned int ResetValue);

eProDasDLL_API int eProDas_AddPeriodicAction_RotateLeftPort(unsigned int DeviceIdx, unsigned int PortIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_RotateLeftSubPort(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int StartPin, unsigned int EndPin);
eProDasDLL_API int eProDas_AddPeriodicAction_RotateLeftSubPortWithReset(unsigned int DeviceIdx, unsigned int PortIdx, unsigned int StartPin, unsigned int EndPin, unsigned int MatchValue, unsigned int ResetValue);

eProDasDLL_API int eProDas_AddPeriodicAction_ReadInternalAD(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_ReadInternalAD_8BitLeftAligned(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_AddPeriodicAction_ReadInternalComparators(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_ReadInternalAD_Comparators(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_AddPeriodicAction_WaitInternalAD(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_FlushUSB_WaitInternalAD(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_AddPeriodicAction_StartInternalAD(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_AddPeriodicAction_AcquireConstInternalAD(unsigned int DeviceIdx, unsigned int ADChannel);

eProDasDLL_API int eProDas_AddPeriodicAction_AcquireInternalAD(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_CalcInternalAD_AcquisitionCode(unsigned int ADChannel, unsigned char &Code);

eProDasDLL_API int eProDas_AddPeriodicAction_AcquireNextInternalADChannelInChain(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_AddPeriodicAction_SetConstInternalVoltageReference(unsigned int DeviceIdx, unsigned int Enabled, unsigned int Value, unsigned int Range, unsigned int SourceOnPin, unsigned int OutputOnPin);

eProDasDLL_API int eProDas_AddPeriodicAction_SetInternalVoltageReference(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_CalcVoltageReferenceCode(unsigned int Enabled, unsigned int Value, unsigned int Range, unsigned int SourceOnPin, unsigned int OutputOnPin, unsigned char &Code);

eProDasDLL_API int eProDas_AddPeriodicAction_Delay(unsigned int DeviceIdx, unsigned int Length_ICs);

eProDasDLL_API int eProDas_AddPeriodicAction_FlushUSB(unsigned int DeviceIdx);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Periodic commands related to SPI bus
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_AddPeriodicAction_SPI_Transfer(unsigned int DeviceIdx, unsigned int TxMode, unsigned int TxConst, unsigned int CorrectFirstBit, unsigned int EnableRx, unsigned int WaitSPI, int TestPoint);

eProDasDLL_API int eProDas_AddPeriodicAction_Start_SPI_Transfer(unsigned int DeviceIdx, unsigned int TxMode, unsigned int TxConst, unsigned int CorrectFirstBit);
eProDasDLL_API int eProDas_AddPeriodicAction_Wait_SPI_Transfer(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_Finish_SPI_Transfer(unsigned int DeviceIdx, unsigned int EnableRx, int TestPoint);

eProDasDLL_API int eProDas_AddPeriodicAction_Change_SPI_Clock(unsigned int DeviceIdx, int IN_SampleAtTheEnd, int ClockIdleStateHigh, int ClockSpeed, unsigned int ClockPeriod, unsigned int ClockPrescaler);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Out of the box support for SPI periphery
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_AddPeriodicAction_MCP3208(unsigned int DeviceIdx, unsigned int Channel, unsigned int SingleEnded, unsigned int ChipSelectPort, unsigned int ChipSelectPin, unsigned int CorrectFirstBit, unsigned int WaitSPI, int TestPoint);

eProDasDLL_API int eProDas_AddPeriodicAction_MCP3208_Part1(unsigned int DeviceIdx, unsigned int Channel, unsigned int SingleEnded, unsigned int ChipSelectPort, unsigned int ChipSelectPin, unsigned int CorrectFirstBit);
eProDasDLL_API int eProDas_AddPeriodicAction_MCP3208_Part2(unsigned int DeviceIdx, unsigned int Channel, unsigned int CorrectFirstBit, int TestPoint);
eProDasDLL_API int eProDas_AddPeriodicAction_MCP3208_Part3(unsigned int DeviceIdx, unsigned int CorrectFirstBit, int TestPoint);
eProDasDLL_API int eProDas_AddPeriodicAction_MCP3208_Part4(unsigned int DeviceIdx, unsigned int ChipSelectPort, unsigned int ChipSelectPin, int TestPoint);

eProDasDLL_API int eProDas_Calc_MCP3208_ChannelCode(unsigned int Channel, unsigned int SingleEnded, unsigned char &Code);

eProDasDLL_API unsigned int eProDas_MCP3208_BuildResult(unsigned char *Data);
eProDasDLL_API unsigned int eProDas_MCP3208_BuildResult_Advance(unsigned char *&Data);

eProDasDLL_API unsigned int eProDas_MCP3208_BuildResult_Separated(unsigned char FirstByte, unsigned char SecondByte);

eProDasDLL_API int eProDas_AddPeriodicAction_SPI_Clock_MCP3208(unsigned int DeviceIdx, unsigned int ReconfigFrequency, unsigned int ReconfigSampleInstant, unsigned int ReconfigIdleState);

eProDasDLL_API int eProDas_AddPeriodicAction_MCP3208_9bit(unsigned int DeviceIdx, unsigned int Channel, unsigned int SingleEnded, unsigned int ChipSelectPort, unsigned int ChipSelectPin, unsigned int CorrectFirstBit, unsigned int WaitSPI, int TestPoint);

eProDasDLL_API int eProDas_AddPeriodicAction_MCP3208_9bit_Part1(unsigned int DeviceIdx, unsigned int Channel, unsigned int SingleEnded, unsigned int ChipSelectPort, unsigned int ChipSelectPin, unsigned int CorrectFirstBit);
eProDasDLL_API int eProDas_AddPeriodicAction_MCP3208_9bit_Part2(unsigned int DeviceIdx, unsigned int CorrectFirstBit, int TestPoint);
eProDasDLL_API int eProDas_AddPeriodicAction_MCP3208_9bit_Part3(unsigned int DeviceIdx, unsigned int ChipSelectPort, unsigned int ChipSelectPin, int TestPoint);

eProDasDLL_API unsigned int eProDas_MCP3208_9bit_BuildResult(unsigned char *Data);
eProDasDLL_API unsigned int eProDas_MCP3208_9bit_BuildResult_Advance(unsigned char *&Data);

eProDasDLL_API unsigned int eProDas_MCP3208_9bit_BuildResult_Separated(unsigned char FirstByte, unsigned char SecondByte);

eProDasDLL_API int eProDas_Calc_MCP3208_9bit_ChannelCode(unsigned int Channel, unsigned int SingleEnded, unsigned char &Code);

eProDasDLL_API int eProDas_AddPeriodicAction_MCP3208_8bit(unsigned int DeviceIdx, unsigned int Channel, unsigned int SingleEnded, unsigned int ChipSelectPort, unsigned int ChipSelectPin, unsigned int CorrectFirstBit, unsigned int WaitSPI, int TestPoint);

eProDasDLL_API int eProDas_AddPeriodicAction_MCP3208_8bit_Part1(unsigned int DeviceIdx, unsigned int Channel, unsigned int SingleEnded, unsigned int ChipSelectPort, unsigned int ChipSelectPin, unsigned int CorrectFirstBit);
eProDasDLL_API int eProDas_AddPeriodicAction_MCP3208_8bit_Part2(unsigned int DeviceIdx, unsigned int CorrectFirstBit, int TestPoint);
eProDasDLL_API int eProDas_AddPeriodicAction_MCP3208_8bit_Part3(unsigned int DeviceIdx, unsigned int ChipSelectPort, unsigned int ChipSelectPin, int TestPoint);

eProDasDLL_API unsigned int eProDas_MCP3208_8bit_BuildResult(unsigned char *Data);
eProDasDLL_API unsigned int eProDas_MCP3208_8bit_BuildResult_Advance(unsigned char *&Data);

eProDasDLL_API int eProDas_Calc_MCP3208_8bit_ChannelCode(unsigned int Channel, unsigned int SingleEnded, unsigned char &Code);

eProDasDLL_API int eProDas_AddPeriodicAction_ADS7816(unsigned int DeviceIdx, unsigned int ChipSelectPort, unsigned int ChipSelectPin, unsigned int CorrectFirstBit, unsigned int WaitSPI, int TestPoint);

eProDasDLL_API int eProDas_AddPeriodicAction_ADS7816_Part1(unsigned int DeviceIdx, unsigned int ChipSelectPort, unsigned int ChipSelectPin, unsigned int CorrectFirstBit);
eProDasDLL_API int eProDas_AddPeriodicAction_ADS7816_Part2(unsigned int DeviceIdx, unsigned int CorrectFirstBit, int TestPoint);
eProDasDLL_API int eProDas_AddPeriodicAction_ADS7816_Part3(unsigned int DeviceIdx, unsigned int ChipSelectPort, unsigned int ChipSelectPin, int TestPoint);

eProDasDLL_API unsigned int eProDas_ADS7816_BuildResult(unsigned char *Data);
eProDasDLL_API unsigned int eProDas_ADS7816_BuildResult_Advance(unsigned char *&Data);

eProDasDLL_API unsigned int eProDas_ADS7816_BuildResult_Separated(unsigned char FirstByte, unsigned char SecondByte);

eProDasDLL_API int eProDas_AddPeriodicAction_SPI_Clock_ADS7816(unsigned int DeviceIdx, unsigned int ReconfigFrequency, unsigned int ReconfigSampleInstant, unsigned int ReconfigIdleState);

eProDasDLL_API int eProDas_AddPeriodicAction_DAC7611(unsigned int DeviceIdx, unsigned int Value, unsigned int ChipSelectPort, unsigned int ChipSelectPin, unsigned int LoadPort, unsigned int LoadPin, unsigned int CorrectFirstBit, unsigned int WaitSPI, int TestPoint);

eProDasDLL_API int eProDas_AddPeriodicAction_DAC7611_Part1(unsigned int DeviceIdx, unsigned int Value, unsigned int ChipSelectPort, unsigned int ChipSelectPin, unsigned int CorrectFirstBit);
eProDasDLL_API int eProDas_AddPeriodicAction_DAC7611_Part2(unsigned int DeviceIdx, unsigned int Value, unsigned int CorrectFirstBit, int TestPoint);
eProDasDLL_API int eProDas_AddPeriodicAction_DAC7611_Part3(unsigned int DeviceIdx, unsigned int ChipSelectPort, unsigned int ChipSelectPin, unsigned int LoadPort, unsigned int LoadPin, int TestPoint);

eProDasDLL_API int eProDas_DAC7611_BuildValue(unsigned int Value, unsigned char *Data);
eProDasDLL_API int eProDas_DAC7611_BuildValue_Advance(unsigned int Value, unsigned char *&Data);

eProDasDLL_API int eProDas_DAC7611_BuildValue_Separated(unsigned int Value, unsigned char &Byte1, unsigned char &Byte2);

eProDasDLL_API int eProDas_AddPeriodicAction_SPI_Clock_DAC7611(unsigned int DeviceIdx, unsigned int ReconfigFrequency, unsigned int ReconfigSampleInstant, unsigned int ReconfigIdleState);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Advanced periodic commands
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_ClearTestPoints(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_ReadTestPoints(unsigned int DeviceIdx, unsigned int &TestPoints);

eProDasDLL_API int eProDas_AddPeriodicAction_ReadWREG(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_AddPeriodicAction_WriteConst2WREG(unsigned int DeviceIdx, unsigned int Const);

eProDasDLL_API int eProDas_AddPeriodicAction_CopyPort2WREG(unsigned int DeviceIdx, unsigned int PortIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_CopyLatch2WREG(unsigned int DeviceIdx, unsigned int PortIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_CopyTris2WREG(unsigned int DeviceIdx, unsigned int PortIdx);

eProDasDLL_API int eProDas_AddPeriodicAction_CopyWREG2Port(unsigned int DeviceIdx, unsigned int PortIdx);
eProDasDLL_API int eProDas_AddPeriodicAction_CopyWREG2Tris(unsigned int DeviceIdx, unsigned int PortIdx);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Defining new periodic commands
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_DisablePeriodicAnnotations(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_EnablePeriodicAnnotations(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_AnnotateNewPeriodicAction(unsigned int DeviceIdx, char *Annotation);

eProDasDLL_API int eProDas_AnnotateNewPeriodicAction(unsigned int DeviceIdx, char *Annotation);
eProDasDLL_API int eProDas_InsertNewPeriodicLabel(unsigned int DeviceIdx, char *Label);
eProDasDLL_API int eProDas_AddPeriodicAction_CodeASM(unsigned int DeviceIdx, unsigned int CodeASM);

eProDasDLL_API int eProDas_ClearAllPeriodicHints(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_SetPeriodicHint_StartInternalAD(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_SetPeriodicHint_StopInternalAD(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_SetPeriodicHint_WaitInternalAD(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_SetPeriodicHint_AD_ResultLow_Consumed(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_SetPeriodicHint_AD_ResultHigh_Consumed(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_SetPeriodicHint_StartSPI(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_SetPeriodicHint_WaitSPI(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_SetPeriodicHint_FinishSPI(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_SetPeriodicHint_ChangeSPIClock(unsigned int DeviceIdx, unsigned int NewTransferDuration);

eProDasDLL_API int eProDas_SetPeriodicHint_FlushUSB(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_SetPeriodicHint_CorrectDuration(unsigned int DeviceIdx, int Correction);

eProDasDLL_API int eProDas_SetPeriodicHint_Ignore_FSR0_Changes(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_SetPeriodicHint_Ignore_FSR1_Changes(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_SetPeriodicHint_Ignore_FSR2_Changes(unsigned int DeviceIdx);

eProDasDLL_API int eProDas_ClearPeriodicHint_Ignore_FSR0_Changes(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_ClearPeriodicHint_Ignore_FSR1_Changes(unsigned int DeviceIdx);
eProDasDLL_API int eProDas_ClearPeriodicHint_Ignore_FSR2_Changes(unsigned int DeviceIdx);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// SPI & USART backbone
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_TransferBackbone(unsigned int DeviceIdx, unsigned char *CommandPacket, unsigned char *ReturningPacket, unsigned int CommandPacketLength, unsigned int ReturningPacketLength);

eProDasDLL_API int eProDas_Transfer_CMD_SPI_Transfer(unsigned int Send, unsigned int Receive, unsigned int Length, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_SPI_Transfer_AutoFill(unsigned int Receive, unsigned int Length, unsigned char *&CmdBuffer, unsigned char *OutData);

eProDasDLL_API int eProDas_Transfer_CMD_SPI_RepeatTransfer(unsigned int TogglePinBefore, unsigned int TogglePinAfter, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_SPI_RepeatTransfer_AutoFill(unsigned int TogglePinBefore, unsigned int TogglePinAfter, unsigned int Length, unsigned char *&CmdBuffer, unsigned char *OutData);

eProDasDLL_API int eProDas_Transfer_CMD_SPI_ConfigFirstBitCorrection(unsigned int Action, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_Transfer_CMD_SPI_ClockSpeed(unsigned int ClockRegime, unsigned int Timer2Period, unsigned int Timer2Prescaler, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_SPI_ClockConfig(unsigned int IN_SampleAtTheEnd, unsigned int ClockIdleStateHigh, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_Transfer_CMD_USART_OUT_Transfer(unsigned int Length, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_USART_OUT_Transfer_AutoFill(unsigned int Length, unsigned char *&CmdBuffer, unsigned char *OutData);

eProDasDLL_API int eProDas_Transfer_CMD_USART_IN_Transfer(unsigned int Length, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_Transfer_CMD_USART_DuplexTransfer(unsigned int Length, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_USART_DuplexTransfer_AutoFill(unsigned int Length, unsigned char *&CmdBuffer, unsigned char *OutData);

eProDasDLL_API int eProDas_Transfer_CMD_USART_BaudRate(unsigned int BaudRate, unsigned char *&CmdBuffer, unsigned int &ResultedBaudRate);

eProDasDLL_API int eProDas_Transfer_CMD_USART_ClearReceptionBuffer(unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_Transfer_CMD_SwitchFrom_SPI_To_USART(unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_SwitchFrom_USART_To_SPI(unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_Transfer_CMD_ReadWritePorts(unsigned int ReadFlags, unsigned int WriteFlags, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_ReadWritePorts_AutoFill(unsigned int ReadFlags, unsigned int WriteFlags, unsigned char *WriteValues, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_Transfer_CMD_Read_XOR_Ports(unsigned int ReadFlags, unsigned int XORFlags, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_Read_XOR_Ports_AutoFill(unsigned int ReadFlags, unsigned int XORFlags, unsigned char *XORValues, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_Transfer_CMD_Write_XOR_TRISes(unsigned int WriteFlags, unsigned int XORFlags, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_Write_XOR_TRISes_AutoFill(unsigned int WriteFlags, unsigned int XORFlags, unsigned char *WriteXORValues, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_Transfer_CMD_ADD_PortWithBitmask(unsigned int Port, unsigned int BitMask, unsigned int ValueToAdd, unsigned int MatchValue, unsigned int ResetValue, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_ROT_PortWithBitmask(unsigned int Port, unsigned int StartPin, unsigned int EndPin, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_WritePortWithBitmask(unsigned int Port, unsigned int BitMask, unsigned int ValueToWrite, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_Transfer_CMD_TogglePin(unsigned int Port, unsigned int Pin, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_WaitPinState(unsigned int Port, unsigned int Pin, unsigned int State, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_Transfer_CMD_ReadAllInternalADChannels(unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_ReadSelectedInternalADChannels(unsigned int ChannelFlags, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_Transfer_CMD_ReadInternalADChannel(unsigned int Channel, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_ReadInternalADChannel_0_3(unsigned int Channel, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_Transfer_CMD_AcquireFirstInternalADChannelInChain(unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_AcquireReadFirstInternalADChannelInChain(unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_Transfer_CMD_AcquireReadNextInternalADChannelInChain(unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_ReadAcquireNextInternalADChannelInChain(unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_Transfer_CMD_ReadInternalComparators(unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_ConfigureInternalVoltageReference(unsigned int Enabled, unsigned int Value, unsigned int Range, unsigned int SourceOnPin, unsigned int OutputOnPin, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_Transfer_CMD_Delay(unsigned int Delay, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_InterTransferDelay(unsigned int Delay, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_Transfer_CMD_Exit(unsigned char *&CmdBuffer);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// WaitState backbone
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_WaitStateBackbone(unsigned int DeviceIdx, unsigned char *CommandPacket, unsigned char *ReturningPacket, unsigned int CommandPacketLength, unsigned int ReturningPacketLength);

eProDasDLL_API int eProDas_WaitState_CMD_PinState(unsigned int Port, unsigned int Pin, unsigned int State, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_WaitState_CMD_PortState(unsigned int Port, unsigned int BitMask, unsigned int State, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_WaitState_CMD_ComparatorsState(unsigned int MonitorComp1, unsigned int MonitorComp2, unsigned int State1, unsigned int State2, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_WaitState_CMD_InternalAD(unsigned int Channel, unsigned int LowThreshold, unsigned int HighThreshold, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_WaitState_CMD_RepetitivePinState(unsigned int Repetitions, unsigned int Port, unsigned int Pin, unsigned int State, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_WaitState_CMD_RepetitivePortState(unsigned int Repetitions, unsigned int Port, unsigned int BitMask, unsigned int State, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_WaitState_CMD_RepetitiveComparatorsState(unsigned int Repetitions, unsigned int MonitorComp1, unsigned int MonitorComp2, unsigned int State1, unsigned int State2, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_WaitState_CMD_StablePortState(unsigned int Repetitions, unsigned int Port, unsigned int BitMask, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_WaitState_CMD_StableComparatorsState(unsigned int Repetitions, unsigned int MonitorComp1, unsigned int MonitorComp2, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_WaitState_CMD_Exit(unsigned char *&CmdBuffer);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Direct memory access
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_ReadProgramRAM(unsigned int DeviceIdx, unsigned int StartAddress, unsigned int Length, unsigned char *Buffer);

eProDasDLL_API int eProDas_EraseProgramRAM(unsigned int DeviceIdx, unsigned int StartAddress, unsigned int Length);
eProDasDLL_API int eProDas_WriteProgramRAM(unsigned int DeviceIdx, unsigned int StartAddress, unsigned char *Values);

eProDasDLL_API int eProDas_ReadConfigurationByte(unsigned int DeviceIdx, unsigned int ByteOffset, unsigned char &Result);
eProDasDLL_API int eProDas_WriteConfigurationByte(unsigned int DeviceIdx, unsigned int ByteOffset, unsigned char Value);

eProDasDLL_API int eProDas_ReadDataRAM(unsigned int DeviceIdx, unsigned int StartAddress, unsigned int Length, unsigned char *Buffer);
eProDasDLL_API int eProDas_WriteDataRAM(unsigned int DeviceIdx, unsigned int StartAddress, unsigned int Length, unsigned char *Values);

eProDasDLL_API int eProDas_WriteDataRAMWithBitMask(unsigned int DeviceIdx, unsigned int StartAddress, unsigned int Length, unsigned char *AND_OR_Masks);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Access RAM / Special Function Registers
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_ReadAccessSFR(unsigned int DeviceIdx, unsigned char LowAddress, unsigned int Length, unsigned char *Buffer);
eProDasDLL_API int eProDas_WriteAccessSFR(unsigned int DeviceIdx, unsigned char LowAddress, unsigned int Length, unsigned char *Values);

eProDasDLL_API int eProDas_AND_AccessSFR(unsigned int DeviceIdx, unsigned char LowAddress, unsigned int Length, unsigned char *Values);
eProDasDLL_API int eProDas_OR_AccessSFR(unsigned int DeviceIdx, unsigned char LowAddress, unsigned int Length, unsigned char *Values);
eProDasDLL_API int eProDas_XOR_AccessSFR(unsigned int DeviceIdx, unsigned char LowAddress, unsigned int Length, unsigned char *Values);
eProDasDLL_API int eProDas_XORXOR_AccessSFR(unsigned int DeviceIdx, unsigned char LowAddress, unsigned int Length, unsigned char *Values);
eProDasDLL_API int eProDas_ADD_AccessSFR(unsigned int DeviceIdx, unsigned char LowAddress, unsigned char Value);
eProDasDLL_API int eProDas_VarOperations(unsigned int DeviceIdx, unsigned char LowAddress, unsigned char Flags);

eProDasDLL_API int eProDas_WriteAccessSFRWithBitMask(unsigned int DeviceIdx, unsigned char LowAddress, unsigned int Length, unsigned char *AND_OR_Masks);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// General purpose AccessRAM & SFR registers manipulator
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_AccessSFR(unsigned int DeviceIdx, unsigned char *OutPacket, unsigned int OutLength, unsigned char *InPacket, unsigned int InLength);

eProDasDLL_API int eProDas_AccessSFR_CMD_Exit(unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_AccessSFR_CMD_SwitchRead(unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_AccessSFR_CMD_SwitchReadInc(unsigned int Repetitions, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_AccessSFR_CMD_SwitchWrite(unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_AccessSFR_CMD_SwitchWriteInc(unsigned int Repetitions, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_AccessSFR_CMD_SwitchAND(unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_AccessSFR_CMD_SwitchANDInc(unsigned int Repetitions, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_AccessSFR_CMD_SwitchOR(unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_AccessSFR_CMD_SwitchORInc(unsigned int Repetitions, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_AccessSFR_CMD_SwitchXOR(unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_AccessSFR_CMD_SwitchXORInc(unsigned int Repetitions, unsigned char *&CmdBuffer);

eProDasDLL_API int eProDas_AccessSFR_CMD_AddAddress(unsigned char LowAddress, unsigned char *&CmdBuffer);
eProDasDLL_API int eProDas_AccessSFR_CMD_AddData(unsigned char Data, unsigned char *&CmdBuffer);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Assembly of PIC's instruction codes
/////////////////////////////////////////////////////////////////////////////////////////////////////////

//SK:        4-bit literal

//K:         8-bit literal

//LK:        12-bit literal

//File:      8-bit address in the file register

//File1,2:   12-bit address in the file register

//Dest:      0 = WREG, 1 = FILE

//Bank:      0 = access RAM, 1 = banked through BSR

//Fast:      0 = no copying to shadow registers, 1 = WREG,STATUS,BSR are copied into shadow registers (call)
//           0 = no restoration from shadow registers, 1 = WREG,STATUS,BSR are restored from shadow registers (return, retfie)

//Bit:       bit number from 0 to 7

//Disp:      8-bit displacement (signed)

//LDisp:     11-bit displacement (signed)

//Address:   20-bit absolute address

//FSR:       FSR register from 0 to 2

eProDasDLL_API int eProDas_CodeASM_ADDLW(unsigned int K, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_ADDWF(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_ADDWFC(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_ANDLW(unsigned int K, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_ANDWF(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_BCF(unsigned int File, unsigned int Bit, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_BSF(unsigned int File, unsigned int Bit, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_BTFSC(unsigned int File, unsigned int Bit, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_BTFSS(unsigned int File, unsigned int Bit, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_BTG(unsigned int File, unsigned int Bit, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_BRA(int LDisp, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_BC(int Disp, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_BN(int Disp, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_BNC(int Disp, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_BNN(int Disp, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_BNOV(int Disp, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_BNZ(int Disp, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_BOV(int Disp, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_BZ(int Disp, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_CALL(unsigned int Address, unsigned int Fast, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_CLRF(unsigned int File, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_CLRWDT(unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_COMF(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_CPFSEQ(unsigned int File, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_CPFSGT(unsigned int File, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_CPFSLT(unsigned int File, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_DECF(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_DECFSZ(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_DCFSNZ(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_DAW(unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_GOTO(unsigned int Address, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_INCF(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_INCFSZ(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_INFSNZ(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_IORLW(unsigned int K, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_IORWF(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_LFSR(unsigned int FSR, unsigned int LK, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_MOVLB(unsigned int SK, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_MOVLW(unsigned int K, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_MOVF(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_MOVFF(unsigned int File1, unsigned int File2, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_MOVWF(unsigned int File, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_NEGF(unsigned int File, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_NOP(unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_POP(unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_PUSH(unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_RCALL(int LDisp, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_RESET(unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_RETFIE(unsigned int Fast, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_RETLW(unsigned int K, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_RETURN(unsigned int Fast, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_RLCF(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_RLNCF(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_RRCF(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_RRNCF(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_SETF(unsigned int File, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_SLEEP(unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_SUBLW(unsigned int K, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_SUBFWB(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_SUBWF(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_SUBWFB(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_SWAPF(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_TBLRD_A(unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_TBLRD_AP(unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_TBLRD_AM(unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_TBLRD_PA(unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_TBLWT_A(unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_TBLWT_AP(unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_TBLWT_AM(unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_TBLWT_PA(unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_TSTFSZ(unsigned int File, unsigned int Bank, unsigned int &Code);

eProDasDLL_API int eProDas_CodeASM_XORLW(unsigned int K, unsigned int &Code);
eProDasDLL_API int eProDas_CodeASM_XORWF(unsigned int File, unsigned int Dest, unsigned int Bank, unsigned int &Code);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Disassembly of PIC's instruction codes
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_DisassembleCode(unsigned int CodeASM, unsigned int Address, char *BufferTXT, unsigned int &IC_Length, unsigned int &IC_Duration, int &FSR0_Change, int &FSR1_Change, int &FSR2_Change);

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// unsorted
/////////////////////////////////////////////////////////////////////////////////////////////////////////

eProDasDLL_API int eProDas_UpgradeFirmware(unsigned int DeviceIdx, char *HEXFileName, unsigned int &TotalEraseRetries, unsigned int &TotalWriteRetries);

} //extern "C"

#endif //eProDas_H
