weixin_39912163
weixin_39912163
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
...
</portb_interrupt></portb_interrupt></portb_interrupt>

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.

该提问来源于开源项目:PaulStoffregen/cores

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

4条回答

为你推荐

换一换