@@ -318,15 +318,15 @@ impl DWT {
318318/// Whether the comparator should match on read, write or read/write operations.
319319#[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
320320pub enum AccessType {
321- /// Generate packet only when matched adress is read from.
321+ /// Generate packet only when matched address is read from.
322322 ReadOnly ,
323- /// Generate packet only when matched adress is written to.
323+ /// Generate packet only when matched address is written to.
324324 WriteOnly ,
325- /// Generate packet when matched adress is both read from and written to.
325+ /// Generate packet when matched address is both read from and written to.
326326 ReadWrite ,
327327}
328328
329- /// The sequence of packet(s) that should be emitted on comparator match.
329+ /// The sequence of packet(s) or events that should be emitted/generated on comparator match.
330330#[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
331331pub enum EmitOption {
332332 /// Emit only trace data value packet.
@@ -341,6 +341,15 @@ pub enum EmitOption {
341341 AddressData ,
342342 /// Emit trace PC value and data value packets.
343343 PCData ,
344+ /// Generate a watchpoint debug event.
345+ ///
346+ /// either halts execution or fires a `DebugMonitor` exception.
347+ /// See more in section "Watchpoint debug event generation" page C1-729
348+ WatchpointDebugEvent ,
349+ /// Generate a `CMPMATCH[N]` event.
350+ ///
351+ /// See more in section "CMPMATCH[N] event generation" page C1-730
352+ CompareMatchEvent ,
344353}
345354
346355/// Settings for address matching
@@ -359,6 +368,9 @@ pub struct ComparatorAddressSettings {
359368/// Settings for cycle count matching
360369#[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
361370pub struct CycleCountSettings {
371+ /// The function selection used.
372+ /// See Table C1-15 DWT cycle count comparison functions
373+ pub emit : EmitOption ,
362374 /// The cycle count value to compare against.
363375 pub compare : u32 ,
364376 /// The cycle count mask value to use.
@@ -396,16 +408,22 @@ impl Comparator {
396408 ( AccessType :: ReadOnly , EmitOption :: Address ) => ( 0b1100 , true ) ,
397409 ( AccessType :: ReadOnly , EmitOption :: AddressData ) => ( 0b1110 , true ) ,
398410 ( AccessType :: ReadOnly , EmitOption :: PCData ) => ( 0b1110 , false ) ,
411+ ( AccessType :: ReadOnly , EmitOption :: WatchpointDebugEvent ) => ( 0b0101 , false ) ,
412+ ( AccessType :: ReadOnly , EmitOption :: CompareMatchEvent ) => ( 0b1001 , false ) ,
399413
400414 ( AccessType :: WriteOnly , EmitOption :: Data ) => ( 0b1101 , false ) ,
401415 ( AccessType :: WriteOnly , EmitOption :: Address ) => ( 0b1101 , true ) ,
402416 ( AccessType :: WriteOnly , EmitOption :: AddressData ) => ( 0b1111 , true ) ,
403417 ( AccessType :: WriteOnly , EmitOption :: PCData ) => ( 0b1111 , false ) ,
418+ ( AccessType :: WriteOnly , EmitOption :: WatchpointDebugEvent ) => ( 0b0110 , false ) ,
419+ ( AccessType :: WriteOnly , EmitOption :: CompareMatchEvent ) => ( 0b1010 , false ) ,
404420
405421 ( AccessType :: ReadWrite , EmitOption :: Data ) => ( 0b0010 , false ) ,
406422 ( AccessType :: ReadWrite , EmitOption :: Address ) => ( 0b0001 , true ) ,
407423 ( AccessType :: ReadWrite , EmitOption :: AddressData ) => ( 0b0010 , true ) ,
408424 ( AccessType :: ReadWrite , EmitOption :: PCData ) => ( 0b0011 , false ) ,
425+ ( AccessType :: ReadWrite , EmitOption :: WatchpointDebugEvent ) => ( 0b0111 , false ) ,
426+ ( AccessType :: ReadWrite , EmitOption :: CompareMatchEvent ) => ( 0b1011 , false ) ,
409427
410428 ( AccessType :: ReadWrite , EmitOption :: PC ) => ( 0b0001 , false ) ,
411429 ( _, EmitOption :: PC ) => return Err ( DwtError :: InvalidFunction ) ,
@@ -429,12 +447,16 @@ impl Comparator {
429447 }
430448 }
431449 ComparatorFunction :: CycleCount ( settings) => {
450+ let function = match & settings. emit {
451+ EmitOption :: PCData => 0b0001 ,
452+ EmitOption :: WatchpointDebugEvent => 0b0100 ,
453+ EmitOption :: CompareMatchEvent => 0b1000 ,
454+ _ => return Err ( DwtError :: InvalidFunction ) ,
455+ } ;
456+
432457 unsafe {
433458 self . function . modify ( |mut r| {
434- // emit a Debug Watchpoint event, either halting execution or
435- // firing a `DebugMonitor` exception
436- // See Table C1-15 DWT cycle count comparison functions
437- r. set_function ( 0b0100 ) ;
459+ r. set_function ( function) ;
438460 // emit_range is N/A for cycle count compare
439461 r. set_emitrange ( false ) ;
440462 // don't compare data
0 commit comments