(* (volatile unsigned long *) detailed

Source: Internet
Author: User

(* (volatile unsigned long *)

for different computer architectures, the device may be port-mapped or memory-mapped. If the system architecture supports a separate IO address space and is a port mapping, you must use assembly language to complete the actual control of the device, because C does not provide a true "port" concept. If it's a memory map, it's much more convenient.

Take the #define IOPIN (* (volatile unsigned long *) 0xe0028000) as an example: as a macro definition statement, define is a pseudo-directive that defines a variable or constant. The first (volatile unsigned long *) means that the subsequent address is coerced into a volatile unsigned long *, unsigned long is unsigned, and volatile is a type qualifier, such as a const , when using volatile qualification, it means that the variable is implemented by the system, that the variable is modified by other programs or computer hardware, and because the address depends on the hardware, volatile indicates that his value is dependent on the hardware.

The volatile type is this, and its data may indeed change in unknown circumstances. For example, the hardware device's terminal changed it, and now hardware devices often have their own private memory addresses, such as video memory, they are generally reflected through the image of a particular memory address, so that under certain conditions, the program can directly access the private memory. Also, for example, a shared memory address, when multiple programs are operating on it. Your program does not know when this memory has been changed. If you do not add this voliatile modification, the program is using the data in the catch, that may be outdated, add voliatile, when needed, the program to go back to that address to extract, to ensure that the latest. summed up as follows:

1. Volatile variable allows to modify his content in addition to programs such as hardware
2. Access to the data at any time will directly access the content at that address, that is, improved access speed through the cache optimization is canceled

For (volatile unsigned long *) 0xe0028000 is an address defined with hardware needs, preceded by a "*" pointer, for direct point to the address, the entire definition of the Convention symbol Iopin instead, when called directly to the address register to write the content can be. This is actually the convenience of the memory-mapping mechanism. The volatile keyword is an important feature of embedded system development. The above expression is disassembled to analyze, first (volatile unsigned long *) 0xe0028000 means to convert 0xe0028000 to volatile unsigned a long type of pointer, tentatively as P, then is # define A * P, that is, a is the content of the P pointer pointing to the position. This is the memory addressable access to register a, which can read/write operations.

for (volatile unsigned char *) 0x20 let's analyze it again, it's made up of two parts:
1) (unsigned char *) 0x20,0x20 is just a value, the front plus (unsigned char *) means that 0x20 is an address, and this address type is unsigned char, meaning that when you read and write this address, write it into unsigned char The value, read out is also unsigned char.
2) Volatile, keyword volatile ensures that this instruction is not omitted due to the C compiler's optimizations and requires each direct read value. For example, when using the while ((unsigned char *) 0x20), sometimes the system may not actually read the value of 0x20, but instead use the first read-out value, and if so, then the loop may be a dead loop. With volatile, it is required to read the actual value of the 0x20 every time.

Then (volatile unsigned char *) 0x20 is a fixed pointer, is immutable, not a variable. Char *u is a pointer variable.
Add "*" to the front: * (volatile unsigned char *) 0x20 becomes variable (normal unsigned char variable, not pointer variable) If # define I (* (volatile unsigned char *) 0x20) , then the unsigned char i is the same, except that the address of the front i is fixed.

Then your question will be answered, (* (volatile unsigned char *) 0x20) can be considered as a common variable, which has a fixed address, pointing to 0x20. And 0x20 is just a constant, not a pointer, not a variable.

Reprint: http://www.openedv.com/posts/list/918.htm

(* (volatile unsigned long *) detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.