Polling or Interrupt based method

前端 未结 14 2580
暗喜
暗喜 2020-12-12 13:44

When should one use polling method and when should one use interrupt based method ? Are there scenarios in which both can be used ?

14条回答
  •  余生分开走
    2020-12-12 14:40

    See, we have main 5 methodologies:

    1) Blind

    CPU checks every x ms for data. ETC check pin 12.

    2)Polling( Busy/Wait)

    The CPU is always checking and waiting for Flag to be raised, like UART raising a flag after a packet is transferred. Forever checking the Flag register. (Best response time) but the CPU cant perform anything else.

    3) Interrupt:

    CPU performs normally, if interrupt happens, CPU will switch context to ISR. if Pin 18 saw a falling edge, perform ISR (1). Not bad response time and CPU can do anything while the ISR is not active. Do it with urgent apps that you do not know when it might happen.

    4)Periodic Polling:

    CPU is doing its stuff but, every ms seconds its checking pin 11. Blind is doing nothing in between. The worse response time, not urgent apps, do it when you don't trust the hardware will raise the interrupt. it can be created using a timer interrupt.

    5) Direct memory access.

    Advanced interfacing approach. Transfers data directly from/to memory. Input will be read to memory directly. Output will be written from memory directly. Both uses a controller.

提交回复
热议问题