block_am335x_adc.c 3.12 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
	Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007
	Copyright Stichting C.A. Muller Radioastronomiestation, 2007

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.

 */

#include <controller/controller_block.h>

struct controller_block_private {
	float ain0;
	float ain1;
	float ain2;
	float ain3;
	float ain4;
	float ain5;
	float ain6;
	float ain7;

	float gain0;
	float gain1;
	float gain2;
	float gain3;
	float gain4;
	float gain5;
	float gain6;
	float gain7;
	float offset0;
	float offset1;
	float offset2;
	float offset3;
	float offset4;
	float offset5;
	float offset6;
	float offset7;
};

static void adc_calculate(struct controller_block *adc)
{
//	struct controller_block_private *priv = adc->private;
}

static struct controller_block_outterm_list outterms[] = {
	{ "ain0", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, ain0) },
	{ "ain1", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, ain1) },
	{ "ain2", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, ain2) },
	{ "ain3", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, ain3) },
	{ "ain4", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, ain4) },
	{ "ain5", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, ain5) },
	{ "ain6", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, ain6) },
	{ "ain7", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, ain7) },
	{ NULL }
};

static struct controller_block_param_list params[] = {
	{ "gain0", false },
	{ "gain1", false },
	{ "gain2", false },
	{ "gain3", false },
	{ "gain4", false },
	{ "gain5", false },
	{ "gain6", false },
	{ "gain7", false },
	{ "offset0", false },
	{ "offset1", false },
	{ "offset2", false },
	{ "offset3", false },
	{ "offset4", false },
	{ "offset5", false },
	{ "offset6", false },
	{ "offset7", false },
	{ NULL },
};

static void param_set(struct controller_block *adc, int param, va_list val)
{
	switch (param) {
		case 0:
			adc->private->gain0 = va_arg(val, double);
			break;
	}
}

struct controller_block * block_am335x_adc_create(char *name)
{
	struct controller_block *adc;
	
	if (!(adc = controller_block_alloc("am355x_adc", name, sizeof(struct controller_block_private))))
		return NULL;

	if (controller_block_outterm_list_init(adc, outterms))
		goto err_block;

	adc->calculate = adc_calculate;

	if (controller_block_param_list_init(adc, params))
		goto err_block;

	adc->param_set = param_set;

	controller_block_add(adc);
	return adc;

err_block:
	controller_block_free(adc);
	return NULL;
}