script.h 3.29 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
 * (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

20
21
#include "list.h"

22
23
#define GPIO_BANK_MAX	13 /* N */

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
/** 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;
};

59
60
61
62
63
64
65
/** entry with 32b value */
struct script_single_entry {
	struct script_entry entry;

	uint32_t value;
};

66
67
68
69
70
71
72
73
/** entry with string value */
struct script_string_entry {
	struct script_entry entry;

	size_t l;
	char string[];
};

74
75
76
77
78
/** entry describing a GPIO */
struct script_gpio_entry {
	struct script_entry entry;

	unsigned port, port_num;
79
	int32_t data[4];
80
81
};

82
83
/** create a new script tree */
struct script *script_new(void);
84
85
/** deletes a tree recursively */
void script_delete(struct script *);
86
87

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

93
/** find existing section */
94
struct script_section *script_find_section(struct script *script,
95
96
					   const char *name);

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

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/** 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,
115
						int32_t data[4]);
116

117
118
119
/** find existing entry in a giving section */
struct script_entry *script_find_entry(struct script_section *section,
				       const char *name);
120
#endif