/*
 * s_demux.h
 *
 *  Created on: 29-10-2019
 *      Author: Krzysztof Jakubczyk
 */

#ifndef S_DEMUX_H_
#define S_DEMUX_H_

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

extern u16 comm_bits_act[3];
extern u16 comm_bits_restored[3];

struct s_demux_logic
{
	struct stream_frame *stream_in[3];
	struct binary_io stream_in_act[3];
	struct stream_frame *astream_in[3];
	struct binary_io astream_in_act[3];
	struct stream_frame stream_out[3];
	struct binary_io streams_ok;

	struct stream_frame *ostream_ptr[3];
	struct binary_io przeglad[3];
	struct binary_io three_endpoints;

	u32 snum_cur[3];
	u32 snum_prev[3];
	u32 sfault_delay_cnt[3];
	u32 jednostki;
};

struct s_demux_io
{
	u32 stream1_ptr_in;
	u32 stream1_act_in;
	u32 astream1_ptr_in;
	u32 astream1_act_in;

	u32 stream2_ptr_in;
	u32 stream2_act_in;
	u32 astream2_ptr_in;
	u32 astream2_act_in;

	u32 stream3_ptr_in;
	u32 stream3_act_in;
	u32 astream3_ptr_in;
	u32 astream3_act_in;

	u32 stream1_ptr_out;
	u32 stream2_ptr_out;
	u32 stream3_ptr_out;
	u32 streams_ok_out;

	u32 przeglad1_out;
	u32 przeglad2_out;
	u32 przeglad3_out;

	u32 three_endpoints_out;
}__attribute__((__packed__));


struct s_demux_params
{
	u32 liczba_jednostek;
}__attribute__((__packed__));

struct s_demux_args
{
	struct s_demux_io io;
	struct s_demux_params params;
//	u16 crc;
}__attribute__((__packed__));

extern void s_demux(void *args, void *logic);
extern int s_demux_initlog(void *arguments, void *logic);

#endif
