json_object *obj;
json_object *name;
json_object *index;
-
+
struct interface_s *t_iface=NULL;
if(!interface || !iface)
eprintf("Invalid argument\n");
goto out;
}
-
+
if(!json_object_is_type(interface, json_type_array))
{
ret=RC_JSERROR;
static int module_list_free(struct module_s *mod)
{
- int ret=RC_OK;
+ int ret=RC_OK;
struct module_s *mnext;
int i;
while(mod)
for(i = 0; i < n; i++)
{
tobj = json_object_array_get_idx(obj, i);
+
if(!json_object_object_get_ex(tobj, "module", &name))
{
- ret=RC_JSERROR;
- eprintf("expected \"module\" in object (%s)\n", json_object_to_json_string(tobj));
- goto out;
+ continue;
}
if(!json_object_object_get_ex(tobj, "interface", &interface))
tickfirst=NULL;
json_object_object_get_ex(tobj, "tickfirst", &tickfirst);
-
+
if(m)
{
goto out;
}
len = 0;
-
+
while(m->iface[len++].name);
m->niface= len-1;
m->name = strdup(json_object_get_string(name));
m->tickfirst = json_object_get_boolean(tickfirst);
}
}
+
+ if (!m)
+ {
+ ret = RC_JSERROR;
+ eprintf("No modules found in config file:\n%s\n", json_object_to_json_string(obj));
+ goto out;
+ }
+
*mod = first;
first=NULL;
return ret;
}
-int litex_sim_file_to_module_list(char *filename, struct module_s **mod)
+static int json_get_timebase(json_object *obj, uint64_t *timebase)
+{
+ json_object *tobj;
+ int ret=RC_OK;
+ int i, n;
+ uint64_t _timebase = 0;
+ json_object *json_timebase;
+
+ if(!obj || !timebase)
+ {
+ ret = RC_INVARG;
+ eprintf("Wrong arguments\n");
+ goto out;
+ }
+
+ if(!json_object_is_type(obj, json_type_array))
+ {
+ ret=RC_JSERROR;
+ eprintf("Config file must be an array\n");
+ goto out;
+ }
+
+ n = json_object_array_length(obj);
+ for(i = 0; i < n; i++)
+ {
+ tobj = json_object_array_get_idx(obj, i);
+
+ if(!json_object_object_get_ex(tobj, "timebase", &json_timebase))
+ {
+ continue;
+ }
+
+ if (_timebase != 0)
+ {
+ ret=RC_JSERROR;
+ eprintf("\"timebase\" found multiple times: in object (%s)\n", json_object_to_json_string(tobj));
+ goto out;
+ }
+
+ _timebase = json_object_get_int64(json_timebase);
+ if (_timebase == 0)
+ {
+ ret=RC_JSERROR;
+ eprintf("\"timebase\" cannot be zero: in object (%s)\n", json_object_to_json_string(tobj));
+ goto out;
+ }
+ }
+
+ if (_timebase == 0)
+ {
+ ret=RC_JSERROR;
+ eprintf("No \"timebase\" found in config:\n%s\n", json_object_to_json_string(obj));
+ goto out;
+ }
+ *timebase = _timebase;
+
+out:
+ return ret;
+}
+
+
+int litex_sim_file_parse(char *filename, struct module_s **mod, uint64_t *timebase)
{
struct module_s *m=NULL;
json_object *obj=NULL;
goto out;
}
+ ret = json_get_timebase(obj, timebase);
+ if(RC_OK != ret)
+ {
+ goto out;
+ }
+
ret = json_to_module_list(obj, &m);
if(RC_OK != ret)
{