//---------------------------------------------------------------------------------------------
// Include-файл для DLL-библиотеки lcard_ad.dll
// Заголовки функций для работы с платами АЦП/ЦАП
// (C)opyright AO L-Card 1995, 96
//---------------------------------------------------------------------------------------------
// Внимание: в 32-битной версии все данные - 32-битные знаковые числа, за следующими исключениями
// - логические номера каналов  - 16-битные беззнаковые числа;
// - данные АЦП и ЦАП - 16-битные числа со знаком.
// Эти соглашения актуальны при работе с МАССИВАМИ данных.
//---------------------------------------------------------------------------------------------

#ifndef __LC_PROCS_H
#define __LC_PROCS_H

#ifdef __cplusplus
extern "C" {
#endif

void           _EXPORT INSTALLLOGIO();
void           _EXPORT DEINSTALLLOGIO();

unsigned       _EXPORT IN_BYTE(unsigned Port);
unsigned       _EXPORT IN_WORD(unsigned Port);
unsigned       _EXPORT OUT_BYTE(unsigned Port, unsigned Value);
unsigned       _EXPORT OUT_WORD(unsigned Port, unsigned Value);

void           _EXPORT _SEND_COMMAND(WORD Command);
void           _EXPORT _PUT_DATA(WORD Data);
WORD           _EXPORT _GET_DATA();

PTErrorHandler _EXPORT GET_ERROR_HANDLER();
void           _EXPORT SET_ERROR_HANDLER(PTErrorHandler NewErrorHandler);
DWORD          _EXPORT GET_TIMEOUT();
void           _EXPORT SET_TIMEOUT(DWORD Value);

void           _EXPORT REQUESTDMACHANNEL(WORD* Data, unsigned NPoint, unsigned Channel, unsigned Dmm);
void           _EXPORT RELEASEDMACHANNEL(unsigned Channel);

void           _EXPORT SELECT_DEVICE(int DeviceNumber);
void           _EXPORT SET_BOARD_TYPE(int BoardType);
int            _EXPORT GET_BOARD_TYPE();
void           _EXPORT SET_INTERFACE_TYPE(int aEppMode);
void           _EXPORT SET_DEVICE_BINDING(int InterfaceDevice);

void           _EXPORT SET_BASE_ADDRESS(int Address);
void           _EXPORT ENABLE_INT(int _IntEnabled);


int            _EXPORT PLATA_TEST();
WORD           _EXPORT CREATE_CHANNEL(int Channel, int Usil, int Mode);
int            _EXPORT MEMORY_STATE();
int            _EXPORT MEMORY_PM_STATE();
void           _EXPORT SET_INTER_DELAY(int delay_value);
int            _EXPORT LOADBIOS(char* FileName, int DslOff);
void           _EXPORT SET_ADSP_SPEED(int DspType);
void           _EXPORT SET_WAIT_STATE(int wait_state);
void           _EXPORT SET_TIMER_SCALE(int ScaleValue);

void           _EXPORT TIMER_L154_L164(int TimerNumber, int Mode, int Rate);
void           _EXPORT WAIT_TICK_L154_L164(int TimerNumber);
int            _EXPORT GET_TIMER_L154_L164();
void           _EXPORT CALIBRATION();

void           _EXPORT INIT_COMPARATOR(int Channel, int Porog, int BitNPoint, int HandleMode);
void           _EXPORT LOW_POWER(int ModeReg);
void           _EXPORT RESERVED4(WORD* p1, int p2, int p3);
void           _EXPORT RESERVED2(WORD* p1, int p2, int p3);

// Работа с крейто
int            _EXPORT GET_SLOT_CODE(int CraitNumber, int ModuleNumber);
void           _EXPORT RESET_ALL();
WORD           _EXPORT MAKE_CHANNEL(int CraitNumber, int ModuleNumber, int Chan, int Kadrr,
                                    int Usil);
void           _EXPORT PROGRAM_FILTER(int CraitNumber, int ModuleNumber, int CutFrequency,
                                      int AnalogFilterType);
void           _EXPORT PROGRAM_LM_201(int CraitNumber, int ModuleNumber, int Chan,
                                      int Usil1, int Source);
void           _EXPORT PROGRAM_LM_102(int CraitNumber, int ModuleNumber, int Usil1);
void           _EXPORT PROGRAM_LM_501(int CraitNumber, int ModuleNumber,
                                      int M3, int M2, int M1, int EN, int EP, int AN, int AP);
void           _EXPORT PROGRAM_LM_DAC(int CraitNumber, int ModuleNumber, int Mode,
                                      int Coded, int DacCh);
int            _EXPORT GET_LM_401(int CraitNumber, int ModuleNumber);
WORD           _EXPORT LM_404(WORD Coded);
void           _EXPORT PROGRAM_LM_TTLOUT(int CraitNumber, int ModuleNumber, WORD Coded);


// Аналоговый ввод-вывод
void           _EXPORT SETCHANNEL(WORD Channel);
WORD           _EXPORT SAMPLE();
WORD           _EXPORT ADCHAN(WORD Chan);
void           _EXPORT KADR(WORD* Datad, WORD* Chans, int Nch);
void           _EXPORT STREAM(WORD* Datad, int Npoint, WORD Chan, int Rate);
void           _EXPORT SOFT(WORD* Datad, int Nkadr, WORD* Chan, int Nch,
                                          int Rate);
///#ifndef WIN32
void           _EXPORT SOFT_HUGE(WORD* Datad, unsigned long Nkadr, WORD* Chan, int Nch,
                                 int Rate);
///#endif
#ifdef WIN32
void           _EXPORT ALLOCATEBUFFER(DWORD Size, WORD** PLinear, WORD** PPhysical);
void           _EXPORT FREEBUFFER(WORD* Linear);
#else
void           _EXPORT ALLOCATEBUFFER(PTDmaChannel PDmaChannel, unsigned NeedCopy=0);
void           _EXPORT FREEBUFFER(PTDmaChannel PDmaChannel, unsigned NeedCopy=0);
#endif

void           _EXPORT DMAONE(WORD* Datad, int Npoint, int Chan,
                              int Rate, int Dmm);

void           _EXPORT DMAALL(WORD* Datad, int Nkadr, WORD* Chan, int Nch,
                              int Rate, int Dmm);
void           _EXPORT DMA_ALL_DA(WORD* AdDatad, int AdNkadr, WORD* Chan, int Nch,
                                  int Rate, int AdDmm, WORD* DaDatad, int DaNkadr, int DaDmm, int DaNumber);
void           _EXPORT OUTDA(int Coded);
void           _EXPORT SET_DA_NUMBER(int SoftDaMode, int DaNumber);
void           _EXPORT STREAM_OUTDA(WORD Coded);
void           _EXPORT DASTREAM(int Rate, int Npoint, WORD* Datad);
void           _EXPORT DASTREAM_HUGE(int Rate, unsigned long Npoint, WORD* Datad);
void           _EXPORT DADMASTREAM(WORD* Datad, int Npoint, int Rate, int Dmm);

// Ввод-вывод цифровых линий
void           _EXPORT OUTBYTE(int CodeVal);
int            _EXPORT INPBYTE();
int            _EXPORT DSP_INPBYTE();
void           _EXPORT DSP_OUTBYTE(int CodeVal);


// Работа с прерывания
void           _EXPORT INTR_SETUP(int Number);
void           _EXPORT STOP_INTR();
void           _EXPORT RESET_IRQ();

#ifdef WIN32
HANDLE         _EXPORT INIT_SIMPLE_INTR(int Rate, int Rate1, INT_HANDLER Vector);
HANDLE         _EXPORT STREAM_INTR(int Rate, INT_HANDLER Vector, WORD Chan);
HANDLE         _EXPORT SOFT_INTR(int Rate, INT_HANDLER Vector, WORD* Chan, int Nch);
#else
void           _EXPORT INIT_SIMPLE_INTR(int Rate, int Rate1, INT_HANDLER Vector);
void           _EXPORT STREAM_INTR(int Rate, INT_HANDLER Vector, WORD Chan);
void           _EXPORT SOFT_INTR(int Rate, INT_HANDLER Vector, WORD* Chan, int Nch);
#endif
int            _EXPORT READ_DATA();
int            _EXPORT DATA_READY();

// Синхронизация
void           _EXPORT SYNCHRO_MODE(int SMode, int TtlMask, WORD AdChannel, WORD AdValue);

// Ввод во внутреннюю память
void           _EXPORT SOFT_MEMORY_START(unsigned long Nkadr, WORD* Chan, int Nch,
                                         int Rate, int PageNumber, int OffsetNumber, int RestartMode);
int            _EXPORT TEST_FOR_INPUT_END();
void           _EXPORT GET_INPUT_DATA(WORD* Datad, int Npoint);
void           _EXPORT SOFT_MEMORY_RESTART();

// Контроллер DMA
void           _EXPORT DMA_OFF();
int            _EXPORT DMA_TEST();
int            _EXPORT DMA_COUNTER_IN();
int            _EXPORT DMA_COUNTER_OUT();

void           _EXPORT GET_BUFFER(WORD* Data);
int            _EXPORT GET_BUFFER_HALF(WORD* Data);
void           _EXPORT PUT_BUFFER(WORD* Data);
int            _EXPORT PUT_BUFFER_HALF(WORD* Data);

// Настройка FIFO
void           _EXPORT CONFIG_FIFO(int fifo_mode);
void           _EXPORT CONFIG_2FIFO_TYPE(int fifo_type, int fifo_length);
void           _EXPORT READ_FIFO(WORD* Datad, int Npoint);
#ifdef WIN32
HANDLE         _EXPORT STREAM_FIFO2_BEGIN(int Rate, INT_HANDLER Vector, WORD* Chan, int Nch);
#else
void           _EXPORT STREAM_FIFO2_BEGIN(int Rate, INT_HANDLER Vector, WORD* Chan, int Nch);
#endif

//---------------------------------------------------------------------------------------------
// Специальные функции платы L1056 (16 выходных и 40 выходных ТТЛШ линий)
//---------------------------------------------------------------------------------------------
void           _EXPORT GET_DIGITS_1056(int Chan, WORD* Data);
void           _EXPORT OUT_DIGITS_1056(int Data);
void           _EXPORT STREAM_1056(WORD* Datad, int NKadr, int Chan, int Rate);
void           _EXPORT STREAM_DMA_1056(WORD* Datad, int Nkadr, int Chan,
                                       int Rate, int Dmm);
void           _EXPORT OUT_STREAM_1056(WORD* Datad, int NPoint, int Rate);
void           _EXPORT OUT_STREAM_DMA_1056(WORD* Datad, int Npoint, int Rate, int Dmm);
///#ifndef WIN32
void           _EXPORT INIT_INTR_1056(int Rate, int Chan, INT_HANDLER Vector);
///#endif
void           _EXPORT SET_SYNCHRO_MODE_1056(int s_mode, int s_number, int s_mask);

// Специальные функции платы L1208 (16-канальный ЦАП)
void           _EXPORT ZERO_MODE_1208(int Mode);
void           _EXPORT OUTDA_1208(WORD Coded, int DacNumber);
void           _EXPORT KADR_1208(int Nch, WORD* Datad, WORD* DacNumber);
void           _EXPORT SOFT_1208(WORD* Datad, int NPoint, WORD* DacNumber, int NCh, int Rate);
void           _EXPORT SOFT_FON_1208(WORD* Datad, int NPoint, WORD* DacNumber, int NCh,
                                     int Rate);
void           _EXPORT DMASOFT_1208(WORD* Datad, int NPoint, WORD* DacNumber, int Nch,
                                    int Rate, int Dmm);
///#ifndef WIN32
void           _EXPORT SOFT_INTR_1208(int Rate, INT_HANDLER Vector, int Nch);
///#endif

//---------------------------------------------------------------------------------------------
// Специальные функции платы E330 (плата АЦП на EPP-порту)
//---------------------------------------------------------------------------------------------
void           _EXPORT POWER_AND_PRINTER_E330(int ModePower, int ModePrinter);
void           _EXPORT SET_FIFO_PARAMETERS_E330(int FifoSize, int FifoMode);
void           _EXPORT SET_SOFT_PARM_E330(int Nch, WORD* Channels);
void           _EXPORT SET_TIME_PARAMETERS_E330(int Rate);
void           _EXPORT TIMER_INPUT_START_E330();
void           _EXPORT STOP_FUNC_E330();
void           _EXPORT TIMER_INPUT_E330(WORD* Datad, int NWords);

void           _EXPORT SOFT_MEMORY_PREPARE_E330(DWORD Nkadr, int PageNumber,
                                                int OffsetNumber, int RestartMode);
void           _EXPORT SOFT_MEMORY_START_E330();
///#ifndef WIN32
void           _EXPORT TIMER_INPUT_IRQ_START_E330(INT_HANDLER Vector);
void           _EXPORT IRQ_SLOW_START_E330(int IrqPeriod, INT_HANDLER Vector);
///#endif

void           _EXPORT SET_DAC_BUFER_E330(int Npoint, WORD* Data);
void           _EXPORT START_LOOP_DAC_E330();


void           _EXPORT EXEC_ADSP_COMMAND(int Command, int NWordsOut, WORD* WordsOut,
                                         int NWordsIn, WORD* WordsIn);



// Отладочные функц
int            _EXPORT GET_DATA();
void           _EXPORT PUT_DATA(WORD Data);
void           _EXPORT READ_INT_MEMORY(WORD* Datad, int Page, int StartAddr, int NWords);
void           _EXPORT WRITE_INT_MEMORY(WORD* Datad, int Page, int StartAddr, int NWords);
void           _EXPORT SET_TEST_SPEED_MODE_E330(int TestMode);
void           _EXPORT WRITE_BY_ADDRESS_E330(int Address, WORD Data);
WORD           _EXPORT READ_BY_ADDRESS_E330(int Address);

void           _EXPORT BOARD_SPECIFIC_INIT(int LowPowerMode);


//-----------------------------------------------------------------------------------------
// Special functions for board L241
//-----------------------------------------------------------------------------------------
long           _EXPORT ADCHAN_L241(int LogChannel);
void           _EXPORT SELFCALIBR_L241(int LogChannel, long Control);



int            _EXPORT LOADBIOSFROMARRAY_L1211(WORD* BiosCode);
void           _EXPORT SET_AD_MODE(int Mode);
void           _EXPORT TIMER_INPUT();
#ifdef WIN32
HANDLE         _EXPORT TIMER_INPUT_INTR(INT_HANDLER Vector);
#else
void           _EXPORT TIMER_INPUT_INTR(INT_HANDLER Vector);
#endif
void           _EXPORT STOP_INPUT();
void           _EXPORT GET_HALF_FIFO(WORD* Datad, int NPoint, int Mode);
void           _EXPORT SET_TIME(int Rate, int Scale, int Epocha);
void           _EXPORT SET_CHANNELS(WORD Nch, WORD Single);
void           _EXPORT GET_INPUT_POINTS(DWORD* Datad);
void           _EXPORT GET_TABLE(WORD* Table, int NWords);

// Устаревшие функции или функции с измененными имена
void           _EXPORT SELECT_BOARD(int Board);
void           _EXPORT SETBASEADDRESS(int Address);
void           _EXPORT SELECT_SLOT(int Slot);
void           _EXPORT SET_EPP_MODE_E330(int aEppMode);
void           _EXPORT GET_INI_SETTINGS();


WORD           _EXPORT QADCHAN(WORD Chan);
void           _EXPORT QSOFT(WORD* Datad, unsigned Rate);


#ifdef __cplusplus
};
#endif
// extern "C"

#endif
// ifndef __LC_PROCS_H

