source: trunk/IPs/systemC/processor/Morpheo/Behavioural/src/Component_port_map.cpp @ 131

Last change on this file since 131 was 131, checked in by rosiere, 15 years ago

1) add constant method
2) test with systemc 2.2.0

  • Property svn:keywords set to Id
File size: 4.5 KB
RevLine 
[31]1/*
2 * $Id: Component_port_map.cpp 131 2009-07-08 18:40:08Z rosiere $
3 *
[82]4 * [ Description ]
[31]5 *
6 */
7
[42]8#include "Behavioural/include/Component.h"
[31]9
10namespace morpheo              {
11namespace behavioural          {
12
[43]13#undef  FUNCTION
14#define FUNCTION "Component::port_map"
[75]15  void Component::port_map (std::string component_src ,
16                            std::string port_src      ,
17                            std::string component_dest,
18                            std::string port_dest     )
[31]19  {
[43]20    log_printf(FUNC,Behavioural,FUNCTION,"Begin");
21
[88]22//     log_printf(INFO,Behavioural,FUNCTION,"Map %s.%s with %s.%s",
[78]23//             component_src.c_str(),
24//             port_src.c_str(),
25//             component_dest.c_str(),
26//             port_dest.c_str());
27
[75]28    std::string name_entity = _entity->get_name();
[31]29
[42]30    // First entity
31    Entity * entity_dest = find_entity(component_dest);
[31]32
[42]33    if (entity_dest == NULL)
[82]34      throw (ERRORMORPHEO (FUNCTION,"In component \""+name_entity+"\", try map \""+component_src+"."+port_src+"\" with \""+component_dest+"."+port_dest+"\" but the component \""+component_dest+"\" is unknow.\n"));
[31]35
[42]36    Signal * signal_dest = entity_dest->find_signal (port_dest);
[31]37
[42]38    if (signal_dest == NULL)
[82]39      throw (ERRORMORPHEO (FUNCTION,"In component \""+name_entity+"\",try map \""+component_src+"."+port_src+"\" with \""+component_dest+"."+port_dest+"\" but the component \""+component_dest+"\" have not the signal \""+port_dest+"\".\n"));
[31]40
[42]41    // Second entity
42    Entity * entity_src = find_entity(component_src);
[31]43
[42]44    if (entity_src == NULL)
[82]45      throw (ERRORMORPHEO (FUNCTION,"In component \""+name_entity+"\", try map \""+component_src+"."+port_src+"\" with \""+component_dest+"."+port_dest+"\" but the component \""+component_src+"\" is unknow.\n"));
[31]46
[42]47    Signal * signal_src = entity_src->find_signal (port_src);
[31]48
[42]49    if (signal_src == NULL)
[82]50      throw (ERRORMORPHEO (FUNCTION,"In component \""+name_entity+"\", try map \""+component_src+"."+port_src+"\" with \""+component_dest+"."+port_dest+"\" but the component \""+component_src+"\" have not the signal \""+port_src+"\".\n"));
[31]51
[42]52    // If all is ok, mapping
[131]53    log_printf(TRACE,Behavioural,FUNCTION, _("Signal \"%s.%s\" (0x%x) \tlink with \"%s.%s\" (0x%x)")
54               ,     entity_src ->get_name().c_str()
55               ,     signal_src ->get_name().c_str()
56               ,(int)signal_src ->get_sc_signal()
57               ,     entity_dest->get_name().c_str()
58               ,     signal_dest->get_name().c_str()
59               ,(int)signal_dest->get_sc_signal()
60               );
[43]61
[62]62    // need an internal signal ?
[78]63    bool src_is_port  = (entity_src  == _entity);
64    bool dest_is_port = (entity_dest == _entity);
[62]65
66    if (src_is_port == true)
[82]67      throw (ERRORMORPHEO (FUNCTION,"In component \""+name_entity+"\", try map \""+component_src+"."+port_src+"\" with \""+component_dest+"."+port_dest+"\" but the component \""+component_src+" is the Top_level, and we can't be use interface's port of the top level as a source.\n"));
[43]68   
[62]69    // 2 cases :
70    //  a) dest is a top level port -> direct connection
71    //  b) dest is a component port -> need internal signal
72    if (dest_is_port == false)
73      {
74        // 1) find productor of signal
75        //       
76        // Interface      Component
[78]77        //    |              |     
[62]78        //  ----> (IN)     --X-> (IN)
[78]79        //    |              |     
[62]80        //  <-X-- (OUT)    <---- (OUT)
81        //    |              |       
82       
83        Signal * signal_productor;
84        Entity * entity_productor;
[113]85        Signal * signal_consumer ;
86        Entity * entity_consumer ;
[62]87
88        bool     src_is_productor = (signal_src->get_direction() == OUT);
89
90        if (src_is_productor == true)
91          {
[113]92            signal_productor = signal_src ;
93            entity_productor = entity_src ;
94            signal_consumer  = signal_dest;
95            entity_consumer  = entity_dest;
[62]96          }
97        else
98          {
99            signal_productor = signal_dest;
100            entity_productor = entity_dest;
[113]101            signal_consumer  = signal_src ;
102            entity_consumer  = entity_src ;
[62]103          }
104
[78]105        // Create internal signal
[113]106        signal_dest= signal_internal (entity_productor,
107                                      signal_productor,
108                                      entity_consumer ,
109                                      signal_consumer );
[65]110        signal_dest->set_size_max(signal_src->get_size());
[62]111      }
112   
113    try
114      {
115        signal_src->link(signal_dest,
116                         dest_is_port);
117      }
118    catch (morpheo::ErrorMorpheo & error)
119      {
[82]120      throw (ERRORMORPHEO (FUNCTION,"In component \""+name_entity+"\", try map \""+component_src+"."+port_src+"\" with \""+component_dest+"."+port_dest+"\" but "+error.what ()));
[62]121      }
122    //catch (...)
123    //  {
124    //  }
125
[43]126    log_printf(FUNC,Behavioural,FUNCTION,"End");
[31]127  };
128
129}; // end namespace behavioural         
130}; // end namespace morpheo             
Note: See TracBrowser for help on using the repository browser.