-
Notifications
You must be signed in to change notification settings - Fork 420
/
script.h
120 lines (99 loc) · 3.31 KB
/
script.h
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
120
/*
* Copyright (C) 2012 Alejandro Mery <[email protected]>
*
* 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 2 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/>.
*/
#ifndef _SUNXI_TOOLS_SCRIPT_H
#define _SUNXI_TOOLS_SCRIPT_H
#include "list.h"
#define GPIO_BANK_MAX 14 /* N, (zero-based) index 13 */
/** 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;
};
/** entry with 32b value */
struct script_single_entry {
struct script_entry entry;
uint32_t value;
};
/** entry with string value */
struct script_string_entry {
struct script_entry entry;
size_t l;
char string[];
};
/** entry describing a GPIO */
struct script_gpio_entry {
struct script_entry entry;
unsigned port, port_num;
int32_t data[4];
};
/** create a new script tree */
struct script *script_new(void);
/** deletes a tree recursively */
void script_delete(struct script *);
/** create a new section appended to a given tree */
struct script_section *script_section_new(struct script *script,
const char *name);
/** deletes a section recursvely and removes it from the script */
void script_section_delete(struct script_section *section);
/** find existing section */
struct script_section *script_find_section(struct script *script,
const char *name);
/** deletes an entry and removes it from the section */
void script_entry_delete(struct script_entry *entry);
/** 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,
int32_t data[4]);
/** find existing entry in a giving section */
struct script_entry *script_find_entry(struct script_section *section,
const char *name);
#endif