In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use C++ to write interruptions and events". The content in the article is simple and clear, and it is easy to learn and understand. let's study and learn "how to use C++ to write interruptions and events".
In general, when you use an object-oriented language, you will naturally think of encapsulation for some concepts, and the portability of the encapsulated class library will be more convenient. The ISR function has some particularities that can not be simply defined in C++.
1. Without changing the startup code:
If you do not want to change the startup code, the interrupt function cannot be defined directly in the C++ code, and you need to extend asm ("interrupt function name") in the language provided by GCC, for example:
Class Interrupt {/ * * External Interrupt Request 0 * / static inline void INT0_IRQHandler () asm ("_ _ vector_1"); / / other interrupts.}
Then you can define it in the cpp file: void Interrupt::INT0_IRQHandler () {/ code /}
two。 Write their own startup code, this is compared to NB, in general, some manufacturers will provide C startup code, you can refer to its rewritten C++ code. In addition to writing code for related functions such as data initialization and BSS initialization, the main task is to define interrupt vectors. There are two styles of interrupt vectors:
2-1. Interrupt vectors with jump statements, such as AVR, are defined as follows:
Typedef void ISR (void); struct ISR_Type {uint8_t code [2]; ISR* isr;}; _ _ attribute__ ((section (".isr _ vectors")) static const vectors [] = {{0x0C 0x94}, Interrupt::Reset}, {{0x0C 0x94}, Interrupt::INT0_IRQHandler}, / * other interrupt vectors * /}
2-2. Interrupt vector in the form of address, ARM series
_ _ attribute__ ((section (".isr _ vector"), used)) static IRQ_Handler* isrVector [] {_ estack, reset, it::NMI_Handler, / * other functions * /}
3. Define ISR in the H file (excluding interrupt functions using the asm () instruction) to increase compilation speed, but you need to precede each function with inline.
Thank you for your reading. the above is the content of "how to use C++ to write interrupts and events". After the study of this article, I believe you have a deeper understanding of the problem of how to use C++ to write interruptions and events. the specific use also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.