@@ -356,12 +356,23 @@ pub struct ComparatorAddressSettings {
356
356
pub access_type : AccessType ,
357
357
}
358
358
359
+ /// Settings for cycle count matching
360
+ #[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
361
+ pub struct CycleCountSettings {
362
+ /// The cycle count value to compare against.
363
+ pub compare : u32 ,
364
+ /// The cycle count mask value to use.
365
+ pub mask : u32 ,
366
+ }
367
+
359
368
/// The available functions of a DWT comparator.
360
369
#[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
361
370
#[ non_exhaustive]
362
371
pub enum ComparatorFunction {
363
372
/// Compare accessed memory addresses.
364
373
Address ( ComparatorAddressSettings ) ,
374
+ /// Compare cycle count & target value.
375
+ CycleCount ( CycleCountSettings ) ,
365
376
}
366
377
367
378
/// Possible error values returned on [Comparator::configure].
@@ -376,8 +387,8 @@ impl Comparator {
376
387
/// Configure the function of the comparator
377
388
#[ allow( clippy:: missing_inline_in_public_items) ]
378
389
pub fn configure ( & self , settings : ComparatorFunction ) -> Result < ( ) , DwtError > {
379
- match settings {
380
- ComparatorFunction :: Address ( settings) => unsafe {
390
+ let ( func , emit , data_match , cyc_match , comp , mask ) = match settings {
391
+ ComparatorFunction :: Address ( settings) => {
381
392
// FUNCTION, EMITRANGE
382
393
// See Table C1-14
383
394
let ( function, emit_range) = match ( & settings. access_type , & settings. emit ) {
@@ -400,25 +411,50 @@ impl Comparator {
400
411
( _, EmitOption :: PC ) => return Err ( DwtError :: InvalidFunction ) ,
401
412
} ;
402
413
403
- self . function . modify ( |mut r| {
404
- r. set_function ( function) ;
405
- r. set_emitrange ( emit_range) ;
406
-
414
+ (
415
+ function,
416
+ emit_range,
407
417
// don't compare data value
408
- r. set_datavmatch ( false ) ;
409
-
418
+ false ,
410
419
// don't compare cycle counter value
411
420
// NOTE: only needed for comparator 0, but is SBZP.
412
- r. set_cycmatch ( false ) ;
421
+ false ,
422
+ settings. address ,
423
+ settings. mask ,
424
+ )
425
+ }
426
+ ComparatorFunction :: CycleCount ( settings) => {
427
+ (
428
+ // emit a Debug Watchpoint event, either halting execution or
429
+ // firing a `DebugMonitor` exception
430
+ 0b0111 ,
431
+ // don't emit (we're going to fire an exception not trace)
432
+ false ,
433
+ // don't compare data
434
+ false ,
435
+ // compare cyccnt
436
+ true ,
437
+ settings. compare ,
438
+ settings. mask ,
439
+ )
440
+ }
441
+ } ;
413
442
414
- r
415
- } ) ;
443
+ unsafe {
444
+ self . function . modify ( |mut r| {
445
+ r. set_function ( func) ;
446
+ r. set_emitrange ( emit) ;
447
+ r. set_datavmatch ( data_match) ;
416
448
417
- self . comp . write ( settings. address ) ;
418
- self . mask . write ( settings. mask ) ;
419
- } ,
420
- }
449
+ // NOTE: only valid for comparator 0, but is SBZP.
450
+ r. set_cycmatch ( cyc_match) ;
451
+
452
+ r
453
+ } ) ;
421
454
455
+ self . comp . write ( comp) ;
456
+ self . mask . write ( mask) ;
457
+ }
422
458
Ok ( ( ) )
423
459
}
424
460
}
0 commit comments