summaryrefslogtreecommitdiff
path: root/bsp/fh8620/platform/common/board_info.c
blob: aa56cbac626b49e4ceeb50b9fc332b9272b44739 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
 *  This file is part of FH8620 BSP for RT-Thread distribution.
 *
 *	Copyright (c) 2016 Shanghai Fullhan Microelectronics Co., Ltd. 
 *	All rights reserved
 *
 *  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, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *	Visit http://www.fullhan.com to get contact with Fullhan.
 *
 * Change Logs:
 * Date           Author       Notes
 */
 
/*****************************************************************************
 *  Include Section
 *  add all #include here
 *****************************************************************************/
#include "board_info.h"
#include <rtdevice.h>
#include <string.h>
/*****************************************************************************
 * Define section
 * add all #define here
 *****************************************************************************/
struct fh_board_info_list_node {
	struct fh_board_info obj;
	rt_list_t list;
};

#define CHECK_TEST_LIST_EMPTY		\
		if(rt_list_isempty(&board_info_head.list)) \
		rt_kprintf("board info is null...please register first..\n")

/****************************************************************************
 * ADT section
 *  add definition of user defined Data Type that only be used in this file  here
 ***************************************************************************/

#define list_for_each_entry_safe(pos, n, head, member)			\
	for (pos = rt_list_entry((head)->next, typeof(*pos), member),	\
		n = rt_list_entry(pos->member.next, typeof(*pos), member);	\
	     &pos->member != (head); 					\
	     pos = n, n = rt_list_entry(n->member.next, typeof(*n), member))

#define PARA_ERROR			(-1)
#define PROBE_FUNC_MISS		(-2)

/******************************************************************************
 * Function prototype section
 * add prototypes for all functions called by this file,execepting those
 * declared in header file
 *****************************************************************************/

//static void fh81_soc_free_all_test(void);
//static void fh81_soc_print_all_test(void);
//static void fh81_soc_auto_test_all(void);
//static void fh81_soc_test_help(void);
/*****************************************************************************
 * Global variables section - Exported
 * add declaration of global variables that will be exported here
 * e.g.
 *  int8_t foo;
 ****************************************************************************/

/*****************************************************************************

 *  static fun;
 *****************************************************************************/
static struct fh_board_info_list_node board_info_head;



/*****************************************************************************
 * Global variables section - Local
 * define global variables(will be refered only in this file) here,
 * static keyword should be used to limit scope of local variable to this file
 * e.g.
 *  static uint8_t ufoo;
 *****************************************************************************/


 /* function body */
/*****************************************************************************
 * Description:
 *      add funtion description here
 * Parameters:
 *      description for each argument, new argument starts at new line
 * Return:
 *      what does this function returned?
 *****************************************************************************/

int fh_board_info_init(void) {

	memset(&board_info_head, 0x0, sizeof(struct fh_board_info_list_node));
	rt_list_init(&board_info_head.list);
	board_info_head.obj.name = "NO INFO";
	return 0;
}

void fh_free_all_info(void) {
	rt_list_t *p_list;
	struct fh_board_info_list_node *info_node;
	struct fh_board_info_list_node *_info_node;
	p_list = &board_info_head.list;

	CHECK_TEST_LIST_EMPTY;

	list_for_each_entry_safe(info_node, _info_node, p_list, list)
	{

		if (info_node->obj.ops->exit) {
			info_node->obj.ops->exit(info_node->obj.data);
		}
		rt_kprintf("soc free list name:(%s)\n", info_node->obj.name);
		rt_free(info_node);
	}
	fh_board_info_init();
}

void fh_print_all_board_info(void) {
	rt_list_t *p_list;

	struct fh_board_info_list_node *info_node;
	struct fh_board_info_list_node *_info_node;
	p_list = &board_info_head.list;

	CHECK_TEST_LIST_EMPTY;

	list_for_each_entry_safe(info_node, _info_node, p_list, list)
	{
		rt_kprintf("%s\n", info_node->obj.name);
	}
}

/*****************************************************************************
 * Description:
 *      add funtion description here
 * Parameters:
 *      description for each argument, new argument starts at new line
 * Return:
 *      what does this function returned?
 *****************************************************************************/

//register the platform info such as base add,isr no..
//caution:do not free the name and data because of here not copy
struct fh_board_info *fh_board_info_register(char *info_name, void *data) {
	rt_list_t *p_list;
	struct fh_board_info_list_node *new_node;
	struct fh_board_info_list_node *info_node;
	struct fh_board_info_list_node *_info_node;
	p_list = &board_info_head.list;

	if (RT_NULL == info_name || RT_NULL == data) {
		rt_kprintf("info name or info data is NULL!\n");
		return RT_NULL;
	}

	//check if the func is already in the test list....
#if(0)
	list_for_each_entry_safe(info_node, _info_node, p_list, list) {
		if (!memcmp(info_node->obj.name, info_name, strlen(info_name))) {
			rt_kprintf("info_name(%s) is already registered\n", info_name);
			return RT_NULL;
		}
	}
#endif

	new_node = (struct fh_board_info_list_node *) rt_malloc(
			sizeof(struct fh_board_info_list_node));
	if (!new_node) {
		rt_kprintf("malloc new_list_node failed~\n");
		return RT_NULL;
	}

	new_node->obj.name = info_name;
	new_node->obj.data = data;
	//here insert "before" and test is "after" will make the list like a fifo...
	rt_list_insert_before(&board_info_head.list, &new_node->list);
	return &new_node->obj;
}

//back the platform info
static void *fh_get_board_info_data(char *info_name) {

	rt_list_t *p_list;
	struct fh_board_info_list_node *info_node;
	struct fh_board_info_list_node *_info_node;
	p_list = &board_info_head.list;

	//check info name
	if (RT_NULL == info_name) {
		rt_kprintf("info name is NULL!\n");
		return RT_NULL;
	}

	CHECK_TEST_LIST_EMPTY;

	list_for_each_entry_safe(info_node, _info_node, p_list, list)
	{
		if (!strcmp(info_node->obj.name, info_name)) {
			return info_node->obj.data;
		}
	}

	rt_kprintf("Can't find the board info name:%s\n", info_name);
}

int fh_board_driver_register(char *info_name, struct fh_board_ops *ops) {

	rt_list_t *p_list;
	struct fh_board_info_list_node *new_node;
	struct fh_board_info_list_node *info_node;
	struct fh_board_info_list_node *_info_node;
	p_list = &board_info_head.list;

	if (RT_NULL == info_name || RT_NULL == ops) {
		rt_kprintf("info name or ops func is NULL!\n");
		return PARA_ERROR;
	}

	list_for_each_entry_safe(info_node, _info_node, p_list, list)
	{
		if (!strcmp(info_node->obj.name, info_name)) {

			info_node->obj.ops = ops;
			if (info_node->obj.ops->probe) {
				info_node->obj.ops->probe(info_node->obj.data);
			}

			//return info_node->obj.data;
		}
	}

	//rt_kprintf("Can't find the board info name:%s\n",info_name);

	return 0;
}