Learn ARM development(16)

Publisher:technology78Latest update time:2024-11-14 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

There are many things to learn about ARM, and interrupts are definitely something that needs to be learned. Since the CPU introduced interrupts, we have truly entered the multi-tasking system and greatly improved work efficiency. Interrupts take up less CPU time than previous query methods, allowing the system to provide better performance. So what are interrupts like in S3C44B0? How do you respond when developing ARM programs? This is what I need to learn.


After checking the manual of S3C44B0, I found that it has 7 working modes, each of which is different. The most commonly used ones are SVC and IRQ modes. Before using the interrupt, you must initialize the stack pointer SP of each mode. If you do not initialize it, you will definitely get an error. When the CPU is initialized, you need to enter the IRQ mode in turn, initialize SP, and then enter the SVC mode to initialize SP. In this way, these two modes can be used. Then initialize the IRQ interrupt handler in the interrupt table of S3C44B0. This code is used to call different interrupt subroutines according to different interrupt bits.


For interrupt subroutines written in C language, some specific modifiers must be added, otherwise the C compiler will not generate a program suitable for running in interrupt mode. Since I don't know much about GCC, I debugged it for several days and found that the interrupt handler I wrote did not return. The reason is that without these interrupt modifiers, the GCC compiler did not generate a suitable return instruction. When I added the following:

void Eint4567Isr(void) __attribute__ ((interrupt ("IRQ")));

After the modification, a suitable interrupt handler will be generated. GCC will compile it into the following code:
sub lr, lr, #4 ;
stmdb sp!, {r0, r1, r2, r3, r4, ip, lr}
......
......
ldmia sp!, {r0, r1, r2, r3, r4, ip, pc}^

Since returning from IRQ mode to SVC mode requires LR to be reduced by 4, it is the instruction of PC. If the above interrupt modifier definition is not added, such code will not be generated, and such function cannot be used for interrupt processing.


Of course, I also compiled these codes, disassembled them, and found that they were different. Then it can also be achieved through embedded assembly. For example:

void foo(void)
{
asm volatile ( "sub lr, lr, #4" );
asm volatile ( "stmdb sp!, {r0, r1, r2, r3, r4, ip, lr}" );
......
......

asm volatile ( "ldmia sp!, {r0, r1, r2, r3, r4, ip, pc}" );
return;
}

Originally, before I found this definition, I manually added the above code to achieve it. This interrupt code taught me how to handle interrupts, from SVC to IRQ mode, and then from IRQ mode back to SVC mode. As long as I move from LR to PC, it will automatically switch back to SVC mode.


By looking up the GCC help documentation, the following link:

http://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Function-Attributes.html , you can see the interrupt function declaration in GCC.

5.24 Declaring Attributes of Functions

Variable Attributes ) and for types (see Type Attributes ).

You may also specify attributes with `__' preceding and following each keyword. This allows you to use them in header files without being concerned about a possible macro of the same name. For example, you may use __noreturn__ instead of noreturn.

See Attribute Syntax , for details of the exact syntax for using attributes.

Then look at its interrupt function declaration:

  • interrupt

  • Use this attribute on the ARM, AVR, C4x, M32R/D and Xstormy16 ports to indicate that the specified function is an interrupt handler. The compiler will generate function entry and exit sequences suitable for use in an interrupt handler when this attribute is present.

    Note, interrupt handlers for the m68k, H8/300, H8/300H, H8S, and SH processors can be specified via the interrupt_handler attribute.

    Note, on the AVR, interrupts will be enabled inside the function.

    Note, for the ARM, you can specify the kind of interrupt to be handled by adding an optional parameter to the interrupt attribute like this:

              void f () __attribute__ ((interrupt ("IRQ")));

    Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF.

  • In addition to using the IRQ interrupt method, you can also write FIQ, SWI, ABORT, and UNDEF interrupt processing functions.


Reference address:Learn ARM development(16)

Previous article:Learn ARM development(17)
Next article:最后一页

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号