5 years ago
about the stack reset by its own and data lost
Posted byliuluan0020 points 2 repliesHi Dialog,
我现在使用堆栈来做广告,我已经设置的时间段是2.5s通过使用计时器。我在我的程序中使用的“current_role”用于控制程序“app_task.c”和“app.c”中的角色切换。但是当它运行25次的角色切换时,它将重置整个程序,并丢失了所有的东西之前放入了RAM之前,请您帮助您解决这个问题吗?
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)
{
//重置完成
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
案例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(msgs,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(msgs,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);
}
5 years ago
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?