-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.c
100 lines (85 loc) · 3.65 KB
/
scheduler.c
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
87
88
89
90
91
92
93
94
95
96
97
/**
* @file scheduler.c
* @author Sonal Tamrakar
* @date 09/24/2021
* @brief Prioritizes an event and cycles through the interrupts until the interrupts have been attended and serviced.
* Works analogous to a state machine and cycle through interrupts. By using a scheduler, code is less strenuous to write.
*
*/
#include "scheduler.h"
//*******************
//private variables
static unsigned int event_scheduled;
//*******************
/***************************************************************************//**
* @brief
* The void scheduler_open(void) opens the scheduler and it's functions.
*
* @details
* Either setting or resetting the event_scheduled to 0. The three CORE statements are ensuring that the code is atomic.
*
* @note
* The CORE statements are added to ensure that the code in between will definitely occur, and won't be interrupted by global interrupts.
******************************************************************************/
void scheduler_open(void) {
CORE_DECLARE_IRQ_STATE;
CORE_ENTER_CRITICAL();
event_scheduled = 0;
CORE_EXIT_CRITICAL();
}
/***************************************************************************//**
* @brief
* The void add_scheduled_event utilizes the BITWISE operator OR, to OR the new event with the existing scheduled event.
*
* @details
* event_scheduled is set by the (uint32_t event) which is the input variable to the function. The three CORE statements are ensuring that the code is atomic.
*
* @note
* The CORE statements are added to ensure that the code in between will definitely occur, and won't be interrupted by global interrupts.
*
* @param[in] event
* The input uint32_t argument to the function that gets OR'ed with the event_scheduled.
*****************************************************************************/
void add_scheduled_event(uint32_t event) {
CORE_DECLARE_IRQ_STATE;
CORE_ENTER_CRITICAL();
event_scheduled |= event;
CORE_EXIT_CRITICAL();
}
/***************************************************************************//**
* @brief
* The void remove_scheduled_event utilizes the BITWISE operator ~ and &, to remove an event from the event_scheduled.
*
* @details
* ANDing the current event_scheduled with the input variable which will remove an event. The three CORE statements are ensuring that the code is atomic.
*
* @note
* The CORE statements are added to ensure that the code in between will definitely occur, and won't be interrupted by global interrupts.
*
* @param[in] event
* The input uint32_t argument to the function that gets AND'ed with the event_scheduled.
*****************************************************************************/
void remove_scheduled_event(uint32_t event) {
CORE_DECLARE_IRQ_STATE;
CORE_ENTER_CRITICAL();
event_scheduled = event_scheduled & ~event;
//CORE_DECLARE_IRQ_STATE;
CORE_EXIT_CRITICAL();
}
/***************************************************************************//**
* @brief
* The get_scheduled_event(void) returns the current state of event_scheduled (static variable)
*
* @details
* Outputs event_scheduled, which is the current state of the static variable.
*
* @note
* The CORE statements are added to ensure that the code in between will definitely occur, and won't be interrupted by global interrupts.
*
* @param[out] event_scheduled
* event_scheduled is the static variable declared at the top of the .c file.
*
*****************************************************************************/
uint32_t get_scheduled_events(void) {
return event_scheduled; //returns the current state of the private(static) variable event_scheduled
}