Commit af71a78f authored by Mart Lubbers's avatar Mart Lubbers
Browse files

don't start preloaded tasks on boot

parent de270c42
Pipeline #53975 passed with stage
in 1 minute and 23 seconds
Subproject commit dc91d25586178b40d50eae51a8ba82b831b91d1d
Subproject commit b2a59c3c8842278534aeb084465292caf072799b
......@@ -75,7 +75,21 @@ preloadTask :: (Main (BCInterpret (TaskValue u))) -> Task String | type u
*/
preloadTaskWithOptions :: CompileOpts (Main (BCInterpret (TaskValue u))) -> Task String | type u
/**
* Prepare a list of boxed tasks for preloading.
*
* @param mTask tasks boxed in MTaskBox types
* @result the code to put in preloaded_task.h
*/
preloadTasks :: [MTaskBox] -> Task String
/**
* Prepare a list of boxed tasks for preloading and use the compilation options
* provided
*
* @param mTask tasks boxed in MTaskBox types
* @result the code to put in preloaded_task.h
*/
preloadTasksWithOptions :: CompileOpts [MTaskBox] -> Task String
/**
......
......@@ -6,12 +6,15 @@ import Control.Applicative
import Data.Either
import Data.Func
import Data.Functor
import Data.GenHash
import Data.List => qualified group
import Data.Map => qualified union, difference, find, updateAt, get
import Data.Map.GenJSON
import Data.Tuple
import Data.UInt
import Text
import Text.HTML
import System.Time
import iTasks
import mTask.Interpret.ByteCodeEncoding
......@@ -21,7 +24,7 @@ import mTask.Interpret.Compile
import mTask.Interpret.String255
import mTask.Interpret.VoidPointer
import mTask.Interpret
import System.Time
import Data.UInt
derive class iTask MTDeviceData, MTaskStatus
......@@ -147,8 +150,6 @@ mTaskSafe t = try (Right <$> t) \e->case e of
preloadTasks :: [MTaskBox] -> Task String
preloadTasks ts = preloadTasksWithOptions zero ts
import Text.HTML, Data.GenHash
preloadTasksWithOptions :: CompileOpts [MTaskBox] -> Task String
preloadTasksWithOptions opts tasks = header <$> ptwo [zero..] tasks footer
>>- viewInformation [ViewAs \a->PreTag [] [Text a]] o join "\n"
......@@ -156,15 +157,15 @@ where
ptwo :: [UInt8] [MTaskBox] [String] -> Task [String]
ptwo _ [] c = return c
ptwo [n:ns] [(MTB t):ts] c = mkMessage n opts t \_ td
# td & status = MTPreloaded
# td & status = MTNeedsInit
# bytes = join ", " [toString c\\c<-gCSerialise{|*|} td []]
= ptwo ns ts
[ concat5 "#define PRELOADED_HASH" (toString n) " " (toString $ gHash{|*|} bytes) "ll"
, concat5 "static const uint8_t preloaded_task" (toString n) "[] PROGMEM = {" bytes "};"
: c]
footer =
[ concat3 "static const uint8_t *preloaded_tasks[] PROGMEM = {" (join ", " ["preloaded_task" +++ toString n\\n<-[0..length tasks-1]]) "};"
, concat3 "static const int64_t preloaded_hashes[] PROGMEM = {" (join ", " ["PRELOADED_HASH" +++ toString n\\n<-[0..length tasks-1]]) "};"
footer =
[ concat3 "static const uint8_t *const preloaded_tasks[PRELOADED_TASKS_NUM] PROGMEM = {" (join ", " ["preloaded_task" +++ toString n\\n<-[0..length tasks-1]]) "};"
, concat3 "static const int64_t preloaded_hashes[PRELOADED_TASKS_NUM] PROGMEM = {" (join ", " ["PRELOADED_HASH" +++ toString n\\n<-[0..length tasks-1]]) "};"
, ""
, "#ifdef __cplusplus"
, "}"
......@@ -212,7 +213,7 @@ mkMessage sid opts task f
, peripherals = hardware
, shares = {i\\i<-shares}
, instructions = BCIs {i\\i<-instructions}
, status = MTUnevaluated
, status = MTNeedsInit
, execution_min = UInt32 0
, execution_max = UInt32 0
, lastrun = UInt32 0
......@@ -221,6 +222,12 @@ mkMessage sid opts task f
liftmTask :: (Main (BCInterpret (TaskValue u))) MTDevice -> Task u | type u
liftmTask a b = liftmTaskWithOptions zero a b
taskAccepted MTSPrepack = True
taskAccepted MTSAcked = True
taskAccepted (MTSValue _) = True
taskAccepted (MTSException _) = True
taskAccepted _ = False
liftmTaskWithOptions :: CompileOpts (Main (BCInterpret (TaskValue u))) MTDevice -> Task u | type u
liftmTaskWithOptions opts task (MTDevice dev sdsupdates channels)
= get dev
......@@ -234,11 +241,16 @@ liftmTaskWithOptions opts task (MTDevice dev sdsupdates channels)
//Add task to sdsupdates map
upd (put sid []) sdsupdates
//Send the prep
>-| sendMessage (MTTTaskPrep sid) channels
>-| sendMessage (MTTTaskPrep {taskid=sid, hash=0}) channels
//Wait for the prepack
>-| watch taskView
>>* [OnValue $ ifValue (\t->t=:MTSPrepack || t =: MTSAcked || t =: (MTSValue _) || t =: (MTSException _))
\_->sendMessage (MTTTask msg) channels]
>>* [OnValue $ ifValue taskAccepted \t->case t of
//If it was loaded from cache we don't need to send anything
MTSAcked -> return ()
MTSValue _ -> return ()
MTSException _ -> return ()
_ -> sendMessage (MTTTask msg) channels @! ()
]
//Wait for task ack
>-| watch taskView
>>* [OnValue $ ifValue (\t->t =: MTSAcked || t =: (MTSValue _) || t =: (MTSException _))
......
......@@ -22,7 +22,9 @@ from mTask.Interpret.VoidPointer import :: VoidPointer
//* taskid returnwidth peripherals shares instructions
= MTTTask MTaskMeta
//* taskid (task prep for devices that have small comm buffers)
| MTTTaskPrep UInt8
//* @param hash of the task
//* @param taskid
| MTTTaskPrep MTaskPrepData
//* taskid
| MTTTaskDel UInt8
//*
......@@ -32,6 +34,8 @@ from mTask.Interpret.VoidPointer import :: VoidPointer
//* taskid sdsid sds value
| MTTSdsUpdate UInt8 UInt8 String255
:: MTaskPrepData = { taskid :: UInt8, hash :: Int }
:: MTaskMeta =
{ taskid :: UInt8
, tree :: VoidPointer
......@@ -47,10 +51,13 @@ from mTask.Interpret.VoidPointer import :: VoidPointer
}
:: MTaskValueState = MTNoValue | MTUnstable | MTStable
// MTEvaluated: task tree is evaluated and the previously calculated execution interval is still correct
// MTPurged: task tree is evaluated, but the execution interval needs to be recalculated
// MTUnevaluated: task tree contains unevaluated parts, the execution interval is [0,0]
:: MTaskEvalStatus = MTPreloaded | MTEvaluated | MTPurged | MTUnevaluated | MTRemoved
//* Status of the task
:: MTaskEvalStatus
= MTEvaluated //* task tree is evaluated and the previous execution interval is still correct
| MTPurged //* task tree is evaluated, but the execution interval needs to be recalculated
| MTUnevaluated //* task tree contains unevaluated parts, the execution interval is [0,0]
| MTRemoved //* task is removed
| MTNeedsInit //* task doesn't have a tasktree yet
:: MTMessageFro
//* taskid
......@@ -85,8 +92,8 @@ from mTask.Interpret.VoidPointer import :: VoidPointer
| MTERTSError
| MTEUnexpectedDisconnect
derive class iTask MTMessageFro, MTMessageTo, MTException, MTaskMeta, MTaskValueState, MTaskEvalStatus
derive gCSerialise MTMessageFro, MTMessageTo, MTException, MTaskMeta, TaskValue, MTaskValueState, MTaskEvalStatus
derive gCDeserialise MTMessageFro, MTMessageTo, MTException, MTaskMeta, TaskValue, MTaskValueState, MTaskEvalStatus
derive class iTask MTMessageFro, MTMessageTo, MTException, MTaskMeta, MTaskValueState, MTaskEvalStatus, MTaskPrepData
derive gCSerialise MTMessageFro, MTMessageTo, MTException, MTaskMeta, TaskValue, MTaskValueState, MTaskEvalStatus, MTaskPrepData
derive gCDeserialise MTMessageFro, MTMessageTo, MTException, MTaskMeta, TaskValue, MTaskValueState, MTaskEvalStatus, MTaskPrepData
instance toString MTException
......@@ -9,7 +9,7 @@ import mTask.Interpret.Instructions
import mTask.Interpret.Compile
import mTask.Interpret.VoidPointer
derive class iTask MTMessageFro, MTMessageTo, MTException, MTaskMeta, MTaskValueState, MTaskEvalStatus
derive gCSerialise MTMessageFro, MTMessageTo, MTException, MTaskMeta, TaskValue, MTaskValueState, MTaskEvalStatus
derive gCDeserialise MTMessageFro, MTMessageTo, MTException, MTaskMeta, TaskValue, MTaskValueState, MTaskEvalStatus
derive class iTask MTMessageFro, MTMessageTo, MTException, MTaskMeta, MTaskValueState, MTaskEvalStatus, MTaskPrepData
derive gCSerialise MTMessageFro, MTMessageTo, MTException, MTaskMeta, TaskValue, MTaskValueState, MTaskEvalStatus, MTaskPrepData
derive gCDeserialise MTMessageFro, MTMessageTo, MTException, MTaskMeta, TaskValue, MTaskValueState, MTaskEvalStatus, MTaskPrepData
instance toString MTException where toString e = toSingleLineText e
......@@ -25,7 +25,6 @@ instance zero MTDeviceSpec
, haveLS :: Bool
, haveAQS :: Bool
, haveGes :: Bool
, preloadedTasks :: Int
}
derive gCSerialise MTDeviceSpec
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment