]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/sfunction_frayconfig.c
032c763732175bc97efe73c305fa22010ade3877
[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 is in Markdown mark-up
92 Description: |
93
94   This block ...
95
96 Status:
97   Tested:
98   Untested:
99   Not working:
100     - Unknown status
101
102 RPP API functions used:
103
104 Relevant demos:
105 ...
106 */
107
108 #define S_FUNCTION_NAME sfunction_frayconfig
109 #include "header.c"
110 #include <stdio.h>
111
112 enum params {
113         gColdStartAttempts_IDX                 = 0,
114         gListenNoise_IDX                                   = 1,
115         gMacroPerCycle_IDX                                 = 2,
116         gMaxWithoutClockCorrectionFatal_IDX    = 3,
117         gMaxWithoutClockCorrectionPassive_IDX  = 4,
118         gNetworkManagementVectorLength_IDX     = 5,
119         gNumberOfMinislots_IDX                 = 6,
120         gNumberOfStaticSlots_IDX                   = 7,
121         gOffsetCorrectionStart_IDX                 = 8,
122         gPayloadLengthStatic_IDX                   = 9,
123         gSyncNodeMax_IDX                                   = 10,
124         gdActionPointOffset_IDX                    = 11,
125         gdCASRxLowMax_IDX                                  = 12,
126         gdDynamicSlotIdlePhase_IDX                 = 13,
127         gdMinislot_IDX                             = 14,
128         gdMinislotActionPointOffset_IDX        = 15,
129         gdNIT_IDX                                                  = 16,
130         gdSampleClockPeriod_IDX                    = 17,
131         gdStaticSlot_IDX                                   = 18,
132         gdTSSTransmitter_IDX                       = 19,
133         gdWakeupSymbolRxIdle_IDX                   = 20,
134         gdWakeupSymbolRxLow_IDX                    = 21,
135         gdWakeupSymbolRxWindow_IDX                 = 22,
136         gdWakeupSymbolTxIdle_IDX                   = 23,
137         gdWakeupSymbolTxLow_IDX                    = 24,
138
139         pAllowHaltDueToClock_IDX                   = 25,
140         pAllowPassiveToActive_IDX                  = 26,
141         pChannels_IDX                                      = 27,
142         pClusterDriftDamping_IDX                   = 28,
143         pDelayCompensationA_IDX                    = 29,
144         pDelayCompensationB_IDX                    = 30,
145         pExternOffsetCorrection_IDX            = 31,
146         pExternRateCorrection_IDX                  = 32,
147         pKeySlotUsedForStartup_IDX                 = 33,
148         pKeySlotUsedForSync_IDX                    = 34,
149         pLatestTx_IDX                                      = 35,
150         pMacroInitialOffsetA_IDX                   = 36,
151         pMacroInitialOffsetB_IDX                   = 37,
152         pMicroInitialOffsetA_IDX                   = 38,
153         pMicroInitialOffsetB_IDX                   = 39,
154         pMicroPerCycle_IDX                                 = 40,
155         pRateCorrectionOut_IDX                 = 41,
156         pOffsetCorrectionOut_IDX                   = 42,
157         pSamplesPerMicrotick_IDX                   = 43,
158         pSingleSlotEnabled_IDX                 = 44,
159         pWakeupChannel_IDX                                 = 45,
160         pWakeupPattern_IDX                                 = 46,
161         pdAcceptedStartupRange_IDX                 = 47,
162         pdListenTimeout_IDX                        = 48,
163         pdMaxDrift_IDX                             = 49,
164         pDecodingCorrection_IDX                    = 50,
165         syncFramePayloadMultiplexEnabled_IDX   = 51,
166         secureBuffers_IDX                                  = 52,
167         PARAM_COUNT
168 };
169
170
171 static void mdlInitializeSizes(SimStruct *S)
172 {
173
174     if (!rppSetNumParams(S, PARAM_COUNT)) {
175         return;
176     }
177
178     /*
179      * Configure input ports: 0
180      */
181     if (!ssSetNumInputPorts(S, 0)) {
182         return;
183     }
184
185     /*
186      * Configure output ports: 1
187      *  - Error flag.
188      */
189     if (!ssSetNumOutputPorts(S, 1)) {
190         return;
191     }
192     rppAddOutputPort(S, 0, SS_BOOLEAN);
193
194     /* Set standard options for this block */
195     rppSetStandardOptions(S);
196 }
197
198
199 #ifdef MATLAB_MEX_FILE
200 #define MDL_CHECK_PARAMETERS
201 static void mdlCheckParameters(SimStruct *S)
202 {
203
204 }
205 #endif
206
207
208 #ifdef MATLAB_MEX_FILE
209 #define MDL_SET_WORK_WIDTHS
210 static void mdlSetWorkWidths(SimStruct *S)
211 {
212     /* Set number of run-time parameters */
213     if (!ssSetNumRunTimeParams(S, PARAM_COUNT)) {
214         return;
215     }
216
217     /* Register the run-time parameter 1 */
218         ssRegDlgParamAsRunTimeParam(S, gColdStartAttempts_IDX, gColdStartAttempts_IDX, "gColdStartAttempts", SS_UINT8);
219         ssRegDlgParamAsRunTimeParam(S, gListenNoise_IDX, gListenNoise_IDX, "gListenNoise", SS_UINT8);
220         ssRegDlgParamAsRunTimeParam(S, gMacroPerCycle_IDX, gMacroPerCycle_IDX, "gMacroPerCycle", SS_UINT16);
221         ssRegDlgParamAsRunTimeParam(S, gMaxWithoutClockCorrectionFatal_IDX, gMaxWithoutClockCorrectionFatal_IDX, "gMaxWithoutClockCorrectionFatal", SS_UINT8);
222         ssRegDlgParamAsRunTimeParam(S, gMaxWithoutClockCorrectionPassive_IDX, gMaxWithoutClockCorrectionPassive_IDX, "gMaxWithoutClockCorrectionPassive", SS_UINT8);
223         ssRegDlgParamAsRunTimeParam(S, gNetworkManagementVectorLength_IDX, gNetworkManagementVectorLength_IDX, "gNetworkManagementVectorLength", SS_UINT8);
224         ssRegDlgParamAsRunTimeParam(S, gNumberOfMinislots_IDX, gNumberOfMinislots_IDX, "gNumberOfMinislots", SS_UINT16);
225         ssRegDlgParamAsRunTimeParam(S, gNumberOfStaticSlots_IDX, gNumberOfStaticSlots_IDX, "gNumberOfStaticSlots", SS_UINT16);
226         ssRegDlgParamAsRunTimeParam(S, gOffsetCorrectionStart_IDX, gOffsetCorrectionStart_IDX, "gOffsetCorrectionStart", SS_UINT16);
227         ssRegDlgParamAsRunTimeParam(S, gPayloadLengthStatic_IDX, gPayloadLengthStatic_IDX, "gPayloadLengthStatic", SS_UINT8);
228         ssRegDlgParamAsRunTimeParam(S, gSyncNodeMax_IDX, gSyncNodeMax_IDX, "gSyncNodeMax", SS_UINT8);
229         ssRegDlgParamAsRunTimeParam(S, gdActionPointOffset_IDX, gdActionPointOffset_IDX, "gdActionPointOffset", SS_UINT8);
230         ssRegDlgParamAsRunTimeParam(S, gdCASRxLowMax_IDX, gdCASRxLowMax_IDX, "gdCASRxLowMax", SS_UINT8);
231         ssRegDlgParamAsRunTimeParam(S, gdDynamicSlotIdlePhase_IDX, gdDynamicSlotIdlePhase_IDX, "gdDynamicSlotIdlePhase", SS_UINT8);
232         ssRegDlgParamAsRunTimeParam(S, gdMinislot_IDX, gdMinislot_IDX, "gdMinislot", SS_UINT8);
233         ssRegDlgParamAsRunTimeParam(S, gdMinislotActionPointOffset_IDX, gdMinislotActionPointOffset_IDX, "gdMinislotActionPointOffset", SS_UINT8);
234         ssRegDlgParamAsRunTimeParam(S, gdNIT_IDX, gdNIT_IDX, "gdNIT", SS_UINT16);
235         ssRegDlgParamAsRunTimeParam(S, gdSampleClockPeriod_IDX, gdSampleClockPeriod_IDX, "gdSampleClockPeriod", SS_UINT8);
236         ssRegDlgParamAsRunTimeParam(S, gdStaticSlot_IDX, gdStaticSlot_IDX, "gdStaticSlot", SS_UINT16);
237         ssRegDlgParamAsRunTimeParam(S, gdTSSTransmitter_IDX, gdTSSTransmitter_IDX, "gdTSSTransmitter", SS_UINT8);
238         ssRegDlgParamAsRunTimeParam(S, gdWakeupSymbolRxIdle_IDX, gdWakeupSymbolRxIdle_IDX, "gdWakeupSymbolRxIdle", SS_UINT8);
239         ssRegDlgParamAsRunTimeParam(S, gdWakeupSymbolRxLow_IDX, gdWakeupSymbolRxLow_IDX, "gdWakeupSymbolRxLow", SS_UINT8);
240         ssRegDlgParamAsRunTimeParam(S, gdWakeupSymbolRxWindow_IDX, gdWakeupSymbolRxWindow_IDX, "gdWakeupSymbolRxWindow", SS_UINT16);
241         ssRegDlgParamAsRunTimeParam(S, gdWakeupSymbolTxIdle_IDX, gdWakeupSymbolTxIdle_IDX, "gdWakeupSymbolTxIdle", SS_UINT8);
242         ssRegDlgParamAsRunTimeParam(S, gdWakeupSymbolTxLow_IDX, gdWakeupSymbolTxLow_IDX, "gdWakeupSymbolTxLow", SS_UINT8);
243
244         ssRegDlgParamAsRunTimeParam(S, pAllowHaltDueToClock_IDX, pAllowHaltDueToClock_IDX, "pAllowHaltDueToClock", SS_BOOLEAN);
245         ssRegDlgParamAsRunTimeParam(S, pAllowPassiveToActive_IDX, pAllowPassiveToActive_IDX, "pAllowPassiveToActive", SS_UINT8);
246         ssRegDlgParamAsRunTimeParam(S, pChannels_IDX, pChannels_IDX, "pChannels", SS_UINT8);
247         ssRegDlgParamAsRunTimeParam(S, pClusterDriftDamping_IDX, pClusterDriftDamping_IDX, "pClusterDriftDamping", SS_UINT8);
248         ssRegDlgParamAsRunTimeParam(S, pDelayCompensationA_IDX, pDelayCompensationA_IDX, "pDelayCompensationA", SS_UINT16);
249         ssRegDlgParamAsRunTimeParam(S, pDelayCompensationB_IDX, pDelayCompensationB_IDX, "pDelayCompensationB", SS_UINT16);
250         ssRegDlgParamAsRunTimeParam(S, pExternOffsetCorrection_IDX, pExternOffsetCorrection_IDX, "pExternOffsetCorrection", SS_UINT8);
251         ssRegDlgParamAsRunTimeParam(S, pExternRateCorrection_IDX, pExternRateCorrection_IDX, "pExternRateCorrection", SS_UINT8);
252         ssRegDlgParamAsRunTimeParam(S, pKeySlotUsedForStartup_IDX, pKeySlotUsedForStartup_IDX, "pKeySlotUsedForStartup", SS_BOOLEAN);
253         ssRegDlgParamAsRunTimeParam(S, pKeySlotUsedForSync_IDX, pKeySlotUsedForSync_IDX, "pKeySlotUsedForSync", SS_BOOLEAN);
254         ssRegDlgParamAsRunTimeParam(S, pLatestTx_IDX, pLatestTx_IDX, "pLatestTx", SS_UINT16);
255         ssRegDlgParamAsRunTimeParam(S, pMacroInitialOffsetA_IDX, pMacroInitialOffsetA_IDX, "pMacroInitialOffsetA", SS_UINT8);
256         ssRegDlgParamAsRunTimeParam(S, pMacroInitialOffsetB_IDX, pMacroInitialOffsetB_IDX, "pMacroInitialOffsetB", SS_UINT8);
257         ssRegDlgParamAsRunTimeParam(S, pMicroInitialOffsetA_IDX, pMicroInitialOffsetA_IDX, "pMicroInitialOffsetA", SS_UINT8);
258         ssRegDlgParamAsRunTimeParam(S, pMicroInitialOffsetB_IDX, pMicroInitialOffsetB_IDX, "pMicroInitialOffsetB", SS_UINT8);
259         ssRegDlgParamAsRunTimeParam(S, pMicroPerCycle_IDX, pMicroPerCycle_IDX, "pMicroPerCycle", SS_UINT32);
260         ssRegDlgParamAsRunTimeParam(S, pRateCorrectionOut_IDX, pRateCorrectionOut_IDX, "pRateCorrectionOut", SS_UINT16);
261         ssRegDlgParamAsRunTimeParam(S, pOffsetCorrectionOut_IDX, pOffsetCorrectionOut_IDX, "pOffsetCorrectionOut", SS_UINT16);
262         ssRegDlgParamAsRunTimeParam(S, pSamplesPerMicrotick_IDX, pSamplesPerMicrotick_IDX, "pSamplesPerMicrotick", SS_UINT8);
263         ssRegDlgParamAsRunTimeParam(S, pSingleSlotEnabled_IDX, pSingleSlotEnabled_IDX, "pSingleSlotEnabled", SS_UINT8);
264         ssRegDlgParamAsRunTimeParam(S, pWakeupChannel_IDX, pWakeupChannel_IDX, "pWakeupChannel", SS_UINT8);
265         ssRegDlgParamAsRunTimeParam(S, pWakeupPattern_IDX, pWakeupPattern_IDX, "pWakeupPattern", SS_UINT8);
266         ssRegDlgParamAsRunTimeParam(S, pdAcceptedStartupRange_IDX, pdAcceptedStartupRange_IDX, "pdAcceptedStartupRange", SS_UINT16);
267         ssRegDlgParamAsRunTimeParam(S, pdListenTimeout_IDX, pdListenTimeout_IDX, "pdListenTimeout", SS_UINT32);
268         ssRegDlgParamAsRunTimeParam(S, pdMaxDrift_IDX, pdMaxDrift_IDX, "pdMaxDrift", SS_UINT16);
269         ssRegDlgParamAsRunTimeParam(S, pDecodingCorrection_IDX, pDecodingCorrection_IDX, "pDecodingCorrection", SS_UINT8);
270         ssRegDlgParamAsRunTimeParam(S, syncFramePayloadMultiplexEnabled_IDX, syncFramePayloadMultiplexEnabled_IDX, "syncFramePayloadMultiplexEnabled", SS_BOOLEAN);
271         ssRegDlgParamAsRunTimeParam(S, secureBuffers_IDX, secureBuffers_IDX, "secureBuffers", SS_UINT8);
272 }
273 #endif
274
275
276 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
277 #define UNUSED_MDLOUTPUTS
278 #define UNUSED_MDLTERMINATE
279 #include "trailer.c"