/*
 * zzr.h
 *
 *  Created on: 11-07-2017
 *      Author: Krzysztof Jakubczyk
 */

#ifndef ZZR_H_
#define ZZR_H_

#include "tdefs.h"
#include "config.h"

#define ZZR_AKT	0x00000001
#define ZZR_AT	0x00000002

enum zzr_mode
{
	low_imped_sum_ip,
	low_imped_ip_max
};

enum zzr_characteristic
{
	linear_simple,
	linear_advanced
};

struct zzr_logic
{
	struct binary_io bl;
	struct binary_io test;
	struct binary_io P;
	struct binary_io W;

	float *InL1_orta;
	float *InL1_ortb;
	float *InL1_esk;
	float *InL2_orta;
	float *InL2_ortb;
	float *InL2_esk;
	float *InL3_orta;
	float *InL3_ortb;
	float *InL3_esk;
	float *In2L1_orta;
	float *In2L1_ortb;
	float *In2L1_esk;
	float *In2L2_orta;
	float *In2L2_ortb;
	float *In2L2_esk;
	float *In2L3_orta;
	float *In2L3_ortb;
	float *In2L3_esk;
	float *Iy_orta;
	float *Iy_ortb;
	float *Iy_esk;

	float *kamN_out;
	float *kamY_out;
	float *Id_out;
	float *Ir_out;

	float kamNa;
	float kamN2a;
	float kamYa;

	u8 P_ch;
	short P_ch_cnt;

	u32 td_ms;
	u32 t_cnt;
};

struct zzr_io
{
	u32 bl_in;
	u32 InL1_orta;
	u32 InL1_ortb;
	u32 InL1_esk;
	u32 InL2_orta;
	u32 InL2_ortb;
	u32 InL2_esk;
	u32 InL3_orta;
	u32 InL3_ortb;
	u32 InL3_esk;

	u32 In2L1_orta;
	u32 In2L1_ortb;
	u32 In2L1_esk;
	u32 In2L2_orta;
	u32 In2L2_ortb;
	u32 In2L2_esk;
	u32 In2L3_orta;
	u32 In2L3_ortb;
	u32 In2L3_esk;

	u32 Iy_orta;
	u32 Iy_ortb;
	u32 Iy_esk;
	u32 test_in;
	u32 Id_float_out;
	u32 Ir_float_out;
	u32 P_out;
	u32 W_out;
}__attribute__((__packed__));

struct zzr_params
{
	u32 bits;
	u32 mode;
	double kamN;
	double kamY;
	u32 characteristic;
	double Id_start;
	double m1;
	double m2;
	double Ir_m2;
	double Id_max;
	double td;
	double kamN2;
}__attribute__((__packed__));

struct zzr_args
{
	struct zzr_io io;
	struct zzr_params params;
//	u16 crc;
}__attribute__((__packed__));

extern void zzr(void *args, void *logic);
extern int zzr_initlog(void *arguments, void *logic);

#endif /* ZZR_H_ */
