4.4.2. Attributes

The attribute specifier for the behavior must be one of the following:

master

the behavior must be implemented and is for a master port. A default implementation is not permitted.

slave

the behavior must be implemented and is for a slave port. A default implementation is not permitted.

optional master

the behavior not required to be implemented. If it is implemented, it is for a master port. A default implementation can be provided as part of the prototype definition.

optional slave

the behavior not required to be implemented. If it is implemented, it is for a slave port. A default implementation can be provided as part of the prototype definition.

The attribute specifier for the behavior in the protocol definition must:

In the large majority of cases, your protocol behavior is a slave, or optional slave, behavior. Master behaviors are not common.

Note

The presence of default behaviors is part of the protocol definition.

Mandatory behavior

For the following example of a behavior declaration in a protocol:

slave behavior f();
  • Behavior f() must be implemented by all slave ports using this protocol.

  • Calling f() invokes all behaviors f() in all slave ports connected to the same port.

  • Behavior f() might not be implemented in master ports.

  • The slave must provide read and write functions to access resources.

  • A default implementation cannot be provided because the optional keyword is not used. If a default implementation is present, an error is generated.

Optional behavior without default implementation

For the following example of an optional behavior declaration in a protocol:

optional slave behavior f();
  • Behavior f() might not be implemented by all slave ports that use this protocol. There is no default behavior, so a call to the behavior results in an error.

  • Calling f() invokes all behaviors f() in all slave ports connected to the same port. A master might, for example, notify or query information from all connected slaves, but the handling of this is optional.

  • A master must check whether at least one behavior is connected to a behavior in the specified port:

    if (myport.f.implemented()) myport.f(); 
    

    Note

    The use of the implemented() test is only recommended if the default implementation in protocol cannot be used. You are advised to ensure that optional behaviors in new code have default implementations. However, if you are using unmodified legacy code and the called behavior has the optional keyword but no default implementation, you must test for implementation.

  • Calling a behavior on a port that is not implemented in any of the slaves causes a run-time error.

Optional behavior with default implementation

For the following example of an optional behavior declaration in a protocol:

optional slave behavior f()
{
// default implementation. Can be empty
}
  • Behavior f() might not be implemented by all slave ports that use this protocol. If a slave does not implement the behavior, the default implementation is used instead. The default can be {} if no action is required.

  • If behavior f() is implemented by the port, that implementation is used instead of the default implementation.

  • Calling f() invokes all behaviors f() in all slave ports connected to the same port. A master might, for example, notify or query information from all connected slaves, but the handling of this is optional.

  • It is not required that a master use the form:

    if (myport.f.implemented()) myport.f(); 
    

    to test for implementation of the behavior in a port. The default implementation means that f.implemented() returns true whether or not they have a local implementation.

  • If a behavior returns a value, for example,

    optional slave behavior f() : uint8_t
    {
        // additional code can be present here, but is not required
        return 0;
    }
    

    the default implementation can return 0 or any another value that is valid in the context of the calling function.If the return value is undefined, the compiler generates a warning if such warnings are enabled. System Canvas does not issue a warning.

Copyright © 2007-2009 ARM Limited. All rights reserved.ARM DUI 0372G
Non-Confidential