aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPalmer Dabbelt <palmer@dabbelt.com>2016-07-10 16:22:57 -0700
committerPalmer Dabbelt <palmer@dabbelt.com>2016-07-10 16:22:57 -0700
commita2235c06a42858f84f26b85d79addabb1613fe48 (patch)
tree9a9a1e068da4b33b25824ab6684bd2492d582d3e
parentc6c10b4ea84850779e04bfb5762b1dff6f60caaa (diff)
downloadriscv-tests-a2235c06a42858f84f26b85d79addabb1613fe48.zip
riscv-tests-a2235c06a42858f84f26b85d79addabb1613fe48.tar.gz
riscv-tests-a2235c06a42858f84f26b85d79addabb1613fe48.tar.bz2
Add a test harness for the SMI IO example
-rw-r--r--benchmarks/ioexample/ioexample_main.c127
1 files changed, 122 insertions, 5 deletions
diff --git a/benchmarks/ioexample/ioexample_main.c b/benchmarks/ioexample/ioexample_main.c
index 9ac8509..a2de7c1 100644
--- a/benchmarks/ioexample/ioexample_main.c
+++ b/benchmarks/ioexample/ioexample_main.c
@@ -2,13 +2,130 @@
#include "util.h"
-int main( int argc, char* argv[] )
+const char *find_config_string(void)
+{
+ const int* boot_rom = (int*)(0x1000);
+ const int config_string_addr_offset = 3;
+ const char *config_string = (char *)((long)boot_rom[config_string_addr_offset]);
+ return config_string;
+}
+
+int isspace(int c)
+{
+ if (c == ' ') return 1;
+ if (c == '\t') return 1;
+ if (c == '\n') return 1;
+ if (c == '\r') return 1;
+ return 0;
+}
+
+const char *advance_until_slash(const char *path)
+{
+ while ((*path != '\0') && (*path != '/'))
+ path++;
+ if (*path == '/')
+ path++;
+
+ return path;
+}
+
+const char *advance_until_entered(const char *config_string)
+{
+ while ((*config_string != '\0') && (*config_string != '{'))
+ config_string++;
+
+ if (*config_string == '{')
+ config_string++;
+
+ return config_string;
+}
+
+const char *advance_until_over(const char *config_string)
+{
+ config_string = advance_until_entered(config_string);
+ int open = 1;
+ while ((*config_string != '\0') && (open > 0)) {
+ if (*config_string == '{') open++;
+ if (*config_string == '}') open--;
+ config_string++;
+ }
+ if (*config_string == ';')
+ config_string++;
+
+ return config_string;
+}
+
+int compare_until_slash(const char *config_string, const char *path)
+{
+ while (isspace(*config_string)) config_string++;
+ while ((*path != '\0') && (*path != '/') && (*config_string != '\0')) {
+ if (*path != *config_string)
+ return 0;
+ path++;
+ config_string++;
+ }
+
+ if (!isspace(*config_string))
+ return 0;
+
+ return 1;
+}
+
+long fromhex(char c)
+{
+ if (c >= 'A' && c <= 'F') return c - 'A' + 10;
+ if (c >= 'a' && c <= 'f') return c - 'a' + 10;
+ if (c >= '0' && c <= '9') return c - '0' + 0;
+ return -1;
+}
+
+long tolong(const char *config_snippet)
{
- volatile long *base = (long *)0x48000000UL;
- for (long i = 0; i < 8; ++i) {
- base[i] = (i + (1UL << 8)) << 32UL;
- printf("base[%d]: %llx (0x%p)\n", i, base[i], &base[i]);
+ if (config_snippet[0] == '0' && config_snippet[1] == 'x')
+ config_snippet += 2;
+
+ long out = 0;
+ while (*config_snippet != '\0' && *config_snippet != ';')
+ out = (out << 4) + fromhex(*config_snippet++);
+
+ return out;
+}
+
+const char *find_in_config_string(const char *config_string, const char *path)
+{
+ while (*path != '\0' && *config_string != '\0') {
+ if (compare_until_slash(config_string, path)) {
+ path = advance_until_slash(path);
+ if (*path != '\0')
+ config_string = advance_until_entered(config_string);
+ } else {
+ config_string = advance_until_over(config_string);
+ }
}
+ /* Remove any whitespace from the config string, then strip off the key. */
+ while (*config_string != '\0' && isspace(*config_string)) config_string++;
+ while (*config_string != '\0' && !isspace(*config_string)) config_string++;
+ while (*config_string != '\0' && isspace(*config_string)) config_string++;
+
+ return config_string;
+}
+
+int main( int argc, char* argv[] )
+{
+ volatile long *base = (long *)(tolong(find_in_config_string(find_config_string(), "smiexample/addr")));
+ printf("smiexample/addr: %lx\n", base);
+
+ base[1] = 10; // Period
+ base[2] = 2; // Duty Cycle
+ base[0] = 1; // Enable
+
+ printf("Peroid: %d\n", base[1]);
+
+ base[1] = 15; // Peroid
+ base[2] = 7; // Duty Cycle
+
+ printf("Peroid: %d\n", base[1]);
+
return 0;
}