script.h 2.97 KB
Newer Older
1
2
3
4
5
/*
 * Copyright (C) 2012  Alejandro Mery <amery@geeks.cl>
 *
 * 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
Alejandro Mery's avatar
Alejandro Mery committed
6
 * the Free Software Foundation, either version 2 of the License, or
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
 * (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/>.
 */
#ifndef _SUNXI_TOOLS_SCRIPT_H
#define _SUNXI_TOOLS_SCRIPT_H

/** head of the data tree */
struct script {
	struct list_entry sections;
};

/** head of each section */
struct script_section {
	char name[32];

	struct list_entry sections;
	struct list_entry entries;
};

/** types of values */
enum script_value_type {
	SCRIPT_VALUE_TYPE_SINGLE_WORD = 1,
	SCRIPT_VALUE_TYPE_STRING,
	SCRIPT_VALUE_TYPE_MULTI_WORD,
	SCRIPT_VALUE_TYPE_GPIO,
	SCRIPT_VALUE_TYPE_NULL,
};

/** generic entry */
struct script_entry {
	char name[32];
	enum script_value_type type;

	struct list_entry entries;
};

/** null entry */
struct script_null_entry {
	struct script_entry entry;
};

55
56
57
58
59
60
61
/** entry with 32b value */
struct script_single_entry {
	struct script_entry entry;

	uint32_t value;
};

62
63
64
65
66
67
68
69
/** entry with string value */
struct script_string_entry {
	struct script_entry entry;

	size_t l;
	char string[];
};

70
71
72
73
74
/** entry describing a GPIO */
struct script_gpio_entry {
	struct script_entry entry;

	unsigned port, port_num;
75
	int32_t data[4];
76
77
};

78
79
/** create a new script tree */
struct script *script_new(void);
80
81
/** deletes a tree recursively */
void script_delete(struct script *);
82
83

/** create a new section appended to a given tree */
84
85
struct script_section *script_section_new(struct script *script,
					  const char *name);
86
87
88
89
90
/** deletes a section recursvely and removes it from the script */
void script_section_delete(struct script_section *section);

/** deletes an entry and removes it from the section */
void script_entry_delete(struct script_entry *entry);
91

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/** create a new empty/null entry appended to a section */
struct script_null_entry *script_null_entry_new(struct script_section *section,
						const char *name);
/** create a new single word entry appended to a section */
struct script_single_entry *script_single_entry_new(struct script_section *section,
						    const char *name,
						    uint32_t value);
/** create a new string entry appended to a section */
struct script_string_entry *script_string_entry_new(struct script_section *section,
						    const char *name,
						    size_t l, const char *s);
/** create a new GPIO entry appended to a section */
struct script_gpio_entry *script_gpio_entry_new(struct script_section *script,
						const char *name,
						unsigned port, unsigned num,
107
						int32_t data[4]);
108
109

#endif