block_or2.c 1.93 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
79
80
81
82
83
84
85
/* Automaticly generated block 'or2' */

#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	*a;
	bool	*b;

	/* Output variables: */
	bool	q;

	/* Local variables: */

	/* Param variables: */
};


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

	_il2c_acc_ui32 = a;
	_il2c_acc_ui32 = ((bool)_il2c_acc_ui32) | b;
	q = (bool)(_il2c_acc_ui32 & 0x1);

	block->private->q = q;
}

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

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

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

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


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

	block->outputs = 1;
	if (!(block->output = malloc(sizeof(struct controller_block_outterm) * 1)))
		return NULL;
	block->output[0].name = "q";
	block->output[0].type = CONTROLLER_BLOCK_TERM_BOOL;
	block->output[0].value.v = (void*)&block->private->q;
	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;
}