1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 
5 #include "py/mperrno.h"
6 #include "py/obj.h"
7 #include "py/runtime.h"
8 #include "py/builtin.h"
9 
10 #include "ulog/ulog.h"
11 
12 #define LOG_TAG "MOD_SYSTEMINFO"
13 
14 // this is the actual C-structure for our new object
15 typedef struct
16 {
17     // base represents some basic information, like type
18     mp_obj_base_t Base;
19     // a member created by us
20     char *ModuleName;
21 } mp_system_obj_t;
obj_open(size_t n_args,const mp_obj_t * args)22 STATIC mp_obj_t obj_open(size_t n_args, const mp_obj_t *args)
23 {
24     LOGD(LOG_TAG, "entern  %s; n_args = %d;\n", __func__, n_args);
25     int ret = -1;
26     void* instance = NULL;
27     if (n_args < 1)
28     {
29         LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
30         return mp_const_none;
31     }
32     LOGD(LOG_TAG, "%s:out\n", __func__);
33 
34     return mp_const_none;
35 }
36 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(system_obj_open, 1, obj_open);
37 
obj_close(size_t n_args,const mp_obj_t * args)38 STATIC mp_obj_t obj_close(size_t n_args, const mp_obj_t *args)
39 {
40     LOGD(LOG_TAG, "entern  %s; n_args = %d;\n", __func__, n_args);
41     int ret = -1;
42     void* instance = NULL;
43     if (n_args < 1)
44     {
45         LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
46         return mp_const_none;
47     }
48     LOGD(LOG_TAG, "%s:out\n", __func__);
49 
50     return mp_const_none;
51 }
52 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(system_obj_close, 1, obj_close);
53 
obj_versions(size_t n_args,const mp_obj_t * args)54 STATIC mp_obj_t obj_versions(size_t n_args, const mp_obj_t *args)
55 {
56     LOGD(LOG_TAG, "entern  %s; n_args = %d;\n", __func__, n_args);
57     int ret = -1;
58 
59     char * version = NULL;
60     if (n_args < 1)
61     {
62         LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
63         return mp_const_none;
64     }
65     //version = amp_get_system_version();
66     LOGD(LOG_TAG, "%s:out\n", __func__);
67 
68     return MP_ROM_QSTR(version);
69 }
70 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(system_obj_versions, 1, obj_versions);
71 
obj_version(size_t n_args,const mp_obj_t * args)72 STATIC mp_obj_t obj_version(size_t n_args, const mp_obj_t *args)
73 {
74     LOGD(LOG_TAG, "entern  %s; n_args = %d;\n", __func__, n_args);
75     int ret = -1;
76 
77     //char version[AMP_VERSION_LENGTH] = {0};
78     if (n_args < 1)
79     {
80         LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
81         return mp_const_none;
82     }
83     //amp_version_get(version);
84     LOGD(LOG_TAG, "%s:out\n", __func__);
85 
86     //return MP_ROM_QSTR(version);
87     return mp_const_none;
88 }
89 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(system_obj_version, 1, obj_version);
90 
obj_platform(size_t n_args,const mp_obj_t * args)91 STATIC mp_obj_t obj_platform(size_t n_args, const mp_obj_t *args)
92 {
93     LOGD(LOG_TAG, "entern  %s; n_args = %d;\n", __func__, n_args);
94     int ret = -1;
95     char * type = NULL;
96 
97     if (n_args < 1)
98     {
99         LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
100         return mp_const_none;
101     }
102     //type = amp_get_platform_type();
103     LOGD(LOG_TAG, "%s:out\n", __func__);
104 
105     return MP_ROM_QSTR(type);
106 }
107 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(system_obj_platform, 1, obj_platform);
108 
obj_uptime(size_t n_args,const mp_obj_t * args)109 STATIC mp_obj_t obj_uptime(size_t n_args, const mp_obj_t *args)
110 {
111     LOGD(LOG_TAG, "entern  %s; n_args = %d;\n", __func__, n_args);
112     int ret = -1;
113 
114     if (n_args < 1)
115     {
116         LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
117         return mp_const_none;
118     }
119     //ret = amp_uptime();
120     LOGD(LOG_TAG, "%s:out\n", __func__);
121 
122     return MP_ROM_INT(ret);
123 }
124 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(system_obj_uptime, 1, obj_uptime);
125 
obj_memory_total(size_t n_args,const mp_obj_t * args)126 STATIC mp_obj_t obj_memory_total(size_t n_args, const mp_obj_t *args)
127 {
128     LOGD(LOG_TAG, "entern  %s; n_args = %d;\n", __func__, n_args);
129     int ret = -1;
130 
131     //amp_heap_info_t heap_info;
132     if (n_args < 1)
133     {
134         LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
135         return mp_const_none;
136     }
137     //ret = amp_heap_memory_info(&heap_info);
138     if (ret != 0)
139     {
140         LOGE(LOG_TAG, "%s:amp_heap_memory_info failed\n", __func__);
141         return mp_const_none;
142     }
143     //LOGD(LOG_TAG, "%s:heap_info.heap_total = %d;\n", __func__, heap_info.heap_total);
144     //LOGD(LOG_TAG, "%s:heap_info.heap_used = %d;\n", __func__, heap_info.heap_used);
145     LOGD(LOG_TAG, "%s:out\n", __func__);
146 
147     //return MP_ROM_INT(heap_info.heap_total);
148 }
149 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(system_obj_memory_total, 1, obj_memory_total);
150 
obj_memory_used(size_t n_args,const mp_obj_t * args)151 STATIC mp_obj_t obj_memory_used(size_t n_args, const mp_obj_t *args)
152 {
153     LOGD(LOG_TAG, "entern  %s; n_args = %d;\n", __func__, n_args);
154     int ret = -1;
155 
156     //amp_heap_info_t heap_info;
157     if (n_args < 1)
158     {
159         LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
160         return mp_const_none;
161     }
162     //ret = amp_heap_memory_info(&heap_info);
163     if (ret != 0)
164     {
165         LOGE(LOG_TAG, "%s:amp_heap_memory_info failed\n", __func__);
166         return mp_const_none;
167     }
168     //LOGD(LOG_TAG, "%s:heap_info.heap_total = %d;\n", __func__, heap_info.heap_total);
169     //LOGD(LOG_TAG, "%s:heap_info.heap_used = %d;\n", __func__, heap_info.heap_used);
170     LOGD(LOG_TAG, "%s:out\n", __func__);
171 
172     //return MP_ROM_INT(heap_info.heap_used);
173     return mp_const_none;
174 }
175 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(system_obj_memory_used, 1, obj_memory_used);
176 
obj_gc(size_t n_args,const mp_obj_t * args)177 STATIC mp_obj_t obj_gc(size_t n_args, const mp_obj_t *args)
178 {
179     LOGD(LOG_TAG, "entern  %s; n_args = %d;\n", __func__, n_args);
180     int ret = -1;
181     void* instance = NULL;
182     if (n_args < 1)
183     {
184         LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
185         return mp_const_none;
186     }
187     LOGD(LOG_TAG, "%s:out\n", __func__);
188 
189     return mp_const_none;
190 }
191 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(system_obj_gc, 1, obj_gc);
192 
193 STATIC const mp_rom_map_elem_t systeminfo_locals_dict_table[] = {
194     {MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_SystemInfo)},
195     {MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&system_obj_open)},
196     {MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&system_obj_close)},
197     {MP_ROM_QSTR(MP_QSTR_versions), MP_ROM_PTR(&system_obj_versions)},
198     {MP_ROM_QSTR(MP_QSTR_version), MP_ROM_PTR(&system_obj_version)},
199     {MP_ROM_QSTR(MP_QSTR_platform), MP_ROM_PTR(&system_obj_platform)},
200     {MP_ROM_QSTR(MP_QSTR_uptime), MP_ROM_PTR(&system_obj_uptime)},
201     {MP_ROM_QSTR(MP_QSTR_memory_total), MP_ROM_PTR(&system_obj_memory_total)},
202     {MP_ROM_QSTR(MP_QSTR_memory_used), MP_ROM_PTR(&system_obj_memory_used)},
203     {MP_ROM_QSTR(MP_QSTR_gc), MP_ROM_PTR(&system_obj_gc)},
204 };
205 
206 STATIC MP_DEFINE_CONST_DICT(systeminfo_locals_dict, systeminfo_locals_dict_table);
207 
208 const mp_obj_module_t system_info_module = {
209     .base = {&mp_type_module},
210     .globals = (mp_obj_dict_t *)&systeminfo_locals_dict,
211 };
212