嗨,对话,
我现在是用栈做广告的,用定时器设定的时间是2.5秒。我正在使用程序中的“current\u role”来控制程序“app\u task.c”和“app.c”中的角色切换。但是,当它运行25次进行角色切换时,会重置整个程序,并且丢失了之前放入ram的所有东西,您能帮我解决这个问题吗?
以下是app\u task.c程序的一部分:
外部易失性uint8\u t当前角色;
int app\u switch\u role(ke\u msg\u id\u t msgid,void*param,ke\u task\u id\u t dest\u id,ke\u task\u id\u src\u id)
{
app_gapm_reset_op();
返回(已消耗的消息);
}
静态常量结构ke\u msg\u处理程序app\u gap\u进程\u处理程序[]=
{
{GAPM\u DEVICE\u READY\u IND,(ke\u msg\u func\t)GAPM\u DEVICE\u READY\u IND\u handler},
{GAPM\u CMP\u EVT,(ke\u msg\u func\t)GAPM\u CMP\u EVT\u handler},
{GAPC\u CMP\u EVT,(ke\u msg\u func\t)GAPC\u CMP\u EVT\u handler},
{GAPC\u CONNECTION\u REQ\u IND,(ke\u msg\u func\t)GAPC\u CONNECTION\u REQ\u IND\u handler},
{GAPC\u DISCONNECT\u IND,(ke\u msg\u func\t)GAPC\u DISCONNECT\u IND\u handler},
{APP\u MODULE\u INIT\u CMP\u EVT,(ke\u msg\u func\t)APP\u MODULE\u INIT\u CMP\u EVT\u handler},
{GAPM\u ADV\u REPORT\u IND,(ke\u msg\u func\t)GAPM\u ADV\u REPORT\u IND\u handler},
{APP\u DYNAMIC\u ADV\u DATA,(ke\u msg\u func\t)APP\u update\u ADV\u DATA},
{APP\u SWITCH\u ROLE\u TIMER,(ke\u msg\u func\t)APP\u SWITCH\u ROLE},
};
int gapm\u cmp\u evt\u处理程序(ke\u msg\u id\u const msgid,
结构gapm\u cmp\u evt const*参数,
任务id常量目标id,
Keu任务\u id \u t const src \u id)
{
开关(参数->操作)
{
//重置完成
案例GAPM\U重置:
{
如果(参数->状态!=间隙(无错误)
{
断言错误(0);//意外错误
}
其他的
{
//设置设备配置
应用程序\u简单\u差距\u开发\u配置();
#如果调试日志33
printf_字符串(“\r\n GAPM_RESET\r\n”);
uart2_init(UART_波特率_115K2,3);
#结束
}
}
中断;
//设备配置已更新
案例GAPM\u SET\u DEV\u CONFIG:
{
如果(参数->状态!=间隙(无错误)
{
断言错误(0);//意外错误
//尼克拉斯
#如果调试日志33
printf_字符串(“\r\nError253\r\n”);
uart2_init(UART_波特率_115K2,3);
#结束
}
其他的
{
if(1==当前角色)
{
#如果调试日志2
printf_字符串(“\r\nAdv1”);
打印字节(位置1);
printf_字符串(“\r\n”);
uart2_init(UART_波特率_115K2,3);
#结束
记录3();
执行回调无效(app on set dev config complete);
位置1++;
}
其他的
{
#如果调试日志2
printf_字符串(“\r\nAdv2”);
打印字节(位置1);
printf_字符串(“\r\n”);
uart2_init(UART_波特率_115K2,3);
#结束
记录3();
执行回调无效(app on set dev config complete);
位置1++;
}
keu timer\u set(APP\u SWITCH\u ROLE\u timer,TASK\u APP,250)//100*10毫秒
}
}
中断;
//广告结束
case GAPM_ADV_NON_CONN:
案例GAPM\u ADV\u UNDIRECT:
{
#如果调试日志33
printf\u字符串(“\r\n GAPM\u ADV\u UNDIRECT\r\n”);
uart2_init(UART_波特率_115K2,3);
#结束
执行回调参数(app-on-adv-undirect-complete,PARAM->status);
}
中断;
//定向广告完成
案例GAPM\ U ADV\ U DIRECT:
{
#如果调试日志33
printf_string(“\r\n GAPM_ADV_DIRECT\r\n”);
uart2_init(UART_波特率_115K2,3);
#结束
执行回调参数(app\u on\u adv\u direct\u complete,PARAM->status);
}
中断;
案例GAPM\扫描\激活:
案例GAPM\扫描\被动:
{
#如果调试日志33
printf_string(“\r\n GAPM_SCAN_PASSIVE:\r\n”);
uart2_init(UART_波特率_115K2,3);
#结束
执行\u回调\u VOID(app \u on \u scanning \u completed);
}
中断;
案例GAPM\连接\直接:
if(param->status==GAP\u ERR\u CANCELED)
{
#如果调试日志33
printf_string(“\r\n GAPM_CONNECTION_DIRECT:\r\n”);
uart2_init(UART_波特率_115K2,3);
#结束
执行\u CALLBACK \u VOID(app \u on \u connect \u失败);
}
中断;
案例GAPM\U取消:
{
#如果调试日志33
printf_string(“\r\n GAPM_CANCEL:\r\n”);
uart2_init(UART_波特率_115K2,3);
#结束
如果(参数->状态!=间隙(无错误)
{
断言错误(0);//意外错误
}
如果(应用程序\u进程\u捕获\u剩余\u cb=(空)
{
应用\进程\捕获\剩余\ cb(msgid,param,dest\ id,src\ id);
}
}
中断;
违约:
如果(应用程序\u进程\u捕获\u剩余\u cb=(空)
{
#如果调试日志33
printf_字符串(“\r\n默认值:\r\n”);
uart2_init(UART_波特率_115K2,3);
#结束
应用\进程\捕获\剩余\ cb(msgid,param,dest\ id,src\ id);
}
中断;
}
返回(已消耗的消息);
}
以下是app.c程序的一部分:
volatile uint8\u t current\u role=1//
静态结构gapm\u set\u dev\u config\u cmd*app\u easy\u gap\u dev\u config\u create\u msg(void)
{
//为GAP分配消息
if(set \u dev \u config \u cmd==NULL)
{
结构gapm\u set\u dev\u config\u cmd*cmd;
cmd=app_gapm_configure_msg_create();
设置\u dev \u config \u cmd=cmd;
if(用户配置)
{
cmd->operation=GAPM\u SET\u DEV\u CONFIG;
if(1==当前角色)
{
cmd->role=user\u gapm\u conf.role;
当前角色=0;
}
其他的
{
cmd->role=user\u gapm\u conf.role;
当前角色=1;
}
cmd->appearance=user\u gapm\u conf.appearance;
cmd->appearance\u write\u perm=user\u gapm\u conf.appearance\u write\u perm;
cmd->name\u write\u perm=user\u gapm\u conf.name\u write\u perm;
cmd->max\u mtu=user\u gapm\u conf.max\u mtu;
cmd->con\u intv\u min=user\u gapm\u conf.con\u intv\u min;
cmd->con\u intv\u max=user\u gapm\u conf.con\u intv\u max;
cmd->con\u latency=user\u gapm\u conf.con\u latency;
cmd->superv\u to=user\u gapm\u conf.superv\u to;
cmd->flags=user\u gapm\u conf.flags;
memcpy(cmd->irk.key,user\u gapm\u conf.irk,key\u LEN);
}
其他的
memcpy((void*)cmd,(void*)&default\u set\u dev\u config,sizeof(struct gapm\u set\u dev\u config\u cmd));
}
return(设置\开发\配置\命令);
}

你能帮忙吗?在我做了27次角色转换之后,系统会重新初始化所有的东西,你能帮我解决这个问题吗?
你好,刘銮002,
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.
谢谢你的对话