ARM C Programming

Publisher:DelightfulWishLatest update time:2024-07-23 Source: cnblogsKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Access the memory location of the absolute address:
#define pISR_EINT0 (*(unsigned *) (_ISR_STRATADDRESS+0x74))

The above statement casts the unsigned integer _ISR_STRATADDRESS+0x74 to a pointer, pointing to RAM, and then retrieves the instance pointing to the address. The following statement can be used to access it:
pISR_EINT0 = (unsigned int)Eint0_ISR, the address of the instance pointing to the address points to a function address that is cast to U32bit.
In order to access an absolute address, cast an integer to a pointer.

2. __irq:
In order to facilitate the use of high-level languages ​​to write exception handling functions, the ARM compiler has made specific extensions to the exception handling functions. As long as the keyword _irq is used, the compiled function will meet the needs of exception response for scene protection and recovery;

3. Some basic principles for writing interrupt service routines:

√ Avoid doing floating-point operations in interrupt service routines: A good terminal reading program should follow the principle of being short and effective. Doing floating-point operations in interrupt service routines greatly violates this principle. At the same time, some processors/compilers do not allow floating-point operations in interrupt service routines.
√ Interrupt service routines cannot have return values: Therefore, interrupt service routines are defined as returning types of void, that is: void _irq Eint0_ISR(void);
√ Interrupt service functions cannot pass parameters: Therefore, the parameter list is void, that is: void _irq Eint0_ISR(void);

4. Static:
A static variable is actually a global variable, but it has a scope. It can be used to save the intermediate state of the function where the variable is located during the call. For example:
int cCout()
{
Static int loop = 0;
.......
loop++;
.......
}
The value of the loop variable will increase with the number of calls to the function. After the function exits, the value of the loop still exists, but the loop can only be accessed in the function (function scope), and the memory space of the loop will only be allocated and initialized when the function is called for the first time. Each time the function is entered, it will not be allocated for static, but directly use the last value. In a module, a function declared as static can only be called by other functions in this module. Other functions outside the module have no access to it. It is a local global variable.

5. Constant:
If a variable or object is defined as a constant type, it cannot be updated after the definition (readable but not writable), that is, an initial value must be given when defining or describing the type.
Several points to note:
√ If const is on the left side of the asterisk (*), const modifies the variable pointed to by the pointer, that is, the pointer points to a constant; such as: const int *a; or int const *a; these two situations are the same (the location of cost in the variable declarator is irrelevant), the pointer points to a constant, and the content cannot be changed at this time, that is, there cannot be a write operation statement *a=3;
√ If cost is on the right side of the model, cost modifies the pointer itself, that is, the pointer itself is a constant; such as: int* const a; statement indicates that the pointer itself is a constant, and the content it points to is not a constant, that is, a++ is wrong.
√ If there are const modifiers on both sides of the asterisk, such as: const int* const a;, it means that the pointer itself and the content it points to are both constants.

6. Volatile:
Define a volatile variable. The compiler has a technology called data flow analysis, which analyzes where the variables in the program are assigned, where they are used, and where they are invalidated. The analysis results can be used for optimizations such as constant merging and constant propagation. When the compiler checks that the code does not modify the value of the field, it is possible to provide the cache value of the last access when you access the field, which can improve the efficiency of the program, but sometimes these optimizations will cause problems and are not what our program needs. The characteristic is that the program operates on hardware registers. At this time, the volatile keyword can be used to prohibit these optimizations.
Occasions for using volatile variables:
√ Hardware registers usually need to be declared volatile, because each read and write to them may have a different meaning;
√ Variables modified in the interrupt service program for detection by other programs need to be declared volatile; otherwise the compiler may update the variable once and use the cached value each time without updating it immediately;
√ Flags shared between tasks in a multi-tasking environment should be added with the volatile keyword: when multiple threads access a field, the code hopes that these accesses can operate (read) the latest value of the field, and the operation of writing to the variable can be updated immediately; add the volatile keyword to the field, and any request (read/write) to the field will be executed immediately.


Keywords:ARM Reference address:ARM C Programming

Previous article:Relationship between FCLK, HCKL and PCLK
Next article:Memory management mechanism of s3c2440

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号