summaryrefslogtreecommitdiff
path: root/core/nds32/atomic.h
blob: 8928fe337375e2a180ed8ceee14a8cb66f650eeb (plain)
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
/* Copyright 2013 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* Atomic operations for Andes */

#ifndef __CROS_EC_ATOMIC_H
#define __CROS_EC_ATOMIC_H

#include "common.h"
#include "cpu.h"
#include "task.h"

static inline void atomic_clear(uint32_t volatile *addr, uint32_t bits)
{
	uint32_t int_mask = get_int_mask();
	interrupt_disable();
	*addr &= ~bits;
	set_int_mask(int_mask);
}

static inline void atomic_or(uint32_t volatile *addr, uint32_t bits)
{
	uint32_t int_mask = get_int_mask();
	interrupt_disable();
	*addr |= bits;
	set_int_mask(int_mask);
}

static inline void atomic_add(uint32_t volatile *addr, uint32_t value)
{
	uint32_t int_mask = get_int_mask();
	interrupt_disable();
	*addr += value;
	set_int_mask(int_mask);
}

static inline void atomic_sub(uint32_t volatile *addr, uint32_t value)
{
	uint32_t int_mask = get_int_mask();
	interrupt_disable();
	*addr -= value;
	set_int_mask(int_mask);
}

static inline uint32_t atomic_read_clear(uint32_t volatile *addr)
{
	uint32_t val;
	uint32_t int_mask = get_int_mask();
	interrupt_disable();
	val = *addr;
	*addr = 0;
	set_int_mask(int_mask);
	return val;
}
#endif  /* __CROS_EC_ATOMIC_H */