/*
 * eth_ench.h
 *
 *  Created on: 17-05-2024
 *      Author: Krzysztof Jakubczyk
 */

#ifndef ETH_ENCH_H_
#define ETH_ENCH_H_

#include "tdefs.h"
#include "mkstream.h"
#include "helper.h"
#include "comm.h"

#define ETH_ENCH_STREAMS	(ETH_MAX_RECV_STREAMS-ETH_MAX_STREAMS)

struct eth_ench_logic
{
	struct binary_io clr;
	struct binary_io ping;
	struct stream_frame stream_out[ETH_MAX_RECV_STREAMS-ETH_MAX_STREAMS];
	struct binary_io stream_act[ETH_MAX_RECV_STREAMS-ETH_MAX_STREAMS];
	struct binary_io link[ETH_MAX_RECV_STREAMS-ETH_MAX_STREAMS];
	float *stream_errs[ETH_MAX_RECV_STREAMS-ETH_MAX_STREAMS];
	float *stream_synt_errs[ETH_MAX_RECV_STREAMS-ETH_MAX_STREAMS];
	float *ping_time;
	u16 s_delay;
	u32 state;
	u32 tcnt;
	u32 prev_pos[ETH_MAX_RECV_STREAMS-ETH_MAX_STREAMS];
	u32 link_timeout_cnt[ETH_MAX_RECV_STREAMS-ETH_MAX_STREAMS];
	u32 link_up_cnt[ETH_MAX_RECV_STREAMS-ETH_MAX_STREAMS];
	u16 prev_timestamp;
};

struct eth_ench_io
{
	u32 clr_in;
	u32 stream3_ptr_out;
	u32 stream3_act_out;
	u32 stream4_ptr_out;
	u32 stream4_act_out;
	u32 stream5_ptr_out;
	u32 stream5_act_out;
	u32 stream6_ptr_out;
	u32 stream6_act_out;
	u32 stream7_ptr_out;
	u32 stream7_act_out;
	u32 link3_out;
	u32 stream3_errs_float_out;
	u32 link4_out;
	u32 stream4_errs_float_out;
	u32 link5_out;
	u32 stream5_errs_float_out;
	u32 link6_out;
	u32 stream6_errs_float_out;
	u32 link7_out;
	u32 stream7_errs_float_out;
	u32 stream3_synt_errs_float_out;
	u32 stream4_synt_errs_float_out;
	u32 stream5_synt_errs_float_out;
	u32 stream6_synt_errs_float_out;
	u32 stream7_synt_errs_float_out;
}__attribute__((__packed__));


//bits
#define ETH_EN			0x01
#define ETH_EN_BCASTS	0x02
#define ETH_NO_SYNC		0x04

struct eth_ench_params
{
	u32 bits;
	u32 sample_delay;
	u32 multicast_id;
}__attribute__((__packed__));

struct eth_ench_args
{
	struct eth_ench_io io;
	struct eth_ench_params params;
//	u16 crc;
}__attribute__((__packed__));

extern void ethernet_ench(void *args, void *logic);
extern int ethernet_ench_initlog(void *arguments, void *logic);

#endif
