2020-12-25 17:49

Pin interrupt dispatching is not thread/interrupt safe

The port interrupt pin dispatch code if ((isfr & CORE_PIN1_BITMASK) && intFunc[1]) intFunc[1](); compiles down to the following:

  16:   03a1        lsls    r1, r4, #14
  18:   d504        bpl.n   24 <portb_interrupt>
  1a:   4b1a        ldr r3, [pc, #104]  ; (84 <portb_interrupt>)
  1c:   685a        ldr r2, [r3, #4]
  1e:   b10a        cbz r2, 24 <portb_interrupt>
  20:   685b        ldr r3, [r3, #4]
  22:   4798        blx r3

ldr r2, [r3, #4] is a load from the intFunc[] table, loading the pin interrupt address. A NULL check is done, then the intFunc[] table load is performed again and the pointer from the table is called.

A higher priority ISR could be called between the two loads from intFunc[]. If that ISR uses detachInterrupt for the pin, NULL will be called.


  • 点赞
  • 回答
  • 收藏
  • 复制链接分享