-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A DSL for embedded hard realtime applications. -- -- Atom is a Haskell DSL for designing hard realtime embedded software. -- Based on guarded atomic actions (similar to STM), Atom enables highly -- concurrent programming without the need for mutex locking. In -- addition, Atom performs compile-time task scheduling and generates -- code with deterministic execution time and constant memory use, -- simplifying the process of timing verification and memory consumption -- in hard realtime applications. Without mutex locking and run-time task -- scheduling, Atom eliminates the need and overhead of RTOSs for many -- embedded applications. @package atom @version 1.0.3 module Language.Atom.Expressions -- | A typed expression. data E a VRef :: V a -> E a Const :: a -> E a Cast :: E a -> E b Add :: E a -> E a -> E a Sub :: E a -> E a -> E a Mul :: E a -> E a -> E a Div :: E a -> E a -> E a Mod :: E a -> E a -> E a Not :: E Bool -> E Bool And :: E Bool -> E Bool -> E Bool BWNot :: E a -> E a BWAnd :: E a -> E a -> E a BWOr :: E a -> E a -> E a Shift :: E a -> Int -> E a Eq :: E a -> E a -> E Bool Lt :: E a -> E a -> E Bool Mux :: E Bool -> E a -> E a -> E a F2B :: E Float -> E Word32 D2B :: E Double -> E Word64 B2F :: E Word32 -> E Float B2D :: E Word64 -> E Double Retype :: UE -> E a -- | Variables updated by state transition rules. data V a V :: UV -> V a -- | An untyped term. data UE UVRef :: UV -> UE UConst :: Const -> UE UCast :: Type -> UE -> UE UAdd :: UE -> UE -> UE USub :: UE -> UE -> UE UMul :: UE -> UE -> UE UDiv :: UE -> UE -> UE UMod :: UE -> UE -> UE UNot :: UE -> UE UAnd :: [UE] -> UE UBWNot :: UE -> UE UBWAnd :: UE -> UE -> UE UBWOr :: UE -> UE -> UE UShift :: UE -> Int -> UE UEq :: UE -> UE -> UE ULt :: UE -> UE -> UE UMux :: UE -> UE -> UE -> UE UF2B :: UE -> UE UD2B :: UE -> UE UB2F :: UE -> UE UB2D :: UE -> UE -- | Untyped variables. data UV UV :: Int -> String -> Const -> UV UVArray :: UA -> UE -> UV UVExtern :: String -> Type -> UV -- | A typed array. data A a A :: UA -> A a -- | An untyped array. data UA UA :: Int -> String -> [Const] -> UA UAExtern :: String -> Type -> UA class (Eq a) => Expr a eType :: (Expr a) => E a -> Type constant :: (Expr a) => a -> Const expression :: (Expr a) => E a -> Expression variable :: (Expr a) => V a -> Variable rawBits :: (Expr a) => E a -> E Word64 data Expression EBool :: (E Bool) -> Expression EInt8 :: (E Int8) -> Expression EInt16 :: (E Int16) -> Expression EInt32 :: (E Int32) -> Expression EInt64 :: (E Int64) -> Expression EWord8 :: (E Word8) -> Expression EWord16 :: (E Word16) -> Expression EWord32 :: (E Word32) -> Expression EWord64 :: (E Word64) -> Expression EFloat :: (E Float) -> Expression EDouble :: (E Double) -> Expression data Variable VBool :: (V Bool) -> Variable VInt8 :: (V Int8) -> Variable VInt16 :: (V Int16) -> Variable VInt32 :: (V Int32) -> Variable VInt64 :: (V Int64) -> Variable VWord8 :: (V Word8) -> Variable VWord16 :: (V Word16) -> Variable VWord32 :: (V Word32) -> Variable VWord64 :: (V Word64) -> Variable VFloat :: (V Float) -> Variable VDouble :: (V Double) -> Variable -- | The type of a E. data Type Bool :: Type Int8 :: Type Int16 :: Type Int32 :: Type Int64 :: Type Word8 :: Type Word16 :: Type Word32 :: Type Word64 :: Type Float :: Type Double :: Type data Const CBool :: Bool -> Const CInt8 :: Int8 -> Const CInt16 :: Int16 -> Const CInt32 :: Int32 -> Const CInt64 :: Int64 -> Const CWord8 :: Word8 -> Const CWord16 :: Word16 -> Const CWord32 :: Word32 -> Const CWord64 :: Word64 -> Const CFloat :: Float -> Const CDouble :: Double -> Const class Width a width :: (Width a) => a -> Int class TypeOf a typeOf :: (TypeOf a) => a -> Type bytes :: (Width a) => a -> Int -- | Converts an typed expression (E a) to an untyped expression (UE). ue :: (Expr a) => E a -> UE uv :: V a -> UV -- | The list of UEs adjacent upstream of a UE. ueUpstream :: UE -> [UE] -- | The list of all UVs that directly control the value of an expression. nearestUVs :: UE -> [UV] -- | All array indexing subexpressions. arrayIndices :: UE -> [(UA, UE)] class (Num a, Expr a, EqE a, OrdE a) => NumE a class (NumE a, Integral a) => IntegralE a class (RealFloat a, NumE a, OrdE a) => FloatingE a class (Eq a, Expr a) => EqE a class (Eq a, Ord a, EqE a) => OrdE a -- | True term. true :: E Bool -- | False term. false :: E Bool -- | Returns the value of a V. value :: V a -> E a -- | Logical negation. not_ :: E Bool -> E Bool -- | Logical AND. (&&.) :: E Bool -> E Bool -> E Bool -- | Logical OR. (||.) :: E Bool -> E Bool -> E Bool -- | The conjunction of a E Bool list. and_ :: [E Bool] -> E Bool -- | The disjunction of a E Bool list. or_ :: [E Bool] -> E Bool -- | True iff the predicate is true for any element. any_ :: (a -> E Bool) -> [a] -> E Bool -- | True iff the predicate is true for all elements. all_ :: (a -> E Bool) -> [a] -> E Bool imply :: E Bool -> E Bool -> E Bool -- | Equal. (==.) :: (EqE a) => E a -> E a -> E Bool -- | Not equal. (/=.) :: (EqE a) => E a -> E a -> E Bool -- | Less than. (<.) :: (OrdE a) => E a -> E a -> E Bool -- | Less than or equal. (<=.) :: (OrdE a) => E a -> E a -> E Bool -- | Greater than. (>.) :: (OrdE a) => E a -> E a -> E Bool -- | Greater than or equal. (>=.) :: (OrdE a) => E a -> E a -> E Bool -- | Returns the minimum of two numbers. min_ :: (OrdE a) => E a -> E a -> E a -- | Returns the minimum of a list of numbers. minimum_ :: (OrdE a) => [E a] -> E a -- | Returns the maximum of two numbers. max_ :: (OrdE a) => E a -> E a -> E a -- | Returns the maximum of a list of numbers. maximum_ :: (OrdE a) => [E a] -> E a -- | Limits between min and max. limit :: (OrdE a) => E a -> E a -> E a -> E a -- | Division. If both the dividend and divisor are constants, a -- compile-time check is made for divide-by-zero. Otherwise, if the -- divisor ever evaluates to 0, a runtime exception will occur, -- even if the division occurs within the scope of a cond or -- mux that tests for 0 (because Atom generates -- deterministic-time code, every branch of a cond or mux -- is executed). div_ :: (IntegralE a) => E a -> E a -> E a -- | Division, where the C code is instrumented with a runtime check to -- ensure the divisor does not equal 0. If it is equal to -- 0, the 3rd argument is a user-supplied non-zero divsor. div0_ :: (IntegralE a) => E a -> E a -> a -> E a -- | Modulo. If both the dividend and modulus are constants, a compile-time -- check is made for divide-by-zero. Otherwise, if the modulus ever -- evaluates to 0, a runtime exception will occur, even if the -- division occurs within the scope of a cond or mux that -- tests for 0 (because Atom generates deterministic-time code, -- every branch of a cond or mux is executed). mod_ :: (IntegralE a) => E a -> E a -> E a -- | Modulus, where the C code is instrumented with a runtime check to -- ensure the modulus does not equal 0. If it is equal to -- 0, the 3rd argument is a user-supplied non-zero divsor. mod0_ :: (IntegralE a) => E a -> E a -> a -> E a -- | Conditional expression. Note, both branches are evaluated! -- --
--   mux test onTrue onFalse
--   
mux :: (Expr a) => E Bool -> E a -> E a -> E a -- | Array index to variable. (!) :: (Expr a, IntegralE b) => A a -> E b -> V a -- | Array index to expression. (!.) :: (Expr a, IntegralE b) => A a -> E b -> E a ubool :: Bool -> UE unot :: UE -> UE uand :: UE -> UE -> UE uor :: UE -> UE -> UE ueq :: UE -> UE -> UE umux :: UE -> UE -> UE -> UE instance Show UE instance Eq UE instance Ord UE instance Show UA instance Eq UA instance Ord UA instance Eq (A a) instance Show UV instance Eq UV instance Ord UV instance Eq (V a) instance Eq Variable instance Eq Const instance Ord Const instance Show Type instance Read Type instance Eq Type instance Ord Type instance (Expr a, OrdE a, EqE a, IntegralE a, Bits a) => Bits (E a) instance (OrdE a, NumE a, Num a, Fractional a) => Fractional (E a) instance (Num a, NumE a, OrdE a) => Num (E a) instance FloatingE Double instance FloatingE Float instance OrdE Double instance OrdE Float instance OrdE Word64 instance OrdE Word32 instance OrdE Word16 instance OrdE Word8 instance OrdE Int64 instance OrdE Int32 instance OrdE Int16 instance OrdE Int8 instance EqE Double instance EqE Float instance EqE Word64 instance EqE Word32 instance EqE Word16 instance EqE Word8 instance EqE Int64 instance EqE Int32 instance EqE Int16 instance EqE Int8 instance EqE Bool instance IntegralE Word64 instance IntegralE Word32 instance IntegralE Word16 instance IntegralE Word8 instance IntegralE Int64 instance IntegralE Int32 instance IntegralE Int16 instance IntegralE Int8 instance NumE Double instance NumE Float instance NumE Word64 instance NumE Word32 instance NumE Word16 instance NumE Word8 instance NumE Int64 instance NumE Int32 instance NumE Int16 instance NumE Int8 instance Expr Double instance Expr Float instance Expr Word64 instance Expr Word32 instance Expr Word16 instance Expr Word8 instance Expr Int64 instance Expr Int32 instance Expr Int16 instance Expr Int8 instance Expr Bool instance (Expr a) => TypeOf (E a) instance TypeOf UE instance TypeOf (A a) instance TypeOf UA instance TypeOf (V a) instance TypeOf UV instance TypeOf Const instance Width UV instance Width UE instance (Expr a) => Width (V a) instance (Expr a) => Width (E a) instance Width Const instance Width Type instance (Expr a) => Eq (E a) instance Show (E a) instance Show Const module Language.Atom.Elaboration -- | The Atom monad holds variable and rule declarations. data Atom a data AtomDB AtomDB :: Int -> Name -> [Name] -> UE -> [AtomDB] -> Int -> Int -> [(UV, UE)] -> [([String] -> String, [UE])] -> [(Name, UE)] -> [(Name, UE)] -> AtomDB atomId :: AtomDB -> Int atomName :: AtomDB -> Name atomNames :: AtomDB -> [Name] atomEnable :: AtomDB -> UE atomSubs :: AtomDB -> [AtomDB] atomPeriod :: AtomDB -> Int atomPhase :: AtomDB -> Int atomAssigns :: AtomDB -> [(UV, UE)] atomActions :: AtomDB -> [([String] -> String, [UE])] atomAsserts :: AtomDB -> [(Name, UE)] atomCovers :: AtomDB -> [(Name, UE)] data Global Global :: Int -> Int -> Int -> [StateHierarchy] -> [(String, UE)] -> Int -> Int -> Global gRuleId :: Global -> Int gVarId :: Global -> Int gArrayId :: Global -> Int gState :: Global -> [StateHierarchy] gProbes :: Global -> [(String, UE)] gPeriod :: Global -> Int gPhase :: Global -> Int data Rule Rule :: Int -> Name -> UE -> [(UV, UE)] -> [([String] -> String, [UE])] -> Int -> Int -> Rule ruleId :: Rule -> Int ruleName :: Rule -> Name ruleEnable :: Rule -> UE ruleAssigns :: Rule -> [(UV, UE)] ruleActions :: Rule -> [([String] -> String, [UE])] rulePeriod :: Rule -> Int rulePhase :: Rule -> Int Assert :: Name -> UE -> UE -> Rule ruleName :: Rule -> Name ruleEnable :: Rule -> UE ruleAssert :: Rule -> UE Cover :: Name -> UE -> UE -> Rule ruleName :: Rule -> Name ruleEnable :: Rule -> UE ruleCover :: Rule -> UE data StateHierarchy StateHierarchy :: Name -> [StateHierarchy] -> StateHierarchy StateVariable :: Name -> Const -> StateHierarchy StateArray :: Name -> [Const] -> StateHierarchy buildAtom :: Global -> Name -> Atom a -> IO (a, (Global, AtomDB)) type UID = Int -- | A name. type Name = String -- | A hierarchical name. type Path = [Name] -- | A Relation is used for relative performance constraints between -- Actions. data Relation = Higher UID | Lower UID deriving -- (Show, Eq) -- -- Given a top level name and design, elaborates design and returns a -- design database. elaborate :: Name -> Atom () -> IO (Maybe (StateHierarchy, [Rule], [Name], [Name], [(Name, Type)])) -- | Generic local variable declaration. var :: (Expr a) => Name -> a -> Atom (V a) -- | Generic external variable declaration. var' :: Name -> Type -> V a -- | Generic array declaration. array :: (Expr a) => Name -> [a] -> Atom (A a) -- | Generic external array declaration. array' :: (Expr a) => Name -> Type -> A a addName :: Name -> Atom Name get :: Atom (Global, AtomDB) put :: (Global, AtomDB) -> Atom () -- | All the variables that directly and indirectly control the value of an -- expression. allUVs :: [Rule] -> UE -> [UV] -- | All primary expressions used in a rule. allUEs :: Rule -> [UE] instance MonadIO Atom instance Monad Atom instance Show Rule instance Ord AtomDB instance Eq AtomDB instance Show AtomDB module Language.Atom.Analysis -- | Topologically sorts a list of expressions and subexpressions. topo :: [UE] -> [(UE, String)] -- | Number of UE's computed in rule. ruleComplexity :: Rule -> Int -- | Atom rule scheduling. module Language.Atom.Scheduling schedule :: [Rule] -> Schedule type Schedule = [(Int, Int, [Rule])] reportSchedule :: Schedule -> String instance Eq Usage instance Ord Usage -- | The Atom language. module Language.Atom.Language -- | The Atom monad captures variable and transition rule declarations. type Atom = Atom -- | Creates a hierarchical node, where each node could be a atomic rule. atom :: Name -> Atom a -> Atom a -- | Defines the period of execution of sub rules as a factor of the base -- rate of the system. Rule period is bound by the closest period -- assertion. For example: -- --
--   period 10 $ period 2 a   -- Rules in 'a' have a period of 2, not 10.
--   
period :: Int -> Atom a -> Atom a -- | Returns the execution period of the current scope. getPeriod :: Atom Int -- | Defines the earliest phase within the period at which the rule should -- execute. The phase must be at least zero and less than the -- current period. phase :: Int -> Atom a -> Atom a -- | Returns the phase of the current scope. getPhase :: Atom Int -- | Adds an enabling condition to an atom subtree of rules. This condition -- must be true before any rules in hierarchy are allowed to execute. cond :: E Bool -> Atom () class (Expr a) => Assign a (<==) :: (Assign a) => V a -> E a -> Atom () -- | Increments a NumE V. incr :: (Assign a, NumE a) => V a -> Atom () -- | Decrements a NumE V. decr :: (Assign a, NumE a) => V a -> Atom () -- | Generic local variable declaration. var :: (Expr a) => Name -> a -> Atom (V a) -- | Generic external variable declaration. var' :: Name -> Type -> V a -- | Generic array declaration. array :: (Expr a) => Name -> [a] -> Atom (A a) -- | Generic external array declaration. array' :: (Expr a) => Name -> Type -> A a -- | Local boolean variable declaration. bool :: Name -> Bool -> Atom (V Bool) -- | External boolean variable declaration. bool' :: Name -> V Bool -- | Local int8 variable declaration. int8 :: Name -> Int8 -> Atom (V Int8) -- | External int8 variable declaration. int8' :: Name -> V Int8 -- | Local int16 variable declaration. int16 :: Name -> Int16 -> Atom (V Int16) -- | External int16 variable declaration. int16' :: Name -> V Int16 -- | Local int32 variable declaration. int32 :: Name -> Int32 -> Atom (V Int32) -- | External int32 variable declaration. int32' :: Name -> V Int32 -- | Local int64 variable declaration. int64 :: Name -> Int64 -> Atom (V Int64) -- | External int64 variable declaration. int64' :: Name -> V Int64 -- | Local word8 variable declaration. word8 :: Name -> Word8 -> Atom (V Word8) -- | External word8 variable declaration. word8' :: Name -> V Word8 -- | Local word16 variable declaration. word16 :: Name -> Word16 -> Atom (V Word16) -- | External word16 variable declaration. word16' :: Name -> V Word16 -- | Local word32 variable declaration. word32 :: Name -> Word32 -> Atom (V Word32) -- | External word32 variable declaration. word32' :: Name -> V Word32 -- | Local word64 variable declaration. word64 :: Name -> Word64 -> Atom (V Word64) -- | External word64 variable declaration. word64' :: Name -> V Word64 -- | Local float variable declaration. float :: Name -> Float -> Atom (V Float) -- | External float variable declaration. float' :: Name -> V Float -- | Local double variable declaration. double :: Name -> Double -> Atom (V Double) -- | External double variable declaration. double' :: Name -> V Double -- | Declares an action. action :: ([String] -> String) -> [UE] -> Atom () -- | Calls an external C function of type 'void f(void)'. call :: Name -> Atom () -- | Declares a probe. probe :: (Expr a) => Name -> E a -> Atom () -- | Fetches all declared probes to current design point. probes :: Atom [(String, UE)] -- | An assertions checks that an E Bool is true. Assertions are checked -- between the execution of every rule. Parent enabling conditions can -- disable assertions, but period and phase constraints do not. Assertion -- names should be globally unique. assert :: Name -> E Bool -> Atom () -- | A functional coverage point tracks if an event has occured (true). -- Coverage points are checked at the same time as assertions. Coverage -- names should be globally unique. cover :: Name -> E Bool -> Atom () -- | Implication assertions. Creates an implicit coverage point for the -- precondition. assertImply :: Name -> E Bool -> E Bool -> Atom () -- | A name. type Name = String liftIO :: (MonadIO m) => forall a. IO a -> m a -- | Returns the current atom hierarchical path. path :: Atom String -- | Reference to the 64-bit free running clock. clock :: E Word64 -- | Rule coverage information. (current coverage index, coverage data) nextCoverage :: Atom (E Word32, E Word32) instance Assign Double instance Assign Float instance Assign Word64 instance Assign Word32 instance Assign Word16 instance Assign Word8 instance Assign Int64 instance Assign Int32 instance Assign Int16 instance Assign Int8 instance Assign Bool -- | Common Atom functions. module Language.Atom.Common -- | A Timer. data Timer -- | Creates a new timer. timer :: Name -> Atom Timer -- | Starts a Timer. A timer can be restarted at any time. startTimer :: Timer -> E Word64 -> Atom () -- | Conditionally start a Timer. startTimerIf :: Timer -> E Bool -> E Word64 -> Atom () -- | True when a timer has completed. timerDone :: Timer -> E Bool -- | One-shot on a rising transition. oneShotRise :: E Bool -> Atom (E Bool) -- | One-shot on a falling transition. oneShotFall :: E Bool -> Atom (E Bool) -- | Debounces a boolean given an on and off time (ticks) and an initial -- state. debounce :: Name -> E Word64 -> E Word64 -> Bool -> E Bool -> Atom (E Bool) -- | 1-D lookup table. X values out of table range are clipped at end Y -- values. Input table must be monotonically increasing in X. lookupTable :: (FloatingE a) => [(E a, E a)] -> E a -> E a -- | Linear extrapolation and interpolation on a line with 2 points. The -- two x points must be different to prevent a divide-by-zero. linear :: (FloatingE a) => (E a, E a) -> (E a, E a) -> E a -> E a -- | Hysteresis returns True when the input exceeds max and -- False when the input is less than min. The state is -- held when the input is between min and max. -- --
--   hysteresis name min max input
--   
hysteresis :: (OrdE a) => E a -> E a -> E a -> Atom (E Bool) -- | Atom C code generation. module Language.Atom.Code -- | C code configuration parameters. data Config Config :: String -> String -> ([Name] -> [Name] -> [(Name, Type)] -> (String, String)) -> Bool -> Bool -> String -> String -> Config -- | Alternative primary function name. Leave empty to use compile name. cFuncName :: Config -> String -- | Name of state variable structure. Default: state cStateName :: Config -> String -- | Custom C code to insert above and below, given assertion names, -- coverage names, and probe names and types. cCode :: Config -> [Name] -> [Name] -> [(Name, Type)] -> (String, String) -- | Enable rule coverage tracking. cRuleCoverage :: Config -> Bool -- | Enable assertions and functional coverage. cAssert :: Config -> Bool -- | Name of assertion function. Type: void assert(int, bool, uint64_t); cAssertName :: Config -> String -- | Name of coverage function. Type: void cover(int, bool, uint64_t); cCoverName :: Config -> String writeC :: Name -> Config -> StateHierarchy -> [Rule] -> Schedule -> [Name] -> [Name] -> [(Name, Type)] -> IO RuleCoverage -- | Default C code configuration parameters (default function name, no -- pre/post code, ANSI C types). defaults :: Config -- | C99 type naming rules. cType :: Type -> String type RuleCoverage = [(Name, Int, Int)] -- | Atom compilation. module Language.Atom.Compile -- | Compiles an atom description to C. compile :: Name -> Config -> Atom () -> IO (Schedule, RuleCoverage, [Name], [Name], [(Name, Type)]) reportSchedule :: Schedule -> String type Schedule = [(Int, Int, [Rule])] module Language.Atom.Unit -- | Data constructor:Test data Test Test :: String -> Int -> Atom () -> [FilePath] -> [FilePath] -> String -> String -> String -> String -> Test name :: Test -> String cycles :: Test -> Int testbench :: Test -> Atom () modules :: Test -> [FilePath] includes :: Test -> [FilePath] declCode :: Test -> String initCode :: Test -> String loopCode :: Test -> String endCode :: Test -> String defaultTest :: Test class (Expr a) => Random a random :: (Random a) => E a -- | Running TestList runTests :: Int -> [IO Test] -> IO () -- | Printing strings in C using printf. printStrLn :: String -> Atom () -- | Print integral values. printIntegralE :: (IntegralE a) => String -> E a -> Atom () -- | Print floating point values. printFloatingE :: (FloatingE a) => String -> E a -> Atom () instance Random Int64 instance Random Int32 instance Random Int16 instance Random Int8 instance Random Word64 instance Random Word32 instance Random Word16 instance Random Word8 instance Random Bool -- | Atom is a Haskell DSL for designing hard realtime embedded software. -- Based on guarded atomic actions (similar to STM), Atom enables highly -- concurrent programming without the need for mutex locking. In -- addition, Atom performs compile-time task scheduling and generates -- code with deterministic execution time and constant memory use, -- simplifying the process of timing verification and memory consumption -- in hard realtime applications. Without mutex locking and run-time task -- scheduling, Atom eliminates the need and overhead of RTOSs for many -- embedded applications. module Language.Atom -- | An example atom design. module Language.Atom.Example -- | Invoke the atom compiler. compileExample :: IO () -- | An example design that computes the greatest common divisor. example :: Atom ()