prep for notable re-org
This commit is contained in:
parent
024115e389
commit
c8b192cade
32
hs/Bus.hs
32
hs/Bus.hs
|
@ -4,12 +4,12 @@ module Bus() where
|
||||||
import Clash.Prelude
|
import Clash.Prelude
|
||||||
|
|
||||||
import Peripherals.Ram(Ram, RamLine, read, RamAddr)
|
import Peripherals.Ram(Ram, RamLine, read, RamAddr)
|
||||||
import Peripherals.Uart(UartAddr, read)
|
import Peripherals.Uart(UartAddr, read, write)
|
||||||
import Machine(Peripherals(..))
|
import Machine(Peripherals(..))
|
||||||
import BusTypes(
|
import BusTypes(
|
||||||
BusError(..),
|
BusError(..),
|
||||||
TransactionSize(..),
|
TransactionSize(..),
|
||||||
Request(..),
|
ReadRequest(..),
|
||||||
BusResponse(..),
|
BusResponse(..),
|
||||||
BusVal(..),
|
BusVal(..),
|
||||||
ReadResponse(..),
|
ReadResponse(..),
|
||||||
|
@ -32,18 +32,15 @@ alignCheck addr SizeQuadWord = addr `mod` 16 == 0
|
||||||
(uartStart, uartEnd) = (0x10000000 :: Addr, uartStart + 7)
|
(uartStart, uartEnd) = (0x10000000 :: Addr, uartStart + 7)
|
||||||
|
|
||||||
-- reading/writing from/to UART is implemented as reading/writing
|
-- reading/writing from/to UART is implemented as reading/writing
|
||||||
-- from/to STDIO, so we need IO.
|
-- from/to stdin/stdout, so we need IO.
|
||||||
read :: Request -> Peripherals -> IO ReadResponse
|
read :: ReadRequest -> Peripherals -> IO ReadResponse
|
||||||
read (Request addr size) peripherals
|
read (Request addr size) peripherals
|
||||||
| not (alignCheck addr size) = return $ ReadResponse $ Error UnAligned
|
| not (alignCheck addr size) = return $ Left UnAligned
|
||||||
| (addr >= ramStart) && (addr <= ramEnd) =
|
| (addr >= ramStart) && (addr <= ramEnd) =
|
||||||
return $
|
return $ Right $ Peripherals.Ram.read size ramAddr (ram peripherals)
|
||||||
ReadResponse $
|
|
||||||
Result $ Peripherals.Ram.read size ramAddr (ram peripherals)
|
|
||||||
| (addr >= uartStart) && (addr <= uartEnd) =
|
| (addr >= uartStart) && (addr <= uartEnd) =
|
||||||
ReadResponse . Result <$>
|
Right <$> Peripherals.Uart.read size uartAddr
|
||||||
Peripherals.Uart.read size uartAddr
|
| otherwise = return $ Left UnMapped
|
||||||
| otherwise = return $ ReadResponse $ Error UnMapped
|
|
||||||
where
|
where
|
||||||
ramAddrNoOffset = addr - ramStart
|
ramAddrNoOffset = addr - ramStart
|
||||||
ramAddr :: RamAddr
|
ramAddr :: RamAddr
|
||||||
|
@ -52,3 +49,16 @@ read (Request addr size) peripherals
|
||||||
uartAddrNoOffset = addr - uartStart
|
uartAddrNoOffset = addr - uartStart
|
||||||
uartAddr :: UartAddr
|
uartAddr :: UartAddr
|
||||||
uartAddr = resize uartAddrNoOffset
|
uartAddr = resize uartAddrNoOffset
|
||||||
|
|
||||||
|
-- write :: BusVal -> Addr -> Peripherals -> IO WriteResponse
|
||||||
|
-- write val addr peripherals
|
||||||
|
-- | (addr >= uartStart) && (addr <= uartEnd) =
|
||||||
|
-- WriteResponse . Result <$> Peripherals.Uart.write val uartAddr
|
||||||
|
-- where
|
||||||
|
-- ramAddrNoOffset = addr - ramStart
|
||||||
|
-- ramAddr :: RamAddr
|
||||||
|
-- ramAddr = resize ramAddrNoOffset
|
||||||
|
|
||||||
|
-- uartAddrNoOffset = addr - uartStart
|
||||||
|
-- uartAddr :: UartAddr
|
||||||
|
-- uartAddr = resize uartAddrNoOffset
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
module BusTypes(
|
module BusTypes(
|
||||||
BusError(..),
|
BusError(..),
|
||||||
TransactionSize(..),
|
TransactionSize(..),
|
||||||
Request(..),
|
ReadRequest(..),
|
||||||
BusResponse(..),
|
BusResponse(..),
|
||||||
BusVal(..),
|
BusVal(..),
|
||||||
ReadResponse(..),
|
ReadResponse(..),
|
||||||
|
@ -27,7 +27,7 @@ data TransactionSize
|
||||||
| SizeQuadWord
|
| SizeQuadWord
|
||||||
deriving (Generic, Show, Eq, NFDataX)
|
deriving (Generic, Show, Eq, NFDataX)
|
||||||
|
|
||||||
data Request = Request Addr TransactionSize
|
data ReadRequest = Request Addr TransactionSize
|
||||||
deriving (Generic, Show, Eq, NFDataX)
|
deriving (Generic, Show, Eq, NFDataX)
|
||||||
|
|
||||||
data BusResponse a
|
data BusResponse a
|
||||||
|
@ -43,8 +43,10 @@ data BusVal
|
||||||
| BusQuadWord QuadWord
|
| BusQuadWord QuadWord
|
||||||
deriving (Generic, Show, Eq, NFDataX)
|
deriving (Generic, Show, Eq, NFDataX)
|
||||||
|
|
||||||
newtype ReadResponse = ReadResponse (BusResponse BusVal)
|
-- newtype ReadResponse = ReadResponse (BusResponse BusVal)
|
||||||
deriving (Generic, Show, Eq, NFDataX)
|
-- deriving (Generic, Show, Eq, NFDataX)
|
||||||
|
|
||||||
|
type ReadResponse = Either BusError BusVal
|
||||||
|
|
||||||
newtype WriteResponse = WriteResponse (BusResponse ())
|
newtype WriteResponse = WriteResponse (BusResponse ())
|
||||||
deriving (Generic, Show, Eq, NFDataX)
|
deriving (Generic, Show, Eq, NFDataX)
|
||||||
|
|
|
@ -85,6 +85,7 @@ readDoubleWordHelper ram addr = bitCoerce $ bitCoerce word0 ++# bitCoerce word1
|
||||||
word0 = readFullWordHelper ram addr
|
word0 = readFullWordHelper ram addr
|
||||||
word1 = readFullWordHelper ram (addr + 1)
|
word1 = readFullWordHelper ram (addr + 1)
|
||||||
|
|
||||||
|
-- write :: BusVal -> UartAddr -> IO ()
|
||||||
write :: Ram -> RamAddr -> RamLine -> Ram
|
write :: Ram -> RamAddr -> RamLine -> Ram
|
||||||
write ram addr value = replace addr value ram
|
write ram addr value = replace addr value ram
|
||||||
|
|
||||||
|
|
|
@ -68,9 +68,9 @@ read size addr
|
||||||
| otherwise = return $ busValFromByte size 0x00
|
| otherwise = return $ busValFromByte size 0x00
|
||||||
|
|
||||||
extractLowestByte :: BusVal -> Byte
|
extractLowestByte :: BusVal -> Byte
|
||||||
extractLowestByte (BusByte b) = b
|
extractLowestByte (BusByte b) = b
|
||||||
extractLowestByte (BusHalfWord hw) = resize hw
|
extractLowestByte (BusHalfWord hw) = resize hw
|
||||||
extractLowestByte (BusFullWord fw) = resize fw
|
extractLowestByte (BusFullWord fw) = resize fw
|
||||||
extractLowestByte (BusDoubleWord dw) = resize dw
|
extractLowestByte (BusDoubleWord dw) = resize dw
|
||||||
extractLowestByte (BusQuadWord qw) = resize qw
|
extractLowestByte (BusQuadWord qw) = resize qw
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue