MCPcopy Create free account
hub / github.com/DreamSourceLab/DSView / init

Function init

libsigrok4DSL/input/in_binary.c:50–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50static int init(struct sr_input *in, const char *filename)
51{
52 struct sr_channel *probe;
53 uint16_t num_probes, i;
54 char name[SR_MAX_PROBENAME_LEN + 1];
55 char *param;
56 struct context *ctx;
57
58 (void)filename;
59
60 if (!(ctx = malloc(sizeof(struct context)))) {
61 sr_err("Input format context malloc failed.");
62 return SR_ERR_MALLOC;
63 }
64 memset(ctx, 0, sizeof(struct context));
65
66 num_probes = DEFAULT_NUM_PROBES;
67 ctx->samplerate = 0;
68
69 if (in->param) {
70 param = g_hash_table_lookup(in->param, "numprobes");
71 if (param) {
72 num_probes = strtoul(param, NULL, 10);
73 if (num_probes < 1)
74 return SR_ERR;
75 }
76
77 param = g_hash_table_lookup(in->param, "samplerate");
78 if (param) {
79 if (sr_parse_sizestring(param, &ctx->samplerate) != SR_OK)
80 return SR_ERR;
81 }
82 }
83
84 /* Create a virtual device. */
85 in->sdi = sr_dev_inst_new(LOGIC, SR_ST_ACTIVE, NULL, NULL, NULL);
86 in->internal = ctx;
87
88 for (i = 0; i < num_probes; i++) {
89 snprintf(name, SR_MAX_PROBENAME_LEN, "%d", i);
90 /* TODO: Check return value. */
91 if (!(probe = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, name)))
92 return SR_ERR;
93 in->sdi->channels = g_slist_append(in->sdi->channels, probe);
94 }
95
96 return SR_OK;
97}
98
99static int loadfile(struct sr_input *in, const char *filename)
100{

Callers

nothing calls this directly

Calls 3

sr_parse_sizestringFunction · 0.85
sr_dev_inst_newFunction · 0.85
sr_channel_newFunction · 0.85

Tested by

no test coverage detected