113521Sgabeblack@google.com/*****************************************************************************
213521Sgabeblack@google.com
313521Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
413521Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
513521Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
613521Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
713521Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
813521Sgabeblack@google.com  License.  You may obtain a copy of the License at
913521Sgabeblack@google.com
1013521Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1113521Sgabeblack@google.com
1213521Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1313521Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1413521Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1513521Sgabeblack@google.com  implied.  See the License for the specific language governing
1613521Sgabeblack@google.com  permissions and limitations under the License.
1713521Sgabeblack@google.com
1813521Sgabeblack@google.com *****************************************************************************/
1913521Sgabeblack@google.com
2013521Sgabeblack@google.com#ifndef __TLM_CORE_1_REQ_RSP_CHANNELS_FIFO_FIFO_PUT_GET_HH__
2113521Sgabeblack@google.com#define __TLM_CORE_1_REQ_RSP_CHANNELS_FIFO_FIFO_PUT_GET_HH__
2213521Sgabeblack@google.com
2313521Sgabeblack@google.comnamespace tlm
2413521Sgabeblack@google.com{
2513521Sgabeblack@google.com
2613521Sgabeblack@google.com// Get interface.
2713521Sgabeblack@google.comtemplate <typename T>
2813521Sgabeblack@google.cominline T
2913521Sgabeblack@google.comtlm_fifo<T>::get(tlm_tag<T> *)
3013521Sgabeblack@google.com{
3113521Sgabeblack@google.com    while (is_empty()) {
3213521Sgabeblack@google.com        wait(m_data_written_event);
3313521Sgabeblack@google.com    }
3413521Sgabeblack@google.com
3513521Sgabeblack@google.com    m_num_read++;
3613521Sgabeblack@google.com    request_update();
3713521Sgabeblack@google.com
3813521Sgabeblack@google.com    return buffer.read();
3913521Sgabeblack@google.com}
4013521Sgabeblack@google.com
4113521Sgabeblack@google.com// Non-blocking read.
4213521Sgabeblack@google.comtemplate <typename T>
4313521Sgabeblack@google.cominline bool
4413521Sgabeblack@google.comtlm_fifo<T>::nb_get(T &val_)
4513521Sgabeblack@google.com{
4613521Sgabeblack@google.com    if (is_empty()) {
4713521Sgabeblack@google.com        return false;
4813521Sgabeblack@google.com    }
4913521Sgabeblack@google.com
5013521Sgabeblack@google.com    m_num_read++;
5113521Sgabeblack@google.com    request_update();
5213521Sgabeblack@google.com
5313521Sgabeblack@google.com    val_ = buffer.read();
5413521Sgabeblack@google.com
5513521Sgabeblack@google.com    return true;
5613521Sgabeblack@google.com}
5713521Sgabeblack@google.com
5813521Sgabeblack@google.comtemplate <typename T>
5913521Sgabeblack@google.cominline bool
6013521Sgabeblack@google.comtlm_fifo<T>::nb_can_get(tlm_tag<T> *) const
6113521Sgabeblack@google.com{
6213521Sgabeblack@google.com    return !is_empty();
6313521Sgabeblack@google.com}
6413521Sgabeblack@google.com
6513521Sgabeblack@google.com
6613521Sgabeblack@google.com// Put interface.
6713521Sgabeblack@google.comtemplate <typename T>
6813521Sgabeblack@google.cominline void
6913521Sgabeblack@google.comtlm_fifo<T>::put(const T &val_)
7013521Sgabeblack@google.com{
7113521Sgabeblack@google.com    while (is_full()) {
7213521Sgabeblack@google.com        wait(m_data_read_event);
7313521Sgabeblack@google.com    }
7413521Sgabeblack@google.com
7513521Sgabeblack@google.com    if (buffer.is_full()) {
7613521Sgabeblack@google.com        buffer.resize(buffer.size() * 2);
7713521Sgabeblack@google.com    }
7813521Sgabeblack@google.com
7913521Sgabeblack@google.com    m_num_written++;
8013521Sgabeblack@google.com    buffer.write(val_);
8113521Sgabeblack@google.com
8213521Sgabeblack@google.com    request_update();
8313521Sgabeblack@google.com}
8413521Sgabeblack@google.com
8513521Sgabeblack@google.comtemplate <typename T>
8613521Sgabeblack@google.cominline bool
8713521Sgabeblack@google.comtlm_fifo<T>::nb_put(const T &val_)
8813521Sgabeblack@google.com{
8913521Sgabeblack@google.com    if (is_full()) {
9013521Sgabeblack@google.com        return false;
9113521Sgabeblack@google.com    }
9213521Sgabeblack@google.com
9313521Sgabeblack@google.com    if (buffer.is_full()) {
9413521Sgabeblack@google.com        buffer.resize(buffer.size() * 2);
9513521Sgabeblack@google.com    }
9613521Sgabeblack@google.com
9713521Sgabeblack@google.com    m_num_written++;
9813521Sgabeblack@google.com    buffer.write(val_);
9913521Sgabeblack@google.com    request_update();
10013521Sgabeblack@google.com
10113521Sgabeblack@google.com    return true;
10213521Sgabeblack@google.com}
10313521Sgabeblack@google.com
10413521Sgabeblack@google.comtemplate <typename T>
10513521Sgabeblack@google.cominline bool
10613521Sgabeblack@google.comtlm_fifo<T>::nb_can_put(tlm_tag<T> *) const
10713521Sgabeblack@google.com{
10813521Sgabeblack@google.com    return !is_full();
10913521Sgabeblack@google.com}
11013521Sgabeblack@google.com
11113521Sgabeblack@google.com} // namespace tlm
11213521Sgabeblack@google.com
11313521Sgabeblack@google.com#endif /* __TLM_CORE_1_REQ_RSP_CHANNELS_FIFO_FIFO_PUT_GET_HH__ */
114