| |||
| Home > Creating a New Component > Adding ports | |||
Two ports are required for this component. See Figure 6.1:
the slave port receives the serial data
the master port writes out the doubled characters.
Both ports use serial data and they must therefore use the SerialData protocol that is provided in Fast Model Portfolio.
Add the ports to the component:
In
the Block Diagram view of the SerialCharDoubler component,
right click into the blank diagram and select context menu item Add
port...
The Self Port dialog is displayed. See Figure 6.2. Enter in for
the ports Instance Name.
For Type select Slave Port.
To choose the protocol, click the Select... button Protocol. Select SerialData from the displayed list and click OK.
Leave the Self Port dialog by pressing the OK button. A port is added to the block diagram. Click to drop the port on the canvas.
Repeat the procedure for the out master
port:
Instance
Name is out
Type is Master Port
Protocol is SerialData.
Click the Source tab for
the SerialCharDoubler component. The code is
updated as shown in Example 6.2:
Example 6.2. Ports added to char doubler
// This file was generated by System Generator Canvas
// --------------------------------------------------
component SerialCharDoubler
{
composition
{
}
connection
{
}
resources
{
// remember whether we are inside an escape sequence
// which came through 'in'
bool inEscape;
}
slave port<SerialData> in
{
behavior dataTransmit(uint16_t data):void
{
// TODO: place your code here
}
behavior dataReceive():uint16_t
{
// TODO: place your code here
}
behavior signalsSet(uint8_t signal):void
{
// TODO: place your code here
}
behavior signalsGet():uint8_t
{
// TODO: place your code here
}
}
master port<SerialData> out;
{
behavior dataTransmit(uint16_t data):void
{
// TODO: place your code here
}
behavior dataReceive():uint16_t
{
// TODO: place your code here
}
behavior signalsSet(uint8_t signal):void
{
// TODO: place your code here
}
behavior signalsGet():uint8_t
{
// TODO: place your code here
}
}
}