Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Valerii Butorin committed Apr 1, 2024
1 parent c2e82e1 commit 7238f81
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 42 deletions.
24 changes: 12 additions & 12 deletions examples/microarch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ puLibrary:
networks:
net1:
pus:
- type: SPI
name: spi
spi:
type: SPI
mosi: mosi
miso: miso
sclk: sclk
cs: cs
protos:
- type: Fram
name: fram{x} # If you want a PU can be allocated only once, remove {x} from the PU name.
fram{x}: # If you want a PU can be allocated only once, remove {x} from the PU name.
type: Fram
size: 32
- type: Shift
name: shift{x}
shift{x}:
type: Shift
sRight: true
- type: Multiplier
name: mul{x}
- type: Accum
name: accum{x}
mul{x}:
type: Multiplier
accum{x}:
type: Accum
isInt: true
- type: Divider
name: div{x}
div{x}:
type: Divider
pipeline: 4

51 changes: 21 additions & 30 deletions src/NITTA/Model/Microarchitecture/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,21 @@ instance ToJSON PULibrary

data PUConf
= Accum
{ name :: T.Text
}
| Divider
{ name :: T.Text
, pipeline :: Int
{ pipeline :: Int
}
| Multiplier
{ name :: T.Text
}
| Fram
{ name :: T.Text
, size :: Int
{ size :: Int
}
| SPI
{ name :: T.Text
, mosi :: T.Text
{ mosi :: T.Text
, miso :: T.Text
, sclk :: T.Text
, cs :: T.Text
}
| Shift
{ name :: T.Text
, sRight :: Maybe Bool
{ sRight :: Maybe Bool
}
deriving (Generic, Show)

Expand All @@ -91,8 +83,8 @@ instance FromJSON PUConf where
parseJSON = genericParseJSON puConfJsonOptions

data NetworkConf = NetworkConf
{ pus :: [PUConf]
, protos :: [PUConf]
{ pus :: Map T.Text PUConf
, protos :: Map T.Text PUConf
}
deriving (Generic, Show)

Expand Down Expand Up @@ -124,24 +116,24 @@ parseConfig path = do
decodeFileThrow path :: IO MicroarchitectureConf

mkMicroarchitecture :: (Val v, Var x, ToJSON x) => MicroarchitectureConf -> BusNetwork T.Text x v Int
mkMicroarchitecture conf =
mkMicroarchitecture MicroarchitectureConf{mock, valueIoSync, puLibrary, networks} =
let addPU proto
| proto = addCustomPrototype
| otherwise = addCustom
mock_ = mock conf
isSlave_ = isSlave . puLibrary $ conf
bufferSize_ = bufferSize . puLibrary $ conf
bounceFilter_ = bounceFilter . puLibrary $ conf
isSlave_ = isSlave puLibrary
bufferSize_ = bufferSize puLibrary
bounceFilter_ = bounceFilter puLibrary
build NetworkConf{pus, protos} = do
mapM_ (configure False) pus
mapM_ (configure True) protos
mapM_ (configure_ False) $ M.toList pus
mapM_ (configure_ True) $ M.toList protos
where
configure proto Accum{name} = addPU proto name def PU.AccumIO
configure proto Divider{name, pipeline} = addPU proto name (PU.divider pipeline mock_) PU.DividerIO
configure proto Multiplier{name} = addPU proto name (PU.multiplier mock_) PU.MultiplierIO
configure proto Fram{name, size} = addPU proto name (PU.framWithSize size) PU.FramIO
configure proto Shift{name, sRight} = addPU proto name (PU.shift $ Just False /= sRight) PU.ShiftIO
configure proto SPI{name, mosi, miso, sclk, cs} =
configure_ proto (name, pu) = configure proto name pu
configure proto name Accum = addPU proto name def PU.AccumIO
configure proto name Divider{pipeline} = addPU proto name (PU.divider pipeline mock) PU.DividerIO
configure proto name Multiplier = addPU proto name (PU.multiplier mock) PU.MultiplierIO
configure proto name Fram{size} = addPU proto name (PU.framWithSize size) PU.FramIO
configure proto name Shift{sRight} = addPU proto name (PU.shift $ Just False /= sRight) PU.ShiftIO
configure proto name SPI{mosi, miso, sclk, cs} =
addPU proto name (PU.anySPI bounceFilter_ bufferSize_) $
if isSlave_
then
Expand All @@ -158,8 +150,7 @@ mkMicroarchitecture conf =
, master_sclk = PU.OutputPortTag sclk
, master_cs = PU.OutputPortTag cs
}
nets = networks conf
mkNetwork name net = modifyNetwork (busNetwork name $ valueIoSync conf) (build net)
in case M.toList nets of
mkNetwork name net = modifyNetwork (busNetwork name $ valueIoSync) (build net)
in case M.toList networks of
[(name, net)] -> mkNetwork name net
_ -> error "multi-networks are not currently supported"

0 comments on commit 7238f81

Please sign in to comment.