summaryrefslogtreecommitdiff
path: root/infra/bus.h
blob: e986174b0a4bc6fc1744e95788022a70e457ec94 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once

#include <array>
#include <cassert>

#include "infra/sim.h"

namespace infra {
    template<typename T, unsigned int peers> struct shared_bus : public sim {
        std::array<port<T>, peers> peerp;
        port<T> *outp = nullptr;

        void clock() {
            for (unsigned int i = 0; i < peers; ++i) {
                if (peerp[i].can_read()) {
                    assert(outp->can_write());
                    outp->write(peerp[i].read());
                }
            }
        }
    };
}