@@ -364,43 +364,39 @@ impl Comparator {
364
364
pub fn configure ( & self , settings : ComparatorFunction ) -> Result < ( ) , DwtError > {
365
365
match settings {
366
366
ComparatorFunction :: Address ( settings) => unsafe {
367
- if settings. emit == EmitOption :: PC && settings. access_type != AccessType :: ReadWrite
368
- {
369
- return Err ( DWTError :: InvalidFunction ) ;
370
- }
367
+ // FUNCTION, EMITRANGE
368
+ // See Table C1-14
369
+ let ( function, emit_range) = match ( & settings. access_type , & settings. emit ) {
370
+ ( AccessType :: ReadOnly , EmitOption :: Data ) => ( 0b1100 , false ) ,
371
+ ( AccessType :: ReadOnly , EmitOption :: Address ) => ( 0b1100 , true ) ,
372
+ ( AccessType :: ReadOnly , EmitOption :: AddressData ) => ( 0b1110 , true ) ,
373
+ ( AccessType :: ReadOnly , EmitOption :: PCData ) => ( 0b1110 , false ) ,
374
+
375
+ ( AccessType :: WriteOnly , EmitOption :: Data ) => ( 0b1101 , false ) ,
376
+ ( AccessType :: WriteOnly , EmitOption :: Address ) => ( 0b1101 , true ) ,
377
+ ( AccessType :: WriteOnly , EmitOption :: AddressData ) => ( 0b1111 , true ) ,
378
+ ( AccessType :: WriteOnly , EmitOption :: PCData ) => ( 0b1111 , false ) ,
379
+
380
+ ( AccessType :: ReadWrite , EmitOption :: Data ) => ( 0b0010 , false ) ,
381
+ ( AccessType :: ReadWrite , EmitOption :: Address ) => ( 0b0001 , true ) ,
382
+ ( AccessType :: ReadWrite , EmitOption :: AddressData ) => ( 0b0010 , true ) ,
383
+ ( AccessType :: ReadWrite , EmitOption :: PCData ) => ( 0b0011 , false ) ,
384
+
385
+ ( AccessType :: ReadWrite , EmitOption :: PC ) => ( 0b0001 , false ) ,
386
+ ( _, EmitOption :: PC ) => return Err ( DWTError :: InvalidFunction ) ,
387
+ } ;
371
388
372
389
self . function . modify ( |mut r| {
390
+ r. set_function ( function) ;
391
+ r. set_emitrange ( emit_range) ;
392
+
373
393
// don't compare data value
374
394
r. set_datavmatch ( false ) ;
375
395
376
396
// don't compare cycle counter value
377
397
// NOTE: only needed for comparator 0, but is SBZP.
378
398
r. set_cycmatch ( false ) ;
379
399
380
- // FUNCTION, EMITRANGE
381
- // See Table C1-14
382
- let ( function, emit_range) = match ( & settings. access_type , & settings. emit ) {
383
- ( AccessType :: ReadOnly , EmitOption :: Data ) => ( 0b1100 , false ) ,
384
- ( AccessType :: ReadOnly , EmitOption :: Address ) => ( 0b1100 , true ) ,
385
- ( AccessType :: ReadOnly , EmitOption :: AddressData ) => ( 0b1110 , true ) ,
386
- ( AccessType :: ReadOnly , EmitOption :: PCData ) => ( 0b1110 , false ) ,
387
-
388
- ( AccessType :: WriteOnly , EmitOption :: Data ) => ( 0b1101 , false ) ,
389
- ( AccessType :: WriteOnly , EmitOption :: Address ) => ( 0b1101 , true ) ,
390
- ( AccessType :: WriteOnly , EmitOption :: AddressData ) => ( 0b1111 , true ) ,
391
- ( AccessType :: WriteOnly , EmitOption :: PCData ) => ( 0b1111 , false ) ,
392
-
393
- ( AccessType :: ReadWrite , EmitOption :: Data ) => ( 0b0010 , false ) ,
394
- ( AccessType :: ReadWrite , EmitOption :: Address ) => ( 0b0001 , true ) ,
395
- ( AccessType :: ReadWrite , EmitOption :: AddressData ) => ( 0b0010 , true ) ,
396
- ( AccessType :: ReadWrite , EmitOption :: PCData ) => ( 0b0011 , false ) ,
397
-
398
- ( AccessType :: ReadWrite , EmitOption :: PC ) => ( 0b0001 , false ) ,
399
- ( _, EmitOption :: PC ) => unreachable ! ( ) , // cannot return Err here; handled above
400
- } ;
401
- r. set_function ( function) ;
402
- r. set_emitrange ( emit_range) ;
403
-
404
400
r
405
401
} ) ;
406
402
0 commit comments