{#- Power Management Integration Template -#}
{#- Integration code for the pmcsr_stub power management module -#}

    // ── Power Management Integration ─────────────────────────────────────────
    
    // PMCSR (Power Management Control/Status Register) signals
    logic        pmcsr_wr;
    logic [15:0] pmcsr_wdata;
    logic [15:0] pmcsr_rdata;
{%- if enable_wake_events %}
    logic        wake_evt;
{%- endif %}
{%- if enable_pme %}
    logic        pme_req;
{%- endif %}
    
    // Instantiate minimal power management stub
    pmcsr_stub #(
        .CLK_HZ({{ clk_hz }}),
        .TR_NS({{ tr_ns }})
    ) u_pmcsr_stub (
        .clk(clk),
        .reset_n(reset_n),
        .pmcsr_wr(pmcsr_wr),
        .pmcsr_wdata(pmcsr_wdata),
        .pmcsr_rdata(pmcsr_rdata),
{%- if enable_wake_events %}
        .wake_evt(wake_evt),
{%- else %}
        .wake_evt(1'b0),
{%- endif %}
{%- if enable_pme %}
        .pme_req(pme_req)
{%- else %}
        .pme_req()  // Leave unconnected if PME disabled
{%- endif %}
    );
    
    // Connect PMCSR to config space at offset 0x44
    always_comb begin
        pmcsr_wr = cfg_wr_en && (cfg_addr[7:0] == 8'h44);
        pmcsr_wdata = cfg_wr_data[15:0];
        
{%- if enable_wake_events %}
        // Wake event can be triggered by external signals or internal logic
        wake_evt = 1'b0;  // Connect to actual wake sources as needed
{%- endif %}
    end
    
    // Integrate PMCSR read data into config space
    always_comb begin
        if (cfg_addr[7:0] == 8'h44) begin
            cfg_rd_data[15:0] = pmcsr_rdata;
            cfg_rd_data[31:16] = 16'h0;  // Upper 16 bits reserved
        end
    end