Skip to content
Snippets Groups Projects
SysCAMSTBlockTDF.java 9.49 KiB
Newer Older
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
 * 
 * ludovic.apvrille AT enst.fr
 * 
 * This software is a computer program whose purpose is to allow the
 * edition of TURTLE analysis, design and deployment diagrams, to
 * allow the generation of RT-LOTOS or Java code from this diagram,
 * and at last to allow the analysis of formal validation traces
 * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
 * from INRIA Rhone-Alpes.
 * 
 * This software is governed by the CeCILL  license under French law and
 * abiding by the rules of distribution of free software.  You can  use,
 * modify and/ or redistribute the software under the terms of the CeCILL
 * license as circulated by CEA, CNRS and INRIA at the following URL
 * "http://www.cecill.info".
 * 
 * As a counterpart to the access to the source code and  rights to copy,
 * modify and redistribute granted by the license, users are provided only
 * with a limited warranty  and the software's author,  the holder of the
 * economic rights,  and the successive licensors  have only  limited
 * liability.
 * 
 * In this respect, the user's attention is drawn to the risks associated
 * with loading,  using,  modifying and/or developing or reproducing the
 * software by the user in light of its specific status of free software,
 * that may mean  that it is complicated to manipulate,  and  that  also
 * therefore means  that it is reserved for developers  and  experienced
 * professionals having in-depth computer knowledge. Users are therefore
 * encouraged to load and test the software's suitability as regards their
 * requirements in conditions enabling the security of their systems and/or
 * data to be ensured and,  more generally, to use and operate it in the
 * same conditions as regards security.
 * 
 * The fact that you are presently reading this means that you have had
 * knowledge of the CeCILL license and that you accept its terms.
 */

package syscamstranslator;

Irina LEE's avatar
Irina LEE committed
import java.util.LinkedList;
import javax.swing.DefaultListModel;

 * Class SysCAMSTBlockTDF
 * Parameters of a SystemC-AMS block TDF
Irina LEE's avatar
Irina LEE committed
 * Creation: 19/05/2018
 * @version 1.0 19/05/2018
 * @author Irina Kit Yan LEE
 * @version 1.1 06/08/2018
 * @author Rodrigo CORTES PORTO
*/

public class SysCAMSTBlockTDF extends SysCAMSTComponent {
	private String name;
	private String time;
	private String processCode;
Daniela Genius's avatar
Daniela Genius committed
    private String constructorCode;
	private DefaultListModel<String> listStruct;
	private String nameTemplate;
	private String typeTemplate;
Daniela Genius's avatar
Daniela Genius committed
    private String valueTemplate;
	private DefaultListModel<String> listTypedef;
Irina LEE's avatar
Irina LEE committed
	private SysCAMSTCluster cluster;
	
	private LinkedList<SysCAMSTPortTDF> portTDF;
	private LinkedList<SysCAMSTPortConverter> portConverter;
Daniela Genius's avatar
Daniela Genius committed
    private LinkedList<SysCAMSTPortConverter> localPortConverterList;
Daniela Genius's avatar
Daniela Genius committed
	public SysCAMSTBlockTDF(String _name, double _period, String _time, String _processCode, String _constructorCode, DefaultListModel<String> _listStruct, String _nameTemplate, String _typeTemplate, String _valueTemplate, DefaultListModel<String> _listTypedef, SysCAMSTCluster _cluster) {
		name = _name;
		period = _period;
		time = _time;
		processCode = _processCode;
Daniela Genius's avatar
Daniela Genius committed
        constructorCode = _constructorCode;
		listStruct = _listStruct;
		nameTemplate = _nameTemplate;
		typeTemplate = _typeTemplate;
Daniela Genius's avatar
Daniela Genius committed
        valueTemplate = _valueTemplate;
		listTypedef = _listTypedef;
Irina LEE's avatar
Irina LEE committed
		cluster = _cluster;
		portTDF = new LinkedList<SysCAMSTPortTDF>();
		portConverter = new LinkedList<SysCAMSTPortConverter>();
Daniela Genius's avatar
Daniela Genius committed
        localPortConverterList = new LinkedList<SysCAMSTPortConverter>();
	public String getName() {
		return name;
	}
	
		return period;
	}
    
    public void setPeriod(double _period) {
		period = _period;
	}
Ludovic Apvrille's avatar
Ludovic Apvrille committed

    /*    	public Boolean getDynamic() {
    public void setDynamic(Boolean _dynamic) {
		dynamic = _dynamic;
	
	public String getTime() {
		return time;
	}

	public String getProcessCode() {
		return processCode;
	}
Daniela Genius's avatar
Daniela Genius committed
    
    public String getConstructorCode() {
		return constructorCode;
	}
	public DefaultListModel<String> getListStruct() {
		return listStruct;
	}

	public String getNameTemplate() {
		return nameTemplate;
	}

	public String getTypeTemplate() {
		return typeTemplate;
	}
Daniela Genius's avatar
Daniela Genius committed
    
    public String getValueTemplate() {
		return valueTemplate;
	}

	public DefaultListModel<String> getListTypedef() {
		return listTypedef;
Irina LEE's avatar
Irina LEE committed
	public SysCAMSTCluster getCluster() {
		return cluster;
Irina LEE's avatar
Irina LEE committed
	public LinkedList<SysCAMSTPortTDF> getPortTDF(){
		return portTDF;
	}

	public void addPortTDF(SysCAMSTPortTDF tdf){
		portTDF.add(tdf);
	}

	public LinkedList<SysCAMSTPortConverter> getPortConverter(){
		return portConverter;
	}

	public void addPortConverter(SysCAMSTPortConverter converter){
		portConverter.add(converter);
	}
    
    public boolean getIsTimestepPropagated() {
        return isTimestepPropagated;
    }
    
    public void setIsTimestepPropagated() {
        isTimestepPropagated = true;
    }

    public void syncTDFBlockDEBlock(double[] time_prev) throws SysCAMSValidateException {
        double tp;
        try{
Daniela Genius's avatar
Daniela Genius committed
            //Order list to have input converter ports first, in case of multirate-multiport single-modules
            localPortConverterList.clear();
            for(int i = 0; i < portConverter.size(); i++) {
                localPortConverter = portConverter.get(i);
Daniela Genius's avatar
Daniela Genius committed
                if(localPortConverter.getOrigin() == 0) { //Input
                    localPortConverterList.addFirst(localPortConverter);
                } else if (localPortConverter.getOrigin() == 1) { //Output
                    localPortConverterList.addLast(localPortConverter);
                }
            }
            
            for(int i = 0; i < localPortConverterList.size(); i++) {
                localPortConverter = localPortConverterList.get(i);
                if(localPortConverter.getOrigin() == 0) { //Input
                    check_causality_in(time_prev);
                } else if (localPortConverter.getOrigin() == 1) { //Output
                    check_causality_out(time_prev);
                }
            }
            //Increase number of times block has been executed
            n++;
        } catch (SysCAMSValidateException se){
             throw new SysCAMSValidateException(se.getMessage());
        }
    }
    
    private void check_causality_in(double[] time_prev_max) throws SysCAMSValidateException {
Daniela Genius's avatar
Daniela Genius committed
        double time_now_max_de;
        int d = 0;
        int k = 1;
        if(period > 0)
            tm = period;
        if(localPortConverter.getPeriod() > 0)
            tp = localPortConverter.getPeriod();
        if(localPortConverter.getRate() > 0)
            r = localPortConverter.getRate();
        if(localPortConverter.getDelay() > 0)
            d = localPortConverter.getDelay();

Daniela Genius's avatar
Daniela Genius committed
        time_now_max_de = (n*tm)+((r-1)*tp)-(d*tp);
Daniela Genius's avatar
Daniela Genius committed
               
        /*if(time_now_min_tdf2 < time_prev_max[1]) {
            localPortConverter.setDelay((int)Math.ceil((time_prev_max[1]-time_now_min_tdf2)/tp) + d);
            throw new SysCAMSValidateException("Timestamp of previous write port executed module is: " + time_prev_max[1]
                 + " and current timestamp is: " + time_now_min_tdf + ".\n"
Daniela Genius's avatar
Daniela Genius committed
                 + "Suggested delay in port \"" + localPortConverter.getName() + "\" using time_now_min_tdf: " + (Math.ceil((time_prev_max[1]-time_now_min_tdf)/tp) + d)
                 + " and using time_now_min_de: " + (Math.ceil((time_prev_max[1]-time_now_min_de)/tp) + d));
        }*/
        time_prev_max[0] = Double.valueOf(Math.max(time_prev_max[0],time_now_max_de));
    }
    
    private void check_causality_out(double[] time_prev_max) throws SysCAMSValidateException {
Daniela Genius's avatar
Daniela Genius committed
        double time_now_min_tdf, time_now_max_de2;
        int d = 0;
        int k = 1;
        if(period > 0)
            tm = period;
        if(localPortConverter.getPeriod() > 0)
            tp = localPortConverter.getPeriod();
        if(localPortConverter.getRate() > 0)
            r = localPortConverter.getRate();
        if(localPortConverter.getDelay() > 0)
            d = localPortConverter.getDelay();

Daniela Genius's avatar
Daniela Genius committed
        time_now_min_tdf = (n*tm)+((1-1)*tp)+(d*tp);
        
        time_now_max_de2 = (n*tm)+((r-1)*tp)-(d*tp);
Daniela Genius's avatar
Daniela Genius committed
        if(time_now_min_tdf < time_prev_max[0]) {
            localPortConverter.setDelay((int)Math.ceil((time_prev_max[0]-time_now_min_tdf)/tp) + d);
            throw new SysCAMSValidateException("Timestamp of previous read port executed module is: " + time_prev_max[0]
Daniela Genius's avatar
Daniela Genius committed
                 + " and current timestamp is: " + time_now_min_tdf + ".\n"
                 + "Suggested delay in port " + localPortConverter.getName() + ": " + (Math.ceil((time_prev_max[0]-time_now_min_tdf)/tp) + d));
Daniela Genius's avatar
Daniela Genius committed
        time_prev_max[1] = Double.valueOf(Math.max(time_prev_max[1],time_now_max_de2));