]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/tlc_c/sfunction_fraytransmit.tlc
Merge branch 'master' of rtime.felk.cvut.cz:jenkicar/rpp-simulink
[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 %% This document contains proprietary information belonging to Czech
7 %% Technical University in Prague. Passing on and copying of this
8 %% document, and communication of its contents is not permitted
9 %% without prior written authorization.
10 %%
11 %% File : sfunction_fraytransmit.tlc
12 %% Abstract:
13 %%     TLC file for inlining RPP FlexRay node configuration.
14 %%
15 %% References:
16 %%     BlockTypeSetup() : refs/rtw_tlc.pdf p. 277
17 %%     Outputs()        : refs/rtw_tlc.pdf p. 281
18
19
20 %implements sfunction_fraytransmit "C"
21
22 %include "common.tlc"
23
24 %% Function: BlockTypeSetup ====================================================
25 %function BlockTypeSetup(block, system) void
26
27     %% Ensure required header files are included
28     %<RppCommonBlockTypeSetup(block, system)>
29     %<LibAddToCommonIncludes("rpp/rpp.h")>
30
31 %endfunction
32
33 %function BlockInstanceSetup(block, system) void
34   %assign channel_val                                    = LibBlockParameterValue(channel, 0)
35   %assign cycleCounterFiltering_val      = LibBlockParameterValue(cycleCounterFiltering, 0)
36   %assign maxPayload_val                                 = LibBlockParameterValue(maxPayload, 0)
37   %assign msgBufferInterrupt_val                 = LibBlockParameterValue(msgBufferInterrupt, 0)
38   %assign payloadPreambleIndicatorTr_val = LibBlockParameterValue(payloadPreambleIndicatorTr, 0)
39   %assign singleTransmit_val                     = LibBlockParameterValue(singleTransmit, 0)
40   %assign slotId_val                                     = LibBlockParameterValue(slotId, 0)
41   %assign bufferId_val                                   = LibBlockParameterValue(bufferId, 0)
42
43   %if EXISTS(::rpp_fr_bufferId_%<bufferId_val>_flg) == 1
44     %<LibBlockReportError(block, "Buffer ID is already used by another FlexRay block.")>
45   %endif
46   %assign ::rpp_fr_bufferId_%<bufferId_val>_flg = 1
47
48   %openfile buffer
49   {
50     // Buffer %<bufferId_val>
51         %if channel_val == 1U
52           .channel = FR_CHANNEL_A,
53         %elseif channel_val == 2U
54           .channel = FR_CHANNEL_B,
55         %else
56           .channel = FR_CHANNEL_AB,       
57         %endif
58         .cycleCounterFiltering = %<cycleCounterFiltering_val>,
59         .fidMask = 0,
60         .isTx = TRUE,
61         .maxPayload = %<maxPayload_val>,
62         .msgBufferInterrupt = %<msgBufferInterrupt_val>,
63         .payloadPreambleIndicatorTr = %<payloadPreambleIndicatorTr_val>,
64         .rejectNullFrames = FALSE,
65         .rejectStaticSegment = FALSE,
66         .singleTransmit = %<singleTransmit_val>,
67         .slotId = %<slotId_val>
68   },
69   %closefile buffer
70
71   %if ISEQUAL(::rpp_fray_buffer_key_slot, "")
72         %assign ::rpp_fray_buffer_key_slot = "%<buffer>"
73   %else
74         %assign ::rpp_fray_buffer_config = "%<::rpp_fray_buffer_config> %<buffer>"
75   %endif
76   %assign ::rpp_fray_buffer_count = %<::rpp_fray_buffer_count> + 1      
77
78 %endfunction
79
80
81 %% Function: Start =============================================================
82 %function Start(block, system) Output
83
84     %if !SLibCodeGenForSim()
85
86           %if EXISTS(::rpp_fray_config_present) == 0
87                 %<LibBlockReportError(block, "FlexRay config block not present!")>
88           %endif
89     %endif
90 %endfunction
91
92 %% Function: Outputs ===========================================================
93 %function Outputs(block, system) Output
94
95         %if EXISTS("_RPP_FRAYSTEP_TMP_VARS_") == 0
96             %assign ::_RPP_FRAYSTEP_TMP_VARS_ = 1
97                 int8_t retVal;
98         %endif
99
100
101     %if !SLibCodeGenForSim()
102                 %% Get parameters
103         %assign slotId_val = LibBlockParameterValue(slotId, 0)
104         %assign maxPayload_val = LibBlockParameterValue(maxPayload, 0)
105         %assign bufferId_val = LibBlockParameterValue(bufferId, 0)
106
107         %% Get IO signals
108         %assign message = LibBlockInputSignal(0, "", "", 0)
109         %assign err_flag = LibBlockOutputSignal(0, "", "", 0)
110
111                 rpp_sci_printf("sending message %#x on slot %d from buffer %d.\n", %<message>, %<slotId_val>, %<bufferId_val>);
112
113                 retVal = rpp_fr_transmit_lpdu(0, %<bufferId_val>, &%<message>, %<maxPayload_val>*2);
114                 if (retVal == FAILURE) {
115                         rpp_sci_printf("Sending a message from buffer %#x failed.\n", %<bufferId_val>);
116                         %<err_flag> = TRUE;
117                 }
118     %endif
119 %endfunction
120
121
122 %% [EOF]