112027Sjungma@eit.uni-kl.de/***************************************************************************** 212027Sjungma@eit.uni-kl.de 312027Sjungma@eit.uni-kl.de Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412027Sjungma@eit.uni-kl.de more contributor license agreements. See the NOTICE file distributed 512027Sjungma@eit.uni-kl.de with this work for additional information regarding copyright ownership. 612027Sjungma@eit.uni-kl.de Accellera licenses this file to you under the Apache License, Version 2.0 712027Sjungma@eit.uni-kl.de (the "License"); you may not use this file except in compliance with the 812027Sjungma@eit.uni-kl.de License. You may obtain a copy of the License at 912027Sjungma@eit.uni-kl.de 1012027Sjungma@eit.uni-kl.de http://www.apache.org/licenses/LICENSE-2.0 1112027Sjungma@eit.uni-kl.de 1212027Sjungma@eit.uni-kl.de Unless required by applicable law or agreed to in writing, software 1312027Sjungma@eit.uni-kl.de distributed under the License is distributed on an "AS IS" BASIS, 1412027Sjungma@eit.uni-kl.de WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512027Sjungma@eit.uni-kl.de implied. See the License for the specific language governing 1612027Sjungma@eit.uni-kl.de permissions and limitations under the License. 1712027Sjungma@eit.uni-kl.de 1812027Sjungma@eit.uni-kl.de *****************************************************************************/ 1912027Sjungma@eit.uni-kl.de 2012027Sjungma@eit.uni-kl.de#ifndef __TLM_GLOBAL_QUANTUM_H__ 2112027Sjungma@eit.uni-kl.de#define __TLM_GLOBAL_QUANTUM_H__ 2212027Sjungma@eit.uni-kl.de 2312027Sjungma@eit.uni-kl.de#include <systemc> 2412027Sjungma@eit.uni-kl.de 2512027Sjungma@eit.uni-kl.denamespace tlm { 2612027Sjungma@eit.uni-kl.de 2712027Sjungma@eit.uni-kl.de// 2812027Sjungma@eit.uni-kl.de// tlm_global_quantum class 2912027Sjungma@eit.uni-kl.de// 3012027Sjungma@eit.uni-kl.de// The global quantum is the maximum time an initiator can run ahead of 3112027Sjungma@eit.uni-kl.de// systemC time. All initiators should synchronize on timingpoints that 3212027Sjungma@eit.uni-kl.de// are multiples of the global quantum value. 3312027Sjungma@eit.uni-kl.de// 3412027Sjungma@eit.uni-kl.de// sc_set_time_resolution can only be called before the first 3512027Sjungma@eit.uni-kl.de// sc_time object is created. This means that after setting the 3612027Sjungma@eit.uni-kl.de// global quantum it will not be possible to call sc_set_time_resolution. 3712027Sjungma@eit.uni-kl.de// If sc_set_time_resolution must be called this must be done before 3812027Sjungma@eit.uni-kl.de// the global quantum is set. 3912027Sjungma@eit.uni-kl.de// 4012027Sjungma@eit.uni-kl.de 4112027Sjungma@eit.uni-kl.declass tlm_global_quantum 4212027Sjungma@eit.uni-kl.de{ 4312027Sjungma@eit.uni-kl.depublic: 4412027Sjungma@eit.uni-kl.de // 4512027Sjungma@eit.uni-kl.de // Returns a reference to the tlm_global_quantum singleton 4612027Sjungma@eit.uni-kl.de // 4712027Sjungma@eit.uni-kl.de static tlm_global_quantum& instance() 4812027Sjungma@eit.uni-kl.de { 4912027Sjungma@eit.uni-kl.de static tlm_global_quantum instance_; 5012027Sjungma@eit.uni-kl.de return instance_; 5112027Sjungma@eit.uni-kl.de } 5212027Sjungma@eit.uni-kl.de 5312027Sjungma@eit.uni-kl.depublic: 5412027Sjungma@eit.uni-kl.de 5512027Sjungma@eit.uni-kl.de // 5612027Sjungma@eit.uni-kl.de // Setter/getter for the global quantum 5712027Sjungma@eit.uni-kl.de // 5812027Sjungma@eit.uni-kl.de void set(const sc_core::sc_time& t) 5912027Sjungma@eit.uni-kl.de { 6012027Sjungma@eit.uni-kl.de m_global_quantum = t; 6112027Sjungma@eit.uni-kl.de } 6212027Sjungma@eit.uni-kl.de 6312027Sjungma@eit.uni-kl.de const sc_core::sc_time& get() const 6412027Sjungma@eit.uni-kl.de { 6512027Sjungma@eit.uni-kl.de return m_global_quantum; 6612027Sjungma@eit.uni-kl.de } 6712027Sjungma@eit.uni-kl.de 6812027Sjungma@eit.uni-kl.de // 6912027Sjungma@eit.uni-kl.de // This function will calculate the maximum value for the next local 7012027Sjungma@eit.uni-kl.de // quantum for an initiator. All initiators should synchronize on 7112027Sjungma@eit.uni-kl.de // integer multiples of the global quantum value. The value for the 7212027Sjungma@eit.uni-kl.de // local quantum of an initiator can be smaller, but should never be 7312027Sjungma@eit.uni-kl.de // greater than the value returned by this method. 7412027Sjungma@eit.uni-kl.de // 7512027Sjungma@eit.uni-kl.de sc_core::sc_time compute_local_quantum() 7612027Sjungma@eit.uni-kl.de { 7712027Sjungma@eit.uni-kl.de if (m_global_quantum != sc_core::SC_ZERO_TIME) { 7812027Sjungma@eit.uni-kl.de const sc_core::sc_time current = sc_core::sc_time_stamp(); 7912027Sjungma@eit.uni-kl.de const sc_core::sc_time g_quant = m_global_quantum; 8012027Sjungma@eit.uni-kl.de return g_quant - (current % g_quant); 8112027Sjungma@eit.uni-kl.de } else { 8212027Sjungma@eit.uni-kl.de return sc_core::SC_ZERO_TIME; 8312027Sjungma@eit.uni-kl.de } 8412027Sjungma@eit.uni-kl.de } 8512027Sjungma@eit.uni-kl.de 8612027Sjungma@eit.uni-kl.deprotected: 8712027Sjungma@eit.uni-kl.de tlm_global_quantum() : m_global_quantum(sc_core::SC_ZERO_TIME) 8812027Sjungma@eit.uni-kl.de { 8912027Sjungma@eit.uni-kl.de } 9012027Sjungma@eit.uni-kl.de 9112027Sjungma@eit.uni-kl.deprotected: 9212027Sjungma@eit.uni-kl.de sc_core::sc_time m_global_quantum; 9312027Sjungma@eit.uni-kl.de}; 9412027Sjungma@eit.uni-kl.de 9512027Sjungma@eit.uni-kl.de} // namespace tlm 9612027Sjungma@eit.uni-kl.de 9712027Sjungma@eit.uni-kl.de#endif 98