Main Content

Configure Timer Service Interfaces for Aperiodic Export Functions

For component deployment of aperiodic export-function models, you can generate code that accesses the function clock tick provided by the target environment. A function clock tick value is the number of time ticks from the start of program execution to the present time for a function. Generated code for an aperiodic function can access the target platform function clock tick value by calling a function provided by the platform timer service.

You represent requests for the function clock tick in a top model implicitly when you include Discrete Time Integrator and Weighted Sample Time blocks. The code generator produces code that calls a timer service function if the aperiodic functions use Discrete Time Integrator or Weighted Sampletime blocks. If you do not want to use the default timer service interface specified in the Embedded Coder Dictionary, you can configure the timer service interface by using the Code Mappings Editor.

Timer service interfaces can be configured to access timer services:

  • Outside execution: The platform service communicates clock tick value outside (before and after) function execution.

  • During execution: The platform communicates clock tick value immediately during function execution.

Configure Timer Service Interfaces by Using the Code Mappings Editor

In this example, the component model references a shared coder dictionary that defines the default timer service interfaces for exported functions in the component model. To configure the timer to use something other than the default service interface, use the Code Mappings editor.

Open the component model, ComponentDeploymentFcn.


Screenshot of component model

In this model, the Function-Call Subsystem block Integrator uses a timer service because it contains a Discrete-Time Integrator block.

Verify that the component model references the shared coder dictionary, ComponentDeploymentCoderDictionary.sldd.

In the Model Configuration Parameters dialog box, verify that the Shared coder dictionary parameter is set to ComponentDeploymentCoderDictionary.sldd. This dictionary defines default service interfaces, including the timer services, of the component model.

Open the Embedded Coder app.

To configure the integrator function to use a timer service interface other than the default defined by the shared coder dictionary, use the Code Mappings editor.

To open the Code Mappings editor, in the C Code tab, click Code Interface > Component Interface.

On the Functions tab, on the table row for the Exported Function:Aperiodic function, click the pencil icon. The Timer Service, is set to Dictionary default: get_tick_outside.

Default configuration of the code mappings by using dictionary default values

To configure the function to access clock tick value immediately during function execution instead of before or after execution as specified in the dictionary, set the Timer Service of Exported Function:Aperiodic to get_tick_during.

Code mappings editor with timer service for Exported Function:Aperiodic configured to get_tick_during

Configure Timer Service Interfaces Programmatically

To configure timer services of a function component programmatically, access the code mapping properties of the component model.

Open the model.


Get the code mappings for the model by using the coder.mapping.api.get function.

cm = coder.mapping.api.get('ComponentDeploymentFcn');

In this model, the exported function Aperiodic, represented by the Function-Call Subsystem, Integrator, requires timer services in the platform environment. Get the current timer service interface configuration by using the getFunction function.

getFunction(cm, 'ExportedFunction:Aperiodic', 'TimerService')
ans =

    'Dictionary default'
The function is configured to use the default timer service interface defined in the shared coder dictionary.

To configure the function to access timer services during function execution instead of before or after execution as specified in the dictionary, use the setFunction function and set the TimerService property to get_tick_during, which is defined in the dictionary.

setFunction(cm, 'ExportedFunction:Aperiodic',...
 'TimerService', 'get_tick_during')

See Also

| | |

Related Topics