|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries |
| 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 "py/obj.h" |
| 28 | +#include "py/runtime.h" |
| 29 | + |
| 30 | +#include "esp-idf/components/heap/include/esp_heap_caps.h" |
| 31 | + |
| 32 | +//| """Direct access to a few ESP-IDF details. This module *should not* include any functionality |
| 33 | +//| that could be implemented by other frameworks. It should only include ESP-IDF specific |
| 34 | +//| things.""" |
| 35 | + |
| 36 | +//| def heap_caps_get_total_size() -> int: |
| 37 | +//| """Return the total size of the ESP-IDF, which includes the CircuitPython heap.""" |
| 38 | +//| ... |
| 39 | +//| |
| 40 | + |
| 41 | +STATIC mp_obj_t espidf_heap_caps_get_total_size(void) { |
| 42 | + return MP_OBJ_NEW_SMALL_INT(heap_caps_get_total_size(MALLOC_CAP_8BIT)); |
| 43 | +} |
| 44 | +MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_total_size_obj, espidf_heap_caps_get_total_size); |
| 45 | + |
| 46 | +//| def heap_caps_get_free_size() -> int: |
| 47 | +//| """Return total free memory in the ESP-IDF heap.""" |
| 48 | +//| ... |
| 49 | +//| |
| 50 | + |
| 51 | +STATIC mp_obj_t espidf_heap_caps_get_free_size(void) { |
| 52 | + return MP_OBJ_NEW_SMALL_INT(heap_caps_get_free_size(MALLOC_CAP_8BIT)); |
| 53 | +} |
| 54 | +MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_free_size_obj, espidf_heap_caps_get_free_size); |
| 55 | + |
| 56 | +//| def heap_caps_get_largest_free_block() -> int: |
| 57 | +//| """Return the size of largest free memory block in the ESP-IDF heap.""" |
| 58 | +//| ... |
| 59 | +//| |
| 60 | + |
| 61 | +STATIC mp_obj_t espidf_heap_caps_get_largest_free_block(void) { |
| 62 | + return MP_OBJ_NEW_SMALL_INT(heap_caps_get_largest_free_block(MALLOC_CAP_8BIT)); |
| 63 | +} |
| 64 | +MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_largest_free_block_obj, espidf_heap_caps_get_largest_free_block); |
| 65 | + |
| 66 | +STATIC const mp_rom_map_elem_t espidf_module_globals_table[] = { |
| 67 | + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_espidf) }, |
| 68 | + |
| 69 | + { MP_ROM_QSTR(MP_QSTR_heap_caps_get_total_size), MP_ROM_PTR(&espidf_heap_caps_get_total_size_obj)}, |
| 70 | + { MP_ROM_QSTR(MP_QSTR_heap_caps_get_free_size), MP_ROM_PTR(&espidf_heap_caps_get_free_size_obj)}, |
| 71 | + { MP_ROM_QSTR(MP_QSTR_heap_caps_get_largest_free_block), MP_ROM_PTR(&espidf_heap_caps_get_largest_free_block_obj)}, |
| 72 | +}; |
| 73 | + |
| 74 | +STATIC MP_DEFINE_CONST_DICT(espidf_module_globals, espidf_module_globals_table); |
| 75 | + |
| 76 | +const mp_obj_module_t espidf_module = { |
| 77 | + .base = { &mp_type_module }, |
| 78 | + .globals = (mp_obj_dict_t*)&espidf_module_globals, |
| 79 | +}; |
0 commit comments