-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathram.c
212 lines (198 loc) · 4.35 KB
/
ram.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/**
* \file
*
* A PSP module to satisfy the "RAM" API on systems which
* can access physical memory directly.
*/
#include "cfe_psp.h"
#include "cfe_psp_module.h"
CFE_PSP_MODULE_DECLARE_SIMPLE(ram_direct);
void ram_direct_Init(uint32 PspModuleId)
{
/* Inform the user that this module is in use */
printf("CFE_PSP: Using DIRECT memory mapped RAM implementation\n");
}
/*
** global memory
*/
/*
** Name: CFE_PSP_MemRead8
**
** Purpose:
** Read one byte of memory.
**
**
** Parameters:
** MemoryAddress : Address to be read
** ByteValue : The address content will be copied to the location pointed by this argument
**
** Global Inputs: None
**
** Global Outputs: None
**
**
**
** Return Values: CFE_PSP_SUCCESS
*/
int32 CFE_PSP_MemRead8(cpuaddr MemoryAddress, uint8 *ByteValue)
{
(*ByteValue) = *((uint8 *)MemoryAddress);
return (CFE_PSP_SUCCESS);
}
/*
** Name: CFE_PSP_MemWrite8
**
** Purpose:
** Write one byte of memory.
**
**
** Parameters:
** MemoryAddress : Address to be written to
** ByteValue : The content pointed by this argument will be copied to the address
**
** Global Inputs: None
**
** Global Outputs: None
**
**
**
** Return Values:
** CFE_PSP_SUCCESS
*/
int32 CFE_PSP_MemWrite8(cpuaddr MemoryAddress, uint8 ByteValue)
{
*((uint8 *)MemoryAddress) = ByteValue;
return (CFE_PSP_SUCCESS);
}
/*
** Name: CFE_PSP_MemRead16
**
** Purpose:
** Read 2 bytes of memory.
**
**
** Parameters:
** MemoryAddress : Address to be read
** uint16Value : The address content will be copied to the location pointed by
** this argument
**
** Global Inputs: None
**
** Global Outputs: None
**
**
**
** Return Values:
** CFE_PSP_SUCCESS
** CFE_PSP_ERROR_ADD_MISALIGNED The Address is not aligned to 16 bit
** addressing scheme.
*/
int32 CFE_PSP_MemRead16(cpuaddr MemoryAddress, uint16 *uint16Value)
{
/* check 16 bit alignment , check the 1st lsb */
if (MemoryAddress & 0x00000001)
{
return (CFE_PSP_ERROR_ADDRESS_MISALIGNED);
}
(*uint16Value) = *((uint16 *)MemoryAddress);
return (CFE_PSP_SUCCESS);
}
/*
** Name: CFE_PSP_MemWrite16
**
** Purpose:
** Write 2 byte of memory.
**
**
** Parameters:
** MemoryAddress : Address to be written to
** uint16Value : The content pointed by this argument will be copied to the
** address
**
** Global Inputs: None
**
** Global Outputs: None
**
**
**
** Return Values:
** CFE_PSP_SUCCESS
** CFE_PSP_ERROR_ADD_MISALIGNED The MemoryAddress is not aligned to 16 bit
** addressing scheme.
*/
int32 CFE_PSP_MemWrite16(cpuaddr MemoryAddress, uint16 uint16Value)
{
/* check 16 bit alignment , check the 1st lsb */
if (MemoryAddress & 0x00000001)
{
return (CFE_PSP_ERROR_ADDRESS_MISALIGNED);
}
*((uint16 *)MemoryAddress) = uint16Value;
return (CFE_PSP_SUCCESS);
}
/*
** Name: CFE_PSP_MemRead32
**
** Purpose:
** Read 4 bytes of memory.
**
**
** Parameters:
** MemoryAddress : Address to be read
** uint32Value : The address content will be copied to the location pointed by
** this argument
**
** Global Inputs: None
**
** Global Outputs: None
**
**
**
** Return Values:
** CFE_PSP_SUCCESS
** CFE_PSP_ERROR_ADD_MISALIGNED The Address is not aligned to 16 bit
** addressing scheme.
*/
int32 CFE_PSP_MemRead32(cpuaddr MemoryAddress, uint32 *uint32Value)
{
/* check 32 bit alignment */
if (MemoryAddress & 0x00000003)
{
return (CFE_PSP_ERROR_ADDRESS_MISALIGNED);
}
(*uint32Value) = *((uint32 *)MemoryAddress);
return (CFE_PSP_SUCCESS);
}
/*
** Name: CFE_PSP_MemWrite32
**
** Purpose:
** Write 4 byte of memory.
**
**
** Parameters:
** MemoryAddress : Address to be written to
** uint32Value : The content pointed by this argument will be copied to the
** address
**
** Global Inputs: None
**
** Global Outputs: None
**
**
**
** Return Values:
** CFE_PSP_SUCCESS
** CFE_PSP_ERROR_ADD_MISALIGNED The Address is not aligned to 16 bit
** addressing scheme.
*/
int32 CFE_PSP_MemWrite32(cpuaddr MemoryAddress, uint32 uint32Value)
{
/* check 32 bit alignment */
if (MemoryAddress & 0x00000003)
{
return (CFE_PSP_ERROR_ADDRESS_MISALIGNED);
}
*((uint32 *)MemoryAddress) = uint32Value;
return (CFE_PSP_SUCCESS);
}