1 %% Copyright (C) 2014 Czech Technical University in Prague
4 %% Michal Horn <hornmich@fel.cvut.cz>
5 %% Michal Sojka <sojkam1@fel.cvut.cz>
7 %% This document contains proprietary information belonging to Czech
8 %% Technical University in Prague. Passing on and copying of this
9 %% document, and communication of its contents is not permitted
10 %% without prior written authorization.
12 %% File : sfunction_cantransmit.tlc
14 %% TLC file for configuring the CAN TX buffer on the TI TMS570LS3137 MCU
17 %% BlockTypeSetup() : refs/rtw_tlc.pdf p. 277
18 %% Outputs() : refs/rtw_tlc.pdf p. 281
21 %implements sfunction_cantransmit "C"
24 %include "rpp_can_common.tlc"
26 %% Function: BlockTypeSetup ====================================================
27 %function BlockTypeSetup(block, system) void
28 %<RppCommonBlockTypeSetup(block, system)>
29 %<RppCANCommonBlockTypeSetup()>
30 %<LibAddToCommonIncludes("can_message.h")>
31 %<LibAddToCommonIncludes("rpp/rpp.h")>
35 %% Function: BlockInstanceSetup ================================================
36 %function BlockInstanceSetup(block, system) void
37 %assign module_id_par = LibBlockParameterValue(module_id, 0)
38 %assign mailbox_num_par = LibBlockParameterValue(mailbox_id, 0)
39 %assign message_type_par = LibBlockParameterValue(message_type, 0)
40 %assign message_id_par = LibBlockParameterValue(message_id, 0)
41 %assign mailbox_auto_par = LibBlockParameterValue(mailbox_auto, 0)
43 %% This seems to be the only way to add a record to an array. The
44 %% other way - creating the record with %createrecord and adding
45 %% it later with %addtorecord doesn't work.
46 %addtorecord Rpp.Can.Tx Block { ...
47 HwObj Rpp.Can.Tx.NumBlocks; ...
48 Controller module_id_par; ...
49 MsgObj 0; /% Invalid MsgObj - proper value will be assigned later %/ ...
50 Type message_type_par; ...
51 Id message_id_par; ...
52 Name "%<LibGetBlockName(block)>" ...
54 %assign blockInfo = Rpp.Can.Tx.Block[Rpp.Can.Tx.NumBlocks] /% create alias to the record %/
55 %if %<mailbox_auto_par>==1
56 %<RppPlaceAutomaticMailboxNumber(blockInfo)>
58 %<RppPlaceManualMailboxNumber(blockInfo, mailbox_num_par)>
61 /% Remember which blockInfo record is associated wit this block %/
62 %addtorecord block RppTxInfo blockInfo
63 %assign Rpp.Can.Tx.NumBlocks = Rpp.Can.Tx.NumBlocks + 1
66 %% Function: Start =============================================================
67 %function Start(block, system) Output
69 %if !SLibCodeGenForSim()
70 %if EXISTS(::rpp_can_config_present) == 0
71 %<LibBlockReportError(block, "CAN bus configuration block not present!")>
78 %% Function: Outputs ===========================================================
79 %function Outputs(block, system) Output
80 %if !SLibCodeGenForSim()
81 %assign message = LibBlockInputSignal(0, "", "", 0)
82 %assign msginput_data_type = LibBlockInputSignalDataTypeId(0)
85 struct rpp_can_pdu pdu;
87 %if %<msginput_data_type>==3
90 pdu.data[0]= %<message>;
92 %elseif %<msginput_data_type>==5
95 pdu.data[0]= (%<message>&0xFF);
96 pdu.data[1]= (%<message>&0xFF00)>>8;
97 %elseif %<msginput_data_type>==7
100 pdu.data[0]= (%<message>&0xFF);
101 pdu.data[1]= (%<message>&0xFF00)>>8;
102 pdu.data[2]= (%<message>&0xFF0000)>>16;
103 pdu.data[3]= (%<message>&0xFF000000)>>24;
105 // Transmit CAN_MESSAGE
106 pdu.dlc = %<message>.Length;
107 %foreach msg_index = 8
108 pdu.data[%<msg_index>]= %<message>.Data[%<msg_index>];
111 pdu.id=%<RppTxInfo.Id>;
114 %%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>);
115 %%for (i = 0; i < pdu.dlc; i++ ) {
116 %% rpp_sci_printf("%X ", pdu.data[i]);
118 %%rpp_sci_printf("\n");
119 if (rpp_can_write(%<RppTxInfo.HwObj>, &pdu) != SUCCESS) {
120 /% 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>); %/