Statistics
| Branch: | Tag: | Revision:

root / LUFA / Scheduler / Scheduler.c @ 978b99e5

History | View | Annotate | Download (2.79 KB)

1
/*
2
             LUFA Library
3
     Copyright (C) Dean Camera, 2011.
4

5
  dean [at] fourwalledcubicle [dot] com
6
           www.lufa-lib.org
7
*/
8

    
9
/*
10
  Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com)
11

12
  Permission to use, copy, modify, distribute, and sell this
13
  software and its documentation for any purpose is hereby granted
14
  without fee, provided that the above copyright notice appear in
15
  all copies and that both that the copyright notice and this
16
  permission notice and warranty disclaimer appear in supporting
17
  documentation, and that the name of the author not be used in
18
  advertising or publicity pertaining to distribution of the
19
  software without specific, written prior permission.
20

21
  The author disclaim all warranties with regard to this
22
  software, including all implied warranties of merchantability
23
  and fitness.  In no event shall the author be liable for any
24
  special, indirect or consequential damages or any damages
25
  whatsoever resulting from loss of use, data or profits, whether
26
  in an action of contract, negligence or other tortious action,
27
  arising out of or in connection with the use or performance of
28
  this software.
29
*/
30

    
31
#include "Scheduler.h"
32

    
33
volatile SchedulerDelayCounter_t Scheduler_TickCounter;
34
volatile uint_least8_t           Scheduler_TotalTasks;
35

    
36
bool Scheduler_HasDelayElapsed(const uint_least16_t Delay,
37
                               SchedulerDelayCounter_t* const DelayCounter)
38
{
39
        SchedulerDelayCounter_t CurrentTickValue_LCL;
40
        SchedulerDelayCounter_t DelayCounter_LCL;
41

    
42
        uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
43
        GlobalInterruptDisable();
44

    
45
        CurrentTickValue_LCL = Scheduler_TickCounter;
46

    
47
        SetGlobalInterruptMask(CurrentGlobalInt);
48

    
49
        DelayCounter_LCL = *DelayCounter;
50

    
51
        if (CurrentTickValue_LCL >= DelayCounter_LCL)
52
        {
53
                if ((CurrentTickValue_LCL - DelayCounter_LCL) >= Delay)
54
                {
55
                        *DelayCounter = CurrentTickValue_LCL;
56
                        return true;
57
                }
58
        }
59
        else
60
        {
61
                if (((MAX_DELAYCTR_COUNT - DelayCounter_LCL) + CurrentTickValue_LCL) >= Delay)
62
                {
63
                        *DelayCounter = CurrentTickValue_LCL;
64
                        return true;
65
                }
66
        }
67

    
68
        return false;
69
}
70

    
71
void Scheduler_SetTaskMode(const TaskPtr_t Task,
72
                           const bool TaskStatus)
73
{
74
        TaskEntry_t* CurrTask = &Scheduler_TaskList[0];
75

    
76
        while (CurrTask != &Scheduler_TaskList[Scheduler_TotalTasks])
77
        {
78
                if (CurrTask->Task == Task)
79
                {
80
                        CurrTask->TaskStatus = TaskStatus;
81
                        break;
82
                }
83

    
84
                CurrTask++;
85
        }
86
}
87

    
88
void Scheduler_SetGroupTaskMode(const uint_least8_t GroupID,
89
                                const bool TaskStatus)
90
{
91
        TaskEntry_t* CurrTask = &Scheduler_TaskList[0];
92

    
93
        while (CurrTask != &Scheduler_TaskList[Scheduler_TotalTasks])
94
        {
95
                if (CurrTask->GroupID == GroupID)
96
                  CurrTask->TaskStatus = TaskStatus;
97

    
98
                CurrTask++;
99
        }
100
}
101