Skip to content

Commit 5a427fb

Browse files
authored
irq_add_shared_handler assertion fix earlephilhower#724 (earlephilhower#747)
1 parent bb5a2a3 commit 5a427fb

File tree

1 file changed

+3
-3
lines changed
  • src/rp2_common/hardware_irq

1 file changed

+3
-3
lines changed

src/rp2_common/hardware_irq/irq.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ irq_handler_t irq_get_exclusive_handler(uint num) {
135135
static uint16_t make_branch(uint16_t *from, void *to) {
136136
uint32_t ui_from = (uint32_t)from;
137137
uint32_t ui_to = (uint32_t)to;
138-
uint32_t delta = (ui_to - ui_from - 4) / 2;
139-
assert(!(delta >> 11u));
140-
return (uint16_t)(0xe000 | (delta & 0x7ff));
138+
int32_t delta = (int32_t)(ui_to - ui_from - 4);
139+
assert(delta >= -2048 && delta <= 2046 && !(delta & 1));
140+
return (uint16_t)(0xe000 | ((delta >> 1) & 0x7ff));
141141
}
142142

143143
static void insert_branch_and_link(uint16_t *from, void *to) {

0 commit comments

Comments
 (0)