]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/tlc_c/sfunction_frayreceive.tlc
Change license to MIT
[pes-rpp/rpp-simulink.git] / rpp / blocks / tlc_c / sfunction_frayreceive.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_frayreceive.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_frayreceive "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   // Buffer %<bufferId_val>
66   {
67         %if %<channel_val>==1
68           .channel = FR_CHANNEL_A,
69         %elseif %<channel_val>==2
70           .channel = FR_CHANNEL_B,
71         %else
72           .channel = FR_CHANNEL_AB,
73         %endif
74         .cycleCounterFiltering = %<cycleCounterFiltering_val>,
75         .fidMask = 0,
76         .isTx = FALSE,
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   %assign ::rpp_fray_buffer_config = "%<::rpp_fray_buffer_config> %<buffer>"
87   %assign ::rpp_fray_buffer_count = %<::rpp_fray_buffer_count> + 1
88 %endfunction
89
90 %% Function: Outputs ===========================================================
91 %function Outputs(block, system) Output
92
93         %if EXISTS("_RPP_FRAYSTEP_TMP_VARS_") == 0
94             %assign ::_RPP_FRAYSTEP_TMP_VARS_ = 1
95                 int8_t retVal;
96         %endif
97         %if EXISTS("_RPP_FRAYREC_TMP_VARS_") == 0
98             %assign ::_RPP_FRAYREC_TMP_VARS_ = 1
99                 int8_t i;
100         %endif
101
102     %if !SLibCodeGenForSim()
103                 %% Get parameters
104         %assign maxPayload_val = LibBlockParameterValue(maxPayload, 0)
105         %assign bufferId_val = LibBlockParameterValue(bufferId, 0)
106
107         %% Get IO signals
108         %assign err_flag = LibBlockOutputSignal(0, "", "", 0)
109         %assign message = LibBlockOutputSignal(1, "", "", 0)
110         %assign length = LibBlockOutputSignal(2, "", "", 0)
111         %assign trigger = LibBlockOutputSignal(3, "", "", 0)
112
113                 %if EXISTS("_RPP_FRAYSTEP_RX_VARS_") == 0
114                   %assign ::_RPP_FRAYSTEP_RX_VARS_ = 1
115                   uint8_t rec_msg[%<maxPayload_val>*2];
116                   uint8_t rec_length;
117                   Fr_RxLPduStatusType rec_status;
118                 %endif
119
120
121                 retVal = rpp_fr_receive_lpdu(0, %<bufferId_val>, rec_msg, &rec_status, &rec_length);
122                 if (retVal == FAILURE) {
123                         rpp_sci_printf("Receiving a message from buffer %#x failed.\n", %<bufferId_val>);
124                         %<err_flag> = TRUE;
125                         %<message> = 0;
126                         %<length> = 0;
127                         %<trigger> = 0;
128                 }
129                 else {
130                         if (rec_status == FR_NOT_RECEIVED) {
131                                 %<trigger> = 0;
132                                 %<message> = 0;
133                                 %<length> = 0;
134                         }
135                         else {
136                                 rpp_sci_printf("Message from buffer %#x received:%#x\n", %<bufferId_val>, rec_msg[0]);
137                                 %<trigger> = 1;
138                                 for (i = 0; i < %<maxPayload_val>*2; i++) {
139                                         *(&%<message>+i) = rec_msg[i];
140                                 }
141                                 %<length> = rec_length;
142                         }
143                 }
144     %endif
145 %endfunction
146
147
148 %% [EOF]