1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/lv_misc/lv_task.h

135 lines
2.7 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
*********************/
#include <stdint.h>
#include <stdbool.h>
#include "lv_mem.h"
#include "lv_ll.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**
2017-11-24 17:48:47 +01:00
* Possible priorities for lv_tasks
2017-11-23 20:42:14 +01:00
*/
typedef 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,
}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
*/
typedef struct
{
uint32_t period;
uint32_t last_run;
void (*task) (void*);
void * param;
uint8_t prio:3;
uint8_t once:1;
2017-11-24 17:48:47 +01: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
*/
2017-11-24 17:48:47 +01:00
void lv_task_init(void);
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
*/
2017-11-24 17:48:47 +01:00
void lv_task_handler(void);
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Create a new lv_task
2017-11-23 20:42:14 +01:00
* @param task a function which is the task itself
* @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)
2017-11-23 20:42:14 +01:00
* @param param free parameter
* @return pointer to the new task
*/
2017-11-24 17:48:47 +01:00
lv_task_t* lv_task_create(void (*task) (void *), uint32_t period, lv_task_prio_t prio, void * param);
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Delete a lv_task
* @param lv_task_p pointer to task created by lv_task_p
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
void lv_task_del(lv_task_t* lv_task_p);
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Set new priority for a lv_task
* @param lv_task_p pointer to a lv_task
2017-11-23 20:42:14 +01:00
* @param prio the new priority
*/
2017-11-24 17:48:47 +01:00
void lv_task_set_prio(lv_task_t* lv_task_p, 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
* @param lv_task_p pointer to a lv_task
2017-11-23 20:42:14 +01:00
* @param period the new period
*/
2017-11-24 17:48:47 +01:00
void lv_task_set_period(lv_task_t* lv_task_p, 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.
* @param lv_task_p pointer to a lv_task.
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
void lv_task_ready(lv_task_t* lv_task_p);
2017-11-23 20:42:14 +01:00
/**
2017-11-24 17:48:47 +01:00
* Delete the lv_task after one call
* @param lv_task_p pointer to a lv_task.
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
void lv_task_once(lv_task_t * lv_task_p);
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.
2017-11-24 17:48:47 +01:00
* @param lv_task_p pointer to a lv_task.
2017-11-23 20:42:14 +01:00
*/
2017-11-24 17:48:47 +01:00
void lv_task_reset(lv_task_t* lv_task_p);
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
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif