block_register.c 1.75 KB
Newer Older
Jeroen Vreeken's avatar
Jeroen Vreeken committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* Automaticly generated block 'register' */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <controller/controller_block.h>


struct controller_block_private {
	/* Input variables: */
	bool	*input;

	/* Output variables: */
	bool	output;

	/* Local variables: */

	/* Param variables: */
};


static void calculate(struct controller_block *block)
{
	bool	input = *block->private->input;
	bool	output = block->private->output;
	uint32_t	_il2c_acc_ui32 __attribute__ ((__unused__));
	double	_il2c_acc_double __attribute__ ((__unused__));

	_il2c_acc_ui32 = input;
	output = (bool)(_il2c_acc_ui32 & 0x1);

	block->private->output = output;
}

struct controller_block * block_register_create(char *name)
{
	struct controller_block *block;

	if (!(block = malloc(sizeof(struct controller_block))))
		return NULL;

	block->type = "register";
	if (!(block->name = strdup(name)))
		return NULL;

	if (!(block->private = malloc(sizeof(struct controller_block_private))))
		return NULL;


	block->inputs = 1;
	if (!(block->input = malloc(sizeof(struct controller_block_interm) * 1)))
		return NULL;
	block->input[0].name = "input";
	block->input[0].type = CONTROLLER_BLOCK_TERM_BOOL;
	block->input[0].value.v = (void*)&block->private->input;
	block->input[0].ghostof = NULL;

	block->outputs = 1;
	if (!(block->output = malloc(sizeof(struct controller_block_outterm) * 1)))
		return NULL;
	block->output[0].name = "output";
	block->output[0].type = CONTROLLER_BLOCK_TERM_BOOL;
	block->output[0].value.v = (void*)&block->private->output;
	block->output[0].source = block;

	block->calculate = calculate;

	block->params = 0;
	block->param = NULL;
	block->param_get = NULL;
	block->param_set = NULL;


	controller_block_add(block);
	return block;
}