// ft.h Frank Berndt
// functional test declarations;

#ifndef	__FT_H__
#define	__FT_H__

// each test thread has its own address range;

#define	MEM_SIZE	4*1024*1024
#define	MEM_CPU		(MEM0_START + 0*MEM_SIZE)
#define	MEM_AES		(MEM0_START + 1*MEM_SIZE)
#define	MEM_SHA		(MEM0_START + 2*MEM_SIZE)
#define	MEM_FLA		(MEM0_START + 3*MEM_SIZE)
#define	MEM_AUD		(MEM0_START + 4*MEM_SIZE)
#define	MEM_USB		(MEM0_START + 5*MEM_SIZE)
#define	MEM_CIF		(MEM0_START + 6*MEM_SIZE)

#define	CPU_X		16*1024		// cpu code size;

// device IDs;

#define	ID_CPU		0x00
#define	ID_AES		0x01
#define	ID_SHA		0x02
#define	ID_FLA		0x04
#define	ID_AUD		0x08
#define	ID_USB		0x10
#define	ID_CIF		0x00

// message IDs;

#define	MSG_NONE	0
#define	MSG_REQ		0x100
#define	MSG_ACK		0x200
#define	MSG_ERR		0x300

// aes message structure;

typedef struct aes_msg {
	u32 req;				// request/reply;
	u32 key[4];				// key to use;
	u32 ivptr;				// ptr to iv;
	u32 rptr;				// read ptr;
	u32 wptr;				// write ptr;
	u32 ctrl;				// ctrl reg;
} aes_msg_t;

// sha message structure;

typedef struct sha_msg {
	u32 req;				// request/reply;
	u32 mptr;				// ptr to data;
	u32 hash[5];			// hash result;
	u32 ctrl;				// ctrl reg;
} sha_msg_t;

// flash message structure;

typedef struct fla_msg {
	u32 req;				// request/reply;
	u32 conf;				// config reg;
	u32 ad[2];				// flash page address;
	u32 ma[2];				// memory address;
	u32 ctrl;				// ctrl reg;
} fla_msg_t;

// usb message structure;

typedef struct usb_msg {
	u32 req;				// request/reply;
	u32 ctrl;				// ctrl reg;
	u32 iptr[3];			// in pointers;
	u32 optr[3];			// out pointers;
	u32 ilen[3];			// in len/ctrl;
	u32 olen[3];			// out len/ctrl;
	u32 wait[3];			// wait reg,mask,cmp;
} usb_msg_t;

// cif message structure;

typedef struct cif_msg {
	u32 req;				// request/reply;
	u32 setup;				// sim requests setup;
} cif_msg_t;

#define	CIF_DIS		0		// disable cif;
#define	CIF_RSM		1		// setup for ROM/SRAM tests;

// union of all messages;

typedef union test_msg {
	u32 req;				// request/reply;
	aes_msg_t aes;			// aes;
	sha_msg_t sha;			// sha;
	fla_msg_t fla;			// flash;
	usb_msg_t usb;			// flash;
	cif_msg_t cif;			// cif;
} test_msg_u;

// all test structure;

#define	TT_INIT		0		// thread is initializing;
#define	TT_REQ		1		// send request to sim environment;
#define	TT_REPLY	2		// waiting for reply from sim env;
#define	TT_START	3		// start operation;
#define	TT_WAIT		4		// wait for op to be done;
#define	TT_POST		5		// post-op;
#define	N_TT		6

typedef struct test_thread {
	u8 cpu;					// cpu to service this;
	u8 state;				// state of test thread;
	test_msg_u *msg;		// ptr to msg buffer;
	void (*hdl[N_TT])(u32 cpu, struct test_thread *);
} test_thread_t;

// functions;

extern void msg_wbi(void *ptr, int size);

#endif	// __FT_H__

