aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr/main.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/usr/main.c b/usr/main.c
index b6e540d..1bc5c75 100644
--- a/usr/main.c
+++ b/usr/main.c
@@ -1,3 +1,4 @@
+#include <cpu.h>
#include <globals.h>
#include <graphics/lfb.h>
#include <symbols.h>
@@ -5,6 +6,7 @@
#include <usr/string.h>
#include <usr/timed.h>
#include <usr/uart.h>
+#include <usr/math.h>
static struct SysTimerInfo stime_0 = {
.tick_rate = 5000000,
@@ -42,11 +44,37 @@ static struct GPIOInfo gpinfo = {
void gptest(void)
{
static unsigned long count = 0;
- unsigned long gplev0 = *GPLEV0;
- static char str[14];
- draw_hex32(0, 30, gplev0);
- char* start = ulong_to_string(count++, str);
- draw_string(0, 31, start);
+ static unsigned long long ts[4096*2+20];
+ sys0_64(SYS_TIME, &ts[count++]);
+ if (count == (4096*2+18)) {
+ unsubscribe_irq(GPIO_BANK_1_IRQ);
+ static char str[14];
+ char* start;
+ unsigned long mean=0, stdev=0, max=0;
+ for (unsigned long i = 0; i < 4096; i++) {
+ unsigned long elapsed = ts[2*(i+2)+1]-ts[2*(i+2)];
+ mean += elapsed;
+ if (elapsed > max)
+ max = elapsed;
+ }
+ mean /= 4096;
+ for (unsigned long i = 0; i < 4096; i++) {
+ unsigned long elapsed = ts[2*(i+2)+1]-ts[2*(i+2)];
+ unsigned long term = (elapsed-mean)*(elapsed-mean)/4096;
+ stdev += term;
+ }
+ stdev = sqrt_rnd(stdev);
+ start = ulong_to_string(mean, str);
+ draw_string(0, 10, start);
+ start = ulong_to_string(stdev, str);
+ draw_string(0, 11, start);
+ start = ulong_to_string(max, str);
+ draw_string(0, 12, start);
+ }
+ //unsigned long gplev0 = *GPLEV0;
+ //draw_hex32(0, 30, gplev0);
+ //start = ulong_to_string(count++, str);
+ //draw_string(0, 31, start);
}
void test_super(void);
@@ -58,8 +86,8 @@ void main(void)
//subscribe_irq(SYS_TIMER_1_IRQ, loopt, &stime_1);
//subscribe_irq(SYS_TIMER_2_IRQ, loopt, &stime_2);
//subscribe_irq(SYS_TIMER_3_IRQ, loopt, &stime_3);
- //subscribe_irq(GPIO_BANK_1_IRQ, gptest, &gpinfo);
+ subscribe_irq(GPIO_BANK_1_IRQ, gptest, &gpinfo);
//add_thread(loop, 0, 8);
//add_thread(consumer, 0, 3);
- add_thread(test_super, 0, 4);
+ //add_thread(test_super, 0, 4);
}