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编辑过]
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. The existence of the files can be conditional to project or Processor Expert environment settings and their usage by the beans.Processor Expert produces these files:
This module with its header file is generated for every bean in the project with exception of some beans that generate only an initialization code or special source code modules. Name of this file is the same as the name of the bean.
Header file (.h) contains definitions of all public symbols, which are implemented in the bean module and can be used in the user modules.
The module contains implementation of all enabled methods and may also contain some subroutines for internal usage only. This module could be modified manually under certain conditions, but it is recommended for experienced users only. See chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/SmartBeanModules.html">User Changes in Generated Code for details.
Processor Expert also allows to track and review changes in the generated modules. See chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/trackchanges.html">Tracking Changes in Generated Code for details.
The CPU module is generated according to the currently active target CPU bean. The CPU module contains additionally:
The main module is generated only if it does not already exist (if it exists it is not changed). Name of this module is the same as the name of the project.
The main module contains the main function, which is called after initialization of the CPU (from the CPU module). By default this function is generated empty (without any reasonable code). It is designed so that the user will write his/her own particular code here.
The event module is generated only if it does not exist. If it exists, only new events are added into the module; user written code is not changed.
The event module contains all events selected in the beans. By default these event handler routines are generated empty (without any meaningful code). It is considered that user will write his/her own particular code here.
Event module can also contain the generated ISRs for the beans that require a direct interrupt handling ( MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/BeanCategoriesInfo.html#LevelAbstraction">Peripheral Initialization Beans). Generation of the ISRs is controlled by the project option MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/options.html#GenerateISR">Project Options | Generate ISR.
Note: It is possible to change a name of the event module in ADVANCED view mode of the Bean Inspector.
This is a simple text file {projectname}_SIGNALS.txt or {projectname}_SIGNALS.doc with a list of all used signal names. The signal name can be assigned to an allocated pin in the bean properties (available in ADVANCED view mode). This documentation can be found in the Documentation folder of the Project Panel. See chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/SignalNames.html">Signal names for details.
Control registers and bit structures names and types definitions in C language.
Control registers variable declarations in C language. This file is generated only for the HC(S)08/HC(S)12 versions.
A source code of the interrupt vector table content.
Definition of the constants (speed modes, reset reasons). This file is included in every driver of the bean.
Definition of the C types (bool, byte, word, ...). This file is included in every driver of the bean.
Common error codes. This file contains definition of return error codes of bean's methods. See the generated module for detailed description of the error codes. This file is included in every driver of the bean.
This file contains shared procedures for runtime support of calculations of timing constants.
This external module (visible in the External Modules folder of the MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/projectpanel.html">Project Panel) contains a platform specific startup code and is linked to the application. The name of the file is different for the Processor Expert versions. For datils on the use of the startupfile during the reset see chapter MSITStore:C:\Program%20Files\Freescale\CodeWarrior%20for%20HCS12%20V4.7\Help\ProcessorExpert.chm::/resetscenario.html">Reset Scenario
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.
The existence of the files can be conditional to project or Processor Expert environment settings and their usage by the beans.
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
Type Description Supported for int8_t 8-bit signed integer all int16_t 16-bit signed integer all int32_t 32-bit signed integer all int64_t 32-bit signed integer 56800/E uint8_t 8-bit unsigned integer all uint16_t 16-bit unsigned integer all uint32_t 32-bit unsigned integer all uint64_t 64-bit unsigned integer 56800/E TPE_ErrCode Error code (uint8_t) all except MPC55xx byte 8-bit unsigned integer (unsigned char) all bool Boolean value (unsigned char) (TRUE = any non-zero value / FALSE = 0) all word 16-bit unsigned integer (unsigned int) all dword 32-bit unsigned integer (unsigned long) all dlong array 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_OK 0 OK ERR_SPEED 1 This device does not work in the active speed mode ERR_RANGE 2 Parameter out of range ERR_VALUE 3 Parameter of incorrect value ERR_OVERFLOW 4 Timer overflow ERR_MATH 5 Overflow during evaluation ERR_ENABLED 6 Device is enabled ERR_DISABLED 7 Device is disabled ERR_BUSY 8 Device is busy ERR_NOTAVAIL 9 Requested value not available ERR_RXEMPTY 10 No data in receiver ERR_TXFULL 11 Transmitter is full ERR_BUSOFF 12 Bus not available ERR_OVERRUN 13 Overrun is present ERR_FRAMING 14 Framing error is detected ERR_PARITY 15 Parity error is detected ERR_NOISE 16 Noise error is detected ERR_IDLE 17 Idle error is detected ERR_FAULT 18 Fault error is detected ERR_BREAK 19 Break char is received during communication ERR_CRC 20 CRC error is detected ERR_ARBITR 21 A node loses arbitration. This error occurs if two nodes start transmission at the same time ERR_PROTECT 22 Protection error is detected. ERR_UNDERFLOW 23 Underflow error is detected. ERR_UNDERRUN 24 Underrun error is detected. ERR_COMMON 25 General 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.
Type | Description | Supported for |
int8_t | 8-bit signed integer | all |
int16_t | 16-bit signed integer | all |
int32_t | 32-bit signed integer | all |
int64_t | 32-bit signed integer | 56800/E |
uint8_t | 8-bit unsigned integer | all |
uint16_t | 16-bit unsigned integer | all |
uint32_t | 32-bit unsigned integer | all |
uint64_t | 64-bit unsigned integer | 56800/E |
TPE_ErrCode | Error code (uint8_t) | all except MPC55xx |
byte | 8-bit unsigned integer (unsigned char) | all |
bool | Boolean value (unsigned char) (TRUE = any non-zero value / FALSE = 0) | all |
word | 16-bit unsigned integer (unsigned int) | all |
dword | 32-bit unsigned integer (unsigned long) | all |
dlong | array of two 32-bit unsigned integers (unsigned long) | all |
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 */
/* 16-bit register (big endian format) */ typedef union { word w; struct { byte high,low; } b; } TWREG;
__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.
ERR_OK | 0 | OK |
ERR_SPEED | 1 | This device does not work in the active speed mode |
ERR_RANGE | 2 | Parameter out of range |
ERR_VALUE | 3 | Parameter of incorrect value |
ERR_OVERFLOW | 4 | Timer overflow |
ERR_MATH | 5 | Overflow during evaluation |
ERR_ENABLED | 6 | Device is enabled |
ERR_DISABLED | 7 | Device is disabled |
ERR_BUSY | 8 | Device is busy |
ERR_NOTAVAIL | 9 | Requested value not available |
ERR_RXEMPTY | 10 | No data in receiver |
ERR_TXFULL | 11 | Transmitter is full |
ERR_BUSOFF | 12 | Bus not available |
ERR_OVERRUN | 13 | Overrun is present |
ERR_FRAMING | 14 | Framing error is detected |
ERR_PARITY | 15 | Parity error is detected |
ERR_NOISE | 16 | Noise error is detected |
ERR_IDLE | 17 | Idle error is detected |
ERR_FAULT | 18 | Fault error is detected |
ERR_BREAK | 19 | Break char is received during communication |
ERR_CRC | 20 | CRC error is detected |
ERR_ARBITR | 21 | A node loses arbitration. This error occurs if two nodes start transmission at the same time |
ERR_PROTECT | 22 | Protection error is detected. |
ERR_UNDERFLOW | 23 | Underflow error is detected. |
ERR_UNDERRUN | 24 | Underrun error is detected. |
ERR_COMMON | 25 | General unspecified error of a device. The user can get a specific error code using the method GetError. |
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". 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. 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. 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 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 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 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. Processor Expert defines the TRUE symbol as 1, however true and false logical values in C language are defined according to ANSI-C: 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. Peripheral Initialization Beans
Methods Enable, Disable
Hint: Disabling of the peripheral functionality may save CPU resources. void main(void)
{
...
B1_Enable(); /* enable the bean functionality */
/* handle the bean data or settings */
B1_Disable(); /* disable the bean functionality */
...
}
Methods EnableEvent, DisableEvent
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
int changing_speed_mode = 0;
void B1_BeforeNewSpeed(void)
{
++changing_speed_mode;
}
void B1_AfterNewSpeed(void)
{
--changing_speed_mode;
}
TRUE and FALSE values of the bool type
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) ....
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".
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.
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 */ ... }
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 */ ... }
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.
Processor Expert defines the TRUE symbol as 1, however true and false logical values in C language are defined according to ANSI-C:
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.
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: 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. 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). 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). 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. 1. CH file - manifest constants
2. Mode of code generation for bean modules
3. Mode of code generation for non-bean modules
Viewing User Changes in a Bean Module
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:
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.
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).
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 GenerationThe 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.
这是PE的帮助PDF中的东西吧,不过能传上来很好。谢谢。
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |