/*
 * dfr.h
 *
 *
 *  Created on: 24-06-2014
 *      Author: KJ
 */

#ifndef DFR_H_
#define DFR_H_

#include "tdefs.h"

#define MAX_SAMPLE_SIZE		512

#define REG_BANK_SIZE 			0x400000
#define AN_IS_FLOAT			 	0x80000000

// bank states
#define BANK_EMPTY				0x00
#define BANK_BUFFERING			0x01
#define BANK_TRIGGERED			0x02
#define BANK_FILLED				0x03

#define MAX_REG_BANKS			4

struct reg_data
{
	u8 *data;
	u8 state;
	u32 addr_offset;
	u32 pre_trigger_cnt;
	u32 post_trigger_cnt;
	u32 total_cnt;
	u32 trigger_offset;
	u32 tr_time;
	u32 tr_time_ms;
	u16 sample_size;
	u8 an_count;
	u16 bin_count;
}__attribute__((__packed__));

struct reg_inf
{
	u8 cur_reg_bank;
	struct reg_data bank[MAX_REG_BANKS];
}__attribute__((__packed__));

extern volatile u8 bank0[REG_BANK_SIZE];
extern volatile u8 bank1[REG_BANK_SIZE];
extern volatile u8 bank2[REG_BANK_SIZE];
extern volatile u8 bank3[REG_BANK_SIZE];

extern volatile struct reg_inf regs;

struct dfr_logic
{
	u8 *trigger_ptr;
	u8 trigger_bit_no;
};

struct dfr_io
{
	u32 trigger_in;
}__attribute__((__packed__));

struct dfr_params
{
	u32 pre_trigger_time;
	u32 post_trigger_time;
	u32 max_reg_time;
}__attribute__((__packed__));

struct dfr_args
{
	struct dfr_io io;
	struct dfr_params params;
//	u16 crc;
}__attribute__((__packed__));

extern int dfr_initlog(void *args, void *logic);
extern void dfr(void *args, void *logic);

#endif /* DFR_H_ */
