| |||
Home > Creating a New Component > Behavior section > Adding the new behavior to the SerialCharDoubler slave port |
The slave port must alter the standard behavior for the transmit direction so that characters are doubled.
The receive direction is not changed and this requires only
a call to the same behavior of master port out
to
simply transfer the data from the slave port to the master port.
The modification of the transmitted data is implemented in
slave behavior dataTransmit
. Select the Source tab
to display the LISA source code for SerialCharDoubler.lisa
,
and modify the SerialData
slave port dataTransmit
behavior
as shown in Example 6.3:
Example 6.3. Slave port behavior
slave port<SerialData> in { behavior dataTransmit(uint16_t data) { // start of escape sequence? if(data == '\33') { inEscape = true; } if(inEscape) { // leave escape sequences untouched (only send one char) out.dataTransmit(data); } else { // duplicate char on output out.dataTransmit(data); out.dataTransmit(data); } // end of escape sequence? if(isalpha(data)) { inEscape = false; } } ... }
The data is not doubled for escape sequences but is doubled
for other characters. The end of escape sequences is detected by
the occurrence of an alphabetic character and the resource inEscape
is
reset.
The dataReceive()
behavior calls the respective
behavior of the master port as shown in Example 6.4. Modify
the behavior as shown:
Example 6.4. Slave port receive behavior
behavior dataReceive():uint16_t { return out.dataReceive(); }
Because signals are not effected by the doubling, the behavior to set and get signals are wrappers on the master port behavior as shown in Example 6.5:
Example 6.5. Slave port get and set signals
behavior signalsSet(uint8_t signal) { out.signalsSet(signal); } behavior signalsGet():uint8_t { return out.signalsGet(); }