summaryrefslogtreecommitdiff
path: root/supervisor/shared/memory.c
diff options
context:
space:
mode:
authorBenjamin Shockley <benjaminshockley@hotmail.com>2020-08-20 13:48:15 -0500
committerGitHub <noreply@github.com>2020-08-20 13:48:15 -0500
commit0084f0af24e4e219bc040c52ee723959423de6e2 (patch)
tree1aebdb362f08bf6417caa87836e3e4e739afc964 /supervisor/shared/memory.c
parent9aebe2f1efc99871fcf283c304e3a8700050d736 (diff)
parent4d7b9cde33934a44c4c905a49d2f831339fc8bd2 (diff)
Merge pull request #2 from adafruit/master
Master
Diffstat (limited to 'supervisor/shared/memory.c')
-rwxr-xr-xsupervisor/shared/memory.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/supervisor/shared/memory.c b/supervisor/shared/memory.c
index 6c8be3be8..8ae8a1699 100755
--- a/supervisor/shared/memory.c
+++ b/supervisor/shared/memory.c
@@ -25,24 +25,28 @@
*/
#include "supervisor/memory.h"
+#include "supervisor/port.h"
#include <stddef.h>
-#define CIRCUITPY_SUPERVISOR_ALLOC_COUNT 8
+#include "supervisor/shared/display.h"
+
+#define CIRCUITPY_SUPERVISOR_ALLOC_COUNT (12)
static supervisor_allocation allocations[CIRCUITPY_SUPERVISOR_ALLOC_COUNT];
// We use uint32_t* to ensure word (4 byte) alignment.
uint32_t* low_address;
uint32_t* high_address;
-extern uint32_t _ebss;
-extern uint32_t _estack;
void memory_init(void) {
- low_address = &_ebss;
- high_address = &_estack;
+ low_address = port_heap_get_bottom();
+ high_address = port_heap_get_top();
}
void free_memory(supervisor_allocation* allocation) {
+ if (allocation == NULL) {
+ return;
+ }
int32_t index = 0;
bool found = false;
for (index = 0; index < CIRCUITPY_SUPERVISOR_ALLOC_COUNT; index++) {
@@ -78,6 +82,15 @@ void free_memory(supervisor_allocation* allocation) {
allocation->ptr = NULL;
}
+supervisor_allocation* allocation_from_ptr(void *ptr) {
+ for (size_t index = 0; index < CIRCUITPY_SUPERVISOR_ALLOC_COUNT; index++) {
+ if (allocations[index].ptr == ptr) {
+ return &allocations[index];
+ }
+ }
+ return NULL;
+}
+
supervisor_allocation* allocate_remaining_memory(void) {
if (low_address == high_address) {
return NULL;
@@ -114,3 +127,9 @@ supervisor_allocation* allocate_memory(uint32_t length, bool high) {
alloc->length = length;
return alloc;
}
+
+void supervisor_move_memory(void) {
+ #if CIRCUITPY_DISPLAYIO
+ supervisor_display_move_memory();
+ #endif
+}