1 /*
2  * Copyright (C) 2015-2019 Alibaba Group Holding Limited
3  */
4 
5 #ifndef BE_BOARD_MGR_H
6 #define BE_BOARD_MGR_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include <stdint.h>
13 
14 typedef enum addon_module {
15 
16     MODULE_GPIO = 0x1324,
17     MODULE_UART,
18     MODULE_I2C,
19     MODULE_PWM,
20     MODULE_ADC,
21     MODULE_DAC,
22     MODULE_SPI,
23     MODULE_TIMER,
24     MODULE_RTC,
25     MODULE_BT,
26     MODULE_IR,
27     MODULE_I2S,
28     MODULE_CAN,
29     MODULE_SDIO,
30     MODULE_USB,
31     MODULE_AUDIO,
32     MODULE_I2C_GPIO,
33     MODULE_NUMS,
34 } addon_module_m;
35 
36 typedef struct item_handle {
37     void *handle;
38 } item_handle_t;
39 
40 typedef struct {
41     int irq_mode;
42     int js_cb_ref;
43     void *reserved;
44 } gpio_params_t;
45 
46 /**
47  * initialize mgr system
48  *
49  * @param[in]  json_path  the path of boar-mgr file
50  * @return  the operation status, 0 is OK, others is error
51  */
52 int32_t board_mgr_init(const char* json_path);
53 
54 /**
55  * load driver config
56  *
57  * @param[in]  driver  the path of boar-driver file
58  * @return  the operation status, 0 is OK, others is error
59  */
60 int8_t board_load_drivers(const char* driver);
61 
62 /**
63  * attach a  driver resource
64  *
65  * @param[in]  module   the module type of a driver
66  * @param[in]  name_id  the name of a driver
67  * @param[out] name_id  the resource of a driver
68  * @return  the operation status, 0 is OK, others is error
69  */
70 int8_t board_attach_item(addon_module_m module, const char* name_id,
71                          item_handle_t* out);
72 
73 /**
74  * release a  driver resource
75  *
76  * @param[in]  module   the module type of a driver
77  * @param[in]  handle  the resource of a driver
78  * @return  the operation status, 0 is OK, others is error
79  */
80 int8_t board_disattach_item(addon_module_m module, item_handle_t* handle);
81 
82 /**
83  * the attach status of the driver and resource
84  *
85  * @param[in]  module   the module type of a driver
86  * @param[in]  handle  the resource of a driver
87  * @return  the attach status, 1 is attach, others is dis-attach
88  */
89 int8_t board_check_attach_status(addon_module_m module, item_handle_t* handle);
90 
91 /**
92  * get the resource of a driver by name
93  *
94  * @param[in]  module   the module type of a driver
95  * @param[in]  name_id  the name of a driver
96  * @return  driver resource,  null if not exist,otherwise it's right
97  */
98 void* board_get_node_by_name(addon_module_m module, const char* name_id);
99 
100 /**
101  * get the resource of a driver by the handle of a driver resource
102  *
103  * @param[in]  module   the module type of a driver
104  * @param[in]  handle  the resource of a driver
105  * @return  driver resource,  null if not exist,otherwise it's right
106  */
107 void* board_get_node_by_handle(addon_module_m module, item_handle_t* handle);
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif /* BE_BOARD_MGR_H */