@@ -43,8 +43,7 @@ entity AxiStreamRingBuffer is
43
43
dataRst : in sl := '0' ;
44
44
dataValid : in sl := '1' ;
45
45
dataValue : in slv(8 * DATA_BYTES_G- 1 downto 0 );
46
- bufferEnable : in sl := '0' ;
47
- bufferClear : in sl := '0' ;
46
+ extTrig : in sl := '0' ;
48
47
-- AXI-Lite interface (axilClk domain)
49
48
axilClk : in sl;
50
49
axilRst : in sl;
@@ -73,6 +72,8 @@ architecture rtl of AxiStreamRingBuffer is
73
72
-- Stream clock domain signals
74
73
-- ----------------------------
75
74
type DataRegType is record
75
+ extTrig : sl;
76
+ bufferEnable : sl;
76
77
enable : sl;
77
78
cleared : sl;
78
79
armed : sl;
@@ -85,6 +86,8 @@ architecture rtl of AxiStreamRingBuffer is
85
86
end record ;
86
87
87
88
constant DATA_REG_INIT_C : DataRegType := (
89
+ extTrig => '0' ,
90
+ bufferEnable => '0' ,
88
91
enable => '0' ,
89
92
cleared => '1' , -- Only set HIGH after reset
90
93
armed => '0' ,
@@ -153,11 +156,9 @@ architecture rtl of AxiStreamRingBuffer is
153
156
signal firstAddr : slv(RAM_ADDR_WIDTH_G- 1 downto 0 );
154
157
signal bufferLength : slv(RAM_ADDR_WIDTH_G- 1 downto 0 );
155
158
156
- signal extBufferEnable : sl;
157
- signal extBufferClear : sl;
158
- signal readReq : sl;
159
- signal cleared : sl;
160
- signal armed : sl;
159
+ signal readReq : sl;
160
+ signal cleared : sl;
161
+ signal armed : sl;
161
162
162
163
signal txSlave : AxiStreamSlaveType;
163
164
@@ -232,23 +233,30 @@ begin
232
233
-- ------------------------------------------------
233
234
-- Synchronize AXI registers to data clock dataClk
234
235
-- ------------------------------------------------
235
- U_SyncVec_dataClk : entity surf .SynchronizerVector
236
+ U_bufferEnable : entity surf .Synchronizer
236
237
generic map (
237
- TPD_G => TPD_G,
238
- WIDTH_G => 2 )
238
+ TPD_G => TPD_G)
239
+ port map (
240
+ clk => dataClk,
241
+ rst => dataRst,
242
+ dataIn => axilR.bufferEnable,
243
+ dataOut => bufferEnableSync);
244
+
245
+ U_bufferClear : entity surf .SynchronizerOneShot
246
+ generic map (
247
+ TPD_G => TPD_G,
248
+ PULSE_WIDTH_G => 10 )
239
249
port map (
240
- clk => dataClk,
241
- rst => dataRst,
242
- dataIn(0 ) => axilR.bufferEnable,
243
- dataIn(1 ) => axilR.bufferClear,
244
- dataOut(0 ) => bufferEnableSync,
245
- dataOut(1 ) => bufferClearSync);
250
+ clk => dataClk,
251
+ rst => dataRst,
252
+ dataIn => axilR.bufferClear,
253
+ dataOut => bufferClearSync);
246
254
247
255
-- ------------------------
248
256
-- Main AXI-Stream process
249
257
-- ------------------------
250
- dataComb : process (bufferClear, bufferClearSync, bufferEnable ,
251
- bufferEnableSync, dataR, dataRst, dataValid, dataValue) is
258
+ dataComb : process (bufferClearSync, bufferEnableSync, dataR, dataRst ,
259
+ dataValid, dataValue, extTrig ) is
252
260
variable v : DataRegType;
253
261
begin
254
262
-- Latch the current value
@@ -259,9 +267,15 @@ begin
259
267
v.readReq := '0' ;
260
268
v.cleared := '0' ;
261
269
270
+ -- Check for external trigger
271
+ if (extTrig = '1' ) and (dataR.extTrig = '0' ) then
272
+ v.extTrig := '1' ;
273
+ v.bufferEnable := '1' ;
274
+ end if ;
275
+
262
276
-- Default assignment
263
277
v.ramWrData := dataValue;
264
- v.enable := bufferEnableSync or bufferEnable;
278
+ v.enable := bufferEnableSync or dataR. bufferEnable;
265
279
266
280
-- Increment the addresses on each valid if logging enabled
267
281
if (dataValid = '1' ) and (dataR.enable = '1' ) then
@@ -272,8 +286,9 @@ begin
272
286
v.nextAddr := dataR.nextAddr + 1 ;
273
287
-- Check if the write pointer = read pointer
274
288
if (v.nextAddr = dataR.firstAddr) then
275
- v.firstAddr := dataR.firstAddr + 1 ;
276
- v.armed := '1' ;
289
+ v.firstAddr := dataR.firstAddr + 1 ;
290
+ v.armed := '1' ;
291
+ v.bufferEnable := '0' ;
277
292
end if ;
278
293
-- Calculate the length of the buffer
279
294
v.bufferLength := dataR.nextAddr - dataR.firstAddr;
@@ -285,7 +300,7 @@ begin
285
300
end if ;
286
301
287
302
-- Synchronous Reset
288
- if (dataRst = '1' ) or (bufferClearSync = '1' ) or (bufferClear = '1' ) then
303
+ if (dataRst = '1' ) or (bufferClearSync = '1' ) then
289
304
v := DATA_REG_INIT_C;
290
305
end if ;
291
306
@@ -328,31 +343,30 @@ begin
328
343
U_SyncVec_axilClk : entity surf .SynchronizerVector
329
344
generic map (
330
345
TPD_G => TPD_G,
331
- WIDTH_G => 4 )
346
+ WIDTH_G => 2 )
332
347
port map (
333
348
clk => axilClk,
334
349
rst => axilRst,
335
- dataIn(0 ) => bufferEnable,
336
- dataIn(1 ) => bufferClear,
337
- dataIn(2 ) => dataR.cleared,
338
- dataIn(3 ) => dataR.armed,
339
- dataOut(0 ) => extBufferEnable,
340
- dataOut(1 ) => extbufferClear,
341
- dataOut(2 ) => cleared,
342
- dataOut(3 ) => armed);
350
+ dataIn(0 ) => dataR.cleared,
351
+ dataIn(1 ) => dataR.armed,
352
+ dataOut(0 ) => cleared,
353
+ dataOut(1 ) => armed);
343
354
344
355
-- ----------------------
345
356
-- Main AXI-Lite process
346
357
-- ----------------------
347
358
axiComb : process (armed, axilR, axilReadMaster, axilRst, axilWriteMaster,
348
- bufferLength, cleared, extBufferClear, extBufferEnable ,
349
- firstAddr, ramRdData, readReq, txSlave) is
359
+ bufferLength, cleared, firstAddr, ramRdData, readReq ,
360
+ txSlave) is
350
361
variable v : AxilRegType;
351
362
variable axilEp : AxiLiteEndpointType;
352
363
begin
353
364
-- Latch the current value
354
365
v := axilR;
355
366
367
+ -- Reset strobe
368
+ v.bufferClear := '0' ;
369
+
356
370
-- ----------------------
357
371
-- AXI-Lite Transactions
358
372
-- ----------------------
@@ -362,10 +376,7 @@ begin
362
376
363
377
axiSlaveRegisterR(axilEp, x"0" , 0 , bufferLength);
364
378
axiSlaveRegisterR(axilEp, x"0" , 20 , toSlv(RAM_ADDR_WIDTH_G, 8 ));
365
- axiSlaveRegisterR(axilEp, x"0" , 28 , extBufferClear);
366
- axiSlaveRegisterR(axilEp, x"0" , 29 , extBufferEnable);
367
379
axiSlaveRegisterR(axilEp, x"4" , 0 , axilR.trigCnt);
368
-
369
380
axiSlaveRegister (axilEp, x"8" , 0 , v.trigCnt);
370
381
axiSlaveRegister (axilEp, x"C" , 0 , v.continuous);
371
382
@@ -380,10 +391,10 @@ begin
380
391
-- --------------------------------------------------------------------
381
392
when IDLE_S =>
382
393
-- Check for trigger request
383
- if (axilR.trigCnt /= 0 ) or (axilR.continuous = '1' ) then
394
+ if (( axilR.trigCnt /= 0 ) or (axilR.continuous = '1' )) and (axilR.dataState = IDLE_S ) then
384
395
-- Set the flags
385
- v.bufferClear := '1' ;
386
396
v.bufferEnable := '1' ;
397
+ v.bufferClear := '1' ;
387
398
-- Check if we need to decrement the counter
388
399
if (axilR.trigCnt /= 0 ) then
389
400
-- Decrement the counter
@@ -392,16 +403,14 @@ begin
392
403
-- Next state
393
404
v.trigState := CLEAR_S;
394
405
else
395
- -- Reset the flags
396
- v.bufferClear := '0' ;
406
+ -- Reset the flag
397
407
v.bufferEnable := '0' ;
398
408
end if ;
399
409
-- --------------------------------------------------------------------
400
410
when CLEAR_S =>
401
411
-- Check if cleared
402
412
if (cleared = '1' ) then
403
- -- Set the flags
404
- v.bufferClear := '0' ;
413
+ -- Set the flag
405
414
v.bufferEnable := '1' ;
406
415
-- Next state
407
416
v.trigState := ARMED_S;
@@ -410,16 +419,14 @@ begin
410
419
when ARMED_S =>
411
420
-- Check if armed
412
421
if (armed = '1' ) then
413
- -- Set the flags
414
- v.bufferClear := '0' ;
422
+ -- Set the flag
415
423
v.bufferEnable := '0' ;
416
424
-- Next state
417
425
v.trigState := WAIT_S;
418
426
end if ;
419
427
-- --------------------------------------------------------------------
420
428
when WAIT_S =>
421
- -- Set the flags
422
- v.bufferClear := '0' ;
429
+ -- Set the flag
423
430
v.bufferEnable := '0' ;
424
431
-- --------------------------------------------------------------------
425
432
end case ;
@@ -474,6 +481,9 @@ begin
474
481
-- Set the EOF bit
475
482
v.txMaster.tLast := '1' ;
476
483
484
+ -- Set the clear flag
485
+ v.bufferClear := '1' ;
486
+
477
487
-- Next states
478
488
v.dataState := IDLE_S;
479
489
v.trigState := IDLE_S;
0 commit comments