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_cansetup.tlc
14 %% TLC file for configuring the CAN modules on the TI TMS570LS3137 MCU
17 %% BlockTypeSetup() : refs/rtw_tlc.pdf p. 277
18 %% Outputs() : refs/rtw_tlc.pdf p. 281
21 %implements sfunction_cansetup "C"
24 %include "rpp_can_common.tlc"
26 %% Function: BlockTypeSetup ====================================================
27 %function BlockTypeSetup(block, system) void
29 %% Ensure required header files are included
30 %<RppCommonBlockTypeSetup(block, system)>
31 %<LibAddToCommonIncludes("<sys/ti_drv_dmm.h>")>
32 %<LibAddToCommonIncludes("can_message.h")>
33 %<LibAddToCommonIncludes("rpp/rpp.h")>
34 %assign ::rpp_can_config_present = 1
35 %assign ::rpp_can_present=1
37 %<RppCANCommonBlockTypeSetup()>
40 %function BlockInstanceSetup(block, system) void
41 %if EXISTS("rpp_canc_in_model") == 0
42 %assign ::rpp_canc_in_model = 1
44 %<LibBlockReportError(block, "Only one CAN Setup block is allowed in the model.")>
49 %% Function: Start =============================================================
50 %function Start(block, system) Output
52 #define CAN_TX_COUNT %<Rpp.Can.Tx.NumBlocks>
53 #define CAN_RX_COUNT %<Rpp.Can.Rx.NumBlocks>
55 struct rpp_can_ctrl_config can_ctrl_cfg[3] = {
57 .baudrate = %<LibBlockParameterValue(baudrate_can1, 0)>,
59 .timing_calc_method = RPP_CAN_TIMING_CALC_AUTO,
63 .baudrate = %<LibBlockParameterValue(baudrate_can2, 0)>,
65 .timing_calc_method = RPP_CAN_TIMING_CALC_AUTO,
69 .baudrate = %<LibBlockParameterValue(baudrate_can3, 0)>,
71 .timing_calc_method = RPP_CAN_TIMING_CALC_AUTO,
76 struct rpp_can_tx_config tx_config[CAN_TX_COUNT] = {
77 %foreach id = Rpp.Can.Tx.NumBlocks
78 %with Rpp.Can.Tx.Block[id]
82 .type = RPP_CAN_STANDARD,
84 .type = RPP_CAN_EXTENDED,
86 .type = RPP_CAN_MIXED,
88 .controller = %<Controller>,
95 struct rpp_can_rx_config rx_config[CAN_RX_COUNT] = {
96 %foreach id = Rpp.Can.Rx.NumBlocks
97 %with Rpp.Can.Rx.Block[id]
101 .type = RPP_CAN_STANDARD,
103 .type = RPP_CAN_EXTENDED,
105 .type = RPP_CAN_MIXED,
107 .controller = %<Controller>,
108 .msg_obj = %<MsgObj>,
110 .mask = %<SPRINTF("%#x", Mask)>
116 const struct rpp_can_config can_config = {
117 .num_tx_obj = CAN_TX_COUNT,
118 .num_rx_obj = CAN_RX_COUNT,
119 .tx_config = tx_config,
120 .rx_config = rx_config,
125 %<LibSetSourceFileSection(LibGetModelDotCFile(), "Declarations", buffer)>
128 returnstatus = rpp_can_init(&can_config);
129 if (returnstatus == FAILURE) {
130 rpp_sci_printf("CAN driver initialization error.\n");
133 %% rpp_sci_printf("CAN communication initialized.\n");