I found some questions when I read the header file ccw.x613x. h In rf_example_code_v1.0.
First, let's take a look at ccw.x613x. h.
Three # define examples in:
# Define defc (name, address) _ no_init volatile unsigned char name @ address;
# Define defw (name, address) _ no_init volatile unsigned short name @ address;
# Define defcw (name, address) _ no_init Union
{
Struct
{
Volatile unsigned char name ##_ L;
Volatile unsigned char name ##_ h;
};
Volatile unsigned short name;
} @ Address;
The previous two # define statements have the same usage. First, I can find that there is a keyword _ no_init in the macro definition. View the IAR language in the MSP430 iar c/EC ++ compiler Reference Guide
Extension overview can be found, __no_init is an extension keyword in the IAR extension syntax. The role is to declare a non-volatile type memory address (Support non-valotile memory ).
Therefore, the _ no_init problem is solved.
In addition, I had some questions about the @ character, so I checked the information online. Although the usage of the @ character is still not very clear, it can be clear that:
# Define defc (name, address) _ no_init volatile unsigned char name @ address;
# Define defc (name, address) sfrb name = address;
These two definitions are equivalent, but the latter is true only when embedded programming is compiled. That is to say, "=" is one of the pseudo commands for data distribution in the MSP430 assembly. Let's take a look at the data distribution pseudoinstructions In the MSP430 Compilation:
These commands include the following:
Set (VAR, assign) assigns a temporary value;
Equ (=) assigns a permanent value to the current module;
Define defines a valid value in the entire file;
Bytes of the sfrb register type;
Sfrw register type.
The syntax is as follows:
Label set expr
Label equ expr
Label = expr
Label define expr
[Const] sfrb register = Value
[Const] sfrw register = Value
Where,
Label defines a flag,
Expr flag value,
Register special function registers,
The value of the special function register.
The local variables and global variables are used in the following example.
The symbolic value is defined in
The symbol values are also defined in the module Add2, But they indicate two different quantities, both of which are valid only within their respective modules,
This is a local variable. In the module Add1
The locn defined in is a global variable and represents the same value in the two modules.
Name Add1
Locn define 100 h
Value equ 77
MoV locn, r4
Add # value, r4
Endmod
Name Add2
Value equ 88
MoV locn, R5
Add # value, R5
End
Obviously, "=", that is, equ, is used to assign a permanent value to the current module.
So far,
# Define defcw (name, address) _ no_init Union
{
Struct
{
Volatile unsigned char name ##_ L;
Volatile unsigned char name ##_ h;
};
Volatile unsigned short name;
} @ Address;
This definition is also easy to understand. The preceding definition only adds a Union definition. A 16-bit address bucket is divided into two 8bits or one 16-bit address bucket. Supports word access or byte access. The preceding definition associates an unknown union with the address so that the access to the memory corresponding to the address is the same as the access to the Union.
The following seemingly complex definitions are relatively easy to understand:
# Define rf1aifctl1 _ (0x0f02u)
Defcw (rf1aifctl1, rf1aifctl1 _)
# Define rf1aififg rf1aifctl1_l
# Define rf1aifie rf1aifctl1_h
It can be found that, in the first macro definition, "rf1aifctl1 _" carries an underscore at the end of the string, which actually indicates that this is only an address. And defcw (
Rf1aifctl1, rf1aifctl1 _) will be extended:
_ No_init Union
{
Struct
{
Volatile unsigned char rf1aifctl1_l;
Volatile unsigned char rf1aifctl1_h;
};
Volatile unsigned short rf1aifctl1;
} @ (0x0f02u );
For usage of @, I checked the MSP430 IAR C/EC ++ compiler reference guide and found the result:
A variable that has been explicitly placed at an address, for example by using the compiler @ syntax, will be placed in either the data16_ac or the data16_an segment.
It can be seen that @ is a syntax. The role of the variable is obviously to place the variable in the corresponding address. Use @ to define a storage address for a variable.
Therefore, the previous macro definition is easy to understand.
# Define defc (name, address) _ no_init volatile unsigned char name @ address;
It is to store the name variable in the address, so that you can name each register, that is, each register can correspond to one or more variables.
At this point, another problem in the header file is solved:
# Define rf1aifctl1 _ (0x0f02u)
Defcw (rf1aifctl1, rf1aifctl1 _)
# Define rf1aififg rf1aifctl1_l
# Define rf1aifie rf1aifctl1_h
Defcw (rf1aifctl1, rf1aifctl1 _) is expanded as follows:
_ No_init Union
{
Struct
{
Volatile unsigned char rf1aifctl1_l;
Volatile unsigned char rf1aifctl1_h;
};
Volatile unsigned short rf1aifctl1;
} @ (0x0f02u );
As you can see, rf1aifctl1, rf1aifctl1_l, and rf1aifctl1_h have been declared as a variable, and the storage addresses are 0x0f02u, 0x0f02u + 1, 0x0f02u. Therefore, the following two macro definitions are naturally undefined.
# Define rf1aififg rf1aifctl1_l
# Define rf1aifie rf1aifctl1_h
The function is only used to replace the rf1aifctl1_l variable. rf1aifctl1_h defines another name.