1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/src/lv_misc/lv_task.h

178 lines
3.8 KiB
C
Raw Normal View History

2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* @file lv_task.c
* An 'lv_task' is a void (*fp) (void* param) type function which will be called periodically.
* A priority (5 levels + disable) can be assigned to lv_tasks.
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
#ifndef LV_TASK_H
#define LV_TASK_H
2017-11-23 20:42:14 +01:00
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
2019-03-17 08:33:03 +01:00
#include "../../../lv_conf.h"
#endif
2017-11-23 20:42:14 +01:00
#include <stdint.h>
#include <stdbool.h>
#include "lv_mem.h"
#include "lv_ll.h"
/*********************
* DEFINES
*********************/
#ifndef LV_ATTRIBUTE_TASK_HANDLER
#define LV_ATTRIBUTE_TASK_HANDLER
#endif
2017-11-23 20:42:14 +01:00
/**********************
* TYPEDEFS
**********************/
2019-05-17 07:58:47 +02:00
struct _lv_task_t;
/**
2019-06-25 15:14:47 +02:00
* Tasks execute this type type of functions.
2019-05-17 07:58:47 +02:00
*/
typedef void (*lv_task_cb_t)(struct _lv_task_t *);
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Possible priorities for lv_tasks
2017-11-23 20:42:14 +01:00
*/
2019-04-04 07:15:40 +02:00
enum {
2017-11-24 17:48:47 +01:00
LV_TASK_PRIO_OFF = 0,
LV_TASK_PRIO_LOWEST,
LV_TASK_PRIO_LOW,
LV_TASK_PRIO_MID,
LV_TASK_PRIO_HIGH,
LV_TASK_PRIO_HIGHEST,
_LV_TASK_PRIO_NUM,
2018-09-18 13:59:40 +02:00
};
typedef uint8_t lv_task_prio_t;
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Descriptor of a lv_task
2017-11-23 20:42:14 +01:00
*/
2019-04-30 15:03:52 +02:00
typedef struct _lv_task_t
2017-11-23 20:42:14 +01:00
{
uint32_t period;
uint32_t last_run;
2019-05-17 07:58:47 +02:00
lv_task_cb_t task_cb;
void * user_data;
2019-04-04 07:15:40 +02:00
uint8_t prio : 3;
uint8_t once : 1;
2018-06-19 09:49:58 +02:00
} lv_task_t;
2017-11-23 20:42:14 +01:00
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
2017-11-24 17:48:47 +01:00
* Init the lv_task module
2017-11-23 20:42:14 +01:00
*/
2019-05-17 07:58:47 +02:00
void lv_task_core_init(void);
2017-11-23 20:42:14 +01:00
2019-06-25 15:14:47 +02:00
//! @cond Doxygen_Suppress
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Call it periodically to handle lv_tasks.
2017-11-23 20:42:14 +01:00
*/
2018-03-07 09:22:37 +01:00
LV_ATTRIBUTE_TASK_HANDLER void lv_task_handler(void);
2017-11-23 20:42:14 +01:00
2019-06-25 15:14:47 +02:00
//! @endcond
2019-05-17 08:29:38 +02:00
/**
* Create an "empty" task. It needs to initialzed with at least
* `lv_task_set_cb` and `lv_task_set_period`
* @return pointer to the craeted task
*/
lv_task_t * lv_task_create_basic(void);
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Create a new lv_task
2019-06-20 06:19:07 +02:00
* @param task_xcb a callback which is the task itself. It will be called periodically.
* (the 'x' in the argument name indicates that its not a fully generic function because it not follows
* the `func_name(object, callback, ...)` convention)
2017-11-23 20:42:14 +01:00
* @param period call period in ms unit
2017-11-24 17:48:47 +01:00
* @param prio priority of the task (LV_TASK_PRIO_OFF means the task is stopped)
* @param user_data custom parameter
2019-05-17 08:29:38 +02:00
* @return pointer to the new task
2017-11-23 20:42:14 +01:00
*/
2019-06-20 06:19:07 +02:00
lv_task_t * lv_task_create(lv_task_cb_t task_xcb, uint32_t period, lv_task_prio_t prio, void * user_data);
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Delete a lv_task
2019-05-17 08:29:38 +02:00
* @param task pointer to task_cb created by task
2017-11-23 20:42:14 +01:00
*/
2019-05-17 08:29:38 +02:00
void lv_task_del(lv_task_t * task);
2017-11-23 20:42:14 +01:00
2019-05-17 07:58:47 +02:00
/**
* Set the callback the task (the function to call periodically)
* @param task pointer to a task
2019-05-18 01:31:29 +03:00
* @param task_cb the function to call periodically
2019-05-17 07:58:47 +02:00
*/
2019-05-18 01:31:29 +03:00
void lv_task_set_cb(lv_task_t * task, lv_task_cb_t task_cb);
2019-05-17 07:58:47 +02:00
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Set new priority for a lv_task
2019-05-17 08:29:38 +02:00
* @param task pointer to a lv_task
2017-11-23 20:42:14 +01:00
* @param prio the new priority
*/
2019-05-17 08:29:38 +02:00
void lv_task_set_prio(lv_task_t * task, lv_task_prio_t prio);
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Set new period for a lv_task
2019-05-17 08:29:38 +02:00
* @param task pointer to a lv_task
2017-11-23 20:42:14 +01:00
* @param period the new period
*/
2019-05-17 08:29:38 +02:00
void lv_task_set_period(lv_task_t * task, uint32_t period);
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Make a lv_task ready. It will not wait its period.
2019-05-17 08:29:38 +02:00
* @param task pointer to a lv_task.
2017-11-23 20:42:14 +01:00
*/
2019-05-17 08:29:38 +02:00
void lv_task_ready(lv_task_t * task);
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Delete the lv_task after one call
2019-05-17 08:29:38 +02:00
* @param task pointer to a lv_task.
2017-11-23 20:42:14 +01:00
*/
2019-05-17 08:29:38 +02:00
void lv_task_once(lv_task_t * task);
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Reset a lv_task.
2017-11-23 20:42:14 +01:00
* It will be called the previously set period milliseconds later.
2019-05-17 08:29:38 +02:00
* @param task pointer to a lv_task.
2017-11-23 20:42:14 +01:00
*/
2019-05-17 08:29:38 +02:00
void lv_task_reset(lv_task_t * task);
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Enable or disable the whole lv_task handling
* @param en: true: lv_task handling is running, false: lv_task handling is suspended
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
void lv_task_enable(bool en);
2017-11-23 20:42:14 +01:00
2017-12-20 00:47:37 +01:00
/**
* Get idle percentage
* @return the lv_task idle in percentage
*/
uint8_t lv_task_get_idle(void);
2017-11-23 20:42:14 +01:00
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
2018-06-19 09:49:58 +02:00
#endif