summaryrefslogtreecommitdiff
path: root/util/intelp2m/parser/template.go
blob: 3248152ceddc89db0daa1b322ef0551429717a89 (plain)
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
121
122
123
124
125
126
127
128
129
130
131
132
package parser

import (
	"fmt"
	"strings"
	"unicode"
)

type template func(string, *string, *string, *uint32, *uint32) int

// extractPadFuncFromComment
// line   : string from file with pad config map
// return : pad function string
func extractPadFuncFromComment(line string) string {
	if !strings.Contains(line, "/*") && !strings.Contains(line, "*/") {
		return ""
	}

	fields := strings.Fields(line)
	for i, field := range fields {
		if field == "/*" && len(fields) >= i+2 {
			return fields[i+1]
		}
	}
	return ""
}

// tokenCheck
func tokenCheck(c rune) bool {
	return c != '_' && c != '#' && !unicode.IsLetter(c) && !unicode.IsNumber(c)
}

// useGpioHTemplate
// line      : string from file with pad config map
// *function : the string that means the pad function
// *id       : pad id string
// *dw0      : DW0 register value
// *dw1      : DW1 register value
// return
//   error status
func useInteltoolLogTemplate(line string, function *string,
	id *string, dw0 *uint32, dw1 *uint32) int {

	var val uint64
	// 0x0520: 0x0000003c44000600 GPP_B12  SLP_S0#
	// 0x0438: 0xffffffffffffffff GPP_C7   RESERVED
	if fields := strings.FieldsFunc(line, tokenCheck); len(fields) >= 4 {
		fmt.Sscanf(fields[1], "0x%x", &val)
		*dw0 = uint32(val & 0xffffffff)
		*dw1 = uint32(val >> 32)
		*id = fields[2]
		*function = fields[3]
		// Sometimes the configuration file contains compound functions such as
		// SUSWARN#/SUSPWRDNACK. Since the template does not take this into account,
		// need to collect all parts of the pad function back into a single word
		for i := 4; i < len(fields); i++ {
			*function += "/" + fields[i]
		}
		// clear RO Interrupt Select (INTSEL)
		*dw1 &= 0xffffff00
	}
	return 0
}

// useGpioHTemplate
// line      : string from file with pad config map
// *function : the string that means the pad function
// *id       : pad id string
// *dw0      : DW0 register value
// *dw1      : DW1 register value
// return
//   error status
func useGpioHTemplate(line string, function *string,
	id *string, dw0 *uint32, dw1 *uint32) int {

	// /* RCIN# */	_PAD_CFG_STRUCT(GPP_A0, 0x44000702, 0x00000000),
	// _PAD_CFG_STRUCT(GPP_A0, 0x44000702, 0x00000000), /* RCIN# */
	// _PAD_CFG_STRUCT(GPP_A0, 0x44000702, 0x00000000)
	fields := strings.FieldsFunc(line, tokenCheck)
	for i, field := range fields {
		if field == "_PAD_CFG_STRUCT" {
			if len(fields) < 4 {
				/* the number of definitions does not match the format */
				return -1
			}

			if !strings.Contains(fields[i+2], "0x") || !strings.Contains(fields[i+3], "0x") {
				/* definitions inside the macro do not match the pattern */
				return -1
			}
			*id = fields[i+1]
			fmt.Sscanf(fields[i+2], "0x%x", dw0)
			fmt.Sscanf(fields[i+3], "0x%x", dw1)
			*function = extractPadFuncFromComment(line)
			return 0
		}
	}
	return -1
}

// useYourTemplate
func useYourTemplate(line string, function *string,
	id *string, dw0 *uint32, dw1 *uint32) int {

	// ADD YOUR TEMPLATE HERE
	*function = ""
	*id = ""
	*dw0 = 0
	*dw1 = 0

	fmt.Printf("ADD YOUR TEMPLATE!\n")
	return -1
}

// registerInfoTemplate
// line    : (in)  string from file with pad config map
// *name   : (out) register name
// *offset : (out) offset name
// *value  : (out) register value
// return
//   error status
func registerInfoTemplate(line string, name *string, offset *uint32, value *uint32) int {
	// 0x0088: 0x00ffffff (HOSTSW_OWN_GPP_F)
	// 0x0100: 0x00000000 (GPI_IS_GPP_A)
	if fields := strings.FieldsFunc(line, tokenCheck); len(fields) == 3 {
		*name = fields[2]
		fmt.Sscanf(fields[1], "0x%x", value)
		fmt.Sscanf(fields[0], "0x%x", offset)
		return 0
	}
	return -1
}