3

Can we look at NVIC peripheral on ARM CPUs like some sort of thread? Main application is executing, and at the same time NVIC peripheral doing her own work? Or all of that is single thread application. Can someone explain if I am wrong, where and why?

  • What do you mean by "looking at"? Surely you can use devices like Trace32 debugger for ARM, that allows you to well, trace all of CPU resources, but could you be a bit more specific? – Sven Jul 13 '15 at 12:38
  • @Sven I read that NVIC peripheral works separately from the main application, so it looks like multithreading to me, am I right? –  Jul 13 '15 at 12:40

2 Answers2

1

To some extent, but there are moments when it's critical not to think of the NVIC like this.

First, you have to worry about what you're doing to the stack. IIRC, the Cortex model deals with the stack maintenance and register restoration for you, but if you're doing something silly (or even not so silly), you can cause stack overflows.

Next -- the interrupts are INTERRUPTS. If you're doing non-atomic operations, and the interrupt happens in the middle, things can get pretty screwed up pretty quickly -- and it can be challenging to debug these kind of problems.

Scott Seidman
  • 29,274
  • 4
  • 44
  • 109
1

I came from an Java background into embedded programming, so I asked myself the same question. In Java, you have Threads. With them you can execute some given tasks in a (kind of) parallel way. This is NOT how Interrupts work.

The code in an interrupt routine is not executed while the main loop runs. The main loop stops what it is doing and jumps to the interrupt routine in case an interrupt is fired. After execution of the isr it jumps back to where it was and continues with that.

jwsc
  • 711
  • 4
  • 11
  • ISR is also some kind of application which executes all the time and checking if some conditions are met, if yes then it causes interrupt to stop main program, so it looks pretty much similar to threading, except that main application and ISR turns off each other, but you can also see this while using threads, in some critical situations. –  Jul 13 '15 at 12:51
  • 1
    Hmm, you could see it like that. But I would not call it an "running application". It is no software. Interrupts are hardware-controlled. Hardwired silicon. The same thing with other periperals: adc, i2c, uart, spi.... all of them do their tasks while your software is running. But that does not mean that they are parallel running threads. They are electrical circuits. – jwsc Jul 13 '15 at 12:54
  • Yes, in that case you are right, thanks for clarifying me this. –  Jul 13 '15 at 12:56