/*
 * mux_bin.c
 *
 *  Created on: 29-03-2018
 *      Author: Krzysztof Jakubczyk
 */

#include <math.h>

#include "tdefs.h"
#include "misc.h"

#include "helper.h"
#include "mux_bin.h"

int mux_bin_initlog(void *arguments, void *logic)
{
	struct mux_bin_args *args = (struct mux_bin_args *)arguments;
	struct mux_bin_logic *log = (struct mux_bin_logic *)logic;

	if(set_bit_ptr_struct(args->io.we1_in,&log->we1))
		return -1;
	if(set_bit_ptr_struct(args->io.we2_in,&log->we2))
		return -1;
	if(set_bit_ptr_struct(args->io.a_in,&log->a))
		return -1;
	if(set_bit_ptr_struct(args->io.wy_out,&log->wy))
		return -1;

	return 0;
}

void mux_bin(void *arguments, void *logic)
{
	struct mux_bin_logic *log = (struct mux_bin_logic *)logic;

	if(!check_struct(&log->a))
		check_and_set_struct(check_struct(&log->we1),&log->wy);
	else
		check_and_set_struct(check_struct(&log->we2),&log->wy);
}
