%% Copyright (C) 2014 Czech Technical University in Prague %% %% Authors: %% Michal Horn %% %% This document contains proprietary information belonging to Czech %% Technical University in Prague. Passing on and copying of this %% document, and communication of its contents is not permitted %% without prior written authorization. %% %% File : rpp_can_common.tlc %% Abstract: %% TLC file with common functions and variables for sfunction_canreceive, sfunction_cansetup and sfunction_cantransmit %% %% References: %% Function: RPP_FindFreeMailboxNumber ========================================= %% Finds the first mailbox number in the CAN module, which has not assignd any configuration %% record (buffer). %% The search is done through an array of flags, which signals by their existance whether %% the number is already assigned or not. %% %% Params: end The mximal number of the mailboxes. %% module The CAN module number. For example 1 for CAN1. %% %% Returns the lowest possible free mailbox number. %function RPP_FindFreeMailboxNumber(end, module) %foreach mn = % %assign index = %+1 %if EXISTS("::rpp_can%_mailbox_assigned%_flag") == 0 %return % %break %endif %endforeach %return -1 %endfunction %% Function: RPP_MailboxNumberDuplicite ======================================== %% If the block has manualy specified mailbox number, check whether the number is %% already used by another block with manualy specified mailbox. %% If the mailbox number is not duplicite, the function marks it as used. %% %% Params: module The CAN module number. For example 1 for CAN1. %% mailbox_number The number of the mailbox of the current block. %% mailbox_auto The boolean value telling if the mailbox number is specified automaticaly %% %% Returns 1 if the mailbox_number is duplicite, 0 if not. %function RPP_MailboxNumberDuplicite(module, mailbox_number, mailbox_auto) %if % == 0U %if EXISTS("::rpp_can%_mailbox_number%") == 0 %assign ::rpp_can%_mailbox_number% = 1 %else %return 1 %endif %endif %return 0 %endfunction %% Function: RPP_AssertDirectionSpecificator =================================== %% Check the direction specifyer. Invokes a fatal error if it is invalid. %% The valid specifyer: r; t %% %% Params: direction_sp The specifyer to be checked. %function RPP_AssertDirectionSpecificator(direction_sp) void %if !ISEQUAL(direction_sp, "t") && !ISEQUAL(direction_sp, "r") % %endif %endfunction %% Function: RPP_CreateNewBuffer =============================================== %% Created new record with initialization values for CAN TX or CAN RX record. %% %% Params: module The CAN module number. For example 1 for CAN1. %% mailbox_num The number of the mailbox. %% message_type The type of the message ID. 1-11b, 2-29b, 3-mixed (for RX only) %% message_id The message ID %% mask The mask of the message ID %% direction_sp The direction specifyer. "r" for CAN RX or "t" for CAN TX. %function RPP_CreateNewBuffer(module, mailbox_num, message_type, message_id, mask, direction_sp) void % %if ISEQUAL(direction_sp, "t") %createrecord ::tx_buffer_%<::rpp_can_tx_cnt> {type message_type; controller module; msg_obj mailbox_num; name "%" } %else %createrecord ::rx_buffer_%<::rpp_can_rx_cnt> {type message_type; controller module; msg_obj mailbox_num; name "%"; id message_id; msk mask } %endif %endfunction %% Function: RPP_PlaceAutomaticMailboxNumber =================================== %% Places an automaticaly specified mailbox number for the CAN blocks. %% Finds the first free mailbox number, assigns it to the current block and creates %% a record with initialization data %% %% Params: max_mailbox_number The maximal mailbox number %% module The CAN module number. For example 1 for CAN1. %% message_type The type of the message ID. 1-11b, 2-29b, 3-mixed (for RX only) %% message_id The message ID %% mask The mask of the message ID %% direction_sp The direction specifyer. "r" for CAN RX or "t" for CAN TX. %function RPP_PlaceAutomaticMailboxNumber(max_mailbox_number, module, message_type, message_id, mask, direction_sp) void % %% Find first free mailbox number %assign mailbox_number = FindFreeMailboxNumber(max_mailbox_number, module) %if % < 0 % %endif %assign mailbox_number = mailbox_number+1 %% Mark the mailbox number as used and assign a record about buffer to it %assign ::rpp_can%_mailbox_assigned%_flag = 1 %createrecord ::rpp_can%_mailbox_assigned% { direction "%"; buffer ::rpp_can_%x_cnt } % %endfunction %% Function: RPP_PlaceManualMailboxNumber ====================================== %% Places a manualy specified mailbox number for the CAN blocks. %% If the number is not used yet, just places it and marks it as used. But if it is used %% already by some automaticaly assigned block, the previous one has assigned a new automaticaly %% generated number and this new one takes its place. %% %% Params: max_mailbox_number The maximal mailbox number %% mailbox_num The number of the mailbox. %% module The CAN module number. For example 1 for CAN1. %% message_type The type of the message ID. 1-11b, 2-29b, 3-mixed (for RX only) %% message_id The message ID %% mask The mask of the message ID %% direction_sp The direction specifyer. "r" for CAN RX or "t" for CAN TX. %function RPP_PlaceManualMailboxNumber(max_mailbox_number, mailbox_num, module, message_type, message_id, mask, direction_sp) void % %% Check whether the mailbox number is already used %if EXISTS(::rpp_can%_mailbox_assigned%_flag) == 0 %assign ::rpp_can%_mailbox_assigned%_flag = 1 %createrecord ::rpp_can%_mailbox_assigned% { direction "%"; buffer ::rpp_can_%x_cnt } %else %% The mailbox number is already used by the automaticaly placed buffer. %% The case that it is used by another manualy placed buffer is handeled by the duplication check. %% Find first free mailbox number %assign mailbox_number = FindFreeMailboxNumber(max_mailbox_number, module) %if mailbox_number < 0 % %endif %assign mailbox_number = %+1 %% Mark the mailbox number as used %assign ::rpp_can%_mailbox_assigned%_flag = 1 %% Move record with buffer information to the new slot with free mailbox number id %copyrecord ::rpp_can%_mailbox_assigned% ::rpp_can%_mailbox_assigned% %% Create new record with buffer information in the required slot %createrecord ::rpp_can%_mailbox_assigned% {direction "%"; buffer ::rpp_can_%x_cnt} %% Fix mailbox number in the old buffer record %copyrecord tmp_ma ::rpp_can%_mailbox_assigned% %copyrecord tmp_buf ::%x_buffer_% %if ISEQUAL(tmp_ma.direction, "t") %createrecord tmp_result {type tmp_buf.type; controller tmp_buf.controller; msg_obj mailbox_number; name "%" } %copyrecord ::tx_buffer_% tmp_result %elseif ISEQUAL(tmp_ma.direction, "r") %createrecord rx_buffer_% { type tmp_buf.type; controller tmp_buf.controller; msg_obj mailbox_number; name "%"; id tmp_buf.id; msk tmp_buf.msk } %else % %endif %endif % %endfunction %% [EOF]