@@ -758,6 +758,17 @@ bool hcd_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) {
758758//--------------------------------------------------------------------+
759759// ISR
760760//--------------------------------------------------------------------+
761+ #if defined(__CCRX__ )
762+ TU_ATTR_ALWAYS_INLINE static inline unsigned __builtin_ctz (unsigned int value ) {
763+ unsigned int count = 0 ;
764+ while ((value & 1 ) == 0 ) {
765+ value >>= 1 ;
766+ count ++ ;
767+ }
768+ return count ;
769+ }
770+ #endif
771+
761772void hcd_int_handler (uint8_t rhport , bool in_isr ) {
762773 (void ) in_isr ;
763774
@@ -807,23 +818,12 @@ void hcd_int_handler(uint8_t rhport, bool in_isr) {
807818 }
808819 }
809820
810- #if defined(__CCRX__ )
811- static const int Mod37BitPosition [] = {
812- -1 , 0 , 1 , 26 , 2 , 23 , 27 , 0 , 3 , 16 , 24 , 30 , 28 , 11 , 0 , 13 , 4 ,
813- 7 , 17 , 0 , 25 , 22 , 31 , 15 , 29 , 10 , 12 , 6 , 0 , 21 , 14 , 9 , 5 ,
814- 20 , 8 , 19 , 18 };
815- #endif
816-
817821 if (is0 & RUSB2_INTSTS0_NRDY_Msk ) {
818822 const unsigned m = rusb -> NRDYENB ;
819823 unsigned s = rusb -> NRDYSTS & m ;
820824 rusb -> NRDYSTS = ~s ;
821825 while (s ) {
822- #if defined(__CCRX__ )
823- const unsigned num = Mod37BitPosition [(- s & s ) % 37 ];
824- #else
825826 const unsigned num = __builtin_ctz (s );
826- #endif
827827 process_pipe_nrdy (rhport , num );
828828 s &= ~TU_BIT (num );
829829 }
@@ -833,10 +833,10 @@ void hcd_int_handler(uint8_t rhport, bool in_isr) {
833833 unsigned s = rusb -> BRDYSTS & m ;
834834 /* clear active bits (don't write 0 to already cleared bits according to the HW manual) */
835835 rusb -> BRDYSTS = ~s ;
836- for ( unsigned p = 0 ; p < PIPE_COUNT ; ++ p ) {
837- if ( tu_bit_test ( s , p )) {
838- process_pipe_brdy (rhport , p );
839- }
836+ while ( s ) {
837+ const unsigned num = __builtin_ctz ( s );
838+ process_pipe_brdy (rhport , num );
839+ s &= ~ TU_BIT ( num );
840840 }
841841 }
842842}
0 commit comments