]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/tlc_c/sfunction_frayreceive.tlc
FlexRay library TX and RX blocks prints tuned
[jenkicar/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 %% This program is free software; you can redistribute it and/or modify
7 %% it under the terms of the GNU General Public License as published by
8 %% the Free Software Foundation; either version 2 of the License, or
9 %% (at your option) any later version.
10 %%
11 %% This program is distributed in the hope that it will be useful,
12 %% but WITHOUT ANY WARRANTY; without even the implied warranty of
13 %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 %% GNU General Public License for more details.
15 %%
16 %% You should have received a copy of the GNU General Public License
17 %% along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 %%
19 %% File : sfunction_frayreceive.tlc
20 %% Abstract:
21 %%     TLC file for inlining RPP FlexRay node configuration.
22 %%
23 %% References:
24 %%     BlockTypeSetup() : refs/rtw_tlc.pdf p. 277
25 %%     Outputs()        : refs/rtw_tlc.pdf p. 281
26
27
28 %implements sfunction_frayreceive "C"
29
30 %include "common.tlc"
31
32
33 %% Function: BlockTypeSetup ====================================================
34 %function BlockTypeSetup(block, system) void
35
36     %% Ensure required header files are included
37     %<RppCommonBlockTypeSetup(block, system)>
38
39 %endfunction
40
41
42 %% Function: Start =============================================================
43 %function Start(block, system) Output
44
45     %if !SLibCodeGenForSim()
46         %assign channel_val = LibBlockParameterValue(channel, 0)
47         %assign cycleCounterFiltering_val = LibBlockParameterValue(cycleCounterFiltering, 0)
48         %assign maxPayload_val = LibBlockParameterValue(maxPayload, 0)
49         %assign msgBufferInterrupt_val = LibBlockParameterValue(msgBufferInterrupt, 0)
50         %assign payloadPreambleIndicatorTr_val = LibBlockParameterValue(payloadPreambleIndicatorTr, 0)
51         %assign singleTransmit_val = LibBlockParameterValue(singleTransmit, 0)
52         %assign slotId_val = LibBlockParameterValue(slotId, 0)
53
54         %% Declare temporal variables
55         %if EXISTS("_RPP_FRAYCONFIG_TMP_VARS_") == 0
56             %assign ::_RPP_FRAYCONFIG_TMP_VARS_ = 1
57                         #define MAX_ST_BUF_CFG 62
58                         Fr_TMS570LS_ClusterConfigType cluster_cfg;
59                         Fr_TMS570LS_NodeConfigType node_cfg;
60                         Fr_TMS570LS_BufferConfigType static_buffers_cfg[MAX_ST_BUF_CFG];
61                         Fr_TMS570LS_MsgRAMConfig msg_ram_cfg;
62                         Fr_ConfigType flexray_cfg;
63                         uint8_t static_buffers_cnt = 0;
64         %endif
65                 %if %<channel_val>==1
66                         static_buffers_cfg[static_buffers_cnt].channel = FR_CHANNEL_A;
67                 %elseif %<channel_val>==2
68                         static_buffers_cfg[static_buffers_cnt].channel = FR_CHANNEL_B;
69                 %else
70                         static_buffers_cfg[static_buffers_cnt].channel = FR_CHANNEL_AB;
71                 %endif
72             static_buffers_cfg[static_buffers_cnt].cycleCounterFiltering = %<cycleCounterFiltering_val>;
73             static_buffers_cfg[static_buffers_cnt].isTx = FALSE;
74             static_buffers_cfg[static_buffers_cnt].maxPayload = %<maxPayload_val>;
75             static_buffers_cfg[static_buffers_cnt].msgBufferInterrupt = %<msgBufferInterrupt_val>;
76             static_buffers_cfg[static_buffers_cnt].payloadPreambleIndicatorTr = %<payloadPreambleIndicatorTr_val>;
77             static_buffers_cfg[static_buffers_cnt].singleTransmit = %<singleTransmit_val>;
78             static_buffers_cfg[static_buffers_cnt].slotId = %<slotId_val>;
79                 static_buffers_cnt++;
80                 rpp_sci_printf("RX buffer %d added.\n", static_buffers_cnt);
81     %endif
82 %endfunction
83
84 %% Function: Outputs ===========================================================
85 %function Outputs(block, system) Output
86
87         %if EXISTS("_RPP_FRAYSTEP_TMP_VARS_") == 0
88             %assign ::_RPP_FRAYSTEP_TMP_VARS_ = 1
89                 int8_t retVal;
90         %endif
91
92     %if !SLibCodeGenForSim()
93                 %% Get parameters
94         %assign slotId_val = LibBlockParameterValue(slotId, 0)
95
96         %% Get IO signals
97         %assign err_flag = LibBlockOutputSignal(0, "", "", 0)
98         %assign message = LibBlockOutputSignal(1, "", "", 0)
99         %assign length = LibBlockOutputSignal(2, "", "", 0)
100         %assign trigger = LibBlockOutputSignal(3, "", "", 0)
101
102                 uint8_t rec_msg[16];
103                 uint8_t rec_length;
104                 Fr_RxLPduStatusType rec_status;
105
106                 retVal = rpp_fr_receive_lpdu(0, %<slotId_val>, rec_msg, &rec_status, &rec_length);
107                 if (retVal == FAILURE) {
108                         rpp_sci_printf("Receiving a message from slot %#x failed.\n", %<slotId_val>);
109                         %<err_flag> = TRUE;
110                         %<message> = 0;
111                         %<length> = 0;
112                         %<trigger> = 0;
113                 }
114                 else {
115                         if (rec_status == FR_NOT_RECEIVED) {
116                                 %<trigger> = 0;
117                                 %<message> = 0;
118                                 %<length> = 0;
119                         }
120                         else {
121                                 rpp_sci_printf("Message from slot %#x received:%#x\n", %<slotId_val>, rec_msg[0]);
122                                 %<trigger> = 1;
123                                 %<message> = rec_msg[0];
124                                 %<length> = rec_length;
125                         }
126                 }
127     %endif
128 %endfunction
129
130
131 %% [EOF]