Skip to content

Commit ea1320b

Browse files
committed
Add uheap for debugging the size of objects. Still not perfect though.
1 parent cc412a8 commit ea1320b

File tree

7 files changed

+394
-4
lines changed

7 files changed

+394
-4
lines changed

atmel-samd/Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,22 @@ SRC_BINDINGS = \
224224
SRC_BINDINGS_EXPANDED = $(addprefix shared-bindings/, $(SRC_BINDINGS)) \
225225
$(addprefix common-hal/, $(SRC_BINDINGS))
226226

227+
SRC_SHARED_MODULE = \
228+
bitbangio/__init__.c \
229+
bitbangio/I2C.c \
230+
bitbangio/SPI.c \
231+
uheap/__init__.c \
232+
233+
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
234+
$(addprefix shared-module/, $(SRC_SHARED_MODULE))
235+
227236
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
228237
OBJ += $(addprefix $(BUILD)/, $(SRC_ASF:.c=.o))
229238
OBJ += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o))
230239
OBJ += $(addprefix $(BUILD)/, $(SRC_BINDINGS_EXPANDED:.c=.o))
240+
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
231241

232-
SRC_QSTR += $(SRC_C) $(SRC_BINDINGS_EXPANDED) $(STM_SRC_C)
242+
SRC_QSTR += $(SRC_C) $(SRC_BINDINGS_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED) $(STM_SRC_C)
233243

234244
all: $(BUILD)/firmware.bin
235245

atmel-samd/mpconfigport.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,16 @@ extern const struct _mp_obj_module_t board_module;
118118
extern const struct _mp_obj_module_t uos_module;
119119
extern const struct _mp_obj_module_t time_module;
120120
extern const struct _mp_obj_module_t neopixel_write_module;
121+
extern const struct _mp_obj_module_t uheap_module;
121122

122123
#define MICROPY_PORT_BUILTIN_MODULES \
123124
{ MP_OBJ_NEW_QSTR(MP_QSTR_microcontroller), (mp_obj_t)&microcontroller_module }, \
124125
{ MP_OBJ_NEW_QSTR(MP_QSTR_nativeio), (mp_obj_t)&nativeio_module }, \
125126
{ MP_OBJ_NEW_QSTR(MP_QSTR_board), (mp_obj_t)&board_module }, \
126127
{ MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&uos_module }, \
127128
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \
128-
{ MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write),(mp_obj_t)&neopixel_write_module } \
129+
{ MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write),(mp_obj_t)&neopixel_write_module }, \
130+
{ MP_OBJ_NEW_QSTR(MP_QSTR_uheap),(mp_obj_t)&uheap_module } \
129131

130132
// board specific definitions
131133
#include "mpconfigboard.h"

lib/utils/printf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ int vprintf(const char *fmt, va_list ap) {
6060
}
6161

6262
#if MICROPY_DEBUG_PRINTERS
63+
extern const mp_print_t MICROPY_DEBUG_PRINTER_DEST;
6364
int DEBUG_printf(const char *fmt, ...) {
6465
va_list ap;
6566
va_start(ap, fmt);
6667
#ifndef MICROPY_DEBUG_PRINTER_DEST
6768
#define MICROPY_DEBUG_PRINTER_DEST mp_plat_print
6869
#endif
69-
extern const mp_print_t MICROPY_DEBUG_PRINTER_DEST;
7070
int ret = mp_vprintf(&MICROPY_DEBUG_PRINTER_DEST, fmt, ap);
7171
va_end(ap);
7272
return ret;

shared-bindings/bitbangio/__init__.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
// dependency is nativeio.DigitalInOut.
2929

3030
#include <stdint.h>
31-
#include <stdio.h>
3231

3332
#include "py/obj.h"
3433
#include "py/runtime.h"

shared-bindings/uheap/__init__.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Scott Shawcroft
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include <stdint.h>
28+
29+
#include "py/obj.h"
30+
#include "py/runtime.h"
31+
32+
#include "shared-bindings/uheap/__init__.h"
33+
34+
//| :mod:`uheap` --- Heap size analysis
35+
//| ================================================================
36+
//|
37+
//| .. module:: uheap
38+
//| :synopsis: Heap size analysis
39+
//|
40+
41+
//| .. method:: info(object)
42+
//|
43+
//| Prints memory debugging info for the given object and returns the
44+
//| estimated size.
45+
//|
46+
STATIC mp_obj_t uheap_info(mp_obj_t obj) {
47+
uint32_t size = shared_module_uheap_info(obj);
48+
49+
return MP_OBJ_NEW_SMALL_INT(size);
50+
}
51+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(uheap_info_obj, uheap_info);
52+
53+
STATIC const mp_rom_map_elem_t uheap_module_globals_table[] = {
54+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uheap) },
55+
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&uheap_info_obj) },
56+
};
57+
58+
STATIC MP_DEFINE_CONST_DICT(uheap_module_globals, uheap_module_globals_table);
59+
60+
const mp_obj_module_t uheap_module = {
61+
.base = { &mp_type_module },
62+
.globals = (mp_obj_dict_t*)&uheap_module_globals,
63+
};

shared-bindings/uheap/__init__.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Scott Shawcroft
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_UHEAP___INIT___H__
28+
#define __MICROPY_INCLUDED_SHARED_BINDINGS_UHEAP___INIT___H__
29+
30+
#include "py/obj.h"
31+
32+
extern uint32_t shared_module_uheap_info(mp_obj_t obj);
33+
34+
#endif // __MICROPY_INCLUDED_SHARED_BINDINGS_UHEAP___INIT___H__

0 commit comments

Comments
 (0)