@@ -758,6 +758,17 @@ bool hcd_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) {
758
758
//--------------------------------------------------------------------+
759
759
// ISR
760
760
//--------------------------------------------------------------------+
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
+
761
772
void hcd_int_handler (uint8_t rhport , bool in_isr ) {
762
773
(void ) in_isr ;
763
774
@@ -807,23 +818,12 @@ void hcd_int_handler(uint8_t rhport, bool in_isr) {
807
818
}
808
819
}
809
820
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
-
817
821
if (is0 & RUSB2_INTSTS0_NRDY_Msk ) {
818
822
const unsigned m = rusb -> NRDYENB ;
819
823
unsigned s = rusb -> NRDYSTS & m ;
820
824
rusb -> NRDYSTS = ~s ;
821
825
while (s ) {
822
- #if defined(__CCRX__ )
823
- const unsigned num = Mod37BitPosition [(- s & s ) % 37 ];
824
- #else
825
826
const unsigned num = __builtin_ctz (s );
826
- #endif
827
827
process_pipe_nrdy (rhport , num );
828
828
s &= ~TU_BIT (num );
829
829
}
@@ -833,10 +833,10 @@ void hcd_int_handler(uint8_t rhport, bool in_isr) {
833
833
unsigned s = rusb -> BRDYSTS & m ;
834
834
/* clear active bits (don't write 0 to already cleared bits according to the HW manual) */
835
835
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 );
840
840
}
841
841
}
842
842
}
0 commit comments