interrupts in c language [closed]
The following code uses the __interrupt as the interrupt service routine. How to comment on the below code.
#include<stdio.h>
#define PI 3.14
__interrupt double compute_area(double radius)
{
double area=PI*radius*radius;
printf("\narea=%f",area);
retu开发者_如何学运维rn area;
}
This is the piece of code i got for solving. I haven't tried a program that uses interrupts before, but have read that the interrupts are not a function call and interrupt flags are used to set the interrupt service routine. I don't really have an in-depth knowledge of interrupts. How do you use them? Why would you use them?
I'm not sure exactly what you are asking here. The __interrupt
specifier you are using is not a part of the C language, but is instead an extension to the language. You will need to tell us what system you are compiling for in order to get a more specific answer for your use case.
That code does not appear to be a valid interrupt function. Typically the arguments to the function will be void
or the state of the registers when the interrupt occurred. You can also typically change the value of the registers via the arguments (not always safe to do!). Returning a value from an interrupt handler doesn't make a lot of sense either as it would not be called directly by user code.
Interrupts may be handled in many ways, but a simple mechanism would be to declare a function as an interrupt handler, a pointer to the function would be stored somewhere, and when an interrupt occurs on a specific CPU the registers functions would be called asynchronously (as the interrupt probably did not occur on your current thread).
I don't know that any of this generalist information will help you. I can't really make out what you are asking here. Perhaps if you narrowed things down a bit more we could offer more assistance.
精彩评论