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,
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,
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
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
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
cm = coder.mapping.api.get('ComponentDeploymentFcn');
In this model, the exported function
Aperiodic, represented by the
Integrator, requires timer services in the platform environment. Get
the current timer service interface configuration by using the
getFunction(cm, 'ExportedFunction:Aperiodic', 'TimerService')
ans = 'Dictionary default'
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
get_tick_during, which is defined in the
setFunction(cm, 'ExportedFunction:Aperiodic',... 'TimerService', 'get_tick_during')