forked from jmswu/schedular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schedular.h
86 lines (64 loc) · 2.22 KB
/
schedular.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* File: schedular.h
* Author: james
*
* Created on 11 December 2018, 3:27 PM
*/
#ifndef SCHEDULAR_H
#define SCHEDULAR_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/* define the maximum number of task that is available */
#define TASK_SIZE (10U)
/* function pointer use in task*/
typedef uint8_t (*sch_task_t)(void); /* task function pointer */
typedef uint32_t(*get_ticks_t)(void); /* system tick function pointer */
/* task struct for use in schedular */
typedef struct {
uint32_t ticks_interval; /* task interval */
uint32_t ticks_previous; /* previous ticks */
sch_task_t task; /* function pointer */
} task_t;
typedef struct {
/* will be point to external getTicks() function */
get_ticks_t get_ticks;
/* an task array to store all the task, and their params
* and the task schedular will read this list the run
* task according their params
*/
task_t task_list[TASK_SIZE];
/* the number of tasks */
uint16_t task_count;
} schedular_t;
extern schedular_t schedular;
/*! \brief initial schedular, this must run first
*! \param task - pointer to a task than return system ticks
*/
void schedular_init(get_ticks_t get_ticks);
/*! \brief add a task to the schedular
*! \param task - the task to add
*! \param interval - how often the task need to run
*/
void schedular_add(sch_task_t task, uint32_t interval);
/*! \brief remove a task from the schedular
*! \param task - the task to be removed
*/
void schedular_remove(sch_task_t task);
/* this run the schedular, this should be in the main loop */
void schedular_run(void);
/* print all the task in schedular, this is for debugging */
void schedular_print_task(void);
/*! \brief get the number of free available taskS
*! \return number of free slot availabe
*/
uint16_t schedular_get_free_task(void);
/*! sort the task list from small interval to big interval
*! this will reduce the response time for all the tasks
*/
void schedular_sort(void);
#ifdef __cplusplus
}
#endif
#endif /* SCHEDULAR_H */