/*
 * b1553_fw_types.h
 *
 */

#ifndef B1553_FW_TYPES_H_
#define B1553_FW_TYPES_H_

#include <stdint.h>

struct b1553_fw_ctrl_regs_t
{
	uint32_t tdcw;			//0x00: Terminal Direct CW
	uint32_t ticw;			//0x04: Terminal Interface CW
	uint32_t sbap;			//0x08: Sub-address base address pointer
	uint32_t thp;			//0x0C: Transaction history pointer
	uint32_t tsw;			//0x10: Terminal SW
	uint32_t imcw;			//0x14: Illegal mode code control word
	uint32_t imw;			//0x18: Interrupt mark word
	uint32_t vw;			//0x1C: Vector word
	uint32_t version;		//0x20: version register
	uint32_t ebw;			//0x24: Error BITE word
	uint32_t res_28;    	//0x28
	uint32_t iqp;			//0x2C: Interrupt queue pointer
	uint32_t ttag;			//0x30: timetag counter
	uint32_t reset;			//0x34:
	uint32_t spare[6];  	//0x38: spare register [1..6]
	uint32_t ssflag_ctrl;	//0x50:
	uint32_t bc[3];			//0x54:
	uint32_t res_60;		//0x60
	uint32_t iack;			//0x64: interrupt ACk pointer
	uint32_t bm[3];
	uint32_t cb;
	uint32_t last_tr_ack_r;
	uint32_t bit_word;
	uint32_t last_transcation_tx;

	uint32_t last_synch_word;
};

struct b1553_fw_cmd_regs_t
{
	uint32_t start;
	uint32_t stop;
	uint32_t exec_cl;
	uint32_t clear_exec_cl;
	uint32_t acf;
	uint32_t bit_ack;
	uint32_t reserved;
	uint32_t not_used;
	uint32_t reserved_[5];
	uint32_t restart_timetag;
};

struct b1553_fw_buffer_identify_word_t
{
	unsigned int wc: 6;			//bit 0..5
	unsigned int sadd: 5;		//bit 6..10
	unsigned int brd: 1;		//bit 11 (broadcast)
	unsigned int reserved: 4;   //bit 12..15
	unsigned int timetag: 16;	//LSB=64usec, bit 16..31
};

struct b1553_fw_buffer_t
{
	enum { data_words=32};
	union {
		b1553_fw_buffer_identify_word_t id;
		uint32_t raw;
	} identify;
	uint16_t data[data_words];
	uint32_t spare;
};

struct b1553_fw_sadd_control_word_t
{
	unsigned int eei: 1;
	unsigned int eeti: 1;
	unsigned int ill: 1;
	unsigned int edb: 1;
	unsigned int esc: 1;
	unsigned int not_used_5: 1;
	unsigned int not_used_6: 1;
	unsigned int ecb: 1;
	unsigned int not_used: 8;
	unsigned int dsize: 16;
};

union b1553_fw_sadd_control_word_union_t
{
	b1553_fw_sadd_control_word_t str;
	uint32_t raw;
};

struct b1553_fw_sadd_descriptor_t
{
	b1553_fw_sadd_control_word_union_t cw;

	uint32_t terminal_bufffer_pointer;
	uint32_t host_buffer_pointer;
	uint32_t reserved;
};

struct b1553_fw_memory_t
{
	enum { d_rx=0, d_tx=1, d_brcst=2, desc_blocks=3, desc_num=256};

	//Offset 0
	b1553_fw_sadd_descriptor_t descriptors[desc_blocks][desc_num]; 	//0x0000 = RX
																	//0x1000 = TX
																	//0x2000 = RX BRDC
	b1553_fw_sadd_descriptor_t descriptors_bc[desc_num]; 	//0x0000 = RX

	enum {buff_num=32};

	b1553_fw_buffer_t buffers[desc_blocks][buff_num][2];	//[type][sa][double_buffer]

	uint32_t history_align[640];

	enum { iq_entries=1024, iq_size_w32=4};
	uint32_t iq[iq_entries][iq_size_w32];		//Offset aligned to 16K 0x4000

	enum { th_entries=1024, th_size_w32=4};
	uint32_t thistory[th_entries][th_size_w32]; 	//Offset aligned to 16K 0x4000


};



#endif /* B1553_FW_TYPES_H_ */
