1 %% Copyright (C) 2014 Czech Technical University in Prague
4 %% Michal Horn <hornmich@fel.cvut.cz>
5 %% Michal Sojka <sojkam1@fel.cvut.cz>
7 %% Permission is hereby granted, free of charge, to any person
8 %% obtaining a copy of this software and associated documentation
9 %% files (the "Software"), to deal in the Software without
10 %% restriction, including without limitation the rights to use,
11 %% copy, modify, merge, publish, distribute, sublicense, and/or sell
12 %% copies of the Software, and to permit persons to whom the
13 %% Software is furnished to do so, subject to the following
16 %% The above copyright notice and this permission notice shall be
17 %% included in all copies or substantial portions of the Software.
19 %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 %% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 %% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 %% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 %% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 %% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 %% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 %% OTHER DEALINGS IN THE SOFTWARE.
28 %% File : sfunction_canreceive.tlc
30 %% TLC file for configuring the CAN RX buffer on the TI TMS570LS3137 MCU
33 %% BlockTypeSetup() : refs/rtw_tlc.pdf p. 277
34 %% Outputs() : refs/rtw_tlc.pdf p. 281
37 %implements sfunction_canreceive "C"
40 %include "rpp_can_common.tlc"
42 %% Function: BlockTypeSetup ====================================================
43 %function BlockTypeSetup(block, system) void
44 %<LibAddToCommonIncludes("can_message.h")>
45 %<LibAddToCommonIncludes("rpp/rpp.h")>
46 %<RppCommonBlockTypeSetup(block, system)>
47 %<RppCANCommonBlockTypeSetup()>
50 %% Function: BlockInstanceSetup ================================================
51 %function BlockInstanceSetup(block, system) void
53 %assign module_id_par = LibBlockParameterValue(module_id, 0)
54 %assign mailbox_num_par = LibBlockParameterValue(mailbox_id, 0)
55 %assign message_type_par = LibBlockParameterValue(message_type, 0)
56 %assign message_id_par = LibBlockParameterValue(message_id, 0)
57 %assign data_type_par = LibBlockParameterValue(data_type, 0)
58 %assign message_filter_par = LibBlockParameterValue(message_filter, 0)
59 %assign message_mask_par = LibBlockParameterValue(message_mask, 0)
60 %assign mailbox_auto_par = LibBlockParameterValue(mailbox_auto, 0)
62 %if message_filter_par == 1
63 %assign mask = 8388607 %% 0x7FFFFF
65 %assign mask = message_mask_par
68 %% This seems to be the only way to add a record to an array. The
69 %% other way - creating the record with %createrecord and adding
70 %% it later with %addtorecord doesn't work.
71 %addtorecord Rpp.Can.Rx Block { ...
72 HwObj Rpp.Can.Rx.NumBlocks; ...
73 Controller module_id_par; ...
74 MsgObj 0; /% Invalid MsgObj - proper value will be assigned later %/ ...
75 Type message_type_par; ...
76 Id message_id_par; ...
78 Name "%<LibGetBlockName(block)>" ...
80 %assign blockInfo = Rpp.Can.Rx.Block[Rpp.Can.Rx.NumBlocks] /% create alias to the record %/
81 %if %<mailbox_auto_par>==1
82 %<RppPlaceAutomaticMailboxNumber(blockInfo)>
84 %<RppPlaceManualMailboxNumber(blockInfo, mailbox_num_par)>
87 /% Remember which blockInfo record is associated wit this block %/
88 %addtorecord block RppRxInfo blockInfo
89 %assign Rpp.Can.Rx.NumBlocks = Rpp.Can.Rx.NumBlocks + 1
92 %% Function: Start =============================================================
93 %function Start(block, system) Output
95 %if !SLibCodeGenForSim()
97 %if EXISTS(::rpp_can_config_present) == 0
98 %<LibBlockReportError(block, "CAN buc configuration block not present!")>
105 %% Function: Outputs ===========================================================
106 %function Outputs(block, system) Output
108 %if !SLibCodeGenForSim()
109 %assign data_type_par = LibBlockParameterValue(data_type, 0)
110 %assign message = LibBlockOutputSignal(1, "", "", 1)
113 struct rpp_can_pdu pdu;
116 ret = rpp_can_read(%<RppRxInfo.HwObj>, &pdu);
119 rpp_sci_printf("Receiving CAN message failed (%s).\n", "%<RppRxInfo.Name>");
124 %if %<data_type_par>==4
126 %<message>.Length = pdu.dlc;
127 %<message>.ID = pdu.id;
129 for (i = 0; i < pdu.dlc; i++ ) {
130 %<message>.Data[i] = pdu.data[i];
131 %%rpp_sci_printf("%X ", pdu.data[i]);
133 %elseif %<data_type_par>==3
135 int msg = (pdu.data[0]) |
140 %%rpp_sci_printf("32b: %X ", msg);
141 %elseif %<data_type_par>==2
143 int msg = (pdu.data[0]) |
146 %%rpp_sci_printf("16b: %X ", msg);
149 int msg = pdu.data[0];
151 %%rpp_sci_printf("8b: %X ", msg);
153 %%rpp_sci_printf("\n");
155 %% Call a function to process the received message via function-call subsystem
156 %foreach callIdx = NumSFcnSysOutputCalls
157 %if LibIsEqual(SFcnSystemOutputCall[callIdx].BlockToCall,"unconnected")
160 %% call the downstream system
161 %<LibBlockExecuteFcnCall(block, callIdx)>\