Skip to content

Commit 4bf1487

Browse files
Merge pull request #10 from pulp-platform/commit-and-trigger
Introduce separate COMMIT & TRIGGER mechanism
2 parents 0336a85 + 7b28079 commit 4bf1487

File tree

2 files changed

+50
-40
lines changed

2 files changed

+50
-40
lines changed

rtl/hwpe_ctrl_package.sv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ package hwpe_ctrl_package;
7373
logic is_critical;
7474
logic is_testset;
7575
logic is_trigger;
76+
logic is_commit;
7677
logic is_working;
7778
logic [$clog2(REGFILE_N_CONTEXT)-1:0] pointer_context;
7879
logic [$clog2(REGFILE_N_CONTEXT)-1:0] running_context;

rtl/hwpe_ctrl_slave.sv

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ module hwpe_ctrl_slave
5151
regfile_in_t regfile_in;
5252
regfile_out_t regfile_out;
5353

54-
enum logic [1:0] {idle, running, starting} running_state;
55-
enum logic {idle_c, trigger} context_state;
54+
enum logic [1:0] {RUN_IDLE, RUN_RUN, RUN_STARTING} running_state;
55+
enum logic {CXT_IDLE, CXT_PROGRAM} context_state;
5656

5757
flags_regfile_t regfile_flags;
5858

@@ -66,6 +66,8 @@ module hwpe_ctrl_slave
6666
logic [1:0] s_clear_regfile;
6767
logic clear_regfile;
6868

69+
logic triggered_q;
70+
6971
always_ff @(posedge clk_i or negedge rst_ni)
7072
begin
7173
if(rst_ni == 1'b0)
@@ -77,6 +79,21 @@ module hwpe_ctrl_slave
7779
end
7880
end
7981

82+
always_ff @(posedge clk_i or negedge rst_ni)
83+
begin
84+
if(rst_ni == 1'b0)
85+
triggered_q <= '0;
86+
else if(clear_o) begin
87+
triggered_q <= '0;
88+
end
89+
else if(regfile_flags.is_trigger) begin
90+
triggered_q <= '1;
91+
end
92+
else if(running_context == pointer_context && regfile_flags.full_context == '0 && regfile_flags.true_done == 1) begin
93+
triggered_q <= '0;
94+
end
95+
end
96+
8097
assign flags_o.done = regfile_flags.true_done;
8198

8299
generate
@@ -92,7 +109,7 @@ module hwpe_ctrl_slave
92109
end
93110
else
94111
begin
95-
if (regfile_flags.is_trigger == 1)
112+
if (regfile_flags.is_commit == 1)
96113
begin
97114
for(int i=0; i<N_CORES; i++)
98115
if (cfg.id[i] == 1'b1)
@@ -109,7 +126,7 @@ module hwpe_ctrl_slave
109126
else if(clear_o == 1'b1)
110127
pointer_context <= 0;
111128
else begin
112-
if (regfile_flags.is_trigger == 1)
129+
if (regfile_flags.is_commit == 1)
113130
pointer_context <= pointer_context + 1;
114131
end
115132
end
@@ -133,9 +150,9 @@ module hwpe_ctrl_slave
133150
else if(clear_o == 1'b1)
134151
counter_pending <= 0;
135152
else begin
136-
if ((regfile_flags.is_trigger == 1) && (regfile_flags.true_done == 0))
153+
if ((regfile_flags.is_commit == 1) && (regfile_flags.true_done == 0))
137154
counter_pending <= counter_pending + 1;
138-
else if ((regfile_flags.is_trigger == 0) && (regfile_flags.true_done == 1))
155+
else if ((regfile_flags.is_commit == 0) && (regfile_flags.true_done == 1))
139156
counter_pending <= counter_pending - 1;
140157
end
141158
end
@@ -154,7 +171,7 @@ module hwpe_ctrl_slave
154171
end
155172
else
156173
begin
157-
if (regfile_flags.is_trigger == 1)
174+
if (regfile_flags.is_commit == 1)
158175
begin
159176
for(int i=0; i<N_CORES; i++)
160177
if (cfg.id[i] == 1'b1)
@@ -163,7 +180,7 @@ module hwpe_ctrl_slave
163180
end
164181
end
165182

166-
assign pointer_context = regfile_flags.is_trigger;
183+
assign pointer_context = regfile_flags.is_commit;
167184
assign running_context = 'b0;
168185
assign counter_pending = (flags_o.is_working==1'b1) ? 1 : 'b0;
169186
assign regfile_flags.full_context = flags_o.is_working;
@@ -178,7 +195,8 @@ module hwpe_ctrl_slave
178195
regfile_flags.is_contexted = (cfg.add[LOG_REGS+2-1:2] > N_MANDATORY_REGS+N_RESERVED_REGS+N_MAX_GENERIC_REGS-1) ? 1 : 0; // Accessed reg is contexted
179196
regfile_flags.is_read = (cfg.req == 1'b1 && cfg.wen == 1'b1);
180197
regfile_flags.is_testset = (cfg.req == 1'b1 && cfg.wen == 1'b1 && cfg.add[LOG_REGS+2-1:2] == REGFILE_MANDATORY_ACQUIRE) ? 1 : 0; // Operation is a test&set to register context_ts
181-
regfile_flags.is_trigger = (cfg.req == 1'b1 && cfg.wen == 1'b0 && cfg.add[LOG_REGS+2-1:2] == REGFILE_MANDATORY_TRIGGER) ? 1 : 0; // Operation is a trigger
198+
regfile_flags.is_trigger = (cfg.req == 1'b1 && cfg.wen == 1'b0 && cfg.add[LOG_REGS+2-1:2] == REGFILE_MANDATORY_TRIGGER && cfg.data == '0) ? 1 : 0; // Operation is a trigger
199+
regfile_flags.is_commit = (cfg.req == 1'b1 && cfg.wen == 1'b0 && cfg.add[LOG_REGS+2-1:2] == REGFILE_MANDATORY_TRIGGER) ? 1 : 0; // Operation is a commit (or commit & trigger)
182200
regfile_flags.true_done = ctrl_i.done & flags_o.is_working; // This is necessary because sometimes done is asserted as soon as rst_ni becomes 1
183201
flags_o.enable = s_enable_after[3]; // Enable after three cycles from rst_ni
184202
end
@@ -238,15 +256,6 @@ module hwpe_ctrl_slave
238256

239257
assign cfg.r_data = regfile_out.rdata;
240258

241-
logic start_context;
242-
generate
243-
if(N_CONTEXT>1)
244-
assign start_context = (running_context==pointer_context && regfile_flags.full_context==0) ? 1 : 0;
245-
else
246-
assign start_context = (regfile_flags.is_trigger==1 && flags_o.is_working==0) ? 1 : 0;
247-
248-
endgenerate
249-
250259
// Extension read and write enable, accessing ID LSB
251260
logic ext_access;
252261
logic [4:0] ext_id_n;
@@ -287,49 +296,49 @@ module hwpe_ctrl_slave
287296
always_ff @(posedge clk_i or negedge rst_ni)
288297
begin : fsm_running
289298
if (rst_ni==0) begin
290-
running_state <= idle;
299+
running_state <= RUN_IDLE;
291300
flags_o.start <= 0;
292301
flags_o.is_working <= 0;
293302
end
294303
else if(clear_o == 1'b1) begin
295-
running_state <= idle;
304+
running_state <= RUN_IDLE;
296305
flags_o.start <= 0;
297306
flags_o.is_working <= 0;
298307
end
299308
else begin
300309
case (running_state)
301-
idle : begin
310+
RUN_IDLE : begin
302311
if (running_context == pointer_context && regfile_flags.full_context == 0) begin
303-
running_state <= idle;
312+
running_state <= RUN_IDLE;
304313
flags_o.start <= 0;
305314
flags_o.is_working <= 0;
306315
end
307-
else begin
308-
running_state <= starting;
316+
else if(regfile_flags.is_trigger | triggered_q) begin
317+
running_state <= RUN_STARTING;
309318
flags_o.start <= 0;
310319
flags_o.is_working <= 1;
311320
end
312321
end
313-
starting : begin
314-
// just to separate idle and running by an additional cycle
315-
running_state <= running;
322+
RUN_STARTING : begin
323+
// just to separate RUN_IDLE and running by an additional cycle
324+
running_state <= RUN_RUN;
316325
flags_o.start <= 1;
317326
flags_o.is_working <= 1;
318327
end
319-
running : begin
328+
RUN_RUN : begin
320329
if (regfile_flags.true_done == 1) begin
321-
running_state <= idle;
330+
running_state <= RUN_IDLE;
322331
flags_o.start <= 0;
323332
flags_o.is_working <= 0;
324333
end
325334
else begin
326-
running_state <= running;
335+
running_state <= RUN_RUN;
327336
flags_o.start <= 0;
328337
flags_o.is_working <= 1;
329338
end
330339
end
331340
default : begin
332-
running_state <= idle;
341+
running_state <= RUN_IDLE;
333342
flags_o.start <= 0;
334343
flags_o.is_working <= 0;
335344
end
@@ -342,32 +351,32 @@ module hwpe_ctrl_slave
342351
begin : fsm_context
343352
if (rst_ni==0) begin
344353
regfile_flags.is_critical <= 0;
345-
context_state <= idle_c;
354+
context_state <= CXT_IDLE;
346355
end
347356
else if(clear_o == 1'b1) begin
348357
regfile_flags.is_critical <= 0;
349-
context_state <= idle_c;
358+
context_state <= CXT_IDLE;
350359
end
351360
else begin
352361
case (context_state)
353-
idle_c : begin
362+
CXT_IDLE : begin
354363
if (regfile_flags.is_testset == 1 && regfile_flags.full_context==0) begin
355364
regfile_flags.is_critical <= 1;
356-
context_state <= trigger;
365+
context_state <= CXT_PROGRAM;
357366
end
358367
else begin
359368
regfile_flags.is_critical <= 0;
360-
context_state <= idle_c;
369+
context_state <= CXT_IDLE;
361370
end
362371
end
363-
trigger : begin
364-
if (regfile_flags.is_trigger == 1) begin
372+
CXT_PROGRAM : begin
373+
if (regfile_flags.is_commit == 1) begin
365374
regfile_flags.is_critical <= 0;
366-
context_state <= idle_c;
375+
context_state <= CXT_IDLE;
367376
end
368377
else begin
369378
regfile_flags.is_critical <= 1;
370-
context_state <= trigger;
379+
context_state <= CXT_PROGRAM;
371380
end
372381
end
373382
endcase

0 commit comments

Comments
 (0)