From: Eric van Tassell <evt@evtM17x.(none)>
---
Android.mk | 4 +-
Makefile | 2 +-
delimi.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++
delimi.h | 30 +++++++++++++++
pwrdm.regdefs.omap4 | 33 ++++++++++++++++
utils.c | 12 ++++++
utils.h | 11 +++++-
vdd.regdefs.omap4 | 68 +++++++++++++++++++++++++++++++++
8 files changed, 262 insertions(+), 4 deletions(-)
create mode 100644 delimi.c
create mode 100644 delimi.h
create mode 100644 pwrdm.regdefs.omap4
create mode 100644 vdd.regdefs.omap4
diff --git a/Android.mk b/Android.mk
index e062c1c..f448d48 100644
--- a/Android.mk
+++ b/Android.mk
@@ -28,7 +28,7 @@ LOCAL_C_INCLUDES += external/stlport/stlport/ \
external/ncurses/include/ncurses
LOCAL_SRC_FILES += \
- powerdebug.c sensor.c clocks.c regulator.c \
- display.c tree.c utils.c mainloop.c
+ powerdebug.c sensor.c clocks.c regulator.c gpio.c \
+ display.c tree.c utils.c mainloop.c delimi.c
include $(BUILD_EXECUTABLE)
diff --git a/Makefile b/Makefile
index 2da9d67..5007972 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ CFLAGS?=-O1 -g -Wall -Wshadow
CC?=gcc
OBJS = powerdebug.o sensor.o clocks.o regulator.o gpio.o \
- display.o tree.o utils.o mainloop.o
+ display.o tree.o utils.o mainloop.o delimi.o
default: powerdebug
diff --git a/delimi.c b/delimi.c
new file mode 100644
index 0000000..8c7dbee
--- /dev/null
+++ b/delimi.c
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (C) 2012, Linaro Limited.
+ *
+ * This file is part of PowerDebug.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eric van Tassell
+ * - initial API and implementation
+
******************************************************************************/
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#undef _GNU_SOURCE
+#include <sys/types.h>
+#include <stdbool.h>
+#include <dirent.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include "display.h"
+#include "utils.h"
+#include "delimi.h"
+
+struct delim_iterator *delimi_new(char *buf, char delim)
+{
+ char *p;
+ struct delim_iterator *delimi;
+
+ delimi = (struct delim_iterator *) calloc(1, sizeof(struct
delim_iterator));
+ if (!delimi)
+ return NULL;
+
+ delimi->str = delimi->val = calloc(1, strlen(buf));
+ delimi->delim = delim;
+
+ for (p = delimi->str; *buf; buf++) {
+ /* skip blanks & newlines */
+ if (isblank(*buf) || (*buf == '\n'))
+ continue;
+ *p++ = *buf;
+ }
+ delimi->val_end = strchrnul(delimi->val, delimi->delim);
+ delimi->val_end--;
+ return delimi;
+}
+
+void delimi_free(struct delim_iterator *delimi)
+{
+ if (!delimi)
+ return;
+ if (delimi->str)
+ free(delimi->str);
+ free(delimi);
+}
+
+void delimi_next(struct delim_iterator *delimi)
+{
+ if (*(delimi->val_end + 1) == '\0') {
+ /* we saw delimi->val_end = "last-value\0" */
+ delimi->val = delimi->val_end = delimi->val_end + 1;
+ } else {
+ /* saw "x,value1,value2,..." */
+ delimi->val = delimi->val_end + 2;
+ delimi->val_end = strchrnul(delimi->val, delimi->delim);
+ if (*(delimi->val_end) == delimi->delim)
+ delimi->val_end--;
+ }
+}
+
+int delimi_empty(struct delim_iterator *delimi)
+{
+ return (delimi->val == delimi->val_end);
+}
+
+#ifdef DEBUG_PARSE
+void delimi_show(struct delim_iterator *delimi)
+{
+ printf("%s:\n\tstr = %s\n\tval = %s\n\tval_end = %s\n\tempty = %s\n",
+ __func__,
+ delimi->str,
+ delimi->val,
+ delimi->val_end,
+ delimi_empty(delimi) ? "true" : "false");
+}
+#endif /* DEBUG_PARSE */
+
+/* allocate space for and get current value */
+char *delimi_aget_val(struct delim_iterator *delimi)
+{
+ char *tmp;
+
+ if (!delimi)
+ BAIL_OUT(("NULL struct delim_iterator *"));
+
+ tmp = calloc(1, delimi->val_end - delimi->val + 2);
+ memcpy(tmp, delimi->val, delimi->val_end - delimi->val + 1);
+ return tmp;
+}
+
diff --git a/delimi.h b/delimi.h
new file mode 100644
index 0000000..f000097
--- /dev/null
+++ b/delimi.h
@@ -0,0 +1,30 @@
+/******************************************************************************
+ * Copyright (C) 2012, Linaro Limited.
+ *
+ * This file is part of PowerDebug.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eric van Tassell
+ * - initial API and implementation
+ *****************************************************************************/
+struct delim_iterator {
+ char *str;
+ char *val;
+ char *val_end;
+ char delim;
+};
+
+/* prototypes for exported functions */
+void delimi_next(struct delim_iterator *delimi);
+int delimi_empty(struct delim_iterator *delimi);
+char *delimi_aget_val(struct delim_iterator *delimi);
+#ifdef DEBUG_PARSE
+void delimi_show(struct delim_iterator *delimi);
+#endif
+struct delim_iterator *delimi_new(char *buf, char delim);
+void delimi_free(struct delim_iterator *delimi);
diff --git a/pwrdm.regdefs.omap4 b/pwrdm.regdefs.omap4
new file mode 100644
index 0000000..30e85b7
--- /dev/null
+++ b/pwrdm.regdefs.omap4
@@ -0,0 +1,33 @@
+#
+# see the README for information on the format of this file
+# this is just a sample, much more could be added
+#
+decoder, boolean, false, true
+decoder, logicst, off, on
+decoder, retst, retention registers, whole logic
+decoder, statest, off, retention, on-inactive, on-active
+push, MPU_PD
+push, PWRSTCTL
+field, lowpowerstatechange, 0x4A306300, 4, 1, boolean
+field, logicretstate, 0x4A306300, 2, 1, retst
+field, powerstate, 0x4A306300, 0, 3, statest
+pop
+push, PWRST
+field, powerstate, 0x4A306304, 0, 3, statest
+pop
+pop
+push, ABE_PD
+push, PWRSTCTL
+field, powerstate, 0x4A306500, 0, 3, statest
+pop
+pop
+push, IVAHD_PD
+push, PWRSTCTL
+field, powerstate, 0x4A306F00, 0, 3, statest
+pop
+pop
+push, EMU_PD
+push, PWRSTCTL
+field, powerstate, 0x4A307900, 0, 3, statest
+pop
+pop
diff --git a/utils.c b/utils.c
index e47c58e..0e95f05 100644
--- a/utils.c
+++ b/utils.c
@@ -53,3 +53,15 @@ out_free:
free(rpath);
return ret;
}
+
+/* bionic lacks strchrnul */
+char *strchrnul(char *str, char delim)
+{
+ char *tmp;
+
+ tmp = strchr(str, delim);
+
+ if (tmp == NULL)
+ tmp = str + strlen(str) - 1;
+ return tmp;
+}
diff --git a/utils.h b/utils.h
index d4ac65a..c5cec51 100644
--- a/utils.h
+++ b/utils.h
@@ -15,8 +15,17 @@
#ifndef __UTILS_H
#define __UTILS_H
+#define BAIL_OUT(x) \
+ { \
+ printf x; \
+ printf("%s@%d:BAILING OUT HERE:\n", __func__, __LINE__); \
+ exit(0); \
+}
+#undef DEBUG_PARSE
+
+/* prototypes */
extern int file_read_value(const char *path, const char *name,
const char *format, void *value);
-
+char *strchrnul(char *str, char delim);
#endif
diff --git a/vdd.regdefs.omap4 b/vdd.regdefs.omap4
new file mode 100644
index 0000000..8b3c3e6
--- /dev/null
+++ b/vdd.regdefs.omap4
@@ -0,0 +1,68 @@
+#
+# see the README for information on the format of this file
+# this is just a sample, much more could be added
+#
+decoder, boolean, false, true
+decoder, initvdd, reset, write_to_voltage_processor
+decoder, forceupd, reset, write_to_SMPS
+#
+push, VDD_CORE_L
+#
+push, CONFIG
+field, INITVOLTAGE, 0x4A307B40, 8, 0xff
+field, TIMEOUTEN, 0x4A307B40, 3, 1, boolean
+field, INITVDD, 0x4A307B40, 2, 1, initvdd
+field, FORCEUPD ,0x4A307B40, 1, 1, forceupd
+field, VPENABLE,0x4A307B40, 0, 1, boolean
+#
+pop
+push, STATUS
+field, VPINIDLE,0x4A307B44, 0, 1
+#
+pop
+push, VOLTAGE
+field, VPVOLTAGE,0x4A307B4C, 0, 0xff
+#
+pop
+pop
+push, VDD_MPU_L
+#
+push, CONFIG
+field, INITVOLTAGE, 0x4A307B58, 8, 0xff
+field, TIMEOUTEN, 0x4A307B58, 3, 1, boolean
+field, INITVDD, 0x4A307B58, 2, 1, initvdd
+field, FORCEUPD ,0x4A307B58, 1, 1, forceupd
+field, VPENABLE,0x4A307B58, 0, 1, boolean
+#
+pop
+push, STATUS
+field, VPINIDLE,0x4A307B5C, 0, 1
+#
+pop
+push, VOLTAGE
+field, VPVOLTAGE,0x4A307B64, 0, 0xff
+#
+pop
+pop
+push, VDD_IVA_L
+#
+push, CONFIG
+field, INITVOLTAGE, 0x4A307B70, 8, 0xff
+field, TIMEOUTEN, 0x4A307B70, 3, 1, boolean
+field, INITVDD, 0x4A307B70, 2, 1, initvdd
+field, FORCEUPD ,0x4A307B70, 1, 1, forceupd
+field, VPENABLE,0x4A307B70, 0, 1, boolean
+#
+pop
+push, STATUS
+field, VPINIDLE,0x4A307B74, 0, 1
+#
+pop
+push, VOLTAGE
+field, VPVOLTAGE,0x4A307B7C, 0, 0xff
+pop
+pop
+#
+push, misc
+push, PRM_VC_CFG_CHANNEL
+field, [31:0], 0x4a307BA4, 0, 0xffffffff
--
1.7.9.5
_______________________________________________
linaro-dev mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/linaro-dev