28 | | In the proposed example, the initiator module is modeled by the '''my_initiator''' class. This class inherit the '''Tlmt::BaseModule'''' class, that is the basis for all TLM-T modules. As there is only one thread in my_initiator, there is only one member variable '''time'' of type '''tlmt_time'''. This object can be accessed through the '''getTime()''', '''addTime()''' and '''setTime()''' methods. The '''execLoop()''' method, describing the initiator activity must be declared as a member function of the '''my_initiator''' class. |
| 28 | In the proposed example, the initiator module is modeled by the '''my_initiator''' class. This class inherit the '''BaseModule''' class, that is the basis for all TLM-T modules. As there is only one thread in this module, there is only one member variable '''time''' of type '''tlmt_time'''. This object can be accessed through the '''getTime()''', '''addTime()''' and '''setTime()''' methods. |
| 29 | |
| 30 | The '''execLoop()''' method, describing the initiator activity must be declared as a member function of the '''my_initiator''' class. |
| 31 | |
| 32 | Finally, the class '''my_initiator''' must contain a member variable '''p_vci''', of type '''VciInitiatorPort'''. This object has a template parameter <'''vci_param'''> defining the widths of the VCI ADRESS & DATA fields. |
70 | | //////// constructor |
71 | | my_initiator ( sc_module_name name, |
72 | | uint32_t initiatorIndex |
73 | | uint32_t lookahead) : |
74 | | p_vci(“vci”, this, &my_initiator::rspReceived, &m_time) , |
75 | | BaseModule(name), |
76 | | m_time(0), |
77 | | { |
78 | | m_index = InitiatorIndex; |
79 | | m_lookahed = lookahead; |
80 | | m_counter = 0; |
81 | | SC_THREAD(execLoop); |
82 | | } // end constructor |
| 76 | //////// constructor |
| 77 | my_initiator (sc_module_name name, |
| 78 | uint32_t initiatorIndex |
| 79 | uint32_t lookahead) : |
| 80 | p_vci(“vci”, this, &my_initiator::rspReceived, &m_time), |
| 81 | BaseModule(name), |
| 82 | m_time(0), |
| 83 | { |
| 84 | m_index = InitiatorIndex; |
| 85 | m_lookahed = lookahead; |
| 86 | m_counter = 0; |
| 87 | SC_THREAD(execLoop); |
| 88 | } // end constructor |
85 | | tlmt_Time m_time; // local clock |
86 | | uint32_t m_index; // initiator index |
87 | | uint32_t m_counter; // iteration counter |
88 | | uint32_t m_lookahed; // lookahead value |
89 | | vci_param::data_t m_data[8]; // local buffer |
90 | | vci_cmd_t m_cmd; // paquet VCI commande |
| 91 | tlmt_Time m_time; // local clock |
| 92 | uint32_t m_index; // initiator index |
| 93 | uint32_t m_counter; // iteration counter |
| 94 | uint32_t m_lookahed; // lookahead value |
| 95 | vci_param::data_t m_data[8]; // local buffer |
| 96 | vci_cmd_t m_cmd; // paquet VCI commande |
92 | | //////// thread |
93 | | void execLoop() |
94 | | { |
95 | | while(1) { |
96 | | … |
97 | | m_cmd.cmd = VCI_CMD_READ; |
98 | | p_vci.cmdSend(&m_cmd, m_time.get_time()); // lecture bloquante |
99 | | p_vci.wait(); |
100 | | … |
101 | | m_cmd.cmd = VCI_CMD_WRITE; |
102 | | p_vci.send(VCI_CMD_WRITE,…); |
103 | | p_vci.cmdSend(&m_cmd, m_time.get_time()); // écriture non bloquante |
104 | | ... |
105 | | // lookahead management |
106 | | m_counter++ ; |
107 | | if (m_counter >= m_lookahead) { |
108 | | m_counter = 0 ; |
109 | | wait(SC_ZERO_TIME) ; |
110 | | } // end if |
111 | | m_time.addtime(1) ; |
112 | | } // end while |
113 | | } // end execLoop() |
| 98 | //////// thread |
| 99 | void execLoop() |
| 100 | { |
| 101 | while(1) { |
| 102 | … |
| 103 | m_cmd.cmd = VCI_CMD_READ; |
| 104 | p_vci.cmdSend(&m_cmd, m_time.getTime()); // lecture bloquante |
| 105 | p_vci.wait(); |
| 106 | … |
| 107 | m_cmd.cmd = VCI_CMD_WRITE; |
| 108 | p_vci.send(VCI_CMD_WRITE,…); |
| 109 | p_vci.cmdSend(&m_cmd, m_time.getTime()); // écriture non bloquante |
| 110 | ... |
| 111 | // lookahead management |
| 112 | m_counter++ ; |
| 113 | if (m_counter >= m_lookahead) { |
| 114 | m_counter = 0 ; |
| 115 | wait(SC_ZERO_TIME) ; |
| 116 | } // end if |
| 117 | m_time.addtime(1) ; |
| 118 | } // end while |
| 119 | } // end execLoop() |
115 | | //////////////// call-back function |
116 | | void rspReceived(vci_cmd_t *cmd, sc_time rsp_time) |
117 | | { |
118 | | if(cmd == VCI_CMD_READ) { |
119 | | m_time.set_time(rsp_time + length); |
120 | | p_vci.notify() ; |
121 | | } |
122 | | } // end rspReceived() |
| 121 | //////////////// call-back function |
| 122 | void rspReceived(vci_cmd_t *cmd, sc_time rsp_time) |
| 123 | { |
| 124 | if(cmd == VCI_CMD_READ) { |
| 125 | m_time.set_time(rsp_time + length); |
| 126 | p_vci.notify() ; |
| 127 | } |
| 128 | } // end rspReceived() |