NVDLA系列之C-model:cvif&glb<103>

备注:NV_NVDLA_cvif.cpp

Reset()

void NV_NVDLA_cvif::Reset() {
    
    
    // 清除寄存器和内部状态

    // 重置 BDMA 模块状态和计数器
    bdma_wr_req_count_ = 0;
    bdma_wr_rsp_count_ = 0;
    bdma_wr_req_ack_is_got_ = false;
    has_bdma_onging_wr_req_ = false;

    // 重置 BDMA 模块的写响应信号
    // cvif2bdma_wr_rsp.initialize(false);

    // 类似地,重置 SDP、PDP、CDP 和 RBK 模块的状态和计数器,并重置相应的写响应信号

    // cvif2ext_wr_req_payload = NULL;
    // cvif2ext_rd_req_payload = NULL;
}

函数总结

  • 函数名称:NV_NVDLA_cvif::Reset
  • 参数:无
  • 返回值:无
  • 功能:此函数用于将 CVIF 模块的各个外部模块的状态和计数器重置为初始状态,并清除相关的内部状态。具体包括 BDMA、SDP、PDP、CDP 和 RBK 模块的写请求和写响应计数器、写请求应答标志等。函数还包括了一些被注释掉的代码,这些代码可能是用于初始化一些信号或对象的。最后两行代码被注释掉,因此并没有实际作用。

文件:cmod/glb/NV_NVDLA_glb.h

NV_NVDLA_glb.h

// File Name: NV_NVDLA_glb.h

#ifndef _NV_NVDLA_GLB_H_
#define _NV_NVDLA_GLB_H_
#define SC_INCLUDE_DYNAMIC_PROCESSES

#include <systemc.h>
#include <tlm.h>
#include "tlm_utils/multi_passthrough_initiator_socket.h"
#include "tlm_utils/multi_passthrough_target_socket.h" 

#include "scsim_common.h"
#include "nvdla_dma_wr_req_iface.h"
#include <systemc.h>
#include "nvdla_xx2csb_resp_iface.h"
#include "NV_NVDLA_glb_base.h"
#include "glb_reg_model.h"
#include "gec_reg_model.h"
#include "NvdlaDataFormatConvertor.h"

// class NvdlaDataFormatConvertor;
SCSIM_NAMESPACE_START(clib)
// clib class forward declaration
SCSIM_NAMESPACE_END()

SCSIM_NAMESPACE_START(cmod)

这段代码是 C++ 头文件的开头,通常包含了一些预处理指令、包含其他头文件、声明命名空间以及其他类的前向声明等。让我帮你理解这段代码的主要内容:

  1. #ifndef _NV_NVDLA_GLB_H_#define _NV_NVDLA_GLB_H_:这是常见的头文件保护宏,用于防止头文件被多次包含。如果 _NV_NVDLA_GLB_H_ 这个宏未被定义,就会执行下面的代码,否则跳过。

  2. #define SC_INCLUDE_DYNAMIC_PROCESSES:这是 SystemC 库的一个宏,用于启用动态进程的支持。

  3. #include <systemc.h>:引入 SystemC 头文件,这是 SystemC 仿真库的一部分。

  4. #include <tlm.h>:引入 TLM(Transaction-Level Modeling) 头文件,用于支持事务级建模。

  5. #include "tlm_utils/multi_passthrough_initiator_socket.h"#include "tlm_utils/multi_passthrough_target_socket.h":引入 TLM 工具库中的多通道穿越(multi_passthrough)初始化器和目标套接字的头文件。这些套接字是用于 TLM 模型之间通信的工具。

  6. #include "scsim_common.h":引入名为 scsim_common.h 的头文件。

  7. #include "nvdla_dma_wr_req_iface.h"#include "nvdla_xx2csb_resp_iface.h":引入两个接口的头文件,这些接口可能用于不同模块之间的通信。

  8. #include "NV_NVDLA_glb_base.h"#include "glb_reg_model.h"#include "gec_reg_model.h":引入三个类的头文件,这些类似乎是与寄存器模型和全局模型相关的。

  9. #include "NvdlaDataFormatConvertor.h":引入名为 NvdlaDataFormatConvertor 的头文件,这可能是一个用于数据格式转换的类。

  10. SCSIM_NAMESPACE_START(clib)SCSIM_NAMESPACE_END():这是一对用于定义命名空间的宏。命名空间被定义在 clib 中。

  11. SCSIM_NAMESPACE_START(cmod):这是一个用于定义命名空间的宏,命名空间被定义在 cmod 中。

这段代码主要是为了引入所需的头文件和定义命名空间,为后续的代码准备必要的依赖项和环境。

class NV_NVDLA_glb


class NV_NVDLA_glb:
    public NV_NVDLA_glb_base,   // ports
    private glb_reg_model,      // glb register accessing
    private gec_reg_model       // gec register accessing
{
    
    
    public:
        SC_HAS_PROCESS(NV_NVDLA_glb);
        NV_NVDLA_glb( sc_module_name module_name );
        ~NV_NVDLA_glb();
        // CSB request transport implementation shall in generated code
        void csb2glb_req_b_transport (int ID, NV_MSDEC_csb2xx_16m_secure_be_lvl_t* payload, sc_time& delay);
        void csb2gec_req_b_transport (int ID, NV_MSDEC_csb2xx_16m_secure_be_lvl_t* payload, sc_time& delay);

    private:
        // Variables
        bool is_there_ongoing_csb2glb_response_;
        bool is_there_ongoing_csb2gec_response_;

        // Delay
        sc_core::sc_time csb_delay_;
        sc_core::sc_time b_transport_delay_;

        // Events
        // GLB config evaluation is done
        sc_event event_glb_config_evaluation_done;

        // Function declaration 
        void UpdateBdmaIntrStatus_0();
        void UpdateBdmaIntrStatus_1();
        void UpdatePdpIntrStatus_0();
        void UpdatePdpIntrStatus_1();
        void UpdateSdpIntrStatus_0();
        void UpdateSdpIntrStatus_1();
        void UpdateCdpIntrStatus_0();
        void UpdateCdpIntrStatus_1();
        void UpdateRbkIntrStatus_0();
        void UpdateRbkIntrStatus_1();
        void UpdateCaccIntrStatus_0();
        void UpdateCaccIntrStatus_1();
        void UpdateCdmaDatIntrStatus_0();
        void UpdateCdmaDatIntrStatus_1();
        void UpdateCdmaWtIntrStatus_0();
        void UpdateCdmaWtIntrStatus_1();

        void Update_nvdla_intr_bdma_0();
        void Update_nvdla_intr_bdma_1();
        void Update_nvdla_intr_pdp_0();
        void Update_nvdla_intr_pdp_1();
        void Update_nvdla_intr_sdp_0();
        void Update_nvdla_intr_sdp_1();
        void Update_nvdla_intr_cdp_0();
        void Update_nvdla_intr_cdp_1();
        void Update_nvdla_intr_rbk_0();
        void Update_nvdla_intr_rbk_1();
        void Update_nvdla_intr_cacc_0();
        void Update_nvdla_intr_cacc_1();
        void Update_nvdla_intr_cdma_dat_0();
        void Update_nvdla_intr_cdma_dat_1();
        void Update_nvdla_intr_cdma_wt_0();
        void Update_nvdla_intr_cdma_wt_1();
        void Update_nvdla_intr_w();

        // ## Reset 
        void Reset();
        void GlbSendCsbResponse(uint8_t type, uint32_t data, uint8_t error_id);
        void GecSendCsbResponse(uint8_t type, uint32_t data, uint8_t error_id);
};

SCSIM_NAMESPACE_END()

extern "C" scsim::cmod::NV_NVDLA_glb * NV_NVDLA_glbCon(sc_module_name module_name);

#endif

这段代码定义了一个名为 NV_NVDLA_glb 的类,该类继承自 NV_NVDLA_glb_base 类,并包含了 glb_reg_modelgec_reg_model 两个私有类作为成员。这个类似乎是一个用于全局控制(Global Control)的模块,可能与 NVDLA(NVIDIA Deep Learning Accelerator)有关。

以下是这个类的主要成员和功能:

  • SC_HAS_PROCESS(NV_NVDLA_glb);:这是 SystemC 宏,用于声明该类是一个 SystemC 进程,意味着它可以包含一个或多个线程。

  • NV_NVDLA_glb(sc_module_name module_name);:构造函数,用于创建 NV_NVDLA_glb 类的实例。

  • ~NV_NVDLA_glb();:析构函数,用于释放类的资源。

  • void csb2glb_req_b_transport(int ID, NV_MSDEC_csb2xx_16m_secure_be_lvl_t* payload, sc_time& delay);void csb2gec_req_b_transport(int ID, NV_MSDEC_csb2xx_16m_secure_be_lvl_t* payload, sc_time& delay);:这两个函数用于处理 CSB(Configuration Space Bus)请求的传输,可能会用于配置模块。

  • 类的私有成员包括一些变量、延迟时间、事件和一组函数。这些函数的名称表明它们用于更新不同模块的中断状态和发送中断信号。

  • Reset():用于重置模块状态的函数。

  • GlbSendCsbResponse(uint8_t type, uint32_t data, uint8_t error_id);GecSendCsbResponse(uint8_t type, uint32_t data, uint8_t error_id);:用于发送 CSB 响应的函数。

此外,代码最后使用 extern "C" 声明了一个函数 NV_NVDLA_glbCon(sc_module_name module_name),可能是用于创建 NV_NVDLA_glb 类实例的外部函数。

总之,这个类似乎是一个用于全局控制和配置的模块,它处理 CSB 请求、更新中断状态以及发送 CSB 响应等功能。

cmod/glb/NV_NVDLA_glb.cpp

// File Name: NV_NVDLA_glb.cpp

#include <algorithm>
#include <iomanip>
#include "NV_NVDLA_glb.h"
#include "NV_NVDLA_glb_glb_gen.h"
#include "NV_NVDLA_glb_gec_gen.h"
#include "arnvdla.uh"
#include "arnvdla.h"
#include "cmacros.uh"
#include "math.h"
#include "log.h"
#define __STDC_FORMAT_MACROS
#include <inttypes.h>

//#include <stdio.h>

USING_SCSIM_NAMESPACE(cmod)
USING_SCSIM_NAMESPACE(clib)
using namespace std;
using namespace tlm;
using namespace sc_core;

这是 C++ 源代码文件 NV_NVDLA_glb.cpp 的一部分。以下是代码文件的一些主要内容:

  • #include 指令:该文件包含了一些标准 C++ 头文件以及一些自定义头文件。其中,NV_NVDLA_glb.h 是前面提到的类的声明文件,其他文件是一些可能包含有用函数和类的头文件。

  • USING_SCSIM_NAMESPACE(cmod)USING_SCSIM_NAMESPACE(clib):这些指令用于引入命名空间,以便在代码中使用命名空间中的成员而无需前缀限定符。

  • using namespace std;:这是引入标准命名空间 std 的指令,以便在代码中使用标准库中的成员而无需前缀限定符。

  • using namespace tlm;using namespace sc_core;:这两个指令用于引入 TLM(Transaction-Level Modeling)和 SystemC 的命名空间,以便在代码中使用相关的类和函数。

这些指令和声明用于在代码中引入必要的命名空间和头文件,以便使用相关的类、函数和类型。该文件的其余部分可能包含了实际的函数实现和其他代码逻辑。

NV_NVDLA_glb::NV_NVDLA_glb


NV_NVDLA_glb::NV_NVDLA_glb( sc_module_name module_name ):
    NV_NVDLA_glb_base(module_name),
    // Delay setup
    csb_delay_(SC_ZERO_TIME),
    b_transport_delay_(SC_ZERO_TIME)
{
    
    
    Reset();
    is_there_ongoing_csb2glb_response_ = false;
    is_there_ongoing_csb2gec_response_ = false;
    // SC_THREAD
    // SC_METHOD
    SC_METHOD(UpdateBdmaIntrStatus_0)
    sensitive << bdma2glb_done_intr[0];
    SC_METHOD(UpdateBdmaIntrStatus_1)
    sensitive << bdma2glb_done_intr[1];

    SC_METHOD(UpdatePdpIntrStatus_0)
    sensitive << pdp2glb_done_intr[0];
    SC_METHOD(UpdatePdpIntrStatus_1)
    sensitive << pdp2glb_done_intr[1];

    SC_METHOD(UpdateSdpIntrStatus_0)
    sensitive << sdp2glb_done_intr[0];
    SC_METHOD(UpdateSdpIntrStatus_1)
    sensitive << sdp2glb_done_intr[1];

    SC_METHOD(UpdateCdpIntrStatus_0)
    sensitive << cdp2glb_done_intr[0];
    SC_METHOD(UpdateCdpIntrStatus_1)
    sensitive << cdp2glb_done_intr[1];

    SC_METHOD(UpdateRbkIntrStatus_0)
    sensitive << rbk2glb_done_intr[0];

    SC_METHOD(UpdateRbkIntrStatus_1)
    sensitive << rbk2glb_done_intr[1];

    SC_METHOD(UpdateCdmaDatIntrStatus_0)
    sensitive << cdma_dat2glb_done_intr[0];

    SC_METHOD(UpdateCdmaDatIntrStatus_1)
    sensitive << cdma_dat2glb_done_intr[1];

    SC_METHOD(UpdateCdmaWtIntrStatus_0)
    sensitive << cdma_wt2glb_done_intr[0];

    SC_METHOD(UpdateCdmaWtIntrStatus_1)
    sensitive << cdma_wt2glb_done_intr[1];

    SC_METHOD(UpdateCaccIntrStatus_0)
    sensitive << cacc2glb_done_intr[0];

    SC_METHOD(UpdateCaccIntrStatus_1)
    sensitive << cacc2glb_done_intr[1];

    SC_METHOD(Update_nvdla_intr_bdma_0)
    sensitive << bdma2glb_done_intr[0];

    SC_METHOD(Update_nvdla_intr_bdma_1)
    sensitive << bdma2glb_done_intr[1];

    SC_METHOD(Update_nvdla_intr_pdp_0)
    sensitive << pdp2glb_done_intr[0];

    SC_METHOD(Update_nvdla_intr_pdp_1)
    sensitive << pdp2glb_done_intr[1];

    SC_METHOD(Update_nvdla_intr_sdp_0)
    sensitive << sdp2glb_done_intr[0];

    SC_METHOD(Update_nvdla_intr_sdp_1)
    sensitive << sdp2glb_done_intr[1];

    SC_METHOD(Update_nvdla_intr_cdp_0)
    sensitive << cdp2glb_done_intr[0];

    SC_METHOD(Update_nvdla_intr_cdp_1)
    sensitive << cdp2glb_done_intr[1];

    SC_METHOD(Update_nvdla_intr_rbk_0)
    sensitive << rbk2glb_done_intr[0];

    SC_METHOD(Update_nvdla_intr_rbk_1)
    sensitive << rbk2glb_done_intr[1];

    SC_METHOD(Update_nvdla_intr_cdma_dat_0)
    sensitive << cdma_dat2glb_done_intr[0];

    SC_METHOD(Update_nvdla_intr_cdma_dat_1)
    sensitive << cdma_dat2glb_done_intr[1];

    SC_METHOD(Update_nvdla_intr_cdma_wt_0)
    sensitive << cdma_wt2glb_done_intr[0];

    SC_METHOD(Update_nvdla_intr_cdma_wt_1)
    sensitive << cdma_wt2glb_done_intr[1];

    SC_METHOD(Update_nvdla_intr_cacc_0)
    sensitive << cacc2glb_done_intr[0];

    SC_METHOD(Update_nvdla_intr_cacc_1)
    sensitive << cacc2glb_done_intr[1];

    // Response to reg write to glb_status
    SC_METHOD(Update_nvdla_intr_w)
    sensitive << glb_reg_model::intr_status_w;
    dont_initialize();
}

这段代码是 NV_NVDLA_glb 类的构造函数的定义部分。构造函数用于初始化类的成员变量和其他属性。以下是代码的主要内容:

  • 构造函数签名:NV_NVDLA_glb::NV_NVDLA_glb(sc_module_name module_name),表示构造函数的名称和参数。

  • 初始化列表:构造函数使用初始化列表来初始化类的基类(NV_NVDLA_glb_base)和成员变量(csb_delay_b_transport_delay_)。这些成员变量在类的私有部分声明中定义。

  • Reset() 函数:在构造函数中调用 Reset() 函数,用于初始化对象的内部状态。

  • 布尔变量的初始化:初始化了两个布尔型成员变量 is_there_ongoing_csb2glb_response_is_there_ongoing_csb2gec_response_,并将它们都设置为 false

  • 多个 SC_METHOD:构造函数中定义了多个 SystemC 方法(SC_METHOD),这些方法用于响应不同的事件或信号变化。每个方法都与特定的故障(如 bdma2glb_done_intr[0])或信号相关联,当这些信号发生变化时,相关的方法将被调用。

  • dont_initialize()Update_nvdla_intr_w 方法使用 dont_initialize() 方法来指示 SystemC 不要在仿真开始时立即执行该方法,而是等待信号触发后再执行。

这些方法和事件处理程序用于管理和更新类的内部状态,以及响应外部事件。构造函数的目的是初始化对象的状态和配置,以便对象可以正确地执行其功能。

猜你喜欢

转载自blog.csdn.net/lincolnjunior_lj/article/details/134994026