]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/tlc_c/sfunction_fraytransmit.tlc
Change license to MIT
[pes-rpp/rpp-simulink.git] / rpp / blocks / tlc_c / sfunction_fraytransmit.tlc
1 %% Copyright (C) 2013, 2014 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_fraytransmit.tlc
28 %% Abstract:
29 %%     TLC file for inlining RPP FlexRay node configuration.
30 %%
31 %% References:
32 %%     BlockTypeSetup() : refs/rtw_tlc.pdf p. 277
33 %%     Outputs()        : refs/rtw_tlc.pdf p. 281
34
35
36 %implements sfunction_fraytransmit "C"
37
38 %include "common.tlc"
39
40 %% Function: BlockTypeSetup ====================================================
41 %function BlockTypeSetup(block, system) void
42
43     %% Ensure required header files are included
44     %<RppCommonBlockTypeSetup(block, system)>
45     %<LibAddToCommonIncludes("rpp/rpp.h")>
46
47 %endfunction
48
49 %function BlockInstanceSetup(block, system) void
50   %assign channel_val                                    = LibBlockParameterValue(channel, 0)
51   %assign cycleCounterFiltering_val      = LibBlockParameterValue(cycleCounterFiltering, 0)
52   %assign maxPayload_val                                 = LibBlockParameterValue(maxPayload, 0)
53   %assign msgBufferInterrupt_val                 = LibBlockParameterValue(msgBufferInterrupt, 0)
54   %assign payloadPreambleIndicatorTr_val = LibBlockParameterValue(payloadPreambleIndicatorTr, 0)
55   %assign singleTransmit_val                     = LibBlockParameterValue(singleTransmit, 0)
56   %assign slotId_val                                     = LibBlockParameterValue(slotId, 0)
57   %assign bufferId_val                                   = LibBlockParameterValue(bufferId, 0)
58
59   %if EXISTS(::rpp_fr_bufferId_%<bufferId_val>_flg) == 1
60     %<LibBlockReportError(block, "Buffer ID is already used by another FlexRay block.")>
61   %endif
62   %assign ::rpp_fr_bufferId_%<bufferId_val>_flg = 1
63
64   %openfile buffer
65   {
66     // Buffer %<bufferId_val>
67         %if channel_val == 1U
68           .channel = FR_CHANNEL_A,
69         %elseif channel_val == 2U
70           .channel = FR_CHANNEL_B,
71         %else
72           .channel = FR_CHANNEL_AB,       
73         %endif
74         .cycleCounterFiltering = %<cycleCounterFiltering_val>,
75         .fidMask = 0,
76         .isTx = TRUE,
77         .maxPayload = %<maxPayload_val>,
78         .msgBufferInterrupt = %<msgBufferInterrupt_val>,
79         .payloadPreambleIndicatorTr = %<payloadPreambleIndicatorTr_val>,
80         .rejectNullFrames = FALSE,
81         .rejectStaticSegment = FALSE,
82         .singleTransmit = %<singleTransmit_val>,
83         .slotId = %<slotId_val>
84   },
85   %closefile buffer
86
87   %if ISEQUAL(::rpp_fray_buffer_key_slot, "")
88         %assign ::rpp_fray_buffer_key_slot = "%<buffer>"
89   %else
90         %assign ::rpp_fray_buffer_config = "%<::rpp_fray_buffer_config> %<buffer>"
91   %endif
92   %assign ::rpp_fray_buffer_count = %<::rpp_fray_buffer_count> + 1      
93
94 %endfunction
95
96
97 %% Function: Start =============================================================
98 %function Start(block, system) Output
99
100     %if !SLibCodeGenForSim()
101
102           %if EXISTS(::rpp_fray_config_present) == 0
103                 %<LibBlockReportError(block, "FlexRay config block not present!")>
104           %endif
105     %endif
106 %endfunction
107
108 %% Function: Outputs ===========================================================
109 %function Outputs(block, system) Output
110
111         %if EXISTS("_RPP_FRAYSTEP_TMP_VARS_") == 0
112             %assign ::_RPP_FRAYSTEP_TMP_VARS_ = 1
113                 int8_t retVal;
114         %endif
115
116
117     %if !SLibCodeGenForSim()
118                 %% Get parameters
119         %assign slotId_val = LibBlockParameterValue(slotId, 0)
120         %assign maxPayload_val = LibBlockParameterValue(maxPayload, 0)
121         %assign bufferId_val = LibBlockParameterValue(bufferId, 0)
122
123         %% Get IO signals
124         %assign message = LibBlockInputSignal(0, "", "", 0)
125         %assign err_flag = LibBlockOutputSignal(0, "", "", 0)
126
127                 rpp_sci_printf("sending message %#x on slot %d from buffer %d.\n", %<message>, %<slotId_val>, %<bufferId_val>);
128
129                 retVal = rpp_fr_transmit_lpdu(0, %<bufferId_val>, &%<message>, %<maxPayload_val>*2);
130                 if (retVal == FAILURE) {
131                         rpp_sci_printf("Sending a message from buffer %#x failed.\n", %<bufferId_val>);
132                         %<err_flag> = TRUE;
133                 }
134     %endif
135 %endfunction
136
137
138 %% [EOF]