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 BeansMSITStore: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, DisableMost 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: - Timer beans: timer counter is stopped if it is not shared with another bean. If the timer is shared, the interrupt may be disabled (if it is not also shared).
- Communication beans (like serial or CAN communication): peripheral is disabled.
- Conversion beans (A/D, D/A): converter is disabled. The conversion is restarted by Enable.
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, DisableEventThese 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, AfterNewSpeedTimed 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 typeProcessor Expert defines the TRUE symbol as 1, however true and false logical values in C language are defined according to ANSI-C: - False is defined as 0 (zero)
- True is any non-zero value.
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 BeansMSITStore: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, DisableMost 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: - Timer beans: timer counter is stopped if it is not shared with another bean. If the timer is shared, the interrupt may be disabled (if it is not also shared).
- Communication beans (like serial or CAN communication): peripheral is disabled.
- Conversion beans (A/D, D/A): converter is disabled. The conversion is restarted by Enable.
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, DisableEventThese 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, AfterNewSpeedTimed 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 typeProcessor Expert defines the TRUE symbol as 1, however true and false logical values in C language are defined according to ANSI-C: - False is defined as 0 (zero)
- True is any non-zero value.
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. |