-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_memory.c
63 lines (59 loc) · 2.29 KB
/
data_memory.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
57
58
59
60
61
62
63
/********************************************************************************
* data_memory.c: Contains function definitions for implementation of a
* 2 kB memory.
********************************************************************************/
#include "data_memory.h"
/********************************************************************************
* data: Data memory with storage capacity for 2000 bytes.
********************************************************************************/
static uint32_t data[DATA_MEMORY_ADDRESS_WIDTH];
/********************************************************************************
* data_memory_reset: Clears entire data memory.
********************************************************************************/
void data_memory_reset(void)
{
for (uint16_t i = 0; i < DATA_MEMORY_ADDRESS_WIDTH; ++i)
{
data[i] = 0x00;
}
return;
}
/********************************************************************************
* 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)
{
if (address < DATA_MEMORY_ADDRESS_WIDTH)
{
data[address] = value;
return 0;
}
else
{
return 1;
}
}
/********************************************************************************
* 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)
{
if (address < DATA_MEMORY_ADDRESS_WIDTH)
{
return data[address];
}
else
{
return 0x00;
}
}