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 : rpp_can_common.tlc
14 %% TLC file with common functions and variables for sfunction_canreceive, sfunction_cansetup and sfunction_cantransmit
17 %% Coding Convention: refs/rtw_tlc.pdf p. 58 (TODO)
20 %% Function: RppCANCommonBlockTypeSetup ========================================
21 %% Declares and initializes all common variables and constants.
23 %function RppCANCommonBlockTypeSetup() void
24 %if EXISTS("::_RPP_MAX_MAILBOX_CNT") == 0
25 %assign ::_RPP_MAX_MAILBOX_CNT = 64
27 /% Global data structure used in call CAN blocks %/
28 %createrecord ::Rpp { Can { ...
29 Tx { NumBlocks 0 } ...
30 Rx { NumBlocks 0 } ...
33 /% Add records for helping with message object allocation %/
34 %foreach i = 3 %% We have 3 CAN controllers
35 %addtorecord Rpp.Can Ctrl {}
40 %function RppCanAssignMsgObj(msgObjNum, blockInfo) void
41 %if msgObjNum < 1 || msgObjNum > ::_RPP_MAX_MAILBOX_CNT
42 %<LibBlockReportError(block, "Invalid mailbox number!")>
44 %addtorecord Rpp.Can.Ctrl[blockInfo.Controller-1] MsgObj%<msgObjNum>UsedBy blockInfo
45 %assign blockInfo.MsgObj = msgObjNum
48 %function RppCanGetBlockInfoFromMsgObj(module, mailbox_number)
49 %return Rpp.Can.Ctrl[module-1].MsgObj%<mailbox_number>UsedBy
52 %function RppCanIsMsgObjAssigned(module, mailbox_number)
53 %return ISFIELD(Rpp.Can.Ctrl[%<module-1>], "MsgObj%<mailbox_number>UsedBy")
56 %% Function: RppFindFreeMailboxNumber =========================================
57 %% Returns the lowest possible free mailbox number or 0 if no mailbox is free.
59 %function RppFindFreeMailboxNumber(module) void
60 %foreach mn = ::_RPP_MAX_MAILBOX_CNT + 1
64 %if RppCanIsMsgObjAssigned(module, mn) == 0
71 %% Function: RppPlaceAutomaticMailboxNumber ===================================
72 %% Assignes an automaticaly determined mailbox number for the CAN block.
74 %function RppPlaceAutomaticMailboxNumber(blockInfo) void
75 %assign msg_obj_number = RppFindFreeMailboxNumber(blockInfo.Controller)
76 %if %<msg_obj_number> == 0
77 %<LibBlockReportError(block, "Too many blocks in one module!")>
79 %addtorecord blockInfo ManualMsgObj 0 /% For MsgObj collision detection %/
80 %<RppCanAssignMsgObj(msg_obj_number, blockInfo)>
83 %% Function: RppPlaceManualMailboxNumber ======================================
85 %% Assigns a manualy specified mailbox number to the CAN blocks.
86 %% Reports collisions with other manually assigned blocks and optionally
87 %% reassignes mailbox numbers of previously assigned automatic blocks.
89 %% Params: msg_obj_num The requested number of the mailbox.
91 %function RppPlaceManualMailboxNumber(blockInfo, msg_obj_number) void
92 %if RppCanIsMsgObjAssigned(blockInfo.Controller, msg_obj_number)
93 %assign prevBlockInfo = RppCanGetBlockInfoFromMsgObj(blockInfo.Controller, msg_obj_number)
94 %if prevBlockInfo.ManualMsgObj
95 %<LibBlockReportError(block, "Colliding mailbox number found!")>
97 %assign new_msg_obj_number = RppFindFreeMailboxNumber(blockInfo.Controller)
98 %if new_msg_obj_number == 0
99 %<LibBlockReportError(block, "Too many blocks in one module!")>
101 %<RppCanAssignMsgObj(new_msg_obj_number, prevBlockInfo)>
103 %addtorecord blockInfo ManualMsgObj 1 /% For MsgObj collision detection %/
104 %<RppCanAssignMsgObj(msg_obj_number, blockInfo)>