summaryrefslogtreecommitdiff
path: root/src/lpc/figure-checksum
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2013-04-18 15:54:13 -0500
committerKeith Packard <keithp@keithp.com>2013-05-17 03:50:07 -0700
commitbcc65597d3d20f1d58df784100af766cee5f0f20 (patch)
tree5967a48c5f841aa04a58881248e164c424d1121b /src/lpc/figure-checksum
parent6735a391c2a1e3be01ac9e68b44ec0974592c11c (diff)
lpc: Initial lpcxpresso bits
This gets the LPC11U14 clock set to the PLL and blinks the LED. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/lpc/figure-checksum')
-rwxr-xr-xsrc/lpc/figure-checksum39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/lpc/figure-checksum b/src/lpc/figure-checksum
new file mode 100755
index 00000000..0b1de578
--- /dev/null
+++ b/src/lpc/figure-checksum
@@ -0,0 +1,39 @@
+#!/usr/bin/env nickle
+
+autoimport Process;
+
+int byteflip(int x) {
+ return ((x >> 24) & 0xff) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | ((x << 24) & 0xff000000);
+}
+
+void main () {
+ file input = popen(popen_direction.read, true, "objdump",
+ "objdump", "-j", ".text",
+ "--start-address=0",
+ "--stop-address=0x20",
+ "-s", argv[1]);
+ int sum = 0;
+
+ void add_in(int addr, int value) {
+ if (addr < 0x1c) {
+ sum += value;
+ } else if (addr == 0x1c) {
+ printf ("-DCKSUM=0x%08x\n", -sum & 0xffffffff);
+ exit(0);
+ }
+ }
+ while (!File::end(input)) {
+ string line = File::fgets(input);
+ string[] words = String::wordsplit(line, " ");
+
+ if (dim(words) < 5)
+ continue;
+ if (words[0] == "0000" || words[0] == "0010") {
+ int addr = string_to_integer(words[0], 16);
+ for (int i = 0; i < 4; i++)
+ add_in(addr + i * 4, byteflip(string_to_integer(words[i+1], 16)));
+ }
+ }
+}
+
+main();