Heart Beat使用参考


REVISION HISTORY

Revision No.
Description
Date
1.0
  • Initial release
  • 06/18/2024
  • Modify the outline.
  • 04/16/2025

    1. 概述

    InterCoreManager是基于sstar平台实现的一套核间通信机制,实现了Heart Beat的功能。InterCoreManager提供了一套callback,让APP可以基于InterCoreManager的框架快速地实现核间通信。

    1.1. 模块说明

    InterCoreManager实现了核间Heart Beat所需要的相关功能,包括扫描、应答、状态更新、心跳发生以及复位。根据运行的平台不同,InterCoreManager底层所用的通信机制也有差异,包括mail box和rpmsg,APP无需关心使用何种通信机制。

    1.2. 开发流程

    1.2.1. InterCoreManager相关的源代码

    arm linux demo: sdk/verify/sample_code/source/pcupid/intercoremgr,参考demo中包含了InterCoreManager linux user space API的调用流程。

    arm linux driver: kernel/drivers/sstar/intercoremgr,该部分会编译user space的libss_intercoremgr。InterCoreManager的linux driver由 SSTAR_INTERCOREMGR 来决定是否编译。

    SStar InterCoreMgr driver
    There is no help available for this option.                                                                                                                                                                                         x
      x Symbol: SSTAR_INTERCOREMGR [=y]                                                                                                                                                                                                     x
      x Type  : tristate                                                                                                                                                                                                                    x
      x Defined at drivers/sstar/intercoremgr/Kconfig:1                                                                                                                                                                                     x
      x   Prompt: SStar InterCoreMgr driver
      x   Depends on: SSTAR_DRIVERS [=y]                                                                                                                                                                                                    x
      x   Location:                                                                                                                                                                                                                         x
      x     -> Device Drivers                                                                                                                                                                                                               x
      x       -> Sstar SoC platform drivers (SSTAR_DRIVERS [=y])
    

    arm linux user space header:kernel/drivers/sstar/include/intercoremgr.h

    riscv rtos demo: proj/sc/application/intercoremgr,InterCoreManager demo由 proj/mak/common/libs_common.mak 决定是否编译。

    ifeq ($(call FIND_COMPILER_OPTION, CONFIG_INTERCOREMGR_SUPPORT), TRUE)
    PRODUCT_SC += intercoremgr_demo
    endif
    
    ifeq ($(call FIND_COMPILER_OPTION, CONFIG_INTERCOREMGR_SUPPORT), TRUE)
    PRODUCT_SC_LIB_REL += intercoremgr
    endif
    

    riscv rtos driver: proj/sc/driver/sysdriver/intercoremgr,InterCoreManager的rtos driver 由 proj/mak/options_pcupid_riscv_isw.mak 中的 CONFIG_INTERCOREMGR_SUPPORT 来决定是否编译。

    # Feature_Name = [DRV] Intercoremgr driver
    # Description = intercoremgr driver support
    # Option_Selection = TRUE, FALSE
    CONFIG_INTERCOREMGR_SUPPORT = TRUE
    

    riscv rtos header: proj/sc/driver/sysdriver/intercoremgr/drv/pub/intercoremgr.h

    1.2.2. 实例介绍

    下图是一种比较常见的使用情况,其中一个CPU主动去扫描远端CPU,双方建立心跳机制。当其中一方因为事件(升级或休眠等)需要停止心跳的发送并通知对方状态的更新。

    2. InterCoreManager API介绍

    API名 功能
    SS_InterCoreMgr_Comm_Init 初始化InterCoreManager
    SS_InterCoreMgr_Comm_DeInit 销毁InterCoreManager
    SS_InterCoreMgr_Scan 扫描远端CPU
    SS_InterCoreMgr_ScanAck 响应扫描
    SS_InterCoreMgr_Heartbeat_Tick 向远端发送心跳
    SS_InterCoreMgr_Heartbeat_Stop 告知远端停止心跳检测
    SS_InterCoreMgr_Notify_State 告知远端本地的状态
    SS_InterCoreMgr_Query_State 查询远端的状态
    SS_InterCoreMgr_Reset_Remote 重启远端CPU
    SS_InterCoreMgr_Reset_Global 重启SOC

    2.1. SS_InterCoreMgr_Comm_Init

    • 说明

      初始化InterCoreManager。

    • 定义

      s32 SS_InterCoreMgr_Comm_Init(ReceiverCallback pRecvCb);
      
    • 形参

      参数名称 描述 输入/输出
      pRecvCb 注册到InterCoreManager的callback 输入
    • 返回值

      • 0:成功。

      • 非0:失败。

    • 相关数据类型

    2.2. SS_InterCoreMgr_Comm_DeInit

    • 说明

      销毁InterCoreManager。

    • 定义

      s32 SS_InterCoreMgr_Comm_DeInit(void);
      
    • 返回值

      • 0:成功。

      • 非0:失败。

    2.3. SS_InterCoreMgr_Scan

    • 说明

      扫描远端Cpu。

    • 定义

      s32 SS_InterCoreMgr_Scan(SS_InterCoreMgr_CPU_e peerCpu, u32 scanTimeoutInMs, SS_InterCoreMgr_ScanInfo_t *pScanInfo);
      
    • 形参

      参数名称 描述 输入/输出
      peerCpu 远端Cpu的类型 输入
      scanTimeoutInMs 扫描超时时间 输入
      pScanInfo 心跳机制建立信息 输入
    • 返回值

      • 0:成功。

      • 非0:失败。

    • 注意

      • 只有当扫描到远端CPU时,心跳信息才会传递给对方。当扫描成功后,需以小于等于pScanInfo中设置的心跳频率给远端CPU发送心跳包,否则会被远端CPU判定为心跳超时。
    • 相关数据类型

    2.4. SS_InterCoreMgr_ScanAck

    • 说明

      响应扫描。

    • 定义

      s32 SS_InterCoreMgr_ScanAck(SS_InterCoreMgr_CPU_e peerCpu, SS_InterCoreMgr_ScanAckInfo_t *pScanAckInfo);
      
    • 形参

      参数名称 描述 输入/输出
      peerCpu 远端Cpu的类型 输入
      pScanAckInfo 心跳机制建立信息 输入
    • 返回值

      • 0:成功。

      • 非0:失败。

    • 注意

      • 当接收到远端CPU的扫描信号时,需调用此接口进行应答,回复远端本地的心跳频率。应答后,需以小于等于pScanAckInfo中设置的心跳频率给远端CPU发送心跳包,否则会被远端CPU判定为心跳超时。
    • 相关数据类型

    2.5. SS_InterCoreMgr_Heartbeat_Tick

    • 说明

      向远端发送心跳。

    • 定义

      s32 SS_InterCoreMgr_Heartbeat_Tick(SS_InterCoreMgr_CPU_e peerCpu, SS_InterCoreMgr_HbInfo_t *pHbInfo);
      
    • 形参

      参数名称 描述 输入/输出
      peerCpu 远端Cpu的类型 输入
      pHbInfo 心跳信息 输入
    • 返回值

      • 0:成功。

      • 非0:失败。

    • 相关数据类型

    2.6. SS_InterCoreMgr_Heartbeat_Stop

    • 说明

      告知远端停止心跳。

    • 定义

      s32 SS_InterCoreMgr_Heartbeat_Stop(SS_InterCoreMgr_CPU_e peerCpu, SS_InterCoreMgr_HbInfo_t *pHbInfo);
      
    • 形参

      参数名称 描述 输入/输出
      peerCpu 远端Cpu的类型 输入
      pHbInfo 心跳信息 输入
    • 返回值

      • 0:成功。

      • 非0:失败。

    • 注意

      • 当调用此接口后,远端会停止对本地进行心跳检测。
    • 相关数据类型

    2.7. SS_InterCoreMgr_Notify_State

    • 说明

      告知远端本地的状态。

    • 定义

      s32 SS_InterCoreMgr_Notify_State(SS_InterCoreMgr_CPU_e peerCpu, SS_InterCoreMgr_stateInfo_t *pStateInfo);
      
    • 形参

      参数名称 描述 输入/输出
      peerCpu 远端Cpu的类型 输入
      pStateInfo 本地状态信息 输入
    • 返回值

      • 0:成功。

      • 非0:失败。

    • 相关数据类型

    2.8. SS_InterCoreMgr_Query_State

    • 说明

      查询远端本地的状态。

    • 定义

      s32 SS_InterCoreMgr_Query_State(SS_InterCoreMgr_CPU_e peerCpu, SS_InterCoreMgr_queryStateInfo_t *pQueryStateInfo);
      
    • 形参

      参数名称 描述 输入/输出
      peerCpu 远端Cpu的类型 输入
      pQueryStateInfo 远端状态信息 输入
    • 返回值

      • 0:成功。

      • 非0:失败。

    • 相关数据类型

    2.9. SS_InterCoreMgr_Reset_Remote

    • 说明

      重启远端CPU。

    • 定义

      s32 SS_InterCoreMgr_Reset_Remote(void);
      
    • 返回值

      • 0:成功。

      • 非0:失败。

    2.10. SS_InterCoreMgr_Reset_Global

    • 说明

      重启Soc。

    • 定义

      s32 SS_InterCoreMgr_Reset_Global(void);
      
    • 返回值

      • 0:成功。

      • 非0:失败。

    3. 数据结构介绍

    数据类型 定义
    SS_InterCoreMgr_Action_e 触发callback的远端行为
    ReceiverCallback InterCoreManager响应callback
    SS_InterCoreMgr_CPU_e 远端CPU的类型
    SS_InterCoreMgr_ScanInfo_t 扫描端心跳机制建立信息
    SS_InterCoreMgr_ScanAckInfo_t 被扫描端心跳机制建立信息
    SS_InterCoreMgr_HbInfo_t 心跳信息
    SS_InterCoreMgr_State_e 状态
    SS_InterCoreMgr_stateInfo_t 状态信息
    SS_InterCoreMgr_queryStateInfo_t 查询远端状态

    3.1. SS_InterCoreMgr_Action_e

    • 说明

      触发callback的远端行为。

    • 定义

      typedef enum
      {
          E_COREMGR_DEFAULT = 0,
          E_COREMGR_SCAN,
          E_COREMGR_SCAN_ACK,
          E_COREMGR_HB,
          E_COREMGR_HB_STOP,
          E_COREMGR_STATE_QUERY,
          E_COREMGR_STATE_NOTIFY,
          E_COREMGR_MAX,
      } SS_InterCoreMgr_Action_e;
      
    • 成员

      成员名称 描述
      E_COREMGR_DEFAULT 保留暂时不做使用
      E_COREMGR_SCAN 收到远端的扫描信息
      E_COREMGR_SCAN_ACK 收到远端的扫描回复信息
      E_COREMGR_HB 收到远端的心跳信息
      E_COREMGR_HB_STOP 收到远端的心跳停止信息
      E_COREMGR_STATE_QUERY 收到远端查询本地的状态信息
      E_COREMGR_STATE_NOTIFY 收到远端反馈的状态信息

    3.2. ReceiverCallback

    • 说明

      InterCoreManager响应callback。

    • 定义

      typedef void (*ReceiverCallback)(SS_InterCoreMgr_Action_e eAction, void *data);
      
    • 注意

      • 通过SS_InterCoreMgr_Comm_Init注册callback后,当远端CPU触发相应的eAction时,会调用该callback进行处理。不同的eAction data所回传的数据结构不同,详情请参考所提供的demo。

    3.3. SS_InterCoreMgr_CPU_e

    • 说明

      远端CPU类型。

    • 定义

      typedef enum
      {
          E_COREMGR_CPU_ARM = 0,
          E_COREMGR_CPU_RISCV,
          E_COREMGR_CPU_CM4,
          E_COREMGR_CPU_MAX,
      } SS_InterCoreMgr_CPU_e;
      
    • 成员

      成员名称 描述
      E_COREMGR_CPU_ARM 远端CPU为ARM
      E_COREMGR_CPU_RISCV 远端CPU为RISCV
      E_COREMGR_CPU_CM4 远端CPU为CM4

    3.4. SS_InterCoreMgr_ScanInfo_t

    • 说明

      扫描端心跳机制建立信息。

    • 定义

      typedef struct SS_InterCoreMgr_ScanInfo_s
      {
          SS_InterCoreMgr_CPU_e scanCPU;
          u16                   hbPeriodInMs;
          u32                   timestampInMs;
      } SS_InterCoreMgr_ScanInfo_t;
      

    3.5. SS_InterCoreMgr_ScanAckInfo_t

    • 说明

      被扫描端心跳机制建立信息。

    • 定义

      typedef struct SS_InterCoreMgr_ScanAckInfo_s
      {
          SS_InterCoreMgr_CPU_e ackCPU;
          u16                   hbPeriodInMs;
          u32                   timestampInMs;
      } SS_InterCoreMgr_ScanAckInfo_t;
      

    3.6. SS_InterCoreMgr_HbInfo_t

    • 说明

      心跳信息。

    • 定义

      typedef struct SS_InterCoreMgr_HbInfo_s
      {
          SS_InterCoreMgr_CPU_e hbCPU;
          u32                   hbSequenceNum;
          u32                   timestampInMs;
      } SS_InterCoreMgr_HbInfo_t;
      

    3.7. SS_InterCoreMgr_State_e

    • 说明

      状态。

    • 定义

      typedef enum
      {
          E_COREMGR_STATE_Normal = 0,
          E_COREMGR_STATE_STR,
          E_COREMGR_STATE_CHARGE,
          E_COREMGR_STATE_MAX,
      } SS_InterCoreMgr_State_e;
      
    • 成员

      成员名称 描述
      E_COREMGR_STATE_Normal normal状态
      E_COREMGR_STATE_STR suspend状态
      E_COREMGR_STATE_CHARGE charge状态

    3.8. SS_InterCoreMgr_stateInfo_t

    • 说明

      状态信息。

    • 定义

      typedef struct SS_COREMGR_stateInfo_s
      {
          SS_InterCoreMgr_CPU_e   notifyCpu;
          SS_InterCoreMgr_State_e newState;
          u32                     timestampInMs;
      } SS_InterCoreMgr_stateInfo_t;