getting closer...
This commit is contained in:
parent
32932f4816
commit
f9248057f9
7 changed files with 107 additions and 51 deletions
|
@ -1,8 +1,29 @@
|
|||
module Peripherals.Setup (setupPeripherals) where
|
||||
module Peripherals.Setup (
|
||||
setupPeripherals, InitializedPeripherals(..)
|
||||
) where
|
||||
|
||||
import Prelude
|
||||
import Peripherals.UartCFFI(initTerminal)
|
||||
import Peripherals.Ram (initRamFromFile, Ram)
|
||||
import Control.Exception (try)
|
||||
import System.IO.Error (ioeGetErrorString)
|
||||
|
||||
setupPeripherals :: IO ()
|
||||
setupPeripherals = do
|
||||
initTerminal
|
||||
type FirmwareFilePath = FilePath
|
||||
|
||||
data InitializedPeripherals
|
||||
= InitializedPeripherals Ram
|
||||
| InitializationError String
|
||||
deriving (Show)
|
||||
|
||||
setupPeripherals :: FirmwareFilePath -> IO InitializedPeripherals
|
||||
setupPeripherals firmwareFilePath = do
|
||||
initTerminal
|
||||
result <- try (initRamFromFile firmwareFilePath)
|
||||
|
||||
return $ case result of
|
||||
Right (Just ram) -> InitializedPeripherals ram
|
||||
Right Nothing -> InitializationError $ firmwareFilePath ++ failure ++ suggestion
|
||||
Left e -> InitializationError $ firmwareFilePath ++ failure ++ suggestion ++ " Error: " ++ ioeGetErrorString e
|
||||
where
|
||||
failure = ": Failed to initialize RAM from file!"
|
||||
suggestion = " Is the file 4-byte aligned?"
|
||||
|
|
Reference in a new issue