freemyipod r559 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r558‎ | r559 | r560 >
Date:14:12, 7 February 2011
Author:theseven
Status:new
Tags:
Comment:
Clock gate analyzer: Only toggle gates if explicitly asked to
Modified paths:
  • /apps/clockgatehunter/main.c (modified) (history)

Diff [purge]

Index: apps/clockgatehunter/main.c
@@ -3,7 +3,7 @@
44
55 struct wakeup eventwakeup;
66 int pos = 64;
7 -int state[65];
 7+bool toggle[65];
88
99 void handler(void* user, enum button_event eventtype, int which, int value)
1010 {
@@ -14,7 +14,7 @@
1515 switch (which)
1616 {
1717 case 0:
18 - state[pos] = !state[pos];
 18+ toggle[pos] = true;
1919 action = true;
2020 break;
2121 case 1:
@@ -41,7 +41,8 @@
4242 if (action) wakeup_signal(&eventwakeup);
4343 }
4444
45 -static void renderline(void* framebuf, int width, int fontwidth, int fontheight, int line)
 45+static void renderline(void* framebuf, int width, int fontwidth,
 46+ int fontheight, int* state, int line)
4647 {
4748 int i;
4849 for (i = 0; i < 16; i++)
@@ -55,8 +56,9 @@
5657 {
5758 int i, j;
5859 char buf[9];
 60+ int state[64];
 61+ for (i = 0; i < 65; i++) toggle[i] = false;
5962 for (i = 0; i < 64; i++) state[i] = clockgate_get_state(i);
60 - state[i] = false;
6163 uint32_t orig[2] = {0xffffffff, 0xffffffff};
6264 uint32_t now[2];
6365 for (i = 0; i < 2; i++)
@@ -85,21 +87,26 @@
8688 wakeup_signal(&eventwakeup);
8789 struct button_hook_entry* hook = button_register_handler(handler, NULL);
8890 if (!hook) panicf(PANIC_KILLTHREAD, "Could not register button hook!");
89 - while (true)
 91+ while (!toggle[64])
9092 {
91 - wakeup_wait(&eventwakeup, TIMEOUT_BLOCK);
 93+ wakeup_wait(&eventwakeup, 500000);
9294 now[0] = 0xffffffff;
9395 now[1] = 0xffffffff;
9496 for (i = 0; i < 2; i++)
9597 for (j = 0; j < 32; j++)
9698 {
97 - bool oldstate = state[i * 32 + j];
98 - clockgate_enable(i * 32 + j, oldstate);
9999 state[i * 32 + j] = clockgate_get_state(i * 32 + j);
100 - if (state[i * 32 + j] != oldstate) state[i * 32 + j] = 2;
 100+ if (toggle[i * 32 + j])
 101+ {
 102+ toggle[i * 32 + j] = false;
 103+ bool newstate = !state[i * 32 + j];
 104+ clockgate_enable(i * 32 + j, newstate);
 105+ state[i * 32 + j] = clockgate_get_state(i * 32 + j);
 106+ if (state[i * 32 + j] != newstate) state[i * 32 + j] = 2;
 107+ }
101108 if (state[i * 32 + j]) now[i] &= ~(1 << j);
102109 }
103 - for (i = 0; i < 4; i++) renderline(framebuf, width, fontwidth, fontheight, i);
 110+ for (i = 0; i < 4; i++) renderline(framebuf, width, fontwidth, fontheight, state, i);
104111 renderchar(framebuf, 2 + fontwidth * 18, 2, width, pos == 64 ? 0xffffffff : 0xff000000,
105112 pos == 64 ? 0xff000000 : 0xffffffff, 'X');
106113 snprintf(buf, sizeof(buf), "%08X", orig[0]);
@@ -112,7 +119,6 @@
113120 rendertext(framebuf, 2 + 9 * fontwidth, 2 + fontheight, width,
114121 0xff000000, 0xffffffff, buf);
115122 displaylcd(xoffs, yoffs, width, height, framebuf, 0, 0, width);
116 - if (state[64]) break;
117123 }
118124 button_unregister_handler(hook);
119125 cprintf(3, "Final state: %08X %08X\n", now[0], now[1]);