1 %% Copyright (C) 2013 Czech Technical University in Prague
4 %% - Michal Horn <hornmich@fel.cvut.cz>
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
15 %% The above copyright notice and this permission notice shall be
16 %% included in all copies or substantial portions of the Software.
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.
27 %% File : sfunction_frayconfig.tlc
29 %% TLC file for inlining RPP FlexRay TX buffer configuration and message transmittion.
32 %% BlockTypeSetup() : refs/rtw_tlc.pdf p. 277
33 %% Outputs() : refs/rtw_tlc.pdf p. 281
36 %implements sfunction_frayconfig "C"
41 %% Function: BlockTypeSetup ====================================================
42 %function BlockTypeSetup(block, system) void
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
52 %function BlockInstanceSetup(block, system) void
57 %% Function: Start =============================================================
58 %function Start(block, system) Output
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)>,
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,
96 .pChannels = FR_CHANNEL_AB,
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,
118 .pWakeupChannel = FR_CHANNEL_B,
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)>,
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>
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,
142 .secureBuffers = FR_SB_ALL_REC_DISABLED_STAT_TR_DISABLED,
144 .statSegmentBufferCount = FRAY_STATIC_BUFFER_COUNT,
145 .dynSegmentBufferCount = 0,
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,
159 %<LibSetSourceFileSection(LibGetModelDotCFile(), "Declarations", buffer)>
161 %if !SLibCodeGenForSim()
164 %assign err_flag = LibBlockOutputSignal(0, "", "", 0)
167 %% Declare temporal variables
168 %if EXISTS("_RPP_FRAYCONFIG_TMP_VARS_") == 0
169 %assign ::_RPP_FRAYCONFIG_TMP_VARS_ = 1
174 retVal = rpp_fr_init_driver(&flexray_cfg, &error);
175 if (retVal == FAILURE) {
176 rpp_sci_printf("FlexRay driver init error.\n");
180 rpp_sci_printf("FlexRay driver initialized.\n");
183 retVal = rpp_fr_init_controller(0, &error);
184 if (retVal == FAILURE) {
185 rpp_sci_printf("FlexRay controller init error: %#x.\n", error);
189 rpp_sci_printf("FlexRay controller initialized.\n");
192 retVal = rpp_fr_start_communication(0, &error);
193 if (retVal == FAILURE) {
194 rpp_sci_printf("FlexRay start communication failed: %#x.\n", error);
198 rpp_sci_printf("FlexRay communication started.\n");
200 retVal = rpp_fr_all_slots(0);
201 if (retVal == FAILURE) {
202 rpp_sci_printf("FlexRay all slots failed: %#x.\n", error);
206 rpp_sci_printf("FlexRay is communicating on all slots.\n");