-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathregulator.c
39 lines (28 loc) · 1.31 KB
/
regulator.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
/*
Thymio-II Firmware
Copyright (C) 2011 Philippe Retornaz <philippe dot retornaz at epfl dot ch>,
Mobots group (http://mobots.epfl.ch), Robotics system laboratory (http://lsro.epfl.ch)
EPFL Ecole polytechnique federale de Lausanne (http://www.epfl.ch)
See authors.txt for more details about other contributors.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "regulator.h"
#include <types/types.h>
static unsigned int refcount;
// There is a thiny race window when VA is disabled, and at the same time is preempted by a va_get
void va_get(void) {
atomic_add(&refcount,1);
VA_ENABLE = 1;
}
void va_put(void) {
if(!atomic_add_and_test(&refcount, -1))
VA_ENABLE = 0;
}