Using the C Code Editor
The Outline, Navigation and "Database"/"Workspace" panes work in the same way as in the block diagram editor. The outline feature is available, but it only serves to structure the methods of the component into groups of public and private methods. The code for the body of each method or process of a C code component is shown in the code pane, when the method or process is selected in the Outline tab. The title bar shows the name of e component, the current project and the current target.
The Target combo box shows the current target. A C code component can contain code for several targets, but the code has to be specified for each target individually. This is because C code is platform-dependent; you cannot assume that C code developed for one platform will run on another platform without modifications.
Different experimentation arithmetic, e.g. floating point or fixed point is possible for each target; the C code has to be specified separately for each of them. It is possible to copy the code for each target/arithmetic combination to any other, so you only need to enter the code once, and it can then be adapted as required.
Note |
|---|
If the body of a C code method or process is empty for the combination of target, arithmetic, and implementation selected in the associated project, the following warning is issued: WARNING (WBdl2): process/method name (using <C Code> specification) is not defined If an empty method requires a return value, an error is issued: ERROR(YBdl22): method <name> must be defined; need a return value |
You will specify the body of a method or process in the code pane. A method corresponds to a function in C, i.e. it can have several arguments but only one return value. A process has neither arguments nor return values. The declaration of the function is generated by ASCET, the user has to define only the content of the function.
calc (a,b)
{
<user-defined content in C Code >
}
The arguments and return values of the function are specified as in the Block Diagram Editor.
If you want to include any system libraries, you can do this with an ordinary include statement. This is written in the header of the class or module. Click the Header tab of the Code pane to display the header. Variables local to a method are also declared here with normal C statements. The scope of a variable is the method or process it has been declared in, i.e. you cannot reference a variable that was declared in one method or process in another one.
Basic elements are created as in the block diagram editor by clicking on one of the element buttons. Elements work like elements in components described by block diagrams, i.e. they can be used in all methods or processes of the component, and can also be made global. Once you have created an element, you can reference it by simply typing its name in the Code pane.
Similarly, you can define arguments and return values for classes, and messages for modules, as you would in a block diagram component. However, if the component is to reference other components there is a difference in syntax; you should therefore decide early on whether the component references others.
See also