From 9f61013faf98f8909e0853954218ec10c3b3c6fb Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 22 Feb 2018 11:14:33 -0500 Subject: [PATCH] things should work now --- include/heap.h | 1 + initrd/init | 12 +++++++++++- libinterp.a | Bin 62144 -> 61980 bytes run.sh | 8 ++++---- src/clock.c | 2 +- src/heap.c | 19 +++++++++++++++---- src/main.c | 4 ++-- src/task.c | 10 ++-------- 8 files changed, 36 insertions(+), 20 deletions(-) diff --git a/include/heap.h b/include/heap.h index c93eb8e..8118384 100644 --- a/include/heap.h +++ b/include/heap.h @@ -4,6 +4,7 @@ #include void heap_init(void *buf); +uint32_t heap_used(void); void *malloc(uint32_t size); void *calloc(uint32_t count, uint32_t size); diff --git a/initrd/init b/initrd/init index 8196511..694c151 100644 --- a/initrd/init +++ b/initrd/init @@ -19,5 +19,15 @@ do set y (y + 20) while (y < 270) -line 80 250 380 90 511 +#line 80 250 380 90 511 +set purple 511 +do + rand 219 > x + rand 379 > y + rand 219 > i + rand 379 > j + line (x + 50) (y + 50) (i + 50) (j + 50) purple + delay 1000 + set purple (purple + 11) +while (1) diff --git a/libinterp.a b/libinterp.a index f15e95662444a589f3b20489ba5c765306e620ff..78845426cf7cb133247face6a3854622bf35f3ad 100644 GIT binary patch delta 5462 zcmaJ_3vg7`8UD}RBqU1+8^TM-b2ntOn>Ps}B!L7%KprvFpd=#Ah6Hvc2>}xbM6*;t zh^3U};G>WMvD85X1eR7rFkl^2Mjdce-VCh*jw6Z|+XyKA{(H}cV8`B>yWjo(*E#3^ z&pG$pJ$%X3{)K66bVzpAu;Do)eAe@iP9|#mmHX9$M89@-5Yhj;udE`vvdTY0EZ0%lC8y6A)hQ9>`gh*;=aed#1mEg2t^fbq@G2&u92Ro=CRj=DXM{==KZU%>uCj^ zay?|NsEnC3$eruiPLDD-kpzd4=mx~5OT4_BeGjuEuM^&EvLyguz29`L&ZxEQHQ^DtSwAS5c2WKd&EpRWXj3j-(S2r zPh{Vm)8o5v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image erase main.hex; reset run; exit" +#openocd -f /usr/share/openocd/scripts/board/st_nucleo_l476rg.cfg \ +# -c "init; reset halt; flash write_image erase main.hex; reset run; exit" -#openocd -f /usr/share/openocd/scripts/board/st_nucleo_l476rg.cfg > /dev/null & -#gdb-multiarch +openocd -f /usr/share/openocd/scripts/board/st_nucleo_l476rg.cfg > /dev/null & +gdb-multiarch -iex "target remote localhost:3333" out/main.elf diff --git a/src/clock.c b/src/clock.c index ab92386..7cb4ecf 100644 --- a/src/clock.c +++ b/src/clock.c @@ -54,7 +54,7 @@ void SysTick_Handler(void) // just keep counting ticks++; - if (!(ticks % 10)) + if (!(ticks % 4)) SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk; asm("mov lr, %0; bx lr" :: "r" (lr)); diff --git a/src/heap.c b/src/heap.c index 5d32a14..0502e76 100644 --- a/src/heap.c +++ b/src/heap.c @@ -19,16 +19,27 @@ void heap_init(void *buf) // what to do... } +uint32_t heap_used(void) +{ + uint32_t total = 0; + alloc_t *a = &root; + while (a->next > 1) { + total += a->size; + a = (void *)(a->next & ~(1)); + } + return total; +} + void *malloc(uint32_t size) { task_hold(1); - if (size < 16) - size = 16; + if (size < HEAP_ALIGN) + size = HEAP_ALIGN; alloc_t *node = &root; while (node->next & 1 || node->size < size) { if ((node->next & ~(1)) == 0) { node->next |= (uint32_t)(heap_end + HEAP_ALIGN) & ~(HEAP_ALIGN - 1); - heap_end += 2 * HEAP_ALIGN + size; + heap_end += HEAP_ALIGN + size; node = (void *)(node->next & ~(1)); node->next = 0; node->size = size; @@ -46,7 +57,7 @@ void *malloc(uint32_t size) void *calloc(uint32_t count, uint32_t size) { uint8_t *buf = malloc(count * size); - for (uint8_t i = 0; i < count * size; i++) + for (uint32_t i = 0; i < count * size; i++) buf[i] = 0; return buf; } diff --git a/src/main.c b/src/main.c index 0245801..a946609 100644 --- a/src/main.c +++ b/src/main.c @@ -107,7 +107,7 @@ int script_color(interpreter *it) igetarg_integer(it, 2)); variable v; v.valtype = INTEGER; - v.value = c; + INT(&v) = c; v.svalue = 0; isetstr(&v); iret(it, &v); @@ -120,7 +120,7 @@ int script_rand(interpreter *it) next = (next * 182 + 1829) % igetarg_integer(it, 0); variable v; v.valtype = INTEGER; - v.value = next; + INT(&v) = next; v.svalue = 0; isetstr(&v); iret(it, &v); diff --git a/src/task.c b/src/task.c index 13e4e75..d0cb3f1 100644 --- a/src/task.c +++ b/src/task.c @@ -54,7 +54,6 @@ void task_init(void (*init)(void)) task_disable = 0; init(); - // you dirty dirty dog /*asm("\ cpsie i; \ mov pc, %0; \ @@ -65,9 +64,8 @@ void task_start(void (*task)(void), uint16_t stackSize) { task_hold(1); task_t *t = task_create(task, stackSize); - task_t *next = (task_t *)current->next; + t->next = current->next; current->next = t; - t->next = next; task_hold(0); } @@ -96,12 +94,8 @@ void PendSV_Handler(void) msr psp, r0; \ isb; \ dsb; \ - " :: "r" (current->sp)); - - // end - asm("\ cpsie i; \ bx lr; \ - "); + " :: "r" (current->sp)); }