/*
 * rec_an.c
 *
 *  Created on: 24-06-2014
 *      Author: KJ
 */


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

#include "rec_an.h"

int rec_an_initlog(void *arguments, void *logic)
{
	struct rec_an_args *args = (struct rec_an_args *)arguments;
	struct rec_an_logic *log = (struct rec_an_logic *)logic;

	u32 *an_params_ptr;

	log->in_ptr = (u16 *)(log_manager.nets_data + (args->io.sample_short_in >> 3));
	if((u8*)log->in_ptr > (log_manager.nets_data+sizeof(log_manager.nets_data)-sizeof(u16)))
		return -1;

	an_params_ptr = (u32 *)(log_manager.nets_data + (args->io.param_an_ptr_in >> 3));
	if((u8*)an_params_ptr > (log_manager.nets_data+sizeof(log_manager.nets_data) - sizeof(void *)))
		return -1;

	if(!*an_params_ptr) // param in not connected or wrong elements order (analog_in should be run before)
		return -1;

	log->an_params=(struct analog_in_params *)*an_params_ptr;

	return 0;
}

