summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2024-04-15 23:56:55 +0700
committerhathach <[email protected]>2024-04-15 23:56:55 +0700
commit6328301bb652458ad752b05129e1944404adc7ca (patch)
treeeae7bada570783e6cc019735e5007f6cecb50f35
parentb992b6d7a6f90cd96f7d53383755dc17e393f00e (diff)
revert to use __builtin_ctz() for optimized time
-rw-r--r--src/portable/renesas/rusb2/dcd_rusb2.c22
-rw-r--r--src/portable/renesas/rusb2/hcd_rusb2.c30
2 files changed, 32 insertions, 20 deletions
diff --git a/src/portable/renesas/rusb2/dcd_rusb2.c b/src/portable/renesas/rusb2/dcd_rusb2.c
index f9523191a..50400d1f5 100644
--- a/src/portable/renesas/rusb2/dcd_rusb2.c
+++ b/src/portable/renesas/rusb2/dcd_rusb2.c
@@ -915,6 +915,18 @@ void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
//--------------------------------------------------------------------+
// ISR
//--------------------------------------------------------------------+
+
+#if defined(__CCRX__)
+TU_ATTR_ALWAYS_INLINE static inline unsigned __builtin_ctz(unsigned int value) {
+ unsigned int count = 0;
+ while ((value & 1) == 0) {
+ value >>= 1;
+ count++;
+ }
+ return count;
+}
+#endif
+
void dcd_int_handler(uint8_t rhport)
{
rusb2_reg_t* rusb = RUSB2_REG(rhport);
@@ -1002,13 +1014,13 @@ void dcd_int_handler(uint8_t rhport)
// Buffer ready
if ( is0 & RUSB2_INTSTS0_BRDY_Msk ) {
const unsigned m = rusb->BRDYENB;
- const unsigned s = rusb->BRDYSTS & m;
+ unsigned s = rusb->BRDYSTS & m;
/* clear active bits (don't write 0 to already cleared bits according to the HW manual) */
rusb->BRDYSTS = ~s;
- for (unsigned p = 0; p < PIPE_COUNT; ++p) {
- if (tu_bit_test(s, p)) {
- process_pipe_brdy(rhport, p);
- }
+ while (s) {
+ const unsigned num = __builtin_ctz(s);
+ process_pipe_brdy(rhport, num);
+ s &= ~TU_BIT(num);
}
}
}
diff --git a/src/portable/renesas/rusb2/hcd_rusb2.c b/src/portable/renesas/rusb2/hcd_rusb2.c
index 1356b696f..f140da690 100644
--- a/src/portable/renesas/rusb2/hcd_rusb2.c
+++ b/src/portable/renesas/rusb2/hcd_rusb2.c
@@ -758,6 +758,17 @@ bool hcd_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) {
//--------------------------------------------------------------------+
// ISR
//--------------------------------------------------------------------+
+#if defined(__CCRX__)
+TU_ATTR_ALWAYS_INLINE static inline unsigned __builtin_ctz(unsigned int value) {
+ unsigned int count = 0;
+ while ((value & 1) == 0) {
+ value >>= 1;
+ count++;
+ }
+ return count;
+}
+#endif
+
void hcd_int_handler(uint8_t rhport, bool in_isr) {
(void) in_isr;
@@ -807,23 +818,12 @@ void hcd_int_handler(uint8_t rhport, bool in_isr) {
}
}
-#if defined(__CCRX__)
- static const int Mod37BitPosition[] = {
- -1, 0, 1, 26, 2, 23, 27, 0, 3, 16, 24, 30, 28, 11, 0, 13, 4,
- 7, 17, 0, 25, 22, 31, 15, 29, 10, 12, 6, 0, 21, 14, 9, 5,
- 20, 8, 19, 18};
-#endif
-
if (is0 & RUSB2_INTSTS0_NRDY_Msk) {
const unsigned m = rusb->NRDYENB;
unsigned s = rusb->NRDYSTS & m;
rusb->NRDYSTS = ~s;
while (s) {
-#if defined(__CCRX__)
- const unsigned num = Mod37BitPosition[(-s & s) % 37];
-#else
const unsigned num = __builtin_ctz(s);
-#endif
process_pipe_nrdy(rhport, num);
s &= ~TU_BIT(num);
}
@@ -833,10 +833,10 @@ void hcd_int_handler(uint8_t rhport, bool in_isr) {
unsigned s = rusb->BRDYSTS & m;
/* clear active bits (don't write 0 to already cleared bits according to the HW manual) */
rusb->BRDYSTS = ~s;
- for (unsigned p = 0; p < PIPE_COUNT; ++p) {
- if (tu_bit_test(s, p)) {
- process_pipe_brdy(rhport, p);
- }
+ while (s) {
+ const unsigned num = __builtin_ctz(s);
+ process_pipe_brdy(rhport, num);
+ s &= ~TU_BIT(num);
}
}
}