Polling or Interrupt based method

前端 未结 14 2408
暗喜
暗喜 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.

    0 讨论(0)
  • 2020-12-12 14:41

    Polling mode can be useful in systems with high frequency events, where the overhead associated with entering and exiting interrupt handlers uses more CPU cycles than simply polling. For example polling might be used in an IP router to maximise CPU bandwidth available to packet processing.

    0 讨论(0)
提交回复
热议问题