Board logo

标题: 关于Processor Expert 的一些资料,希望对大家有所帮助 [打印本页]

作者: fjczd    时间: 2009-1-7 11:16     标题: 关于Processor Expert 的一些资料,希望对大家有所帮助

Code Generation

This chapter informs the user about principles and results of the Processor Expert code generation process and the correct ways and possibilities of using this code in the user application.

Please follow to the subchapters for more information.

This chapter informs the user about principles and results of the Processor Expert code generation process and the correct ways and possibilities of using this code in the user application.

Please follow to the subchapters for more information.

This chapter informs the user about principles and results of the Processor Expert code generation process and the correct ways and possibilities of using this code in the user application.

Please follow to the subchapters for more information.

[此贴子已经被作者于2009-1-7 11:16:33编辑过]


作者: fjczd    时间: 2009-1-7 11:18

Code Generation

Processor Expert | Generate Code '{ProjectName.mcp}'

Generate Code command initiates the code generation process. During this process source code modules containing functionality of the beans contained in the project are generated. The project must be set-up correctly for successful code generation. If the generation is error-free all generated source code files are saved to the destination directory.

Processor Expert produces these files:

The existence of the files can be conditional to project or Processor Expert environment settings and their usage by the beans.

Processor Expert | Generate Code '{ProjectName.mcp}'

Generate Code command initiates the code generation process. During this process source code modules containing functionality of the beans contained in the project are generated. The project must be set-up correctly for successful code generation. If the generation is error-free all generated source code files are saved to the destination directory.

Processor Expert produces these files:

The existence of the files can be conditional to project or Processor Expert environment settings and their usage by the beans.


作者: fjczd    时间: 2009-1-7 11:23

Predefined Types, Macros and Constants

Processor Expert generates definitions of all hardware register structures to the file IO_Map.h. The Processor Expert type definitions are generated to the file PE_Types.h containing also definitions of macros used for a peripheral register access. See chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/registermacros.html">Registers Access for details.

Types

TypeDescriptionSupported for
int8_t8-bit signed integerall
int16_t16-bit signed integerall
int32_t32-bit signed integerall
int64_t32-bit signed integer56800/E
uint8_t8-bit unsigned integerall
uint16_t16-bit unsigned integerall
uint32_t32-bit unsigned integerall
uint64_t64-bit unsigned integer56800/E
TPE_ErrCodeError code (uint8_t)all except MPC55xx
byte8-bit unsigned integer (unsigned char)all
boolBoolean value (unsigned char) (TRUE = any non-zero value / FALSE = 0)all
word16-bit unsigned integer (unsigned int)all
dword32-bit unsigned integer (unsigned long)all
dlongarray of two 32-bit unsigned integers (unsigned long)all

Structure for images

typedef struct {          /* Black&White Image  */
    word width;             /* Image width  */
    word height;            /* Image height */
    byte *pixmap;           /* Image pixel bitmap */
    word size;              /* Image size   */
    char *name;             /* Image name   */
  } TIMAGE;
  typedef TIMAGE* PIMAGE ;  /* Pointer to image */
  

Structure for 16-bit register:

/* 16-bit register (big endian format) */
  typedef union {
     word w;
     struct {
       byte high,low;
     } b;
  } TWREG;
  

Macros

  __DI()             - Disable global interrupts
  __EI()             - Enable global interrupts
  
  EnterCritical()    - It saves CCR register and disable
                       global interrupts
  ExitCritical()     - It restores CCR register saved
                       in EnterCritical()
  
For the list of macros available for Peripheral registers access please see the chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/registermacros.html">Registers Access.

Constants

Methods Error Codes

The error codes are defined in PE_Error module. Error code value is 8bit unsigned byte. Range 0 - 127 is reserved for PE, 128 - 255 for user

ERR_OK0OK
ERR_SPEED1This device does not work in the active speed mode
ERR_RANGE2Parameter out of range
ERR_VALUE3Parameter of incorrect value
ERR_OVERFLOW4Timer overflow
ERR_MATH5Overflow during evaluation
ERR_ENABLED6Device is enabled
ERR_DISABLED7Device is disabled
ERR_BUSY8Device is busy
ERR_NOTAVAIL9Requested value not available
ERR_RXEMPTY10No data in receiver
ERR_TXFULL11Transmitter is full
ERR_BUSOFF12Bus not available
ERR_OVERRUN13Overrun is present
ERR_FRAMING14Framing error is detected
ERR_PARITY15Parity error is detected
ERR_NOISE16Noise error is detected
ERR_IDLE17Idle error is detected
ERR_FAULT18Fault error is detected
ERR_BREAK19Break char is received during communication
ERR_CRC20CRC error is detected
ERR_ARBITR21A node loses arbitration. This error occurs if two nodes start transmission at the same time
ERR_PROTECT 22Protection error is detected.
ERR_UNDERFLOW 23Underflow error is detected.
ERR_UNDERRUN 24Underrun error is detected.
ERR_COMMON 25General unspecified error of a device. The user can get a specific error code using the method GetError.

Processor Expert generates definitions of all hardware register structures to the file IO_Map.h. The Processor Expert type definitions are generated to the file PE_Types.h containing also definitions of macros used for a peripheral register access. See chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/registermacros.html">Registers Access for details.

Types

TypeDescriptionSupported for
int8_t8-bit signed integerall
int16_t16-bit signed integerall
int32_t32-bit signed integerall
int64_t32-bit signed integer56800/E
uint8_t8-bit unsigned integerall
uint16_t16-bit unsigned integerall
uint32_t32-bit unsigned integerall
uint64_t64-bit unsigned integer56800/E
TPE_ErrCodeError code (uint8_t)all except MPC55xx
byte8-bit unsigned integer (unsigned char)all
boolBoolean value (unsigned char) (TRUE = any non-zero value / FALSE = 0)all
word16-bit unsigned integer (unsigned int)all
dword32-bit unsigned integer (unsigned long)all
dlongarray of two 32-bit unsigned integers (unsigned long)all

Structure for images

typedef struct {          /* Black&White Image  */
    word width;             /* Image width  */
    word height;            /* Image height */
    byte *pixmap;           /* Image pixel bitmap */
    word size;              /* Image size   */
    char *name;             /* Image name   */
  } TIMAGE;
  typedef TIMAGE* PIMAGE ;  /* Pointer to image */
  

Structure for 16-bit register:

/* 16-bit register (big endian format) */
  typedef union {
     word w;
     struct {
       byte high,low;
     } b;
  } TWREG;
  

Macros

  __DI()             - Disable global interrupts
  __EI()             - Enable global interrupts
  
  EnterCritical()    - It saves CCR register and disable
                       global interrupts
  ExitCritical()     - It restores CCR register saved
                       in EnterCritical()
  
For the list of macros available for Peripheral registers access please see the chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/registermacros.html">Registers Access.

Constants

Methods Error Codes

The error codes are defined in PE_Error module. Error code value is 8bit unsigned byte. Range 0 - 127 is reserved for PE, 128 - 255 for user

ERR_OK0OK
ERR_SPEED1This device does not work in the active speed mode
ERR_RANGE2Parameter out of range
ERR_VALUE3Parameter of incorrect value
ERR_OVERFLOW4Timer overflow
ERR_MATH5Overflow during evaluation
ERR_ENABLED6Device is enabled
ERR_DISABLED7Device is disabled
ERR_BUSY8Device is busy
ERR_NOTAVAIL9Requested value not available
ERR_RXEMPTY10No data in receiver
ERR_TXFULL11Transmitter is full
ERR_BUSOFF12Bus not available
ERR_OVERRUN13Overrun is present
ERR_FRAMING14Framing error is detected
ERR_PARITY15Parity error is detected
ERR_NOISE16Noise error is detected
ERR_IDLE17Idle error is detected
ERR_FAULT18Fault error is detected
ERR_BREAK19Break char is received during communication
ERR_CRC20CRC error is detected
ERR_ARBITR21A node loses arbitration. This error occurs if two nodes start transmission at the same time
ERR_PROTECT 22Protection error is detected.
ERR_UNDERFLOW 23Underflow error is detected.
ERR_UNDERRUN 24Underrun error is detected.
ERR_COMMON 25General unspecified error of a device. The user can get a specific error code using the method GetError.


作者: fjczd    时间: 2009-1-7 11:26

Typical Usage of the Bean in the User Code

This chapter describes usage of methods and events that are defined in most hardware beans. Usage of other bean specific methods is described in the bean documentation, in the section "Typical Usage" (if supported).

In the following examples please assume a bean named "B1".

Peripheral Initialization Beans

MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/BeanCategoriesInfo.html#LevelAbstraction">Peripheral Initialization Beans are the beans of the lowest level of peripheral abstraction. These beans contain only one method Init providing the initialization of the used peripheral. See chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/BeanInitUsage.html">Typical Peripheral Initialization Beans Usage for details.

Methods Enable, Disable

Most of the hardware beans support the methods Enable and Disable. These methods enable or disable peripheral functionality, which causes disabling of functionality of the bean as well.
Hint: Disabling of the peripheral functionality may save CPU resources.

Overview of the method behavior according to the bean type:

If the bean is disabled, some methods may not be used. Please refer to beans documentation for details.

MAIN.C

  void main(void)
  {
    ...
    B1_Enable();   /* enable the bean functionality */
                /* handle the bean data or settings */
    B1_Disable(); /* disable the bean functionality */
    ...
  }
  

Methods EnableEvent, DisableEvent

These methods enable or disable invocation of all bean events. These methods are usually supported only if the bean services any interrupt vector.

The method DisableEvent may cause disabling of the interrupt, if it is not required by the bean functionality or shared with another bean. The method usually does not disable either peripheral or the bean functionality.

MAIN.C

  void main(void)
  {
    ...
    B1_EnableEvent();  /* enable the bean events */
                       /* bean events may be invoked */
    B1_DisableEvent(); /* disable the bean events */
                       /* bean events are disabled */
    ...
  }
  

Events BeforeNewSpeed, AfterNewSpeed

Timed beans which depends on the CPU clock (such as timer, communication and conversion beans), may support speed modes defined in the CPU bean (in EXPERT view level). The event BeforeNewSpeed is invoked before the speed mode change and AfterNewSpeed is invoked after the speed mode change. Speed mode may be changed using CPU bean methods SetHigh, SetLow or SetSlow.

EVENT.C

  int changing_speed_mode = 0;

  void B1_BeforeNewSpeed(void)
  {
    ++changing_speed_mode;
  }

  void B1_AfterNewSpeed(void)
  {
    --changing_speed_mode;
  }
  

Note: If the speed mode is not supported by the bean, the bean functionality is disabled (as if the method Disable is used). If the supported speed mode is selected again, the bean status is restored.

TRUE and FALSE values of the bool type

Processor Expert defines the TRUE symbol as 1, however true and false logical values in C language are defined according to ANSI-C:


It follows from this definition, that the bool value cannot be tested using the expressions like if (value == TRUE) ...
Processor Expert methods returning bool value often benefit from this definition and they return any non-zero value as TRUE value instead of 1. The correct C expression for such test is: if (value) ....

In our documentation, the "true" or "false" are considered as logical states, not any particular numeric values. The capitalized "TRUE" and "FALSE" are constants defined as FALSE=0 and TRUE=1.

This chapter describes usage of methods and events that are defined in most hardware beans. Usage of other bean specific methods is described in the bean documentation, in the section "Typical Usage" (if supported).

In the following examples please assume a bean named "B1".

Peripheral Initialization Beans

MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/BeanCategoriesInfo.html#LevelAbstraction">Peripheral Initialization Beans are the beans of the lowest level of peripheral abstraction. These beans contain only one method Init providing the initialization of the used peripheral. See chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/BeanInitUsage.html">Typical Peripheral Initialization Beans Usage for details.

Methods Enable, Disable

Most of the hardware beans support the methods Enable and Disable. These methods enable or disable peripheral functionality, which causes disabling of functionality of the bean as well.
Hint: Disabling of the peripheral functionality may save CPU resources.

Overview of the method behavior according to the bean type:

If the bean is disabled, some methods may not be used. Please refer to beans documentation for details.

MAIN.C

  void main(void)
  {
    ...
    B1_Enable();   /* enable the bean functionality */
                /* handle the bean data or settings */
    B1_Disable(); /* disable the bean functionality */
    ...
  }
  

Methods EnableEvent, DisableEvent

These methods enable or disable invocation of all bean events. These methods are usually supported only if the bean services any interrupt vector.

The method DisableEvent may cause disabling of the interrupt, if it is not required by the bean functionality or shared with another bean. The method usually does not disable either peripheral or the bean functionality.

MAIN.C

  void main(void)
  {
    ...
    B1_EnableEvent();  /* enable the bean events */
                       /* bean events may be invoked */
    B1_DisableEvent(); /* disable the bean events */
                       /* bean events are disabled */
    ...
  }
  

Events BeforeNewSpeed, AfterNewSpeed

Timed beans which depends on the CPU clock (such as timer, communication and conversion beans), may support speed modes defined in the CPU bean (in EXPERT view level). The event BeforeNewSpeed is invoked before the speed mode change and AfterNewSpeed is invoked after the speed mode change. Speed mode may be changed using CPU bean methods SetHigh, SetLow or SetSlow.

EVENT.C

  int changing_speed_mode = 0;

  void B1_BeforeNewSpeed(void)
  {
    ++changing_speed_mode;
  }

  void B1_AfterNewSpeed(void)
  {
    --changing_speed_mode;
  }
  

Note: If the speed mode is not supported by the bean, the bean functionality is disabled (as if the method Disable is used). If the supported speed mode is selected again, the bean status is restored.

TRUE and FALSE values of the bool type

Processor Expert defines the TRUE symbol as 1, however true and false logical values in C language are defined according to ANSI-C:


It follows from this definition, that the bool value cannot be tested using the expressions like if (value == TRUE) ...
Processor Expert methods returning bool value often benefit from this definition and they return any non-zero value as TRUE value instead of 1. The correct C expression for such test is: if (value) ....

In our documentation, the "true" or "false" are considered as logical states, not any particular numeric values. The capitalized "TRUE" and "FALSE" are constants defined as FALSE=0 and TRUE=1.


作者: fjczd    时间: 2009-1-7 11:43

User Changes in Generated Code

It's necessary to say at the beginning of the chapter, that modification of the generated code may be done only at user's own risk. Generated code was thoroughly tested by the skilled developers and the functionality of the modified code cannot be guaranteed. We strongly don't recommend modification of the generated code to the beginners. See more information for generated modules in chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/codesign.html">Code Generation.

To support user changes in the bean modules, Processor Expert supports the following features:

1. CH file - manifest constants

Processor Expert automatically produce list of manifest constants for all beans, which encapsulate any CPU peripheral and modifies any of the CPU control registers. The name of each manifest constant is in the following format:

C_[bean+method]_reg_[register name][additional-info]

where

These constants may be used to write user code, which reflects the bean settings. Once the constant is generated into the CH file, it is preserved there even it is already not used in the bean module. The most important advantage of these constants is, that small changes in the bean settings (for example timing) does not cause change of the bean module, but the only CH file is changed.

The name of the CH file is derived from the CPU bean name ([CPUbean].CH). To generate CH file it is necessary to set the following option: MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/options.html#Generatemanifestconstants">Project Options | Generate manifest constants. CH file is generated also while smart generation of bean modules code, see paragraph 3 for details. CH file is always overwritten during the code generation.

2. Mode of code generation for bean modules

It's possible to select mode of the code generation for each bean, the following options can be found in the MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/beanlocalmenu.html">bean's pop-up menu in the project panel:

Code Generation

The mode of code generation is indicated as a bean's status in the project panel. This mode influences only the generation of bean modules (bean.c, bean.h).

3. Mode of code generation for non-bean modules

Processor Expert also allows to enable/disable generation of the modules that not related to a specific bean or that are common for several beans. This option can be configured in the MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/moduleslocalmenu.html#generated">pop-up menu of the module in the Project Panel. Current enable/disable state of this option is signalled by the icon near the bean module name in the Project Panel (MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/images/umchanges1.png" width="16" alt=""/> - enabled, MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/images/umchanges3.png" width="16" alt=""/> - disabled).

Code Generation

Viewing User Changes in a Bean Module

The user changes done in a bean module or bean header module can be viewed using a bean pop-up menu commands Compare With Previously Generated Module and Compare With Previously Generated Header Module. See chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/beanlocalmenu.html#Bean">Beans Pop-up Menus for details. The user can also enable reviewing all changes done into the generated code after each code generation. See chapter Tracking Changes in Generated Code for details.


It's necessary to say at the beginning of the chapter, that modification of the generated code may be done only at user's own risk. Generated code was thoroughly tested by the skilled developers and the functionality of the modified code cannot be guaranteed. We strongly don't recommend modification of the generated code to the beginners. See more information for generated modules in chapter Code Generation.

To support user changes in the bean modules, Processor Expert supports the following features:

1. CH file - manifest constants

Processor Expert automatically produce list of manifest constants for all beans, which encapsulate any CPU peripheral and modifies any of the CPU control registers. The name of each manifest constant is in the following format:

C_[bean+method]_reg_[register name][additional-info]

where

These constants may be used to write user code, which reflects the bean settings. Once the constant is generated into the CH file, it is preserved there even it is already not used in the bean module. The most important advantage of these constants is, that small changes in the bean settings (for example timing) does not cause change of the bean module, but the only CH file is changed.

The name of the CH file is derived from the CPU bean name ([CPUbean].CH). To generate CH file it is necessary to set the following option: Project Options | Generate manifest constants. CH file is generated also while smart generation of bean modules code, see paragraph 3 for details. CH file is always overwritten during the code generation.

2. Mode of code generation for bean modules

It's possible to select mode of the code generation for each bean, the following options can be found in the bean's pop-up menu in the project panel:

Code Generation

The mode of code generation is indicated as a bean's status in the project panel. This mode influences only the generation of bean modules (bean.c, bean.h).

3. Mode of code generation for non-bean modules

Processor Expert also allows to enable/disable generation of the modules that not related to a specific bean or that are common for several beans. This option can be configured in the pop-up menu of the module in the Project Panel. Current enable/disable state of this option is signalled by the icon near the bean module name in the Project Panel ( - enabled, - disabled).

Code Generation

Viewing User Changes in a Bean Module

The user changes done in a bean module or bean header module can be viewed using a bean pop-up menu commands Compare With Previously Generated Module and Compare With Previously Generated Header Module. See chapter Beans Pop-up Menus for details. The user can also enable reviewing all changes done into the generated code after each code generation. See chapter Tracking Changes in Generated Code for details.



作者: xinluoufo    时间: 2009-1-15 11:22

这是PE的帮助PDF中的东西吧,不过能传上来很好。谢谢。






欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0