Hi Dialog,
I am used the stack now to do the advertisement, the period of time I have set is 2.5s by using the timer . I am using the "current_role" in my program for controlling the role switching in the program"app_task.c" and "app.c". However when it is running for 25 times for the role switching, it will reset the whole program, and lost all the things put into the ram before, could you please help with this issue?
Here is some part of the program of app_task.c:
extern volatile uint8_t current_role;
int app_switch_role(ke_msg_id_t msgid, void *param, ke_task_id_t dest_id, ke_task_id_t src_id)
{
app_gapm_reset_op();
return (KE_MSG_CONSUMED);
}
static const struct ke_msg_handler app_gap_process_handlers[]=
{
{GAPM_DEVICE_READY_IND, (ke_msg_func_t)gapm_device_ready_ind_handler},
{GAPM_CMP_EVT, (ke_msg_func_t)gapm_cmp_evt_handler},
{GAPC_CMP_EVT, (ke_msg_func_t)gapc_cmp_evt_handler},
{GAPC_CONNECTION_REQ_IND, (ke_msg_func_t)gapc_connection_req_ind_handler},
{GAPC_DISCONNECT_IND, (ke_msg_func_t)gapc_disconnect_ind_handler},
{APP_MODULE_INIT_CMP_EVT, (ke_msg_func_t)app_module_init_cmp_evt_handler},
{GAPM_ADV_REPORT_IND, (ke_msg_func_t)gapm_adv_report_ind_handler},
{APP_DYNAMIC_ADV_DATA, (ke_msg_func_t)app_update_adv_data},
{APP_SWITCH_ROLE_TIMER, (ke_msg_func_t)app_switch_role},
};
int gapm_cmp_evt_handler(ke_msg_id_t const msgid,
struct gapm_cmp_evt const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
switch(param->operation)
{
// reset completed
case GAPM_RESET:
{
if(param->status != GAP_ERR_NO_ERROR)
{
ASSERT_ERR(0); // unexpected error
}
else
{
// set device configuration
app_easy_gap_dev_configure ();
#if DEBUG_LOG33
printf_string("\r\n GAPM_RESET \r\n");
uart2_init(UART_BAUDRATE_115K2, 3);
#endif
}
}
break;
// device configuration updated
case GAPM_SET_DEV_CONFIG:
{
if(param->status != GAP_ERR_NO_ERROR)
{
ASSERT_ERR(0); // unexpected error
//niklas
#if DEBUG_LOG33
printf_string("\r\nError253\r\n");
uart2_init(UART_BAUDRATE_115K2, 3);
#endif
}
else
{
if( 1 == current_role)
{
#if DEBUG_LOG2
printf_string("\r\nAdv1 ");
printf_byte(position1);
printf_string("\r\n");
uart2_init(UART_BAUDRATE_115K2, 3);
#endif
record3();
EXECUTE_CALLBACK_VOID(app_on_set_dev_config_complete);
position1++;
}
else
{
#if DEBUG_LOG2
printf_string("\r\nAdv2 ");
printf_byte(position1);
printf_string("\r\n");
uart2_init(UART_BAUDRATE_115K2, 3);
#endif
record3();
EXECUTE_CALLBACK_VOID(app_on_set_dev_config_complete);
position1++;
}
ke_timer_set(APP_SWITCH_ROLE_TIMER, TASK_APP, 250); //100*10ms
}
}
break;
// Advertising finished
case GAPM_ADV_NON_CONN:
case GAPM_ADV_UNDIRECT:
{
#if DEBUG_LOG33
printf_string("\r\n GAPM_ADV_UNDIRECT \r\n");
uart2_init(UART_BAUDRATE_115K2, 3);
#endif
EXECUTE_CALLBACK_PARAM(app_on_adv_undirect_complete, param->status);
}
break;
// Directed advertising finished
case GAPM_ADV_DIRECT:
{
#if DEBUG_LOG33
printf_string("\r\n GAPM_ADV_DIRECT \r\n");
uart2_init(UART_BAUDRATE_115K2, 3);
#endif
EXECUTE_CALLBACK_PARAM(app_on_adv_direct_complete, param->status);
}
break;
case GAPM_SCAN_ACTIVE:
case GAPM_SCAN_PASSIVE:
{
#if DEBUG_LOG33
printf_string("\r\n GAPM_SCAN_PASSIVE: \r\n");
uart2_init(UART_BAUDRATE_115K2, 3);
#endif
EXECUTE_CALLBACK_VOID(app_on_scanning_completed);
}
break;
case GAPM_CONNECTION_DIRECT:
if (param->status == GAP_ERR_CANCELED)
{
#if DEBUG_LOG33
printf_string("\r\n GAPM_CONNECTION_DIRECT: \r\n");
uart2_init(UART_BAUDRATE_115K2, 3);
#endif
EXECUTE_CALLBACK_VOID(app_on_connect_failed);
}
break;
case GAPM_CANCEL:
{
#if DEBUG_LOG33
printf_string("\r\n GAPM_CANCEL: \r\n");
uart2_init(UART_BAUDRATE_115K2, 3);
#endif
if(param->status != GAP_ERR_NO_ERROR)
{
ASSERT_ERR(0); // unexpected error
}
if (app_process_catch_rest_cb!=NULL)
{
app_process_catch_rest_cb(msgid,param,dest_id,src_id);
}
}
break;
default:
if (app_process_catch_rest_cb!=NULL)
{
#if DEBUG_LOG33
printf_string("\r\ndefault:\r\n");
uart2_init(UART_BAUDRATE_115K2, 3);
#endif
app_process_catch_rest_cb(msgid,param,dest_id,src_id);
}
break;
}
return (KE_MSG_CONSUMED);
}
Here is some part of the program of app.c:
volatile uint8_t current_role = 1; //
static struct gapm_set_dev_config_cmd* app_easy_gap_dev_config_create_msg(void)
{
// Allocate a message for GAP
if (set_dev_config_cmd == NULL)
{
struct gapm_set_dev_config_cmd* cmd;
cmd = app_gapm_configure_msg_create();
set_dev_config_cmd = cmd;
if(USER_CONFIG)
{
cmd->operation = GAPM_SET_DEV_CONFIG;
if( 1 == current_role )
{
cmd->role = user_gapm_conf.role;
current_role = 0;
}
else
{
cmd->role = user_gapm_conf.role;
current_role = 1;
}
cmd->appearance = user_gapm_conf.appearance;
cmd->appearance_write_perm = user_gapm_conf.appearance_write_perm;
cmd->name_write_perm = user_gapm_conf.name_write_perm;
cmd->max_mtu = user_gapm_conf.max_mtu;
cmd->con_intv_min = user_gapm_conf.con_intv_min;
cmd->con_intv_max = user_gapm_conf.con_intv_max;
cmd - > con_latency = user_gapm_conf.con_latency;
cmd->superv_to = user_gapm_conf.superv_to;
cmd->flags = user_gapm_conf.flags;
memcpy(cmd->irk.key,user_gapm_conf.irk,KEY_LEN);
}
else
memcpy((void*)cmd, (void*)&default_set_dev_config, sizeof(struct gapm_set_dev_config_cmd));
}
return (set_dev_config_cmd);
}
Could you please help? After I have done the role switching for 27 times, the system will re initial again everything, could you please help this issue?
Hi liuluan002,
I suppose that when the code executes the program forces a reset through the platform_reset function. I would say that perhaps there is a memory leak somewhere and that forces the program to go to a platform_reset. You can check this by overriding the platform reset function in the jump_table with a custom function and try to catch it with a break point with the sleep disabled. Just place a while(1) loop into your custom function.
Thanks MT_dialog