6.3.3 Adding a new behavior to a slave port

The slave port must alter the standard behavior of the transmit direction.

Do not change the receive direction. This requires only a call to the same behavior of master port out to transfer the data from the slave port to the master port. The modification of the transmitted data is implemented in slave behavior dataTransmit.

Procedure

  1. Select the Source tab to display the LISA source code for SerialCharDoubler.lisa, and modify the SerialData slave port dataTransmit 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 code does not double data for escape sequences but does for other characters. An alphabetic character signals the end of escape sequences, resetting the resource inEscape.
  2. The dataReceive() behavior calls the respective behavior of the master port. Modify it.
    behavior dataReceive():uint16_t
    {
        return out.dataReceive();
    }
  3. The doubling does not affect signals, so represent the behaviors to set and get signals as wrappers of the master port behaviors.
    behavior signalsSet(uint8_t signal)
    {
        out.signalsSet(signal);
    }
    behavior signalsGet():uint8_t
    {
        return out.signalsGet();
    }
Non-ConfidentialPDF file icon PDF versionARM DUI0370S
Copyright © 2007-2014 ARM. All rights reserved.