1 %% Copyright (C) 2014 Czech Technical University in Prague
4 %% Michal Horn <hornmich@fel.cvut.cz>
5 %% Michal Sojka <sojkam1@fel.cvut.cz>
6 %% Pavel Pisa <pisa@cmp.felk.cvut.cz> - author of SocketCAN port
8 %% Redistribution and use in source and binary forms, with or without
9 %% modification, are permitted provided that the following conditions are
12 %% 1. Redistributions of source code must retain the above copyright
13 %% notice, this list of conditions and the following disclaimer.
15 %% 2. Redistributions in binary form must reproduce the above copyright
16 %% notice, this list of conditions and the following disclaimer in the
17 %% documentation and/or other materials provided with the
20 %% 3. Neither the name of the copyright holder nor the names of its
21 %% contributors may be used to endorse or promote products derived
22 %% from this software without specific prior written permission.
24 %% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 %% "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 %% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 %% A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 %% HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 %% SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 %% LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 %% DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 %% THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 %% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 %% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 %% File : sfunction_cantransmit.tlc
38 %% TLC file for configuring the CAN TX buffer on the TI TMS570LS3137 MCU
41 %% BlockTypeSetup() : refs/rtw_tlc.pdf p. 277
42 %% Outputs() : refs/rtw_tlc.pdf p. 281
45 %implements sfunction_cantransmit "C"
48 %include "rpp_can_common.tlc"
50 %% Function: BlockTypeSetup ====================================================
51 %function BlockTypeSetup(block, system) void
52 %<RppCommonBlockTypeSetup(block, system)>
53 %<RppCANCommonBlockTypeSetup()>
56 %% Function: BlockInstanceSetup ================================================
57 %function BlockInstanceSetup(block, system) void
58 %assign module_id_par = LibBlockParameterValue(module_id, 0)
59 %assign mailbox_num_par = LibBlockParameterValue(mailbox_id, 0)
60 %assign message_type_par = LibBlockParameterValue(message_type, 0)
61 %assign message_id_par = LibBlockParameterValue(message_id, 0)
62 %assign mailbox_auto_par = LibBlockParameterValue(mailbox_auto, 0)
64 %% This seems to be the only way to add a record to an array. The
65 %% other way - creating the record with %createrecord and adding
66 %% it later with %addtorecord doesn't work.
67 %addtorecord Rpp.Can.Tx Block { ...
68 HwObj Rpp.Can.Tx.NumBlocks; ...
69 Controller module_id_par; ...
70 MsgObj 0; /% Invalid MsgObj - proper value will be assigned later %/ ...
71 Type message_type_par; ...
72 Id message_id_par; ...
73 Name "%<LibGetBlockName(block)>" ...
75 %assign blockInfo = Rpp.Can.Tx.Block[Rpp.Can.Tx.NumBlocks] /% create alias to the record %/
76 %if %<mailbox_auto_par>==1
77 %<RppPlaceAutomaticMailboxNumber(blockInfo)>
79 %<RppPlaceManualMailboxNumber(blockInfo, mailbox_num_par)>
82 /% Remember which blockInfo record is associated wit this block %/
83 %addtorecord block RppTxInfo blockInfo
84 %assign Rpp.Can.Tx.NumBlocks = Rpp.Can.Tx.NumBlocks + 1
87 %% Function: Start =============================================================
88 %function Start(block, system) Output
90 %if !SLibCodeGenForSim()
91 %if EXISTS(::rpp_can_config_present) == 0
92 %<LibBlockReportError(block, "CAN bus configuration block not present!")>
99 %% Function: Outputs ===========================================================
100 %function Outputs(block, system) Output
101 %if !SLibCodeGenForSim()
102 %assign message = LibBlockInputSignal(0, "", "", 0)
103 %assign msginput_data_type = LibBlockInputSignalDataTypeId(0)
106 struct can_frame sc_frame;
109 %if %<msginput_data_type>==3
111 sc_frame.can_dlc = 1;
112 sc_frame.data[0]= %<message>;
114 %elseif %<msginput_data_type>==5
116 sc_frame.can_dlc = 2;
117 sc_frame.data[0]= (%<message>&0xFF);
118 sc_frame.data[1]= (%<message>&0xFF00)>>8;
119 %elseif %<msginput_data_type>==7
121 sc_frame.can_dlc = 4;
122 sc_frame.data[0]= (%<message>&0xFF);
123 sc_frame.data[1]= (%<message>&0xFF00)>>8;
124 sc_frame.data[2]= (%<message>&0xFF0000)>>16;
125 sc_frame.data[3]= (%<message>&0xFF000000)>>24;
127 // Transmit CAN_MESSAGE
128 sc_frame.can_dlc = %<message>.Length;
129 %foreach msg_index = 8
130 sc_frame.data[%<msg_index>]= %<message>.Data[%<msg_index>];
133 sc_frame.can_id=%<RppTxInfo.Id>;
134 if (%<RppTxInfo.Type> == 2)
135 sc_frame.can_id|=CAN_EFF_FLAG;
136 %%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>);
137 %%for (i = 0; i < pdu.dlc; i++ ) {
138 %% printf("%X ", pdu.data[i]);
141 ret = send(can_tx_handles[%<RppTxInfo.HwObj>], &sc_frame, sizeof(sc_frame), 0);
142 if (ret < sizeof(sc_frame)) {
143 /% 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>); %/