From c8628b2a715a7cfaaccbd7e403cd1c6c76b918cd Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Sun, 18 Oct 2015 03:47:47 +0200 Subject: Support properties of arbitrary type --- views/CMakeLists.txt | 4 ++-- views/enum.c | 2 +- views/register.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ views/register.h | 19 +++++++++++++++ 4 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 views/register.c create mode 100644 views/register.h (limited to 'views') diff --git a/views/CMakeLists.txt b/views/CMakeLists.txt index 646a982..0e0c20b 100644 --- a/views/CMakeLists.txt +++ b/views/CMakeLists.txt @@ -8,6 +8,6 @@ include_directories( ${UTHASH_INCLUDE_DIRS} ) -set(HEADERS ${HEADERS} enum.h transform.h) +set(HEADERS ${HEADERS} enum.h transform.h register.h) -add_library(views STATIC enum.c transform.c) +add_library(views STATIC enum.c transform.c register.c) diff --git a/views/enum.c b/views/enum.c index d712c71..e049c43 100644 --- a/views/enum.c +++ b/views/enum.c @@ -34,7 +34,7 @@ static int pcilib_enum_view_read(pcilib_t *ctx, pcilib_view_context_t *view_ctx, return pcilib_set_value_from_static_string(ctx, val, v->names[i].name); } - return pcilib_set_value_from_int(ctx, val, regval); + return pcilib_set_value_from_register_value(ctx, val, regval); } static int pcilib_enum_view_write(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t *regval, const pcilib_value_t *val) { diff --git a/views/register.c b/views/register.c new file mode 100644 index 0000000..8256a4a --- /dev/null +++ b/views/register.c @@ -0,0 +1,65 @@ +#define _PCILIB_VIEW_ENUM_C + +#include +#include +#include +#include +#include + +#include + +#include "error.h" +#include "version.h" +#include "model.h" +#include "enum.h" +#include "view.h" +#include "value.h" +#include "register.h" + + +static void pcilib_register_view_free(pcilib_t *ctx, pcilib_view_description_t *view) { + if (view->name) + free((void*)view->name); + free(view); +} + +static int pcilib_register_view_read(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t dummy, pcilib_value_t *val) { + int err; + + const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); + pcilib_register_view_description_t *v = (pcilib_register_view_description_t*)(model_info->views[view_ctx->view]); + + if (v->view) { + return pcilib_read_register_view(ctx, v->bank, v->reg, v->view, val); + } else { + pcilib_register_value_t regval; + + err = pcilib_read_register(ctx, v->bank, v->reg, ®val); + if (err) return err; + + return pcilib_set_value_from_register_value(ctx, val, regval); + } +} + +static int pcilib_register_view_write(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t *dummy, const pcilib_value_t *val) { + int err; + + const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); + pcilib_register_view_description_t *v = (pcilib_register_view_description_t*)(model_info->views[view_ctx->view]); + + if (v->view) { + return pcilib_write_register_view(ctx, v->bank, v->reg, v->view, val); + } else { + pcilib_register_value_t regval; + + regval = pcilib_get_value_as_register_value(ctx, val, &err); + if (err) return err; + + return pcilib_write_register(ctx, v->bank, v->reg, regval); + } + + return err; +} + +const pcilib_view_api_description_t pcilib_register_view_api = + { PCILIB_VERSION, sizeof(pcilib_register_view_description_t), NULL, NULL, pcilib_register_view_free, pcilib_register_view_read, pcilib_register_view_write }; diff --git a/views/register.h b/views/register.h new file mode 100644 index 0000000..e527846 --- /dev/null +++ b/views/register.h @@ -0,0 +1,19 @@ +#ifndef _PCILIB_VIEW_REGISTER_H +#define _PCILIB_VIEW_REGISTER_H + +#include +#include + +typedef struct { + pcilib_view_description_t base; + const char *view; + const char *reg; + const char *bank; +} pcilib_register_view_description_t; + + +#ifndef _PCILIB_VIEW_REGISTER_C +extern const pcilib_view_api_description_t pcilib_register_view_api; +#endif /* _PCILIB_VIEW_REGISTER_C */ + +#endif /* _PCILIB_VIEW_REGISTER_H */ -- cgit v1.2.3