cgsl_0410: Timer service for component deployment
ID: Title | cgsl_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:
| ||
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.
| ||
Notes | When a clock resolution is not specified, the code generator uses these default values for the clock resolution:
When using S-function to set the timer, for aperiodic
functions that are driven by an S-function that specifies the
| ||
Rationale | Robust handling of data access by functions that execute concurrently. | ||
Model Advisor Check | A 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); } |
See Also
Code Interfaces and Code Interface Specification (Embedded Coder)
Create a Service Interface Configuration (Embedded Coder)
Data Communication Methods (Embedded Coder)
Embedded Coder Dictionary (Embedded Coder)
Generate C Timer Service Interface Code for Component Deployment (Embedded Coder)