-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_memory.h
73 lines (64 loc) · 3.6 KB
/
data_memory.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/********************************************************************************
* data_memory.h: Contains function declarations and macro definitions for
* implementation of a 2 kB data memory (2000 x 1 byte).
********************************************************************************/
#ifndef DATA_MEMORY_H_
#define DATA_MEMORY_H_
/* Include directives: */
#include "cpu.h"
/* Macro definitions: */
#define DATA_MEMORY_ADDRESS_WIDTH 300 /* 300 unique addresses in data memory. */
#define DATA_MEMORY_DATA_WIDTH 32 /* 32 bits storage capacity per address. */
/********************************************************************************
* data_memory_reset: Clears entire data memory.
********************************************************************************/
void data_memory_reset(void);
/********************************************************************************
* data_memory_write: Writes an 8-bit value to specified address in data memory.
* The value 0 is returned after successful write. Otherwise
* if invalid address is specified, no write is done and
* error code 1 is returned.
*
* - address: Write location in data memory.
* - value : The 8-bit value to write to data memory.
********************************************************************************/
int data_memory_write(const uint16_t address,
const uint32_t value);
/********************************************************************************
* data_memory_read: Returns content from specified read location in data memory.
* If an invalid address is specified, the value 0 is returned.
*
* - address: Read location in data memory.
********************************************************************************/
uint32_t data_memory_read(const uint16_t address);
/********************************************************************************
* data_memory_set_bit: Sets bit in specified data memory register. The value 0
* is returned after successful write. Otherwise if an
* invalid address is specified, no write is done and
* error code 1 is returned.
*
* - address: Write location in data memory.
* - bit : Bit to set in data memory register.
********************************************************************************/
static inline int data_memory_set_bit(const uint16_t address,
const uint32_t bit)
{
const uint32_t data = data_memory_read(address);
return data_memory_write(address, data | (1 << bit));
}
/********************************************************************************
* data_memory_clear_bit: Clears bit in specified data memory register. The value
* 0 is returned after successful write. Otherwise if
* an invalid address is specified, no write is done and
* error code 1 is returned.
*
* - address: Write location in data memory.
* - bit : Bit to clear in data memory register.
********************************************************************************/
static inline int data_memory_clear_bit(const uint16_t address,
const uint32_t bit)
{
const uint32_t data = data_memory_read(address);
return data_memory_write(address, data & ~(1 << bit));
}
#endif /* DATA_MEMORY_H_ */