@@ -56,6 +56,7 @@ const SM0_PINCTRL = 0x502000dc;
5656const SM2_INSTR = 0x50200108 ;
5757const INTR = 0x50200128 ;
5858const IRQ0_INTE = 0x5020012c ;
59+ const FDEBUG = 0x50200008 ; // Debug register
5960
6061const NVIC_ISPR = 0xe000e200 ;
6162const NVIC_ICPR = 0xe000e280 ;
@@ -85,6 +86,9 @@ const EXECCTRL_WRAP_BOTTOM_SHIFT = 7;
8586const EXECCTRL_WRAP_TOP_SHIFT = 12 ;
8687const EXECCTRL_STATUS_N_SHIFT = 0 ;
8788
89+ // FDEBUG bits
90+ const FDEBUG_TXSTALL = 1 << 24 ;
91+
8892const DBG_PADOUT = 0x5020003c ;
8993
9094const SET_COUNT_SHIFT = 26 ;
@@ -559,6 +563,38 @@ describe('PIO', () => {
559563 expect ( ( await cpu . readUint32 ( NVIC_ISPR ) ) & PIO_IRQ0 ) . toEqual ( PIO_IRQ0 ) ;
560564 } ) ;
561565
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+
562598 it ( 'should update RXFNEMPTY flag in INTR according to the level of the RX FIFO (issue #73)' , async ( ) => {
563599 await resetStateMachines ( ) ;
564600 await cpu . writeUint32 ( IRQ0_INTE , INTR_SM0_RXNEMPTY ) ;
0 commit comments