#ifndef _SA02LIB_H_
#define _SA02LIB_H_
#include "vme.h"
#include "SA02_DEF.h"
#ifdef WIN32
#ifdef _CVI_
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned int uint32_t;
// typedef INT64 int64_t;
// typedef UINT64 uint64_t;
#else
typedef INT8 int8_t;
typedef UINT8 uint8_t;
typedef INT16 int16_t;
typedef UINT16 uint16_t;
typedef INT32 int32_t;
typedef UINT32 uint32_t;
typedef INT64 int64_t;
typedef UINT64 uint64_t;
#endif
#else
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#endif
typedef struct {
unsigned int phasecmps:2;
unsigned int gain:2;
unsigned int shapingtime:2;
unsigned int comparator:1;
unsigned int vrdrive:8;
unsigned int monitor:2;
unsigned int id:9;
unsigned int unused:6;
} sa02AsicGlobalRegister;
typedef struct {
unsigned int decaytime:3;
unsigned int offset:4;
unsigned int fineadj_unipol:4;
unsigned int fineadj_diff:4;
unsigned int reserved:1;
unsigned int tpenb:1;
unsigned int kill:1;
unsigned int unused:14;
} sa02AsicChannelRegister;
//extern uint32_t sa02BoardNumber;
extern uint32_t sa02BoardType;
void sa02PrintGREG(uint32_t *data, const char *txt);
void sa02PrintCREG(uint32_t *data, const char *txt);
#ifdef _CVI_
int sa02Printf(const char *format, ...);
#else
#define sa02Printf printf
#endif
double sa02ampIb(int);
double sa02adc2V(int);
double sa02adc2Vp(int);
double sa02adc2Vm(int);
double sa02adc2V38(int);
double sa02adc2Va(int);
void sa02Tmlnk (int tout);
void sa02Tmulk (void );
void sa02Timerast (int signumber);
extern int sa02TimerOut;
int sa02Help(void);
extern int sa02Verbose;
extern int sa02TimerOut;
extern int sa02BltReadout;
int sa02MuxMap(int i );
uint32_t sa02Write(uint32_t board, uint32_t regh, uint32_t regl, uint32_t *response);
int sa02Reset1( void );
int Sa02SEUTrigger (void);
int Sa02SoftwareTrigger (void);
int Sa02SelectTrigger (uint32_t trg);
int Sa02SelectTriggerWithMaskAndLength (uint32_t trg, uint32_t mask, uint32_t len);
int Sa02TestPulseEnable (uint32_t board, uint32_t rdy );
int Sa02DaqMode (uint32_t mode) ;
int Sa02SetNeve (uint32_t neve);
int Sa02SetPtsOutput(uint32_t mask);
uint32_t Sa02GetNeve (uint32_t*inputtriggers);
uint32_t Sa02GetCounter (uint32_t board, uint32_t *errors);
uint32_t Sa02GetChAddr (uint32_t board);
int sa02Reset( void );
int sa02Read( uint32_t mask, uint32_t * data);
uint32_t sa02Cmd(uint32_t board, uint32_t cmd, uint32_t data, int chip, int ch, int nload, uint32_t *response);
int sa02AsicWrite(uint32_t board, uint32_t reg, uint32_t data, int chip, int ch, uint32_t mask, uint32_t shft );
uint32_t sa02GetCmdCode(char *optarg);
uint32_t sa02GetAsicCode(char *optarg, uint32_t *asicpar, uint32_t *asicshft);
int sa02Init( void );
int sa02LoadParametersFromFile( const char *fname, uint16_t mask);
int sa02GetSerial( uint32_t board, char * serial);
int sa02Status( uint32_t board, char * serial, double *data);
int sa02SetAddress(uint32_t address);
#endif