%% Copyright (C) 2014 Czech Technical University in Prague %% %% Authors: %% Michal Horn %% Michal Sojka %% %% Permission is hereby granted, free of charge, to any person %% obtaining a copy of this software and associated documentation %% files (the "Software"), to deal in the Software without %% restriction, including without limitation the rights to use, %% copy, modify, merge, publish, distribute, sublicense, and/or sell %% copies of the Software, and to permit persons to whom the %% Software is furnished to do so, subject to the following %% conditions: %% The above copyright notice and this permission notice shall be %% included in all copies or substantial portions of the Software. %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, %% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES %% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND %% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT %% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, %% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING %% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR %% OTHER DEALINGS IN THE SOFTWARE. %% %% File : rpp_can_common.tlc %% Abstract: %% TLC file with common functions and variables for sfunction_canreceive, sfunction_cansetup and sfunction_cantransmit %% %% References: %% Coding Convention: refs/rtw_tlc.pdf p. 58 (TODO) %% %% Function: RppCANCommonBlockTypeSetup ======================================== %% Declares and initializes all common variables and constants. %function RppCANCommonBlockTypeSetup() void %if EXISTS("::_RPP_MAX_MAILBOX_CNT") == 0 %assign ::_RPP_MAX_MAILBOX_CNT = 64 /% Global data structure used in call CAN blocks %/ %createrecord ::Rpp { Can { ... Tx { NumBlocks 0 } ... Rx { NumBlocks 0 } ... }} /% Add records for helping with message object allocation %/ %foreach i = 3 %% We have 3 CAN controllers %addtorecord Rpp.Can Ctrl {} %endforeach %endif %endfunction %function RppCanAssignMsgObj(msgObjNum, blockInfo) void %if msgObjNum < 1 || msgObjNum > ::_RPP_MAX_MAILBOX_CNT % %endif %addtorecord Rpp.Can.Ctrl[blockInfo.Controller-1] MsgObj%UsedBy blockInfo %assign blockInfo.MsgObj = msgObjNum %endfunction %function RppCanGetBlockInfoFromMsgObj(module, mailbox_number) %return Rpp.Can.Ctrl[module-1].MsgObj%UsedBy %endfunction %function RppCanIsMsgObjAssigned(module, mailbox_number) %return ISFIELD(Rpp.Can.Ctrl[%], "MsgObj%UsedBy") %endfunction %% Function: RppFindFreeMailboxNumber ========================================= %% Returns the lowest possible free mailbox number or 0 if no mailbox is free. %function RppFindFreeMailboxNumber(module) void %foreach mn = ::_RPP_MAX_MAILBOX_CNT + 1 %if mn == 0 %continue %endif %if RppCanIsMsgObjAssigned(module, mn) == 0 %return % %endif %endforeach %return 0 %endfunction %% Function: RppPlaceAutomaticMailboxNumber =================================== %% Assignes an automaticaly determined mailbox number for the CAN block. %function RppPlaceAutomaticMailboxNumber(blockInfo) void %assign msg_obj_number = RppFindFreeMailboxNumber(blockInfo.Controller) %if % == 0 % %endif %addtorecord blockInfo ManualMsgObj 0 /% For MsgObj collision detection %/ % %endfunction %% Function: RppPlaceManualMailboxNumber ====================================== %% Assigns a manualy specified mailbox number to the CAN blocks. %% Reports collisions with other manually assigned blocks and optionally %% reassignes mailbox numbers of previously assigned automatic blocks. %% %% Params: msg_obj_num The requested number of the mailbox. %function RppPlaceManualMailboxNumber(blockInfo, msg_obj_number) void %if RppCanIsMsgObjAssigned(blockInfo.Controller, msg_obj_number) %assign prevBlockInfo = RppCanGetBlockInfoFromMsgObj(blockInfo.Controller, msg_obj_number) %if prevBlockInfo.ManualMsgObj % %endif %assign new_msg_obj_number = RppFindFreeMailboxNumber(blockInfo.Controller) %if new_msg_obj_number == 0 % %endif % %endif %addtorecord blockInfo ManualMsgObj 1 /% For MsgObj collision detection %/ % %endfunction %% [EOF]