diff options
author | tzlil <tzlils@protonmail.com> | 2024-01-26 22:07:50 +0200 |
---|---|---|
committer | tzlil <tzlils@protonmail.com> | 2024-01-26 22:07:50 +0200 |
commit | d06c0fa5a036ea068487b260e004dc5da8f92fb9 (patch) | |
tree | 2f3a56568e74420c7c906269bc0cb75318e18174 /src/Blinker.hs | |
parent | 5c6635052b6983d2149b936762298200f6419275 (diff) |
nice echo server
Diffstat (limited to 'src/Blinker.hs')
-rw-r--r-- | src/Blinker.hs | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/Blinker.hs b/src/Blinker.hs index 7ee5ff8..9dc9778 100644 --- a/src/Blinker.hs +++ b/src/Blinker.hs @@ -2,6 +2,7 @@ {-# LANGUAGE NumericUnderscores #-} {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE LambdaCase #-} {-# OPTIONS_GHC -option #-} module Blinker where @@ -48,18 +49,23 @@ topEntity clk rx key0 = txBit baud = SNat @115200 uart' = exposeClockResetEnable (uart baud) clk resetGen enableGen (rxWord, txBit, ack) = uart' rx txM - txM = (exposeClockResetEnable mealySB clk resetGen enableGen) (uncurry cpu) Nothing (ack,rxWord) + txM = (exposeClockResetEnable mealyS clk resetGen enableGen) cpu Listening (CPUIn <$> key0 <*> ack <*> rxWord) -type CpuState = Maybe (BitVector 8) -cpu :: Bool -> Maybe (BitVector 8) -> State CpuState (Maybe (BitVector 8)) -cpu _ (Just rx) = do - put (Just rx) - return Nothing -cpu True Nothing = do - put Nothing +data CPUIn = CPUIn { + key0 :: Bit, + ack :: Bool, + rx :: Maybe (BitVector 8) +} + +data CPUState = Transmitting (BitVector 8) | Listening deriving (Generic, NFDataX) +cpu :: CPUIn -> State CPUState (Maybe (BitVector 8)) +cpu CPUIn{rx=Just rx} = do + put $ Transmitting $ rx return Nothing -cpu False Nothing = do - s <- get - return s \ No newline at end of file +cpu CPUIn{ack=True} = put Listening >> return Nothing + +cpu CPUIn{ack=False,rx=Nothing} = get >>= \case + Transmitting s -> return $ Just s + Listening -> return Nothing \ No newline at end of file |