aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2018-02-22 11:14:33 -0500
committerClyne Sullivan <tullivan99@gmail.com>2018-02-22 11:14:33 -0500
commit9f61013faf98f8909e0853954218ec10c3b3c6fb (patch)
tree65def179de443aabc7d38109ef867cbb9d5ebaee
parenteee1be766d35a3ab76b10fc0aeaf1bbe7a88bfbc (diff)
things should work now
-rw-r--r--include/heap.h1
-rw-r--r--initrd/init12
-rw-r--r--libinterp.abin62144 -> 61980 bytes
-rwxr-xr-xrun.sh8
-rw-r--r--src/clock.c2
-rw-r--r--src/heap.c19
-rw-r--r--src/main.c4
-rw-r--r--src/task.c10
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 <stdint.h>
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 f15e956..7884542 100644
--- a/libinterp.a
+++ b/libinterp.a
Binary files differ
diff --git a/run.sh b/run.sh
index 88be7fa..318f1ff 100755
--- a/run.sh
+++ b/run.sh
@@ -1,7 +1,7 @@
#!/bin/bash
-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 \
+# -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));
}