CMSIS-Core (Cortex-M)
Version 5.7.0
CMSIS-Core support for Cortex-M processor-based devices
|
Naming conventions and optional features for accessing peripherals. More...
Macros | |
#define | _VAL2FLD(field, value) |
Mask and shift a bit field value for assigning the result to a peripheral register. More... | |
#define | _FLD2VAL(field, value) |
Extract from a peripheral register value the a bit field value. More... | |
Naming conventions and optional features for accessing peripherals.
The section below describes the naming conventions, requirements, and optional features for accessing device specific peripherals. Most of the rules also apply to the core peripherals. The Device Header File <device.h> contains typically these definition and also includes the core specific header files.
The definitions for Peripheral Access can be generated using the CMSIS-SVD System View Description for Peripherals. Refer to SVDConv.exe for more information.
Each peripheral provides a data type definition with a name that is composed of:
Examples:
The data type definition uses standard C data types defined by the ANSI C header file <stdint.h>.
IO Type Qualifier | Type | Description |
---|---|---|
__IM | Struct member | Defines 'read only' permissions |
__OM | Struct member | Defines 'write only' permissions |
__IOM | Struct member | Defines 'read / write' permissions |
__I | Scalar variable | Defines 'read only' permissions |
__O | Scalar variable | Defines 'write only' permissions |
__IO | Scalar variable | Defines 'read / write' permissions |
To access the registers of the UART defined above, pointers to this register structure are defined. If more instances of a peripheral exist, the variables have a postfix (digit or letter) that identifies the peripheral.
Example: In this example LPC_UART2 and LPC_UART3 are two pointers to UARTs defined with above register structure.
The registers in the various UARTs can now be referred in the user code as shown below:
To access the peripheral registers and related function in a device, the files device.h and core_cm#.h define as a minimum:
These definitions allow accessing peripheral registers with simple assignments.
Optionally, the file device.h may define:
For Core Register, macros define the position and the mask value for a bit field. It is recommended to create such definitions also for other peripheral registers.
Example:
Bit field definitions for register CPUID in SCB (System Control Block).
The macros _VAL2FLD(field, value) and _FLD2VAL(field, value) enable access to bit fields.
#define _FLD2VAL | ( | field, | |
value | |||
) |
Extract from a peripheral register value the a bit field value.
field | name of bit field. |
value | value of the register. This parameter is interpreted as an uint32_t type. |
The macro _FLD2VAL uses the #define's _Pos and _Msk of the related bit field to extract the value of a bit field from a register.
Example:
#define _VAL2FLD | ( | field, | |
value | |||
) |
Mask and shift a bit field value for assigning the result to a peripheral register.
field | name of bit field. |
value | value for the bit field. This parameter is interpreted as an uint32_t type. |
The macro _VAL2FLD uses the #define's _Pos and _Msk of the related bit field to shift bit-field values for assigning to a register.
Example: