Direct Access to Peripheral Registers The direct control of the Peripheral's registers is a low-level way of creating peripheral driver which requires a good knowledge of the target platform and the code is typically not portable to different platform. However, in some cases is this method more effective or even necessary to use (in the case of special chip features not encapsulated within the Embedded bean implementation). See chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/lowl.html">Low-level Access for details.
Register Access MacrosProcessor Expert defines a set of C macros providing an effective access to a specified register or its part. The definitions of all these macros are in the PE_Types.h. The declaration of the registers which could be read/written by the macros is present in the file IO_Map.h. Whole Register Access Macros- getReg{w} (RegName) - Reads the register content
- setReg{w} (RegName, RegValue) - Sets the register content
Register Part Access Macros- testReg{w}Bits (RegName, GetMask) - Tests the masked bits for non-zero value
- clrReg{w}Bits (RegName, ClrMask) - Sets a specified bits to 0.
- setReg{w}Bits (RegName, SetMask) - Sets a specified bits to 1.
- invertReg{w}Bits (RegName, InvMask) - Inverts a specified bits.
- clrSetReg{w}Bits (RegName, ClrMask, SetMask) - Clears bits specified by ClrMask and sets bits specified by SetMask
Access To Named Bits- testReg{w}Bit (RegName, BitName) - Tests whether the bit is set.
- setReg{w}Bit (RegName, BitName) - Sets the bit to 1.
- clrReg{w}Bit (RegName, BitName) - Sets the bit to 0.
- invertReg{w}Bit (RegName, BitName) - Inverts the bit.
Access To Named Groups of Bits- testReg{w}BitGroup (RegName, GroupName) - Test a group of the bit for non-zero value
- getReg{w}BitGroupVal(RegName, GroupName) - Read a value of the bits in group
- setReg{w}BitGroupVal(RegName, GroupName, GroupVal) - Sets the group of the bits to the specified value.
RegName - Register name BitName - Name of the bit GroupName - Name of the group BitMask - Mask of the bit BitsMask - Mask specifying one or more bits BitsVal - Value of the bits masked by BitsMask GroupMask - Mask of the group of bits GetMask - Mask for reading bit(s) ClrMask - Mask for clearing bit(s) SetMask - Mask for setting bit(s) InvMask - Mask for inverting bit(s) RegValue - Value of the whole register BitValue - Value of the bit (0 for 0, anything else = 1) {w} - Width of the register (8, 16, 32). The available width of the registers depends on used platform. ExampleAssume that we have a CPU which has a PWMA channel and it is required to set three bits (0,1,5) in the PWMA_PMCTL to 1. We use the following line: setRegBits(PWMA_PMCTL,35); /* Run counter */
The direct control of the Peripheral's registers is a low-level way of creating peripheral driver which requires a good knowledge of the target platform and the code is typically not portable to different platform. However, in some cases is this method more effective or even necessary to use (in the case of special chip features not encapsulated within the Embedded bean implementation). See chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/lowl.html">Low-level Access for details.
Register Access MacrosProcessor Expert defines a set of C macros providing an effective access to a specified register or its part. The definitions of all these macros are in the PE_Types.h. The declaration of the registers which could be read/written by the macros is present in the file IO_Map.h. Whole Register Access Macros- getReg{w} (RegName) - Reads the register content
- setReg{w} (RegName, RegValue) - Sets the register content
Register Part Access Macros- testReg{w}Bits (RegName, GetMask) - Tests the masked bits for non-zero value
- clrReg{w}Bits (RegName, ClrMask) - Sets a specified bits to 0.
- setReg{w}Bits (RegName, SetMask) - Sets a specified bits to 1.
- invertReg{w}Bits (RegName, InvMask) - Inverts a specified bits.
- clrSetReg{w}Bits (RegName, ClrMask, SetMask) - Clears bits specified by ClrMask and sets bits specified by SetMask
Access To Named Bits- testReg{w}Bit (RegName, BitName) - Tests whether the bit is set.
- setReg{w}Bit (RegName, BitName) - Sets the bit to 1.
- clrReg{w}Bit (RegName, BitName) - Sets the bit to 0.
- invertReg{w}Bit (RegName, BitName) - Inverts the bit.
Access To Named Groups of Bits- testReg{w}BitGroup (RegName, GroupName) - Test a group of the bit for non-zero value
- getReg{w}BitGroupVal(RegName, GroupName) - Read a value of the bits in group
- setReg{w}BitGroupVal(RegName, GroupName, GroupVal) - Sets the group of the bits to the specified value.
RegName - Register name BitName - Name of the bit GroupName - Name of the group BitMask - Mask of the bit BitsMask - Mask specifying one or more bits BitsVal - Value of the bits masked by BitsMask GroupMask - Mask of the group of bits GetMask - Mask for reading bit(s) ClrMask - Mask for clearing bit(s) SetMask - Mask for setting bit(s) InvMask - Mask for inverting bit(s) RegValue - Value of the whole register BitValue - Value of the bit (0 for 0, anything else = 1) {w} - Width of the register (8, 16, 32). The available width of the registers depends on used platform. ExampleAssume that we have a CPU which has a PWMA channel and it is required to set three bits (0,1,5) in the PWMA_PMCTL to 1. We use the following line: setRegBits(PWMA_PMCTL,35); /* Run counter */ |