Skip to content

Commit 53461fb

Browse files
committed
examples/natmod/deepcraft: Add enablement and ex for .mpy gen.
Signed-off-by: NikhitaR-IFX <nikhita.rajasekhar@infineon.com>
1 parent 14bf9b5 commit 53461fb

12 files changed

Lines changed: 9479 additions & 58 deletions

File tree

examples/natmod/deepcraft/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Location of top-level MicroPython directory
2+
MPY_DIR = ../../..
3+
4+
# Name of module
5+
MOD = deepcraft_model
6+
7+
# Source files (.c or .py)
8+
SRC = dc_mp_iface.c model.c
9+
10+
# Architecture to build for (x86, x64, armv7m, xtensa, xtensawin, rv32imc)
11+
ARCH = armv7emsp
12+
13+
# Link with libm.a and libgcc.a from the toolchain
14+
LINK_RUNTIME = 1
15+
16+
# Include to get the rules for compiling and linking the module
17+
include $(MPY_DIR)/py/dynruntime.mk
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#define MICROPY_PY_DEEPCRAFT_MPY (1)
2+
3+
#include "py/dynruntime.h"
4+
5+
#if !defined(__linux__)
6+
void *memcpy(void *dst, const void *src, size_t n) {
7+
return mp_fun_table.memmove_(dst, src, n);
8+
}
9+
void *memset(void *s, int c, size_t n) {
10+
return mp_fun_table.memset_(s, c, n);
11+
}
12+
#endif
13+
14+
int native_errno=0;
15+
#if defined(__linux__)
16+
int *__errno_location (void)
17+
#else
18+
int *__errno (void)
19+
#endif
20+
{
21+
return &native_errno;
22+
}
23+
24+
mp_obj_full_type_t dcmodel_type;
25+
26+
#include "examples/natmod/deepcraft/mp_src.c"
27+
28+
mp_map_elem_t dcmodel_locals_dict_table[3];
29+
static MP_DEFINE_CONST_DICT(dcmodel_locals_dict, dcmodel_locals_dict_table);
30+
31+
mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) {
32+
MP_DYNRUNTIME_INIT_ENTRY
33+
34+
dcmodel_type.base.type = mp_fun_table.type_type;
35+
dcmodel_type.name = MP_QSTR_DEEPCRAFT;
36+
//MP_OBJ_TYPE_SET_SLOT(&dcmodel_type, make_new, &deflateio_make_new, 0);
37+
dcmodel_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_init), MP_OBJ_FROM_PTR(&init_obj) };
38+
dcmodel_locals_dict_table[1] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_enqueue), MP_OBJ_FROM_PTR(&enqueue_obj) };
39+
dcmodel_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_dequeue), MP_OBJ_FROM_PTR(&dequeue_obj) };
40+
MP_OBJ_TYPE_SET_SLOT(&dcmodel_type, locals_dict, (void*)&dcmodel_locals_dict, 2);
41+
42+
mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_deepcraft));
43+
mp_store_global(MP_QSTR_DEEPCRAFT, MP_OBJ_FROM_PTR(&dcmodel_type));
44+
45+
MP_DYNRUNTIME_INIT_EXIT
46+
}

examples/natmod/deepcraft/model.c

Lines changed: 8300 additions & 0 deletions
Large diffs are not rendered by default.

examples/natmod/deepcraft/model.h

Lines changed: 361 additions & 0 deletions
Large diffs are not rendered by default.

examples/natmod/deepcraft/mp_src.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include "py/dynruntime.h"
2+
#include "model.h"
3+
#include <string.h>
4+
5+
static mp_obj_t init(void){
6+
//assign();
7+
IMAI_init();
8+
return mp_const_none;
9+
}
10+
MP_DEFINE_CONST_FUN_OBJ_0(init_obj, init);
11+
12+
static mp_obj_t enqueue(const mp_obj_t data_in_obj){
13+
float data_in[IMAI_DATA_IN_COUNT];
14+
mp_obj_t *data_in_items;
15+
size_t len;
16+
mp_obj_get_array(data_in_obj, &len, &data_in_items);
17+
if (len != IMAI_DATA_IN_COUNT) {
18+
mp_raise_ValueError("data_in must be a list of IMAI_DATA_IN_COUNT floats");
19+
}
20+
for (int i = 0; i < IMAI_DATA_IN_COUNT; i++) {
21+
data_in[i] = mp_obj_get_float(data_in_items[i]);
22+
}
23+
int result = IMAI_enqueue(data_in);
24+
return MP_OBJ_NEW_SMALL_INT(result);
25+
}
26+
MP_DEFINE_CONST_FUN_OBJ_1(enqueue_obj, enqueue);
27+
28+
static mp_obj_t dequeue(mp_obj_t data_out_obj) {
29+
mp_buffer_info_t buf_info;
30+
mp_get_buffer(data_out_obj, &buf_info, MP_BUFFER_WRITE);
31+
float *data_out = (float *)buf_info.buf;
32+
int result = IMAI_dequeue(data_out);
33+
if (result == 0) {
34+
return MP_OBJ_NEW_SMALL_INT(result);
35+
} else if (result == -1) {
36+
return MP_OBJ_NEW_SMALL_INT(result);
37+
} else if (result == -2) {
38+
mp_raise_ValueError(MP_ERROR_TEXT("Internal memory allocation error"));
39+
}
40+
return MP_OBJ_NEW_SMALL_INT(result);
41+
}
42+
MP_DEFINE_CONST_FUN_OBJ_1(dequeue_obj, dequeue);

ports/psoc6/boards/CY8CKIT-062S2-AI/mpconfigboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "CY8C-062S2-AI"
3232

33-
#define MICROPY_GC_HEAP_SIZE (256 * 1024) // 256 KB
33+
#define MICROPY_GC_HEAP_SIZE (800 * 1024) // 800 KB
3434

3535
#if MICROPY_PY_NETWORK
3636
#define MICROPY_PY_HASHLIB (1)

ports/psoc6/boards/CY8CPROTO-062-4343W/mpconfigboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "CY8C-062-4343W"
3232

33-
#define MICROPY_GC_HEAP_SIZE (256 * 1024) // 256 KB
33+
#define MICROPY_GC_HEAP_SIZE (800 * 1024) // 256 KB
3434

3535
#if MICROPY_PY_NETWORK
3636
#define MICROPY_PY_HASHLIB (1)

ports/psoc6/mtb-libs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ LDFLAGS=
174174
LDLIBS=
175175

176176
# Path to the linker script to use (if empty, use the default linker script).
177-
LINKER_SCRIPT=
177+
LINKER_SCRIPT=mpy-psoc.ld
178178

179179
# Custom pre-build commands to run.
180180
PREBUILD=

0 commit comments

Comments
 (0)