diff options
| author | Julian Blake Kongslie | 2022-10-15 13:59:46 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-10-15 13:59:46 -0700 |
| commit | c25e80b08f473fce0fdf11f2445f5b3f3b2bf342 (patch) | |
| tree | 91a22c102d510771cffe79afd2c9d683dbfaeb08 /infra | |
| parent | Some trivial arbiter improvements. (diff) | |
| download | biggolf-c25e80b08f473fce0fdf11f2445f5b3f3b2bf342.tar.xz | |
Move shared_bus into arbiter
Diffstat (limited to 'infra')
| -rw-r--r-- | infra/arbiter.h | 14 | ||||
| -rw-r--r-- | infra/bus.h | 22 |
2 files changed, 14 insertions, 22 deletions
diff --git a/infra/arbiter.h b/infra/arbiter.h index 74e37be..79a9920 100644 --- a/infra/arbiter.h +++ b/infra/arbiter.h | |||
| @@ -38,4 +38,18 @@ namespace infra { | |||
| 38 | initial = 0; | 38 | initial = 0; |
| 39 | } | 39 | } |
| 40 | }; | 40 | }; |
| 41 | |||
| 42 | template<typename T, unsigned int peers> struct shared_bus : public sim { | ||
| 43 | std::array<port<T>, peers> peerp; | ||
| 44 | port<T> *outp = nullptr; | ||
| 45 | |||
| 46 | void clock() { | ||
| 47 | for (unsigned int i = 0; i < peers; ++i) { | ||
| 48 | if (peerp[i].can_read()) { | ||
| 49 | assert(outp->can_write()); | ||
| 50 | outp->write(peerp[i].read()); | ||
| 51 | } | ||
| 52 | } | ||
| 53 | } | ||
| 54 | }; | ||
| 41 | } | 55 | } |
diff --git a/infra/bus.h b/infra/bus.h deleted file mode 100644 index e986174..0000000 --- a/infra/bus.h +++ /dev/null | |||
| @@ -1,22 +0,0 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <array> | ||
| 4 | #include <cassert> | ||
| 5 | |||
| 6 | #include "infra/sim.h" | ||
| 7 | |||
| 8 | namespace infra { | ||
| 9 | template<typename T, unsigned int peers> struct shared_bus : public sim { | ||
| 10 | std::array<port<T>, peers> peerp; | ||
| 11 | port<T> *outp = nullptr; | ||
| 12 | |||
| 13 | void clock() { | ||
| 14 | for (unsigned int i = 0; i < peers; ++i) { | ||
| 15 | if (peerp[i].can_read()) { | ||
| 16 | assert(outp->can_write()); | ||
| 17 | outp->write(peerp[i].read()); | ||
| 18 | } | ||
| 19 | } | ||
| 20 | } | ||
| 21 | }; | ||
| 22 | } | ||
