fix(string): Fix the logical errors of the "mr_ffs32" and "mr_ffs64" series interfaces.

1.Fix the incorrect result caused by the fls numerical conversion error.
2.Remove the ack mechanism in irq.
This commit is contained in:
MacRsh
2025-05-11 23:55:58 +08:00
parent 3d8fcd2fdc
commit c6dc2d83c9
3 changed files with 22 additions and 13 deletions

View File

@@ -47,7 +47,6 @@ typedef struct mr_irq_ops {
void (*unmask)(mr_uint32_t irq, void *args);
void (*disable)(mr_uint32_t irq, void *args);
void (*mask)(mr_uint32_t irq, void *args);
void (*ack)(mr_uint32_t irq, void *args);
} mr_irq_ops_t;
/* Irq type */

View File

@@ -199,7 +199,16 @@ MR_INLINE int mr_ffs64(mr_uint64_t x) {
* @return The index of the last set bit.
*/
MR_INLINE int mr_fls32(mr_uint32_t x) {
return mr_ffs32(x & (-x));
/* Higher order bits */
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x -= x >> 1;
/* Find last set bit */
return mr_ffs32(x);
}
/**
@@ -209,7 +218,16 @@ MR_INLINE int mr_fls32(mr_uint32_t x) {
* @return The index of the last set bit.
*/
MR_INLINE int mr_fls64(mr_uint64_t x) {
return mr_ffs64(x & (-x));
/* Higher order bits */
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x |= x >> 32;
x -= x >> 1;
return mr_ffs64(x);
}
/** @} */

View File

@@ -631,12 +631,8 @@ mr_irq_return_t mr_irq_handle(mr_uint32_t irq) {
/* Get irq run-time */
mr_irq_get(desc->irq);
/* Shield irq mask */
/* Mask irq */
desc->irq->ops->mask(irq, desc->irq->args);
if (desc->flags & MR_IRQ_EDGE_BOTH) {
/* First ack if irq mode is edge */
desc->irq->ops->ack(irq, desc->irq->args);
}
/* Handle irq action */
for (action = desc->action; action; action = action->next) {
@@ -700,12 +696,8 @@ mr_irq_return_t mr_irq_handle(mr_uint32_t irq) {
}
}
/* Unmask irq mask */
/* Unmask irq if irq action is enabled */
if (mr_atomic_load(&desc->depth) == 0) {
if (desc->flags & (MR_IRQ_LEVEL_HIGH | MR_IRQ_LEVEL_LOW)) {
/* Then ack if irq mode is level */
desc->irq->ops->ack(irq, desc->irq->args);
}
desc->irq->ops->unmask(irq, desc->irq->args);
}