]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/sfunction_frayconfig.c
34a59405ea642d9df86428d8b512ae2ac5fe6309
[jenkicar/rpp-simulink.git] / rpp / blocks / sfunction_frayconfig.c
1 /* Copyright (C) 2013, 2014 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Michal Horn <hornimch@fel.cvut.cz>
5  *
6  * This document contains proprietary information belonging to Czech
7  * Technical University in Prague. Passing on and copying of this
8  * document, and communication of its contents is not permitted
9  * without prior written authorization.
10  *
11  * File : sfunction_frayc.c
12  * Abstract:
13  *     C-MEX S-function block for RPP FlexRay cluster configuration.
14  *
15  * References:
16  *     header.c
17  *     trailer.c
18  *
19  * Compile with:
20  *     <matlabroot>/bin/mex sfunction_frayconfig.c
21  */
22
23 /*
24 %YAML 1.2
25 ---
26 Name: Configure FlexRay Node
27 Category: FlexRay
28 Header: rpp/fr.h
29 Mnemonic: FRC
30
31 Inputs:
32
33 Outputs:
34   - { name: "ErrFlag", type: "bool" }
35
36 Parameters:
37   - { name: "gColdStartAttempts",                type: "uint8"  }
38   - { name: "gListenNoise",                      type: "uint8"  }
39   - { name: "gMacroPerCycle",                    type: "uint16" }
40   - { name: "gMaxWithoutClockCorrectionFatal",   type: "uint8"  }
41   - { name: "gMaxWithoutClockCorrectionPassive", type: "uint8"  }
42   - { name: "gNetworkManagementVectorLength",    type: "uint8"  }
43   - { name: "gNumberOfMinislots",                type: "uint16" }
44   - { name: "gNumberOfStaticSlots",              type: "uint16" }
45   - { name: "gOffsetCorrectionStart",            type: "uint16" }
46   - { name: "gPayloadLengthStatic",              type: "uint8"  }
47   - { name: "gSyncNodeMax",                      type: "uint8"  }
48   - { name: "gdActionPointOffset",               type: "uint8"  }
49   - { name: "gdCASRxLowMax",                     type: "uint8"  }
50   - { name: "gdDynamicSlotIdlePhase",            type: "uint8"  }
51   - { name: "gdMinislot",                        type: "uint8"  }
52   - { name: "gdMinislotActionPointOffset",       type: "uint8"  }
53   - { name: "gdNIT",                             type: "uint16" }
54   - { name: "gdSampleClockPeriod",               type: "uint8"  }
55   - { name: "gdStaticSlot",                      type: "uint16" }
56   - { name: "gdTSSTransmitter",                  type: "uint8"  }
57   - { name: "gdWakeupSymbolRxIdle",              type: "uint8"  }
58   - { name: "gdWakeupSymbolRxLow",               type: "uint8"  }
59   - { name: "gdWakeupSymbolRxWindow",            type: "uint16" }
60   - { name: "gdWakeupSymbolTxIdle",              type: "uint8"  }
61   - { name: "gdWakeupSymbolTxLow",               type: "uint8"  }
62   - { name: "pAllowHaltDueToClock",              type: "bool"   }
63   - { name: "pAllowPassiveToActive",             type: "uint8"  }
64   - { name: "pChannels",                         type: "uint8"  }
65   - { name: "pClusterDriftDamping",              type: "uint8"  }
66   - { name: "pDelayCompensationA",               type: "uint16" }
67   - { name: "pDelayCompensationB",               type: "uint16" }
68   - { name: "pExternOffsetCorrection",           type: "uint8"  }
69   - { name: "pExternRateCorrection",             type: "uint8"  }
70   - { name: "pKeySlotUsedForStartup",            type: "bool"   }
71   - { name: "pKeySlotUsedForSync",               type: "bool"   }
72   - { name: "pLatestTx",                         type: "uint16" }
73   - { name: "pMacroInitialOffsetA",              type: "uint8"  }
74   - { name: "pMacroInitialOffsetB",              type: "uint8"  }
75   - { name: "pMicroInitialOffsetA",              type: "uint8"  }
76   - { name: "pMicroInitialOffsetB",              type: "uint8"  }
77   - { name: "pMicroPerCycle",                    type: "uint32" }
78   - { name: "pRateCorrectionOut",                type: "uint16" }
79   - { name: "pOffsetCorrectionOut",              type: "uint16" }
80   - { name: "pSamplesPerMicrotick",              type: "uint8"  }
81   - { name: "pSingleSlotEnabled",                type: "uint8"  }
82   - { name: "pWakeupChannel",                    type: "uint8"  }
83   - { name: "pWakeupPattern",                    type: "uint8"  }
84   - { name: "pdAcceptedStartupRange",            type: "uint16" }
85   - { name: "pdListenTimeout",                   type: "uint32" }
86   - { name: "pdMaxDrift",                        type: "uint16" }
87   - { name: "pDecodingCorrection",               type: "uint8"  }
88   - { name: "syncFramePayloadMultiplexEnabled",  type: "bool"   }
89   - { name: "secureBuffers",                     type: "uint8"  }
90
91 # Description and Help is in Markdown mark-up
92 Description: &desc |
93
94   This block ...
95
96 Help: *desc
97
98 Status:
99   Tested:
100   Untested:
101   Not working:
102     - Unknown status
103
104 RPP API functions used:
105
106 Relevant demos:
107 ...
108 */
109
110 #define S_FUNCTION_NAME sfunction_frayconfig
111 #include "header.c"
112 #include <stdio.h>
113
114 enum params {
115         gColdStartAttempts_IDX                 = 0,
116         gListenNoise_IDX                                   = 1,
117         gMacroPerCycle_IDX                                 = 2,
118         gMaxWithoutClockCorrectionFatal_IDX    = 3,
119         gMaxWithoutClockCorrectionPassive_IDX  = 4,
120         gNetworkManagementVectorLength_IDX     = 5,
121         gNumberOfMinislots_IDX                 = 6,
122         gNumberOfStaticSlots_IDX                   = 7,
123         gOffsetCorrectionStart_IDX                 = 8,
124         gPayloadLengthStatic_IDX                   = 9,
125         gSyncNodeMax_IDX                                   = 10,
126         gdActionPointOffset_IDX                    = 11,
127         gdCASRxLowMax_IDX                                  = 12,
128         gdDynamicSlotIdlePhase_IDX                 = 13,
129         gdMinislot_IDX                             = 14,
130         gdMinislotActionPointOffset_IDX        = 15,
131         gdNIT_IDX                                                  = 16,
132         gdSampleClockPeriod_IDX                    = 17,
133         gdStaticSlot_IDX                                   = 18,
134         gdTSSTransmitter_IDX                       = 19,
135         gdWakeupSymbolRxIdle_IDX                   = 20,
136         gdWakeupSymbolRxLow_IDX                    = 21,
137         gdWakeupSymbolRxWindow_IDX                 = 22,
138         gdWakeupSymbolTxIdle_IDX                   = 23,
139         gdWakeupSymbolTxLow_IDX                    = 24,
140
141         pAllowHaltDueToClock_IDX                   = 25,
142         pAllowPassiveToActive_IDX                  = 26,
143         pChannels_IDX                                      = 27,
144         pClusterDriftDamping_IDX                   = 28,
145         pDelayCompensationA_IDX                    = 29,
146         pDelayCompensationB_IDX                    = 30,
147         pExternOffsetCorrection_IDX            = 31,
148         pExternRateCorrection_IDX                  = 32,
149         pKeySlotUsedForStartup_IDX                 = 33,
150         pKeySlotUsedForSync_IDX                    = 34,
151         pLatestTx_IDX                                      = 35,
152         pMacroInitialOffsetA_IDX                   = 36,
153         pMacroInitialOffsetB_IDX                   = 37,
154         pMicroInitialOffsetA_IDX                   = 38,
155         pMicroInitialOffsetB_IDX                   = 39,
156         pMicroPerCycle_IDX                                 = 40,
157         pRateCorrectionOut_IDX                 = 41,
158         pOffsetCorrectionOut_IDX                   = 42,
159         pSamplesPerMicrotick_IDX                   = 43,
160         pSingleSlotEnabled_IDX                 = 44,
161         pWakeupChannel_IDX                                 = 45,
162         pWakeupPattern_IDX                                 = 46,
163         pdAcceptedStartupRange_IDX                 = 47,
164         pdListenTimeout_IDX                        = 48,
165         pdMaxDrift_IDX                             = 49,
166         pDecodingCorrection_IDX                    = 50,
167         syncFramePayloadMultiplexEnabled_IDX   = 51,
168         secureBuffers_IDX                                  = 52,
169         PARAM_COUNT
170 };
171
172
173 static void mdlInitializeSizes(SimStruct *S)
174 {
175
176     if (!rppSetNumParams(S, PARAM_COUNT)) {
177         return;
178     }
179
180     /*
181      * Configure input ports: 0
182      */
183     if (!ssSetNumInputPorts(S, 0)) {
184         return;
185     }
186
187     /*
188      * Configure output ports: 1
189      *  - Error flag.
190      */
191     if (!ssSetNumOutputPorts(S, 1)) {
192         return;
193     }
194     rppAddOutputPort(S, 0, SS_BOOLEAN);
195
196     /* Set standard options for this block */
197     rppSetStandardOptions(S);
198 }
199
200
201 #ifdef MATLAB_MEX_FILE
202 #define MDL_CHECK_PARAMETERS
203 static void mdlCheckParameters(SimStruct *S)
204 {
205
206 }
207 #endif
208
209
210 #ifdef MATLAB_MEX_FILE
211 #define MDL_SET_WORK_WIDTHS
212 static void mdlSetWorkWidths(SimStruct *S)
213 {
214     /* Set number of run-time parameters */
215     if (!ssSetNumRunTimeParams(S, PARAM_COUNT)) {
216         return;
217     }
218
219     /* Register the run-time parameter 1 */
220         ssRegDlgParamAsRunTimeParam(S, gColdStartAttempts_IDX, gColdStartAttempts_IDX, "gColdStartAttempts", SS_UINT8);
221         ssRegDlgParamAsRunTimeParam(S, gListenNoise_IDX, gListenNoise_IDX, "gListenNoise", SS_UINT8);
222         ssRegDlgParamAsRunTimeParam(S, gMacroPerCycle_IDX, gMacroPerCycle_IDX, "gMacroPerCycle", SS_UINT16);
223         ssRegDlgParamAsRunTimeParam(S, gMaxWithoutClockCorrectionFatal_IDX, gMaxWithoutClockCorrectionFatal_IDX, "gMaxWithoutClockCorrectionFatal", SS_UINT8);
224         ssRegDlgParamAsRunTimeParam(S, gMaxWithoutClockCorrectionPassive_IDX, gMaxWithoutClockCorrectionPassive_IDX, "gMaxWithoutClockCorrectionPassive", SS_UINT8);
225         ssRegDlgParamAsRunTimeParam(S, gNetworkManagementVectorLength_IDX, gNetworkManagementVectorLength_IDX, "gNetworkManagementVectorLength", SS_UINT8);
226         ssRegDlgParamAsRunTimeParam(S, gNumberOfMinislots_IDX, gNumberOfMinislots_IDX, "gNumberOfMinislots", SS_UINT16);
227         ssRegDlgParamAsRunTimeParam(S, gNumberOfStaticSlots_IDX, gNumberOfStaticSlots_IDX, "gNumberOfStaticSlots", SS_UINT16);
228         ssRegDlgParamAsRunTimeParam(S, gOffsetCorrectionStart_IDX, gOffsetCorrectionStart_IDX, "gOffsetCorrectionStart", SS_UINT16);
229         ssRegDlgParamAsRunTimeParam(S, gPayloadLengthStatic_IDX, gPayloadLengthStatic_IDX, "gPayloadLengthStatic", SS_UINT8);
230         ssRegDlgParamAsRunTimeParam(S, gSyncNodeMax_IDX, gSyncNodeMax_IDX, "gSyncNodeMax", SS_UINT8);
231         ssRegDlgParamAsRunTimeParam(S, gdActionPointOffset_IDX, gdActionPointOffset_IDX, "gdActionPointOffset", SS_UINT8);
232         ssRegDlgParamAsRunTimeParam(S, gdCASRxLowMax_IDX, gdCASRxLowMax_IDX, "gdCASRxLowMax", SS_UINT8);
233         ssRegDlgParamAsRunTimeParam(S, gdDynamicSlotIdlePhase_IDX, gdDynamicSlotIdlePhase_IDX, "gdDynamicSlotIdlePhase", SS_UINT8);
234         ssRegDlgParamAsRunTimeParam(S, gdMinislot_IDX, gdMinislot_IDX, "gdMinislot", SS_UINT8);
235         ssRegDlgParamAsRunTimeParam(S, gdMinislotActionPointOffset_IDX, gdMinislotActionPointOffset_IDX, "gdMinislotActionPointOffset", SS_UINT8);
236         ssRegDlgParamAsRunTimeParam(S, gdNIT_IDX, gdNIT_IDX, "gdNIT", SS_UINT16);
237         ssRegDlgParamAsRunTimeParam(S, gdSampleClockPeriod_IDX, gdSampleClockPeriod_IDX, "gdSampleClockPeriod", SS_UINT8);
238         ssRegDlgParamAsRunTimeParam(S, gdStaticSlot_IDX, gdStaticSlot_IDX, "gdStaticSlot", SS_UINT16);
239         ssRegDlgParamAsRunTimeParam(S, gdTSSTransmitter_IDX, gdTSSTransmitter_IDX, "gdTSSTransmitter", SS_UINT8);
240         ssRegDlgParamAsRunTimeParam(S, gdWakeupSymbolRxIdle_IDX, gdWakeupSymbolRxIdle_IDX, "gdWakeupSymbolRxIdle", SS_UINT8);
241         ssRegDlgParamAsRunTimeParam(S, gdWakeupSymbolRxLow_IDX, gdWakeupSymbolRxLow_IDX, "gdWakeupSymbolRxLow", SS_UINT8);
242         ssRegDlgParamAsRunTimeParam(S, gdWakeupSymbolRxWindow_IDX, gdWakeupSymbolRxWindow_IDX, "gdWakeupSymbolRxWindow", SS_UINT16);
243         ssRegDlgParamAsRunTimeParam(S, gdWakeupSymbolTxIdle_IDX, gdWakeupSymbolTxIdle_IDX, "gdWakeupSymbolTxIdle", SS_UINT8);
244         ssRegDlgParamAsRunTimeParam(S, gdWakeupSymbolTxLow_IDX, gdWakeupSymbolTxLow_IDX, "gdWakeupSymbolTxLow", SS_UINT8);
245
246         ssRegDlgParamAsRunTimeParam(S, pAllowHaltDueToClock_IDX, pAllowHaltDueToClock_IDX, "pAllowHaltDueToClock", SS_BOOLEAN);
247         ssRegDlgParamAsRunTimeParam(S, pAllowPassiveToActive_IDX, pAllowPassiveToActive_IDX, "pAllowPassiveToActive", SS_UINT8);
248         ssRegDlgParamAsRunTimeParam(S, pChannels_IDX, pChannels_IDX, "pChannels", SS_UINT8);
249         ssRegDlgParamAsRunTimeParam(S, pClusterDriftDamping_IDX, pClusterDriftDamping_IDX, "pClusterDriftDamping", SS_UINT8);
250         ssRegDlgParamAsRunTimeParam(S, pDelayCompensationA_IDX, pDelayCompensationA_IDX, "pDelayCompensationA", SS_UINT16);
251         ssRegDlgParamAsRunTimeParam(S, pDelayCompensationB_IDX, pDelayCompensationB_IDX, "pDelayCompensationB", SS_UINT16);
252         ssRegDlgParamAsRunTimeParam(S, pExternOffsetCorrection_IDX, pExternOffsetCorrection_IDX, "pExternOffsetCorrection", SS_UINT8);
253         ssRegDlgParamAsRunTimeParam(S, pExternRateCorrection_IDX, pExternRateCorrection_IDX, "pExternRateCorrection", SS_UINT8);
254         ssRegDlgParamAsRunTimeParam(S, pKeySlotUsedForStartup_IDX, pKeySlotUsedForStartup_IDX, "pKeySlotUsedForStartup", SS_BOOLEAN);
255         ssRegDlgParamAsRunTimeParam(S, pKeySlotUsedForSync_IDX, pKeySlotUsedForSync_IDX, "pKeySlotUsedForSync", SS_BOOLEAN);
256         ssRegDlgParamAsRunTimeParam(S, pLatestTx_IDX, pLatestTx_IDX, "pLatestTx", SS_UINT16);
257         ssRegDlgParamAsRunTimeParam(S, pMacroInitialOffsetA_IDX, pMacroInitialOffsetA_IDX, "pMacroInitialOffsetA", SS_UINT8);
258         ssRegDlgParamAsRunTimeParam(S, pMacroInitialOffsetB_IDX, pMacroInitialOffsetB_IDX, "pMacroInitialOffsetB", SS_UINT8);
259         ssRegDlgParamAsRunTimeParam(S, pMicroInitialOffsetA_IDX, pMicroInitialOffsetA_IDX, "pMicroInitialOffsetA", SS_UINT8);
260         ssRegDlgParamAsRunTimeParam(S, pMicroInitialOffsetB_IDX, pMicroInitialOffsetB_IDX, "pMicroInitialOffsetB", SS_UINT8);
261         ssRegDlgParamAsRunTimeParam(S, pMicroPerCycle_IDX, pMicroPerCycle_IDX, "pMicroPerCycle", SS_UINT32);
262         ssRegDlgParamAsRunTimeParam(S, pRateCorrectionOut_IDX, pRateCorrectionOut_IDX, "pRateCorrectionOut", SS_UINT16);
263         ssRegDlgParamAsRunTimeParam(S, pOffsetCorrectionOut_IDX, pOffsetCorrectionOut_IDX, "pOffsetCorrectionOut", SS_UINT16);
264         ssRegDlgParamAsRunTimeParam(S, pSamplesPerMicrotick_IDX, pSamplesPerMicrotick_IDX, "pSamplesPerMicrotick", SS_UINT8);
265         ssRegDlgParamAsRunTimeParam(S, pSingleSlotEnabled_IDX, pSingleSlotEnabled_IDX, "pSingleSlotEnabled", SS_UINT8);
266         ssRegDlgParamAsRunTimeParam(S, pWakeupChannel_IDX, pWakeupChannel_IDX, "pWakeupChannel", SS_UINT8);
267         ssRegDlgParamAsRunTimeParam(S, pWakeupPattern_IDX, pWakeupPattern_IDX, "pWakeupPattern", SS_UINT8);
268         ssRegDlgParamAsRunTimeParam(S, pdAcceptedStartupRange_IDX, pdAcceptedStartupRange_IDX, "pdAcceptedStartupRange", SS_UINT16);
269         ssRegDlgParamAsRunTimeParam(S, pdListenTimeout_IDX, pdListenTimeout_IDX, "pdListenTimeout", SS_UINT32);
270         ssRegDlgParamAsRunTimeParam(S, pdMaxDrift_IDX, pdMaxDrift_IDX, "pdMaxDrift", SS_UINT16);
271         ssRegDlgParamAsRunTimeParam(S, pDecodingCorrection_IDX, pDecodingCorrection_IDX, "pDecodingCorrection", SS_UINT8);
272         ssRegDlgParamAsRunTimeParam(S, syncFramePayloadMultiplexEnabled_IDX, syncFramePayloadMultiplexEnabled_IDX, "syncFramePayloadMultiplexEnabled", SS_BOOLEAN);
273         ssRegDlgParamAsRunTimeParam(S, secureBuffers_IDX, secureBuffers_IDX, "secureBuffers", SS_UINT8);
274 }
275 #endif
276
277
278 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
279 #define UNUSED_MDLOUTPUTS
280 #define UNUSED_MDLTERMINATE
281 #include "trailer.c"