首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

关于Low-level Access to Peripherals

关于Low-level Access to Peripherals

Low-level Access to Peripherals

In some cases, a non-standard use of the peripheral could be required and it might be more efficient to write a custom peripheral driver from scratch than to use the bean. In addition, there are special features present only on a particular chip derivative (not supported by the bean) that could make the user routines more effective; however, the portability of such code is reduced.

Peripheral Initialization

It is possible to use Processor Expert to generate only the initialization code (function) for a peripheral using a MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/BeanCategoriesInfo.html#LevelAbstraction">Peripheral initialization beans. The user can choose a suitable Peripheral initialization bean for the given peripheral using a Bean Selector under a Peripherals tab. See chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/beanselector.html">Bean Selector for details. The initial values which will be set to the peripheral control registers could be viewed by the Peripheral Initialization window. See chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/peripheralinit.html">Peripheral Initialization for details.

Peripheral Driver Implementation

The rest of the peripheral driver can be implemented by the user using one of the following approaches:

Warning: Incorrect change in registers of the peripheral, which is controlled by any Bean driver can cause the incorrect Bean driver function

In some cases, a non-standard use of the peripheral could be required and it might be more efficient to write a custom peripheral driver from scratch than to use the bean. In addition, there are special features present only on a particular chip derivative (not supported by the bean) that could make the user routines more effective; however, the portability of such code is reduced.

Peripheral Initialization

It is possible to use Processor Expert to generate only the initialization code (function) for a peripheral using a MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/BeanCategoriesInfo.html#LevelAbstraction">Peripheral initialization beans. The user can choose a suitable Peripheral initialization bean for the given peripheral using a Bean Selector under a Peripherals tab. See chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/beanselector.html">Bean Selector for details. The initial values which will be set to the peripheral control registers could be viewed by the Peripheral Initialization window. See chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/peripheralinit.html">Peripheral Initialization for details.

Peripheral Driver Implementation

The rest of the peripheral driver can be implemented by the user using one of the following approaches:

Warning: Incorrect change in registers of the peripheral, which is controlled by any Bean driver can cause the incorrect Bean driver function

Processor Expert System Library

Notice: PESL is not available in this version.

PESL (Processor Expert System Library) is dedicated to power programmers, who are familiar with CPU architecture - each bit and each register. PESL provides macros to access the peripherals directly. It should be used only in special cases when the MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/lowl.html">low-level approach is necessary.

PESL is peripheral oriented and complements with Embedded Beans, which are functionality oriented. While Embedded Beans provide very high level of project portability by stable API and inheritance feature across different CPU/DSP/PPC architectures, PESL is more architecture dependent.

Notice: PESL is not available in this version.

PESL (Processor Expert System Library) is dedicated to power programmers, who are familiar with CPU architecture - each bit and each register. PESL provides macros to access the peripherals directly. It should be used only in special cases when the MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/lowl.html">low-level approach is necessary.

PESL is peripheral oriented and complements with Embedded Beans, which are functionality oriented. While Embedded Beans provide very high level of project portability by stable API and inheritance feature across different CPU/DSP/PPC architectures, PESL is more architecture dependent.

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 Macros

Processor 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.

Example

Assume 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 Macros

Processor 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.

Example

Assume 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 */
返回列表