1 %% Copyright (C) 2014 Czech Technical University in Prague
4 %% Michal Horn <hornmich@fel.cvut.cz>
5 %% Michal Sojka <sojkam1@fel.cvut.cz>
7 %% Redistribution and use in source and binary forms, with or without
8 %% modification, are permitted provided that the following conditions are
11 %% 1. Redistributions of source code must retain the above copyright
12 %% notice, this list of conditions and the following disclaimer.
14 %% 2. Redistributions in binary form must reproduce the above copyright
15 %% notice, this list of conditions and the following disclaimer in the
16 %% documentation and/or other materials provided with the
19 %% 3. Neither the name of the copyright holder nor the names of its
20 %% contributors may be used to endorse or promote products derived
21 %% from this software without specific prior written permission.
23 %% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 %% "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 %% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 %% A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 %% HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 %% SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 %% LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 %% DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 %% THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 %% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 %% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 %% File : sfunction_cansetup.tlc
37 %% TLC file for configuring the CAN modules on the TI TMS570LS3137 MCU
40 %% BlockTypeSetup() : refs/rtw_tlc.pdf p. 277
41 %% Outputs() : refs/rtw_tlc.pdf p. 281
44 %implements sfunction_cansetup "C"
47 %include "rpp_can_common.tlc"
49 %% Function: BlockTypeSetup ====================================================
50 %function BlockTypeSetup(block, system) void
52 %% Ensure required header files are included
53 %<RppCommonBlockTypeSetup(block, system)>
54 %<LibAddToCommonIncludes("<sys/ti_drv_dmm.h>")>
56 %assign ::rpp_can_config_present = 1
58 %<RppCANCommonBlockTypeSetup()>
61 %function BlockInstanceSetup(block, system) void
62 %if EXISTS("rpp_canc_in_model") == 0
63 %assign ::rpp_canc_in_model = 1
65 %<LibBlockReportError(block, "Only one CAN Setup block is allowed in the model.")>
70 %% Function: Start =============================================================
71 %function Start(block, system) Output
74 #define CAN_TX_COUNT %<Rpp.Can.Tx.NumBlocks>
75 #define CAN_RX_COUNT %<Rpp.Can.Rx.NumBlocks>
77 struct rpp_can_ctrl_config can_ctrl_cfg[3] = {
79 .baudrate = %<LibBlockParameterValue(baudrate_can1, 0)>
82 .baudrate = %<LibBlockParameterValue(baudrate_can2, 0)>
85 .baudrate = %<LibBlockParameterValue(baudrate_can3, 0)>
89 struct rpp_can_tx_config tx_config[CAN_TX_COUNT] = {
90 %foreach id = Rpp.Can.Tx.NumBlocks
91 %with Rpp.Can.Tx.Block[id]
95 .type = RPP_CAN_STANDARD,
97 .type = RPP_CAN_EXTENDED,
99 .type = RPP_CAN_MIXED,
101 .controller = %<Controller>,
108 struct rpp_can_rx_config rx_config[CAN_RX_COUNT] = {
109 %foreach id = Rpp.Can.Rx.NumBlocks
110 %with Rpp.Can.Rx.Block[id]
114 .type = RPP_CAN_STANDARD,
116 .type = RPP_CAN_EXTENDED,
118 .type = RPP_CAN_MIXED,
120 .controller = %<Controller>,
121 .msg_obj = %<MsgObj>,
123 .mask = %<SPRINTF("%#x", Mask)>
129 const struct rpp_can_config can_config = {
130 .num_tx_obj = CAN_TX_COUNT,
131 .num_rx_obj = CAN_RX_COUNT,
132 .tx_config = tx_config,
133 .rx_config = rx_config,
138 %<LibSetSourceFileSection(LibGetModelDotCFile(), "Declarations", buffer)>
141 dmmREG->PC4 = 1<<13; // set CAN_NSTB
142 dmmREG->PC5 = 1<<15; // clr CAN_EN
143 dmmREG->PC5 = 1<<13; // clr CAN_NSTB
144 dmmREG->PC4 = 1<<13; // set CAN_NSTB
145 dmmREG->PC4 = 1<<15; // set CAN_EN
147 returnstatus = rpp_can_init(&can_config);
148 if (returnstatus == FAILURE) {
149 rpp_sci_printf("CAN driver initialization error.\n");
152 %% rpp_sci_printf("CAN communication initialized.\n");