forked from nanoframework/nf-interpreter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nanoHAL_SystemEvents.c
56 lines (47 loc) · 1.29 KB
/
nanoHAL_SystemEvents.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
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
#include <nanoHAL_v2.h>
#include <nanoWeak.h>
#ifdef __CM0_CMSIS_VERSION
#include <targetHAL.h>
#endif
volatile int32_t SystemStates[SYSTEM_STATE_TOTAL_STATES];
// the functions below are declared as weak so they can be replaced at target/platform level if needed
__nfweak void SystemState_SetNoLock(SYSTEM_STATE_type state)
{
SystemStates[state]++;
}
__nfweak void SystemState_ClearNoLock(SYSTEM_STATE_type state)
{
SystemStates[state]--;
}
__nfweak bool SystemState_QueryNoLock(SYSTEM_STATE_type state)
{
return (SystemStates[state] > 0) ? true : false;
}
__nfweak void SystemState_Set(SYSTEM_STATE_type state)
{
#ifdef __CM0_CMSIS_VERSION
GLOBAL_LOCK();
SystemState_SetNoLock(state);
GLOBAL_UNLOCK();
#else
__atomic_fetch_add(&SystemStates[state], 1, __ATOMIC_RELAXED);
#endif
}
__nfweak void SystemState_Clear(SYSTEM_STATE_type state)
{
#ifdef __CM0_CMSIS_VERSION
GLOBAL_LOCK();
SystemState_ClearNoLock(state);
GLOBAL_UNLOCK();
#else
__atomic_fetch_sub(&SystemStates[state], 1, __ATOMIC_RELAXED);
#endif
}
__nfweak bool SystemState_Query(SYSTEM_STATE_type state)
{
return __atomic_load_n(&state, __ATOMIC_RELAXED) ? true : false;
}