
#ifndef PRXPROTECTED_H
#define PRXPROTECTED_H

#ifdef __cplusplus
extern "C" {
#endif

#include "prx.h"

	// This file contains protected declarations i.e. DLL components that are exported
	// but not part of the public API
	// RQInternal.h contains non-exported declarations that are only visible within the DLL
	// RQ.h contains upblic declarations that form the public API


#ifdef PRX_EXPORTS
	#define PRX_API __declspec(dllexport)
#else
	#define PRX_API __declspec(dllimport)
#endif

#ifdef STDCALL
	#define CALL_CONV __stdcall
#else
	#define CALL_CONV
#endif

#include <stdarg.h>

#include "PRXMemorySpace.h"
#include "PRXStructs.h"
#include "NDTSErrorConstants.h"

#define PRX_MAX_FINE_GAIN				4095
#define PRX_MAX_BACKEND_FILTER_VALUE	7
#define PRX_MAX_FRONTEND_FILTER_VALUE	7
#define PRX_MAX_IMPEDANCE_SETTING		15
#define PRX_MAX_COARSE_GAIN				3
#define PRX_MAX_OVERSAMPLING_DELAY		255
#define PRX_MAX_PULSE_WIDTH				65535
#define PRX_MAX_PULSE_TRAIN_LENGTH		15
#define PRX_MAX_REPETITION_DELAY		0xfffffffful
#define PRX_MAX_STEP_SKIP_COUNT         31

#define PRX_SRAM_BANK_SIZE			0x00400000

#define PRX_FREQUENCY				100000000

	// xe66 is 360v, giving some safety for 400v rated parts.  xfff is the max hardware capable value of 400v
#define PRX_MAX_PULSER_VOLTAGE		0xe66


typedef struct
{
	PRX_Shadow reg_shadow;

	//NDTS_Boolean isDebugMode ;
	NDTS_Boolean isPciInitialised;
	NDTS_Boolean isDMAChannelOpen;
	char diagnosticsFilename[512];
	NDTS_Boolean isDiagnosticsMode;
	NDTS_Boolean isInitialised ;
	PRX_ReturnCode errorCode ;
	unsigned long errorLogStringIndex ;
	char errorLog[PRX_MAXIMUM_NUMBER_OF_ERROR_LOG_STRINGS][PRX_MAXIMUM_ERROR_STRING_LENGTH] ;
	CRITICAL_SECTION criticalSection ;
	unsigned long numberOfSequenceSteps;
	NDTS_Boolean isManualCommit;

	long frontEndHighPassLookup[PRX_MAX_FRONTEND_FILTER_VALUE + 1] ; 
	long frontEndHighPassReverseLookup[PRX_MAX_FRONTEND_FILTER_VALUE + 1] ;
	long frontEndLowPassLookup[PRX_MAX_FRONTEND_FILTER_VALUE + 1] ;
	long frontEndLowPassReverseLookup[PRX_MAX_FRONTEND_FILTER_VALUE + 1] ;
	unsigned long masterRepetitionTime;  // If this card is a slave, this shadows the master (e.g. RapiDAQ) rep rate for overload calculations
	PRX_limitPulseWidthCallback pLimitPulseWidthCallback ;

	NDTS_Boolean isSoftwareFETOverloadProtectionEnabled;
	unsigned long softwareFETOverloadOutputMask;
	NDTS_Boolean softwareFETOverloadIsThisSequenceLimited[SEQUENCE_TABLE_BLOCKS];

	NDTS_Boolean useSonatestMux;
	int sonatestSerialMuxMode;
} PRX_State;
PRX_API PRX_State *pRX_StateArray;


unsigned long prxs_found;
PRX_API NDTS_Boolean CALL_CONV PRX_GetRegister(unsigned long card, unsigned long offset, unsigned long *value);
PRX_API NDTS_Boolean CALL_CONV PRX_SetRegister(unsigned long card, unsigned long offset, unsigned long value);
PRX_API NDTS_Boolean CALL_CONV PRX_StructuresInitialise(unsigned long card);
PRX_API NDTS_Boolean CALL_CONV PRX_PCIInitialise(unsigned long card);

PRX_API NDTS_Boolean CALL_CONV PRX_SetNumberOfSequenceSteps(unsigned long card, unsigned long nSteps);
PRX_API NDTS_Boolean CALL_CONV PRX_SetRepetitionTime(unsigned long card, unsigned long block, unsigned long ticks);
PRX_API void PRX_GetLogLevel(NDTS_LogLevel *pFile, NDTS_LogLevel *pApp, NDTS_LogLevel *pDebugger);
PRX_API void PRX_SetLogLevel(NDTS_LogLevel file, NDTS_LogLevel app, NDTS_LogLevel debugger);

//These functions are onle applicable to the Ultran Pulser (HVPA and PG cards)
PRX_API NDTS_Boolean CALL_CONV PRX_HVPAGetPowerEnable(unsigned long card, unsigned long *flag);
PRX_API NDTS_Boolean CALL_CONV PRX_HVPASetPowerEnable(unsigned long card, unsigned long flag);

// This function is only applicable to the Sonatest external MUX for the WindBlast project with Bodycote
PRX_API NDTS_Boolean CALL_CONV PRX_InitialiseSonatestSerialMux(int iniFileValue);
PRX_API void PRX_SonatestSerialMuxSetGain(unsigned long oneBasedChannel, int gainIndB);
PRX_API void PRX_SonatestSerialMuxSetFilter(unsigned long oneBasedChannel, int filter);
PRX_API void PRX_SonatestSerialMuxSetVoltageClamp(unsigned long volts);

#ifdef __cplusplus
}
#endif


#endif
