// Filename : multiplier.cpp
//
// This file was initially generated by SpaceStudio but is meant to be modified
// by the user.
#include "multiplier.h"
#include "spacecomp_pre_cpp.h"

// Do NOT move macros, functions and includes beginning with "spacecomp".

multiplier::multiplier(SPACECOMP_CTOR_PARAMS(multiplier, INDEX))
	: abstract_module(SPACECOMP_MBASE_ARGS(multiplier, INDEX))
	, SPACECOMP_START_ILIST(multiplier, INDEX)
	// Other initializers may go here
{
	SPACECOMP_THREAD(multiplier, INDEX, thread);
	request_stack(16 * 1024);
}

void multiplier::thread(SPACECOMP_THREAD_PARAMS(multiplier, INDEX, thread)) {
	spacecomp_thread_initialize();
	int32_t operand1;
	int32_t operand2;
	int32_t result;
	while (1) {
		const bool initializing = spacecomp_thread_loop_start();
		if (initializing) {}
		operand1 = read_operand();
		operand2 = read_operand();
		result = multiply(operand1, operand2);
		send_result(result);
	}
}

int32_t multiplier::multiply(int32_t operand1, int32_t operand2) {
	return operand1 * operand2;
}

int32_t multiplier::read_operand() {
	int32_t data;
	ModuleRead(CONTROLLER0_ID, SPACE_BLOCKING, data);
    return data;
}

void multiplier::send_result(int32_t data) {
	ModuleWrite(CONTROLLER0_ID, SPACE_BLOCKING, data);
}

#include "spacecomp_post_cpp.h"
