8000 Share memory.c and a bit of polish. · sparkfun/circuitpython@5704bc8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5704bc8

Browse files
committed
Share memory.c and a bit of polish.
1 parent a88cdac commit 5704bc8

File tree

7 files changed

+14
-117
lines changed

7 files changed

+14
-117
lines changed

ports/atmel-samd/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ SRC_C = \
288288
lib/libc/string0.c \
289289
lib/mp-readline/readline.c \
290290
$(BUILD)/autogen_usb_descriptor.c \
291-
freetouch/adafruit_ptc.c
291+
freetouch/adafruit_ptc.c \
292+
supervisor/shared/memory.c
292293

293294
# Choose which flash filesystem impl to use.
294295
# (Right now INTERNAL_FLASH_FILESYSTEM and SPI_FLASH_FILESYSTEM are mutually exclusive.

ports/nrf/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ SRC_C += \
118118
lib/utils/stdout_helpers.c \
119119
lib/libc/string0.c \
120120
lib/mp-readline/readline.c \
121+
supervisor/shared/memory.c
121122
< 10000 br>
122123
ifeq ($(MCU_SUB_VARIANT),nrf52840)
123124

ports/nrf/supervisor/memory.c

Lines changed: 0 additions & 112 deletions
This file was deleted.

supervisor/memory.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
// Basic allocations outside them for areas such as the VM heap and stack.
28+
// supervisor/shared/memory.c has a basic implementation for a continuous chunk of memory. Add it
29+
// to a SRC_ in a Makefile to use it.
30+
2731
#ifndef MICROPY_INCLUDED_SUPERVISOR_MEMORY_H
2832
#define MICROPY_INCLUDED_SUPERVISOR_MEMORY_H
2933

@@ -38,6 +42,10 @@ typedef struct {
3842
void memory_init(void);
3943
void free_memory(supervisor_allocation* allocation);
4044
supervisor_allocation* allocate_remaining_memory(void);
45+
46+
// Allocate a piece of a given length in bytes. If high_address is true then it should be allocated
47+
// at a lower address from the top of the stack. Otherwise, addresses will increase starting after
48+
// statically allocated memory.
4149
supervisor_allocation* allocate_memory(uint32_t length, bool high_address);
4250

4351
#endif // MICROPY_INCLUDED_SUPERVISOR_MEMORY_H

ports/atmel-samd/supervisor/memory.c renamed to supervisor/shared/memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ supervisor_allocation* allocate_remaining_memory(void) {
8282
}
8383

8484
supervisor_allocation* allocate_memory(uint32_t length, bool high) {
85-
if ((high_address - low_address) * 4 < (int32_t) length) {
85+
if ((high_address - low_address) * 4 < (int32_t) length || length % 4 != 0) {
8686
return NULL;
8787
}
8888
uint8_t index = 0;

supervisor/shared/stack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ void allocate_stack(void) {
5252
}
5353
}
5454

55-
inline void stack_init(void) {
55+
void stack_init(void) {
5656
allocate_stack();
5757
}
5858

59-
inline void stack_resize(void) {
59+
void stack_resize(void) {
6060
if (next_stack_size == current_stack_size) {
6161
return;
6262
}

supervisor/supervisor.mk

Lines chang 6212 ed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
SRC_SUPERVISOR = \
22
main.c \
3-
supervisor/memory.c \
43
supervisor/port.c \
54
supervisor/shared/autoreload.c \
65
supervisor/shared/rgb_led_status.c \

0 commit comments

Comments
 (0)
0