#ifndef XP_CDS_STATUS_BUS_H
#define XP_CDS_STATUS_BUS_H

#include "x_basic_types.h"

#define ITS_WRITE_BUS	0
#define ITS_READ_BUS	1

#define TYPE_CDS_XILINX_NOT_INITED	-1
#define TYPE_CDS_XILINX_SP2			0
#define TYPE_CDS_XILINX_SP6			1


#define MAX_WRITE_ERROR_SBUS_DEFAULT	1 	// количество повторных операций до возникновениЯ ошибки - снЯтие Ready
#define MAX_READ_ERROR_SBUS_DEFAULT		1	// количество повторных операций до возникновениЯ ошибки - снЯтие Ready

#define MAX_WRITE_ERROR_PBUS_DEFAULT	1 	// количество повторных операций до возникновениЯ ошибки - снЯтие Ready
#define MAX_READ_ERROR_PBUS_DEFAULT		1	// количество повторных операций до возникновениЯ ошибки - снЯтие Ready

#define MAX_WRITE_ERROR_HWPBUS_DEFAULT	1 	// количество повторных операций до возникновениЯ ошибки - снЯтие Ready
#define MAX_READ_ERROR_HWPBUS_DEFAULT	1	// количество повторных операций до возникновениЯ ошибки - снЯтие Ready

#define T_cds_status_serial_bus_DEFAULT 	{0,0,0,0,0,0,0,MAX_WRITE_ERROR_SBUS_DEFAULT,MAX_READ_ERROR_SBUS_DEFAULT}
#define T_cds_status_parallel_bus_DEFAULT 	{0,0,0,0,0,0,0,MAX_WRITE_ERROR_PBUS_DEFAULT,MAX_READ_ERROR_PBUS_DEFAULT}
#define T_cds_status_hwp_bus_DEFAULT 		{0,0,0,0,0,0,0,MAX_WRITE_ERROR_HWPBUS_DEFAULT,MAX_READ_ERROR_HWPBUS_DEFAULT}

/*-----------------------------------------------------------------------------
Define the types
-----------------------------------------------------------------------------*/

typedef struct {
	UInt16 status;
	UInt16 count_read_ok;
	UInt16 count_write_ok;
	UInt16 count_read_error;
    UInt16 count_write_error;
	UInt16 cur_read_error;
    UInt16 cur_write_error;
	UInt16 max_write_error;
	UInt16 max_read_error;
} T_cds_status_serial_bus;


typedef struct {
	UInt16 status;
	UInt16 count_read_ok;
	UInt16 count_write_ok;
	UInt16 count_read_error;
    UInt16 count_write_error;
	UInt16 cur_read_error;
    UInt16 cur_write_error;
	UInt16 max_write_error;
	UInt16 max_read_error;
} T_cds_status_parallel_bus;

typedef struct {
	UInt16 status;
	UInt16 count_read_ok;
	UInt16 count_write_ok;
	UInt16 count_read_error;
    UInt16 count_write_error;
	UInt16 cur_read_error;
    UInt16 cur_write_error;
	UInt16 max_write_error;
	UInt16 max_read_error;
} T_cds_status_hwp_bus;

typedef struct {
	UInt16 type_xilinx;
} T_cds_type_xilinx;


#define TYPE_CDS_XILINX_DEFAULTS TYPE_CDS_XILINX_NOT_INITED	
#define TYPE_IN_1_2_DEFAULTS     TYPE_IN_1_2_NOT_INITED

void clear_stat_sbus(T_cds_status_serial_bus *v);
void clear_stat_pbus(T_cds_status_parallel_bus *v);
void clear_stat_hwpbus(T_cds_status_hwp_bus *v);

void clear_cur_stat_sbus(T_cds_status_serial_bus *v);
void clear_cur_stat_pbus(T_cds_status_parallel_bus *v);
void clear_cur_stat_hwpbus(T_cds_status_hwp_bus *v);


int check_cds_ready_sbus(int err, int wr_rd, T_cds_status_serial_bus *v);
int check_cds_ready_pbus(int err, int wr_rd, T_cds_status_parallel_bus *v);
int check_cds_ready_hwpbus(int err, int wr_rd, T_cds_status_hwp_bus *v);

void set_status_cds(int err_ready, T_component_status *ss);




#endif