diff options
author | Louis Collard <louiscollard@chromium.org> | 2018-09-17 20:56:17 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-01-26 03:38:59 -0800 |
commit | 9cb1b936e76809cb68419c3ff3612e17fec81e9c (patch) | |
tree | 573291dd3069ef9ff2150d362dba1374fc36c7af /include | |
parent | 0c0fbbe3275b0c069cf50e71603b797633f7b0a9 (diff) | |
download | chrome-ec-9cb1b936e76809cb68419c3ff3612e17fec81e9c.tar.gz |
ec: Add a task_reset function.
This adds a generic task_reset function that can reset any task
that declares it supports being reset. Tasks that support reset
must call task_reset_cleanup() on startup, and be prepared to
perform any cleanup / re-initialisation necessary. The task can
control when it can be reset using task_enable_resets() and
task_disable_resets().
A task can request another task be reset at any point; if the
reset cannot happen immediately, it will be queued and will happen
at the earliest point allowed by the task to be reset.
Task resets can be blocking or non-blocking, as specified by
the requestor.
BUG=b:73771117
BRANCH=none
TEST=manual testing on local device
Change-Id: I972184381b005c342374fa16c4dce2ac83e89854
Signed-off-by: Louis Collard <louiscollard@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1230394
Reviewed-by: Andrey Pronin <apronin@chromium.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/config.h | 23 | ||||
-rw-r--r-- | include/task.h | 51 |
2 files changed, 73 insertions, 1 deletions
diff --git a/include/config.h b/include/config.h index fa5585f95d..b8bb7419b9 100644 --- a/include/config.h +++ b/include/config.h @@ -1050,6 +1050,7 @@ #define CONFIG_CMD_SYSINFO #define CONFIG_CMD_SYSJUMP #define CONFIG_CMD_SYSLOCK +#undef CONFIG_CMD_TASK_RESET #undef CONFIG_CMD_TASKREADY #define CONFIG_CMD_TEMP_SENSOR #define CONFIG_CMD_TIMERINFO @@ -2961,6 +2962,27 @@ #undef CONFIG_CTS_TASK_LIST /* + * List of tasks that support reset. Tasks listed here must also be included in + * CONFIG_TASK_LIST. + * + * For each task, use macro ENABLE_RESET(n) to enable resets. The parameter n + * must match the value passed to TASK_{ALWAYS,NOTEST} in CONFIG_TASK_LIST. + * + * Tasks that enable resets *must* call task_reset_cleanup() once at the + * beginning of their main function, and perform task-specific cleanup if + * necessary. + * + * By default, tasks can be reset at any time. To change this behavior, call + * task_disable_resets() immediately after task_reset_cleanup(), and then enable + * resets where appropriate. + * + * Tasks that predominantly have resets disabled are expected to periodically + * enable resets, and should always ensure to do so before waiting for long + * periods (eg when waiting for an event to process). + */ +#undef CONFIG_TASK_RESET_LIST + +/* * Enable task profiling. * * Boards may #undef this to reduce image size and RAM usage. @@ -4209,4 +4231,3 @@ #endif /* CONFIG_DPTF_MULTI_PROFILE && !CONFIG_DPTF */ #endif /* __CROS_EC_CONFIG_H */ - diff --git a/include/task.h b/include/task.h index f0b680386b..08acec1714 100644 --- a/include/task.h +++ b/include/task.h @@ -39,6 +39,8 @@ #define TASK_EVENT_DMA_TC (1 << 26) /* ADC interrupt handler event */ #define TASK_EVENT_ADC_DONE (1 << 27) +/* task_reset() that was requested has been completed */ +#define TASK_EVENT_RESET_DONE (1 << 28) /* task_wake() called on task */ #define TASK_EVENT_WAKE (1 << 29) /* Mutex unlocking */ @@ -234,6 +236,55 @@ void task_disable_irq(int irq); */ void task_trigger_irq(int irq); +/* + * A task that supports resets may call this to indicate that it may be reset + * at any point between this call and the next call to task_disable_resets(). + * + * Calling this function will trigger any resets that were requested while + * resets were disabled. + * + * It is not expected for this to be called if resets are already enabled. + */ +void task_enable_resets(void); + +/* + * A task that supports resets may call this to indicate that it may not be + * reset until the next call to task_enable_resets(). Any calls to task_reset() + * during this time will cause a reset request to be queued, and executed + * the next time task_enable_resets() is called. + * + * Must not be called if resets are already disabled. + */ +void task_disable_resets(void); + +/* + * If the current task was reset, completes the reset operation. + * + * Returns a non-zero value if the task was reset; tasks with state outside + * of the stack should perform any necessary cleanup immediately after calling + * this function. + * + * Tasks that support reset must call this function once at startup before + * doing anything else. + * + * Must only be called once at task startup. + */ +int task_reset_cleanup(void); + +/* + * Resets the specified task, which must not be the current task, + * to initial state. + * + * Returns EC_SUCCESS, or EC_ERROR_INVAL if the specified task does + * not support resets. + * + * If wait is true, blocks until the task has been reset. Otherwise, + * returns immediately - in this case the task reset may be delayed until + * that task can be safely reset. The duration of this delay depends on the + * task implementation. + */ +int task_reset(task_id_t id, int wait); + /** * Clear a pending interrupt. * |