Project

General

Profile

Statistics
| Revision:

root / lab4 / .minix-src / include / minix / mmio.h @ 13

History | View | Annotate | Download (1.25 KB)

1 13 up20180614
#ifndef __MMIO_H__
2
#define __MMIO_H__
3
4
#define REG16(x)(*((volatile uint16_t *)(x)))
5
#define REG(x)(*((volatile uint32_t *)(x)))
6
#define BIT(x)(0x1 << x)
7
8
/* Write a uint32_t value to a memory address. */
9
static inline void
10
write32(uint32_t address, uint32_t value)
11
{
12
        REG(address) = value;
13
}
14
15
/* Read an uint32_t from a memory address */
16
static inline uint32_t
17
read32(uint32_t address)
18
{
19
        return REG(address);
20
}
21
22
/* Set a 32 bits value depending on a mask */
23
static inline void
24
set32(uint32_t address, uint32_t mask, uint32_t value)
25
{
26
        uint32_t val;
27
        val = read32(address);
28
        /* clear the bits */
29
        val &= ~(mask);
30
        /* apply the value using the mask */
31
        val |= (value & mask);
32
        write32(address, val);
33
}
34
35
/* Write a uint16_t value to a memory address. */
36
static inline void
37
write16(uint32_t address, uint16_t value)
38
{
39
        REG16(address) = value;
40
}
41
42
/* Read an uint16_t from a memory address */
43
static inline uint16_t
44
read16(uint32_t address)
45
{
46
        return REG16(address);
47
}
48
49
/* Set a 16 bits value depending on a mask */
50
static inline void
51
set16(uint32_t address, uint16_t mask, uint16_t value)
52
{
53
        uint16_t val;
54
        val = read16(address);
55
        /* clear the bits */
56
        val &= ~(mask);
57
        /* apply the value using the mask */
58
        val |= (value & mask);
59
        write16(address, val);
60
}
61
62
#endif /* __MMIO_H__ */