5年前
关于栈被自己重置和数据丢失
发布的liuluan0020点 2回答嗨,对话框中,
我现在使用堆栈来做广告,我已经设置的时间段是2.5s通过使用计时器。我在我的程序中使用的“current_role”用于控制程序“app_task.c”和“app.c”中的角色切换。但是当它运行25次的角色切换时,它将重置整个程序,并丢失了所有的东西之前放入了RAM之前,请您帮助您解决这个问题吗?
下面是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 ();
返回(KE_MSG_CONSUMED);
}
静态const struct ke_msg_handler app_gap_process_handlers[]=
{
(ke_msg_func_t) gapm_device_ready_ind_handler}, {GAPM_DEVICE_READY_IND
(ke_msg_func_t) gapm_cmp_evt_handler}, {GAPM_CMP_EVT
(ke_msg_func_t) gapc_cmp_evt_handler}, {GAPC_CMP_EVT
(ke_msg_func_t) gapc_connection_req_ind_handler}, {GAPC_CONNECTION_REQ_IND
(ke_msg_func_t) gapc_disconnect_ind_handler}, {GAPC_DISCONNECT_IND
(ke_msg_func_t) app_module_init_cmp_evt_handler}, {APP_MODULE_INIT_CMP_EVT
(ke_msg_func_t) gapm_adv_report_ind_handler}, {GAPM_ADV_REPORT_IND
(ke_msg_func_t) app_update_adv_data}, {APP_DYNAMIC_ADV_DATA
(ke_msg_func_t) app_switch_role}, {APP_SWITCH_ROLE_TIMER
};
Int gapm_cmp_evt_handler(ke_msg_id_t)
Struct gapm_cmp_evt const *参数,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
开关(param - >操作)
{
//重置完成
案例GAPM_RESET:
{
如果(param - >状态! = GAP_ERR_NO_ERROR)
{
ASSERT_ERR (0);/ /意想不到的错误
}
其他的
{
//设置设备配置
app_easy_gap_dev_configure ();
#如果DEBUG_LOG33
printf_string(“GAPM_RESET \ r \ n \ r \ n”);
uart2_init (UART_BAUDRATE_115K2 3);
# endif
}
}
打破;
//设备配置更新
案例GAPM_SET_DEV_CONFIG:
{
如果(param - >状态! = GAP_ERR_NO_ERROR)
{
ASSERT_ERR (0);/ /意想不到的错误
/ / niklas
#如果DEBUG_LOG33
printf_string(“\ \ nError253 \ r \ n”);
uart2_init (UART_BAUDRATE_115K2 3);
# endif
}
其他的
{
如果(1 == current_role)
{
#如果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 + +;
}
其他的
{
#如果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 * 10 ms
}
}
打破;
/ /广告完成
案例GAPM_ADV_NON_CONN:
案例GAPM_ADV_UNDIRECT:
{
#如果DEBUG_LOG33
printf_string(“GAPM_ADV_UNDIRECT \ r \ n \ r \ n”);
uart2_init (UART_BAUDRATE_115K2 3);
# endif
EXECUTE_CALLBACK_PARAM (app_on_adv_undirect_complete param - >状态);
}
打破;
//定向广告完成
案例GAPM_ADV_DIRECT:
{
#如果DEBUG_LOG33
printf_string(“GAPM_ADV_DIRECT \ r \ n \ r \ n”);
uart2_init (UART_BAUDRATE_115K2 3);
# endif
EXECUTE_CALLBACK_PARAM (app_on_adv_direct_complete param - >状态);
}
打破;
案例GAPM_SCAN_ACTIVE:
案例GAPM_SCAN_PASSIVE:
{
#如果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);
}
打破;
案例GAPM_CONNECTION_DIRECT:
if (param->status == GAP_ERR_CANCELED) / /取消取消
{
#如果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);
}
打破;
案例GAPM_CANCEL:
{
#如果DEBUG_LOG33
printf_string(“\ r \ n GAPM_CANCEL: \ r \ n”);
uart2_init (UART_BAUDRATE_115K2 3);
# endif
如果(param - >状态! = GAP_ERR_NO_ERROR)
{
ASSERT_ERR (0);/ /意想不到的错误
}
if(app_process_catch_rest_cb!= null)
{
app_process_catch_rest_cb(msgs,param,dest_id,src_id);
}
}
打破;
默认值:
if(app_process_catch_rest_cb!= null)
{
#如果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);
}
打破;
}
返回(KE_MSG_CONSUMED);
}
以下是app.c的部分程序:
Volatile常量uint8_t current_role = 1;//
* app_easy_gap_dev_config_create_msg(无效)
{
//为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;
如果(USER_CONFIG)
{
cmd - >操作= GAPM_SET_DEV_CONFIG;
如果(1 == current_role)
{
cmd - >角色= user_gapm_conf.role;
current_role = 0;
}
其他的
{
cmd - >角色= user_gapm_conf.role;
current_role = 1;
}
cmd - >外观= 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 - >标志= user_gapm_conf.flags;
memcpy (cmd - > irk.key、user_gapm_conf.irk KEY_LEN);
}
其他的
Memcpy ((void*)cmd, (void*)&default_set_dev_config, sizeof(struct gapm_set_dev_config_cmd));
}
返回(set_dev_config_cmd);
}
5年前
你能帮忙吗?我换了27次角色后,系统会重新初始化一切,你能帮忙解决这个问题吗?