Skip to content

Commit

Permalink
Merge branch 'master' of sipeed_ai/MaixPy
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Apr 25, 2019
2 parents 2382795 + 31603f5 commit 59c658e
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions ports/k210-freertos/mpy_support/Maix/Maix_kpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ int model_deinit(kpu_task_t *task)

STATIC mp_obj_t py_kpu_class_load(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
{
int err = 0;
// int err = 0;
char *err = NULL;

py_kpu_net_obj_t *o = m_new_obj(py_kpu_net_obj_t);

uint8_t *model_data = NULL;
Expand All @@ -304,7 +306,8 @@ STATIC mp_obj_t py_kpu_class_load(uint n_args, const mp_obj_t *pos_args, mp_map_
kpu_task = (uint8_t *)malloc(sizeof(kpu_model_context_t));
if(kpu_task == NULL)
{
err = -1;//malloc error
// err = -1;//malloc error
err = "malloc error 0";
goto error;
}

Expand All @@ -326,28 +329,32 @@ STATIC mp_obj_t py_kpu_class_load(uint n_args, const mp_obj_t *pos_args, mp_map_

if(model_size < 0)
{
err = -2;//read error
// err = -2;//read error
err = "read model size error 1";
goto error;
}
mp_printf(&mp_plat_print, "model_size=%d\r\n",model_size);

model_data = (uint8_t *)malloc(model_size * sizeof(uint8_t));
if(model_data == NULL)
{
err = -1;//malloc error
// err = -1;//malloc error
err = "malloc error 1";
goto error;
}

status = w25qxx_read_data_dma(model_addr, model_data, model_size, W25QXX_QUAD_FAST);
if(status != W25QXX_OK)
{
err = -2;//read error
// err = -2;//read error
err = "read model data error 1";
goto error;
}
int ret = kpu_load_kmodel(kpu_task, model_data);
if(ret != 0)
{
err = -3; //load error
// err = -3; //load error
err = "load model data error 1";
goto error;
}
}
Expand All @@ -364,6 +371,7 @@ STATIC mp_obj_t py_kpu_class_load(uint n_args, const mp_obj_t *pos_args, mp_map_
if( err != 0 )
{
model_deinit(kpu_task);
err = "model init error 2";
goto error;
}

Expand All @@ -382,15 +390,17 @@ STATIC mp_obj_t py_kpu_class_load(uint n_args, const mp_obj_t *pos_args, mp_map_

if(model_size <= 0)
{
err = -2;//read error
// err = -2;//read error
err = "read model size error 2";
vfs_internal_close(file, &ferr);
goto error;
}

model_data = (uint8_t *)malloc(model_size * sizeof(uint8_t));
if(model_data == NULL)
{
err = -1;//malloc error
// err = -1;//malloc error
err = "malloc error 2";
goto error;
}

Expand All @@ -409,7 +419,8 @@ STATIC mp_obj_t py_kpu_class_load(uint n_args, const mp_obj_t *pos_args, mp_map_
int ret = kpu_load_kmodel(kpu_task, model_data);
if(ret != 0)
{
err = -3; //load error
// err = -3; //load error
err = "load model data error 2";
goto error;
}

Expand Down Expand Up @@ -450,7 +461,7 @@ STATIC mp_obj_t py_kpu_class_load(uint n_args, const mp_obj_t *pos_args, mp_map_
m_del(py_kpu_net_obj_t, o,sizeof(py_kpu_net_obj_t));

char msg[50];
sprintf(msg,"[MAIXPY]kpu: load error %d", err);
sprintf(msg,"[MAIXPY]:kpu load error: %s", err);
mp_raise_ValueError(msg);
return mp_const_false;
}
Expand Down

0 comments on commit 59c658e

Please sign in to comment.