Provide access to the fuse/lock bit configuration table

Synthesize a Python list, consisting of the individual table entries
as a dictionary. The dictionary, in turn, contains a table with the
individual values.

Quiet complex.
This commit is contained in:
Joerg Wunsch
2024-04-02 23:43:03 +02:00
parent 48bbd4b160
commit 07116d93a0
2 changed files with 74 additions and 0 deletions

View File

@@ -163,6 +163,73 @@ const char *ldata_string(LNODEID p) {
return (const char *)ldata(p);
}
PyObject *get_config_table(const char *name) {
int idx = upidxname(name);
if (idx == -1)
return Py_None;
const uPcore_t *up = uP_table + idx;
int nitems = up->nconfigs;
// found: construct a list object
PyObject *list = PyList_New(nitems);
if (list == NULL) {
return NULL;
}
// now, add list elements
const Configitem_t *cfg = up->cfgtable;
for (int i = 0; i < nitems; i++) {
PyObject* dict = PyDict_New();
if (dict == NULL) {
return NULL;
}
PyDict_SetItem(dict, PyUnicode_FromString("name"),
PyUnicode_FromString(cfg->name));
int nvalues = cfg->nvalues;
PyObject *vlist = PyList_New(nvalues);
if (vlist == NULL) {
return NULL;
}
for (int j = 0; j < nvalues; j++) {
PyObject* vdict = PyDict_New();
if (vdict == NULL) {
return NULL;
}
PyDict_SetItem(vdict, PyUnicode_FromString("value"),
PyLong_FromLong(cfg->vlist[j].value));
PyDict_SetItem(vdict, PyUnicode_FromString("label"),
PyUnicode_FromString(cfg->vlist[j].label));
PyDict_SetItem(vdict, PyUnicode_FromString("vcomment"),
PyUnicode_FromString(cfg->vlist[j].vcomment));
PyList_SetItem(vlist, j, vdict);
}
PyDict_SetItem(dict, PyUnicode_FromString("vlist"),
vlist);
PyDict_SetItem(dict, PyUnicode_FromString("memstr"),
PyUnicode_FromString(cfg->memstr));
PyDict_SetItem(dict, PyUnicode_FromString("memoffset"),
PyLong_FromLong(cfg->memoffset));
PyDict_SetItem(dict, PyUnicode_FromString("mask"),
PyLong_FromLong(cfg->mask));
PyDict_SetItem(dict, PyUnicode_FromString("lsh"),
PyLong_FromLong(cfg->lsh));
PyDict_SetItem(dict, PyUnicode_FromString("initval"),
PyLong_FromLong(cfg->initval));
PyDict_SetItem(dict, PyUnicode_FromString("ccomment"),
PyUnicode_FromString(cfg->ccomment));
PyList_SetItem(list, i, dict);
cfg++;
}
return list;
}
%}
// globals from above are mapped to Python
@@ -638,4 +705,9 @@ int fileio_fmt_autodetect(const char *fname);
int fileio(int oprwv, const char *filename, FILEFMT format,
const AVRPART *p, const char *memstr, int size);
// avrintel stuff - configuration values for various AVRs
%feature("autodoc", "get_config_table(name: str) -> list") get_config_table;
PyObject *get_config_table(const char *name);
%feature("autodoc", "1");

View File

@@ -23,6 +23,8 @@
# ad.fileio(ad.FIO_WRITE, "test.hex", ad.fileio_format("i"), p, "flash", -1)
# cfg=ad.get_config_table('atmega128')
# 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