]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/tlc_c/sfunction_cantransmit.tlc
doc: Update documentation of external mode and related stuff
[pes-rpp/rpp-simulink.git] / rpp / blocks / tlc_c / sfunction_cantransmit.tlc
1 %% Copyright (C) 2014 Czech Technical University in Prague
2 %%
3 %% Authors:
4 %%     Michal Horn  <hornmich@fel.cvut.cz>
5 %%     Michal Sojka <sojkam1@fel.cvut.cz>
6 %%
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.
11 %%
12 %% File : sfunction_cantransmit.tlc
13 %% Abstract:
14 %%     TLC file for configuring the CAN TX buffer on the TI TMS570LS3137 MCU
15 %%
16 %% References:
17 %%     BlockTypeSetup() : refs/rtw_tlc.pdf p. 277
18 %%     Outputs()        : refs/rtw_tlc.pdf p. 281
19
20
21 %implements sfunction_cantransmit "C"
22
23 %include "common.tlc"
24 %include "rpp_can_common.tlc"
25
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")>
32
33 %endfunction
34
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)
42
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)>" ...
53   }
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)>
57   %else
58     %<RppPlaceManualMailboxNumber(blockInfo, mailbox_num_par)>
59   %endif
60
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
64 %endfunction
65
66 %% Function: Start =============================================================
67 %function Start(block, system) Output
68
69   %if !SLibCodeGenForSim()
70     %if EXISTS(::rpp_can_config_present) == 0
71       %<LibBlockReportError(block, "CAN bus configuration block not present!")>
72     %endif
73   %endif
74
75
76 %endfunction
77
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)
83
84     {
85       struct rpp_can_pdu pdu;
86
87       %if %<msginput_data_type>==3
88         // Transmit uint8
89         pdu.dlc = 1;
90         pdu.data[0]= %<message>;
91
92       %elseif %<msginput_data_type>==5
93         // Transmit uint16
94         pdu.dlc = 2;
95         pdu.data[0]= (%<message>&0xFF);
96         pdu.data[1]= (%<message>&0xFF00)>>8;
97       %elseif %<msginput_data_type>==7
98         // Transmit uint32
99         pdu.dlc = 4;
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;
104       %else
105         // Transmit CAN_MESSAGE
106         pdu.dlc = %<message>.Length;
107         %foreach msg_index = 8
108           pdu.data[%<msg_index>]= %<message>.Data[%<msg_index>];
109         %endforeach
110       %endif
111       pdu.id=%<RppTxInfo.Id>;
112
113
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]);
117         %%}
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>); %/
121         }
122       }
123     %endif
124   %endfunction
125
126   %% [EOF]