2015.07.15-系统初始化首个任务时发生fault故障

本文探讨了在初始化BOOT任务时遇到FAULT故障的原因,并通过复位和单步跟踪的方法定位到了初始化CONTAINER时循环下标使用不当导致的内存踩踏问题。提出了使用函数CORE_CreatePoolContainer来根据不同配置初始化容器的解决方案。
【问题现象】
初始化BOOT任务过程中发生FAULT故障。

【定位过程】

任务创建结束进入CORE_SetError设置错误码判断 Current Task 指针不为空:

STATIC E_STATUS SetTaskError(E_STATUS emCode)
{
    LPTASK_CONTEXT lpCurrentContext = GetCurrentTaskContext();

    if (NULL != lpCurrentContext)
    {
        SetContextTaskError(lpCurrentContext, emCode);
        return STATE_SUCCESS;
    }

    SetSystemGlobalError(emCode);

    return STATE_INVALID_TASK;
}
单步调试得到g_CurrentContext全局变量内存地址为0x20000248(R2+0x8 为 g_CurrentContext 指针,R2=0x20000240)


查看内存,发现0x20000248此时值为 0x00000100,即R1的值


复位并重新单步跟踪发现初始化对象管理器后,g_CurrentContext 值发生变化。

【问题原因】

初始化CONTAINER时循环下标使用CONFIG_CORE_POOL_MAX 和 CONFIG_POOL_BLOCK_MAX导致踩内存:



【解决方案】

函数 CORE_CreatePoolContainer 提供了参数Pools(容器支持的POOL数量)和BlockPrePool(每个POOL的块数量),用于处理不同的容器配置,应当针对不同的配置进行初始化:

    SetFreeBitmapMask2Container(lpManager, GetBitsMaskValue(Pools));
    
    for (; Pid < Pools; Pid ++)
    {
        LPCORE_POOL lpCorePool = GetPoolForID(lpManager, Pid);

        SetPoolMagic(lpCorePool, POOL_INITIALIZE_MAGIC);
        
        SetPoolTotalBlocks(lpCorePool, BlockPrePool);
        SetPoolRemainBlocks(lpCorePool, BlockPrePool);
        SetPoolBlockLength(lpCorePool, BytePreBlock);
        
        SetFreeBitmapMask2Pool(lpCorePool, GetBitsMaskValue(BlockPrePool));


下面是我的Linuxcnc控制伺服电机的hal文件,怎么通过引脚的方式让OPenplc可以和Linuxcnc交换数据 loadrt [KINS]KINEMATICS loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS loadusr -W lcec_conf ethercat-conf.xml loadrt lcec loadrt cia402 count=4 addf motion-command-handler servo-thread addf motion-controller servo-thread addf lcec.read-all servo-thread addf lcec.write-all servo-thread addf cia402.0.read-all servo-thread addf cia402.0.write-all servo-thread addf cia402.1.read-all servo-thread addf cia402.1.write-all servo-thread addf cia402.2.read-all servo-thread addf cia402.2.write-all servo-thread addf cia402.3.read-all servo-thread addf cia402.3.write-all servo-thread #config # 模式 1csp 0csv setp cia402.0.csp-mode 1 setp cia402.0.pos-scale 1677721.6 setp cia402.1.csp-mode 1 setp cia402.1.pos-scale 1677721.6 setp cia402.2.csp-mode 1 setp cia402.2.pos-scale 1677721.6 setp cia402.3.csp-mode 1 setp cia402.3.pos-scale 1677721.6 #连接第一台伺服(轴0) #from servo(ethercat) to cia402 net x-statusword lcec.0.0.cia-statusword => cia402.0.statusword net x-opmode-display lcec.0.0.opmode-display => cia402.0.opmode-display net x-drv-act-pos lcec.0.0.actual-position => cia402.0.drv-actual-position net x-drv-act-velo lcec.0.0.actual-velocity => cia402.0.drv-actual-velocity #from cia402 to servo(ethercat) net x-controlword cia402.0.controlword => lcec.0.0.cia-controlword net x-modes-of-operation cia402.0.opmode => lcec.0.0.opmode net x-drv-target-pos cia402.0.drv-target-position => lcec.0.0.target-position net x-drv-target-velo cia402.0.drv-target-velocity => lcec.0.0.target-velocity #连接第二台伺服(轴1) net y-statusword lcec.0.1.cia-statusword => cia402.1.statusword net y-opmode-display lcec.0.1.opmode-display => cia402.1.opmode-display net y-drv-act-pos lcec.0.1.actual-position => cia402.1.drv-actual-position net y-drv-act-velo lcec.0.1.actual-velocity => cia402.1.drv-actual-velocity net y-controlword cia402.1.controlword => lcec.0.1.cia-controlword net y-modes-of-op cia402.1.opmode => lcec.0.1.opmode net y-drv-target-pos cia402.1.drv-target-position => lcec.0.1.target-position net y-drv-target-velo cia402.1.drv-target-velocity => lcec.0.1.target-velocity #连接第三台伺服(轴2) net z-statusword lcec.0.2.cia-statusword => cia402.2.statusword net z-opmode-display lcec.0.2.opmode-display => cia402.2.opmode-display net z-drv-act-pos lcec.0.2.actual-position => cia402.2.drv-actual-position net z-drv-act-velo lcec.0.2.actual-velocity => cia402.2.drv-actual-velocity net z-controlword cia402.2.controlword => lcec.0.2.cia-controlword net z-modes-of-op cia402.2.opmode => lcec.0.2.opmode net z-drv-target-pos cia402.2.drv-target-position => lcec.0.2.target-position net z-drv-target-velo cia402.2.drv-target-velocity => lcec.0.2.target-velocity #连接第四台伺服(轴3) net c-statusword lcec.0.3.cia-statusword => cia402.3.statusword net c-opmode-display lcec.0.3.opmode-display => cia402.3.opmode-display net c-drv-act-pos lcec.0.3.actual-position => cia402.3.drv-actual-position net c-drv-act-velo lcec.0.3.actual-velocity => cia402.3.drv-actual-velocity net c-controlword cia402.3.controlword => lcec.0.3.cia-controlword net c-modes-of-op cia402.3.opmode => lcec.0.3.opmode net c-drv-target-pos cia402.3.drv-target-position => lcec.0.3.target-position net c-drv-target-velo cia402.3.drv-target-velocity => lcec.0.3.target-velocity #from motion to cia net x-enable <= joint.0.amp-enable-out => cia402.0.enable net x-amp-fault => joint.0.amp-fault-in <= cia402.0.drv-fault net x-pos-cmd <= joint.0.motor-pos-cmd => cia402.0.pos-cmd net x-pos-fb => joint.0.motor-pos-fb <= cia402.0.pos-fb net y-enable <= joint.1.amp-enable-out => cia402.1.enable net y-amp-fault => joint.1.amp-fault-in <= cia402.1.drv-fault net y-pos-cmd <= joint.1.motor-pos-cmd => cia402.1.pos-cmd net y-pos-fb => joint.1.motor-pos-fb <= cia402.1.pos-fb net z-enable <= joint.2.amp-enable-out => cia402.2.enable net z-amp-fault => joint.2.amp-fault-in <= cia402.2.drv-fault net z-pos-cmd <= joint.2.motor-pos-cmd => cia402.2.pos-cmd net z-pos-fb => joint.2.motor-pos-fb <= cia402.2.pos-fb net c-enable <= joint.3.amp-enable-out => cia402.3.enable net c-amp-fault => joint.3.amp-fault-in <= cia402.3.drv-fault net c-pos-cmd <= joint.3.motor-pos-cmd => cia402.3.pos-cmd net c-pos-fb => joint.3.motor-pos-fb <= cia402.3.pos-fb setp iocontrol.0.emc-enable-in 1
06-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值