@@ -56,6 +56,7 @@ const SM0_PINCTRL = 0x502000dc;
56
56
const SM2_INSTR = 0x50200108 ;
57
57
const INTR = 0x50200128 ;
58
58
const IRQ0_INTE = 0x5020012c ;
59
+ const FDEBUG = 0x50200008 ; // Debug register
59
60
60
61
const NVIC_ISPR = 0xe000e200 ;
61
62
const NVIC_ICPR = 0xe000e280 ;
@@ -85,6 +86,9 @@ const EXECCTRL_WRAP_BOTTOM_SHIFT = 7;
85
86
const EXECCTRL_WRAP_TOP_SHIFT = 12 ;
86
87
const EXECCTRL_STATUS_N_SHIFT = 0 ;
87
88
89
+ // FDEBUG bits
90
+ const FDEBUG_TXSTALL = 1 << 24 ;
91
+
88
92
const DBG_PADOUT = 0x5020003c ;
89
93
90
94
const SET_COUNT_SHIFT = 26 ;
@@ -559,6 +563,38 @@ describe('PIO', () => {
559
563
expect ( ( await cpu . readUint32 ( NVIC_ISPR ) ) & PIO_IRQ0 ) . toEqual ( PIO_IRQ0 ) ;
560
564
} ) ;
561
565
566
+ it ( 'should set TXSTALL flag in FDEBUG when trying to pull from an empty TX FIFO and only clear it after TX is no longer stalled' , async ( ) => {
567
+ await resetStateMachines ( ) ;
568
+
569
+ // Clear FDEBUG register
570
+ await cpu . writeUint32 ( FDEBUG , 0xffffffff ) ;
571
+ expect ( await cpu . readUint32 ( FDEBUG ) ) . toBe ( 0 ) ;
572
+
573
+ // Make sure TX FIFO is empty
574
+ expect ( await cpu . readUint32 ( FLEVEL ) ) . toEqual ( 0 << TX0_SHIFT ) ;
575
+
576
+ // Attempt to pull from an empty TX FIFO
577
+ await cpu . writeUint32 ( SM0_INSTR , pioPULL ( false , false ) ) ;
578
+
579
+ // Check that the TXSTALL flag is set
580
+ expect ( ( await cpu . readUint32 ( FDEBUG ) ) & ( FDEBUG_TXSTALL << 0 ) ) . toEqual ( FDEBUG_TXSTALL << 0 ) ;
581
+
582
+ // Try clearing the TXSTALL flag while TX FIFO is still empty
583
+ await cpu . writeUint32 ( FDEBUG , FDEBUG_TXSTALL << 0 ) ;
584
+
585
+ // Verify the flag is NOT cleared because TX is still stalled
586
+ expect ( ( await cpu . readUint32 ( FDEBUG ) ) & ( FDEBUG_TXSTALL << 0 ) ) . toEqual ( FDEBUG_TXSTALL << 0 ) ;
587
+
588
+ // Push something to TX FIFO to unstall it
589
+ await cpu . writeUint32 ( TXF0 , 42 ) ;
590
+
591
+ // Now try clearing the flag again
592
+ await cpu . writeUint32 ( FDEBUG , FDEBUG_TXSTALL << 0 ) ;
593
+
594
+ // Now the flag should be cleared
595
+ expect ( ( await cpu . readUint32 ( FDEBUG ) ) & ( FDEBUG_TXSTALL << 0 ) ) . toEqual ( 0 ) ;
596
+ } ) ;
597
+
562
598
it ( 'should update RXFNEMPTY flag in INTR according to the level of the RX FIFO (issue #73)' , async ( ) => {
563
599
await resetStateMachines ( ) ;
564
600
await cpu . writeUint32 ( IRQ0_INTE , INTR_SM0_RXNEMPTY ) ;
0 commit comments