Main Content

cgsl_0410: Timer service for component deployment

ID: Titlecgsl_0410: Timer service for component deployment
Description

To model the timer service code interface, at the root level of the component:

A

Set model configuration parameters:

  • Set System target file to ert.tlc

  • Set solver parameter Type to Fixed-step

  • Set solver parameter Clock resolution to a scalar value of type double

B

To safeguard data for concurrent access, map to a service interface that is configured to use the During Execution or Outside Execution data communication method.

  • During Execution — The generated callable function that implements the algorithm safeguards data access for concurrency.

  • Outside Execution —The target platform service safeguards data access for concurrency.

Notes

When a clock resolution is not specified, the code generator uses these default values for the clock resolution:

  • For aperiodic functions, the model fixed-step size (fundamental sample time)

  • For periodic functions, the function sample time

When using S-function to set the timer, for aperiodic functions that are driven by an S-function that specifies the SS_OPTION_ASYNCHRONOUS option and a clock resolution, the clock resolution that the S-function specifies overrides the setting of the Clock resolution parameter.

Rationale

Robust handling of data access by functions that execute concurrently.

Model Advisor CheckA Model Advisor check is not provided for this guideline.
Examples

This example shows the generated code for the header file.

#Header File ComponentDeploymentFcn.h
#include "services.h"
.
.
.
typedef struct {
  real_T DataTransfer_WriteBuf[10];
  real_T DiscreteTimeIntegrator_PREV_U[10];
  uint32_T Interator_PREV_T;
  uint8_T DiscreteTimeIntegrator_SYSTEM_E;
  boolean_T Integrator_RESET_ELAPS_T;
} D_Work;

typedef struct {
  real_T delay[10];
  real_T dti[10];
} CD_measured_T;
.
.
.
extern void CD_integrator(void);

In this source code example, the data communication method is set to Outside-Execution.

CD_measured_T CD_measured;
.
.
.
void CD_integrator(void)
{
  real_T tmp;
  real_T *tmp_0;
  int32_T i;
  uint32_T Integrator_ELAPS_T;
  tmp_0 = set_CD_integrator_DataTransfer();
  if (rtDwork.Integrator_RESET_ELAPS_T) {
    Integrator_ELAPS_T = 0U;
  } else {
    Integrator_ELAPS_T = (uint32_T)(get_tick_outside_CD_integrator() -
      rtDWork.Integrator_PREV_T);
  }

  rtDWork.Integrator_PREV_T = get_tick_outside_CD_integrator();
  rtDwork.Integrator_RESET_ELAPS_T = false;
  tmp = 1.25 * (real_T)Integrator_ELAPS_T;
  for (i = 0; i < 10; i++) {
    if ((int32_T)rtDWork.DiscreteTimeIntegrator_SYSTEM_E == 0) {
      CD_measured.dti[i] += tmp * rtDWork.DiscreteTimeIntegrator_PREV_U[i];
    }

    rtDWork.DiscreteTimeIntegrator_PREV_U[i] = (get_CD_
    integrator_InBus_u())[i];
}    

  rtDWork.DiscreteTimeIntegrator_SYSTEM_E = 0U;
  memcpy(&tmp_0[0], &CD_measured.dti[0], (uint32_T)(10U * sizeof(real_T)));
}

In this source code example, the data communication method is set to During-Execution.

void CD_integrator(void)
{
  real_T tmp[10];
  real_T tmp_0;
  int32_T i;
  uint32_T Integrator_ELAPS_T;
  rtM->Timing.clockTick2 = get_tick_during_CD_integrator();
  if (rtDWork.Interator_RESET_ELAPS_T) {
    Integrator_ELAPS_T = 0U;
  } else {
    Integrator_ELAPS_T = (uint32_T)(rtM->Timing.clockTick2 - 
      rtDWork.Integrator_PREV_T);
  }

  get_CD_integrator_input_(&tmp[0]);
  rtDWork.Integrator_PREV_T = rtM->Timing.clockTick2;
  rtDWork.Integrator_RESET_ELAPS_T = false;
  tmp_0 = 1.25 * (real_T)Integrator_ELAPS_T;
  for (i = 0; i < 10; i++) {
    if ((int32_T)rtDWork.DiscreteTimeIntegrator_SYSTEM_E == 0) {
      CD_measured.dti[i] += tmp_0 * rtDWork.DiscreteTimeIntegrator_PREV_U[i];
    }

    rtDWork.discreteTimeIntegrator_PREV_U[i] = tmp[i];
}    

  rtDWork.DiscreteTimeIntegrator_SYSTEM_E = 0U;
  set_CD_integrator_DataTransfer(CD_measured.dti);
}

Version History

expand all

Introduced in R2023a