开发者

interrupts in c language [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜