]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/tlc_c/sfunction_frayconfig.tlc
Change license to MIT
[pes-rpp/rpp-simulink.git] / rpp / blocks / tlc_c / sfunction_frayconfig.tlc
1 %% Copyright (C) 2013 Czech Technical University in Prague
2 %%
3 %% Authors:
4 %%     - Michal Horn <hornmich@fel.cvut.cz>
5 %%
6 %% Permission is hereby granted, free of charge, to any person
7 %% obtaining a copy of this software and associated documentation
8 %% files (the "Software"), to deal in the Software without
9 %% restriction, including without limitation the rights to use,
10 %% copy, modify, merge, publish, distribute, sublicense, and/or sell
11 %% copies of the Software, and to permit persons to whom the
12 %% Software is furnished to do so, subject to the following
13 %% conditions:
14
15 %% The above copyright notice and this permission notice shall be
16 %% included in all copies or substantial portions of the Software.
17
18 %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 %% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 %% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 %% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 %% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 %% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 %% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 %% OTHER DEALINGS IN THE SOFTWARE.
26 %%
27 %% File : sfunction_frayconfig.tlc
28 %% Abstract:
29 %%     TLC file for inlining RPP FlexRay TX buffer configuration and message transmittion.
30 %%
31 %% References:
32 %%     BlockTypeSetup() : refs/rtw_tlc.pdf p. 277
33 %%     Outputs()        : refs/rtw_tlc.pdf p. 281
34
35
36 %implements sfunction_frayconfig "C"
37
38 %include "common.tlc"
39
40
41 %% Function: BlockTypeSetup ====================================================
42 %function BlockTypeSetup(block, system) void
43
44     %% Ensure required header files are included
45     %<RppCommonBlockTypeSetup(block, system)>
46     %<LibAddToCommonIncludes("rpp/rpp.h")>
47     %assign ::rpp_fray_config_present = 1
48     %assign ::rpp_fray_present=1
49
50 %endfunction
51
52 %function BlockInstanceSetup(block, system) void
53  
54 %endfunction
55
56
57 %% Function: Start =============================================================
58 %function Start(block, system) Output
59  %openfile buffer
60   static const Fr_TMS570LS_ClusterConfigType fray_cluster_cfg = {
61         .gColdStartAttempts = %<LibBlockParameterValue(gColdStartAttempts, 0)>,
62         .gListenNoise = %<LibBlockParameterValue(gListenNoise, 0)>,
63         .gMacroPerCycle = %<LibBlockParameterValue(gMacroPerCycle, 0)>,
64         .gMaxWithoutClockCorrectionFatal = %<LibBlockParameterValue(gMaxWithoutClockCorrectionFatal, 0)>,
65         .gMaxWithoutClockCorrectionPassive = %<LibBlockParameterValue(gMaxWithoutClockCorrectionPassive, 0)>,
66         .gNetworkManagementVectorLength = %<LibBlockParameterValue(gNetworkManagementVectorLength, 0)>,
67         .gNumberOfMinislots = %<LibBlockParameterValue(gNumberOfMinislots, 0)>,
68         .gNumberOfStaticSlots = %<LibBlockParameterValue(gNumberOfStaticSlots, 0)>,
69         .gOffsetCorrectionStart = %<LibBlockParameterValue(gOffsetCorrectionStart, 0)>,
70         .gPayloadLengthStatic = %<LibBlockParameterValue(gPayloadLengthStatic, 0)>,
71         .gSyncNodeMax = %<LibBlockParameterValue(gSyncNodeMax, 0)>,
72         .gdActionPointOffset = %<LibBlockParameterValue(gdActionPointOffset, 0)>,
73         .gdCASRxLowMax = %<LibBlockParameterValue(gdCASRxLowMax, 0)>,
74         .gdDynamicSlotIdlePhase = %<LibBlockParameterValue(gdDynamicSlotIdlePhase, 0)>,
75         .gdMinislot = %<LibBlockParameterValue(gdMinislot, 0)>,
76         .gdMinislotActionPointOffset = %<LibBlockParameterValue(gdMinislotActionPointOffset, 0)>,
77         .gdNIT = %<LibBlockParameterValue(gdNIT, 0)>,
78         .gdSampleClockPeriod = %<LibBlockParameterValue(gdSampleClockPeriod, 0)>,
79         .gdStaticSlot = %<LibBlockParameterValue(gdStaticSlot, 0)>,
80         .gdTSSTransmitter = %<LibBlockParameterValue(gdTSSTransmitter, 0)>,
81         .gdWakeupSymbolRxIdle = %<LibBlockParameterValue(gdWakeupSymbolRxIdle, 0)>,
82         .gdWakeupSymbolRxLow = %<LibBlockParameterValue(gdWakeupSymbolRxLow, 0)>,
83         .gdWakeupSymbolRxWindow = %<LibBlockParameterValue(gdWakeupSymbolRxWindow, 0)>,
84         .gdWakeupSymbolTxIdle = %<LibBlockParameterValue(gdWakeupSymbolTxIdle, 0)>,
85         .gdWakeupSymbolTxLow = %<LibBlockParameterValue(gdWakeupSymbolTxLow, 0)>,
86   };
87
88   static const Fr_TMS570LS_NodeConfigType fray_node_cfg = {
89         .pAllowHaltDueToClock =  %<LibBlockParameterValue(pAllowHaltDueToClock, 0)>,
90         .pAllowPassiveToActive =  %<LibBlockParameterValue(pAllowPassiveToActive, 0)>,
91         %if %<LibBlockParameterValue(pChannels, 0)>==1
92           .pChannels = FR_CHANNEL_A,
93         %elseif %<LibBlockParameterValue(pChannels, 0)>==2
94           .pChannels = FR_CHANNEL_B,
95         %else
96           .pChannels = FR_CHANNEL_AB,
97         %endif
98         .pClusterDriftDamping =  %<LibBlockParameterValue(pClusterDriftDamping, 0)>,
99         .pDelayCompensationA =  %<LibBlockParameterValue(pDelayCompensationA, 0)>,
100         .pDelayCompensationB =  %<LibBlockParameterValue(pDelayCompensationB, 0)>,
101         .pExternOffsetCorrection =  %<LibBlockParameterValue(pExternOffsetCorrection, 0)>,
102         .pExternRateCorrection =  %<LibBlockParameterValue(pExternRateCorrection, 0)>,
103         .pKeySlotUsedForStartup =  %<LibBlockParameterValue(pKeySlotUsedForStartup, 0)>,
104         .pKeySlotUsedForSync =  %<LibBlockParameterValue(pKeySlotUsedForSync, 0)>,
105         .pLatestTx =  %<LibBlockParameterValue(pLatestTx, 0)>,
106         .pMacroInitialOffsetA =  %<LibBlockParameterValue(pMacroInitialOffsetA, 0)>,
107         .pMacroInitialOffsetB =  %<LibBlockParameterValue(pMacroInitialOffsetB, 0)>,
108         .pMicroInitialOffsetA =  %<LibBlockParameterValue(pMicroInitialOffsetA, 0)>,
109         .pMicroInitialOffsetB =   %<LibBlockParameterValue(pMicroInitialOffsetB, 0)>,
110         .pMicroPerCycle =  %<LibBlockParameterValue(pMicroPerCycle, 0)>,
111         .pRateCorrectionOut =  %<LibBlockParameterValue(pRateCorrectionOut, 0)>,
112         .pOffsetCorrectionOut =  %<LibBlockParameterValue(pOffsetCorrectionOut, 0)>,
113         .pSamplesPerMicrotick =  %<LibBlockParameterValue(pSamplesPerMicrotick, 0)>,
114         .pSingleSlotEnabled =  %<LibBlockParameterValue(pSingleSlotEnabled, 0)>,
115         %if %<LibBlockParameterValue(pWakeupChannel, 0)>==1
116           .pWakeupChannel = FR_CHANNEL_A,
117         %else
118           .pWakeupChannel = FR_CHANNEL_B,
119         %endif
120         .pWakeupPattern =  %<LibBlockParameterValue(pWakeupPattern, 0)>,
121         .pdAcceptedStartupRange =  %<LibBlockParameterValue(pdAcceptedStartupRange, 0)>,
122         .pdListenTimeout =  %<LibBlockParameterValue(pdListenTimeout, 0)>,
123         .pdMaxDrift =  %<LibBlockParameterValue(pdMaxDrift, 0)>,
124         .pDecodingCorrection =  %<LibBlockParameterValue(pDecodingCorrection, 0)>,
125   };
126
127   #define FRAY_STATIC_BUFFER_COUNT %<::rpp_fray_buffer_count>
128   static const Fr_TMS570LS_BufferConfigType fray_static_buffers_cfg[FRAY_STATIC_BUFFER_COUNT] = {
129         %<::rpp_fray_buffer_key_slot>
130         %<::rpp_fray_buffer_config>
131   };
132
133   static const Fr_TMS570LS_MsgRAMConfig fray_msg_ram_cfg = {
134         .syncFramePayloadMultiplexEnabled = %<LibBlockParameterValue(syncFramePayloadMultiplexEnabled, 0)>,
135         %if %<LibBlockParameterValue(secureBuffers, 0)>==1
136           .secureBuffers = FR_SB_RECONFIG_ENABLED,
137         %elseif %<LibBlockParameterValue(secureBuffers, 0)>==2
138           .secureBuffers = FR_SB_STAT_REC_DISABLED_STAT_TR_DISABLED,
139         %elseif %<LibBlockParameterValue(secureBuffers, 0)>==3
140           .secureBuffers = FR_SB_ALL_REC_DISABLED,
141         %else
142           .secureBuffers = FR_SB_ALL_REC_DISABLED_STAT_TR_DISABLED,
143         %endif
144         .statSegmentBufferCount = FRAY_STATIC_BUFFER_COUNT,
145         .dynSegmentBufferCount = 0,
146         .fifoBufferCount = 0
147   };
148
149   static const Fr_ConfigType flexray_cfg = {
150         .clusterConfiguration = &fray_cluster_cfg,
151         .nodeConfiguration = &fray_node_cfg,
152         .msgRAMConfig = &fray_msg_ram_cfg,
153         .staticBufferConfigs =  fray_static_buffers_cfg,
154         .dynamicBufferConfigs = NULL,
155         .fifoBufferConfigs = NULL,
156   };
157
158   %closefile buffer
159   %<LibSetSourceFileSection(LibGetModelDotCFile(), "Declarations", buffer)>
160
161     %if !SLibCodeGenForSim()
162
163                 %% Error flag
164                 %assign err_flag = LibBlockOutputSignal(0, "", "", 0)
165
166
167                 %% Declare temporal variables
168                 %if EXISTS("_RPP_FRAYCONFIG_TMP_VARS_") == 0
169                   %assign ::_RPP_FRAYCONFIG_TMP_VARS_ = 1
170                 %endif
171                 int8_t retVal;
172                 uint32_t error;
173
174                 retVal = rpp_fr_init_driver(&flexray_cfg, &error);
175                 if (retVal == FAILURE) {
176                     rpp_sci_printf("FlexRay driver init error.\n");
177                         %<err_flag> = TRUE;
178                 }
179                 else {
180                         rpp_sci_printf("FlexRay driver initialized.\n");
181                 }
182
183                 retVal = rpp_fr_init_controller(0, &error);
184                 if (retVal == FAILURE) {
185                         rpp_sci_printf("FlexRay controller init error: %#x.\n", error);
186                         %<err_flag> = TRUE;
187                 }
188                 else {
189                         rpp_sci_printf("FlexRay controller initialized.\n");
190                 }
191
192                 retVal = rpp_fr_start_communication(0, &error);
193                 if (retVal == FAILURE) {
194                         rpp_sci_printf("FlexRay start communication failed: %#x.\n", error);
195                         %<err_flag> = TRUE;
196                 }
197                 else {
198                         rpp_sci_printf("FlexRay communication started.\n");
199                 }
200                 retVal = rpp_fr_all_slots(0);
201                 if (retVal == FAILURE) {
202                         rpp_sci_printf("FlexRay all slots failed: %#x.\n", error);
203                         %<err_flag> = TRUE;
204                 }
205                 else {
206                         rpp_sci_printf("FlexRay is communicating on all slots.\n");
207                 }
208     %endif
209 %endfunction
210
211
212 %% [EOF]