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_cantransmit.tlc
30 %% TLC file for configuring the CAN TX 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_cantransmit "C"
40 %include "rpp_can_common.tlc"
42 %% Function: BlockTypeSetup ====================================================
43 %function BlockTypeSetup(block, system) void
44 %<RppCommonBlockTypeSetup(block, system)>
45 %<RppCANCommonBlockTypeSetup()>
46 %<LibAddToCommonIncludes("can_message.h")>
47 %<LibAddToCommonIncludes("rpp/rpp.h")>
51 %% Function: BlockInstanceSetup ================================================
52 %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 mailbox_auto_par = LibBlockParameterValue(mailbox_auto, 0)
59 %% This seems to be the only way to add a record to an array. The
60 %% other way - creating the record with %createrecord and adding
61 %% it later with %addtorecord doesn't work.
62 %addtorecord Rpp.Can.Tx Block { ...
63 HwObj Rpp.Can.Tx.NumBlocks; ...
64 Controller module_id_par; ...
65 MsgObj 0; /% Invalid MsgObj - proper value will be assigned later %/ ...
66 Type message_type_par; ...
67 Id message_id_par; ...
68 Name "%<LibGetBlockName(block)>" ...
70 %assign blockInfo = Rpp.Can.Tx.Block[Rpp.Can.Tx.NumBlocks] /% create alias to the record %/
71 %if %<mailbox_auto_par>==1
72 %<RppPlaceAutomaticMailboxNumber(blockInfo)>
74 %<RppPlaceManualMailboxNumber(blockInfo, mailbox_num_par)>
77 /% Remember which blockInfo record is associated wit this block %/
78 %addtorecord block RppTxInfo blockInfo
79 %assign Rpp.Can.Tx.NumBlocks = Rpp.Can.Tx.NumBlocks + 1
82 %% Function: Start =============================================================
83 %function Start(block, system) Output
85 %if !SLibCodeGenForSim()
86 %if EXISTS(::rpp_can_config_present) == 0
87 %<LibBlockReportError(block, "CAN bus configuration block not present!")>
94 %% Function: Outputs ===========================================================
95 %function Outputs(block, system) Output
96 %if !SLibCodeGenForSim()
97 %assign message = LibBlockInputSignal(0, "", "", 0)
98 %assign msginput_data_type = LibBlockInputSignalDataTypeId(0)
101 struct rpp_can_pdu pdu;
103 %if %<msginput_data_type>==3
106 pdu.data[0]= %<message>;
108 %elseif %<msginput_data_type>==5
111 pdu.data[0]= (%<message>&0xFF);
112 pdu.data[1]= (%<message>&0xFF00)>>8;
113 %elseif %<msginput_data_type>==7
116 pdu.data[0]= (%<message>&0xFF);
117 pdu.data[1]= (%<message>&0xFF00)>>8;
118 pdu.data[2]= (%<message>&0xFF0000)>>16;
119 pdu.data[3]= (%<message>&0xFF000000)>>24;
121 // Transmit CAN_MESSAGE
122 pdu.dlc = %<message>.Length;
123 %foreach msg_index = 8
124 pdu.data[%<msg_index>]= %<message>.Data[%<msg_index>];
127 pdu.id=%<RppTxInfo.Id>;
130 %%rpp_sci_printf("CAN%d (hw_obj: %d): Sending message id 0x%X from mailbox %d. Data: ", %<module_id_par>, %<::rpp_can_tx_hw_obj_cnt>, pdu.id, %<mailbox_num_par>);
131 %%for (i = 0; i < pdu.dlc; i++ ) {
132 %% rpp_sci_printf("%X ", pdu.data[i]);
134 %%rpp_sci_printf("\n");
135 if (rpp_can_write(%<RppTxInfo.HwObj>, &pdu) != SUCCESS) {
136 /% rpp_sci_printf("CAN%d (hw_obj: %d): Sending a message id 0x%X from mailbox %d failed.\n", %<module_id_par>, %<::rpp_can_tx_hw_obj_cnt>, pdu.id, %<mailbox_num_par>); %/