-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory.h
289 lines (214 loc) · 7.01 KB
/
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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/**
MEMORY Generated Driver API Header File
@Company
Microchip Technology Inc.
@File Name
memory.h
@Summary
This is the generated header file for the MEMORY driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description
This header file provides APIs for driver for MEMORY.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F46K20
Driver Version : 2.04
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above
MPLAB : MPLAB X 6.00
*******************************************************************************/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
FOR A PARTICULAR PURPOSE.
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
SOFTWARE.
*/
#ifndef MEMORY_H
#define MEMORY_H
/**
Section: Included Files
*/
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus // Provide C++ Compatibility
extern "C" {
#endif
/**
Section: Macro Declarations
*/
#define WRITE_FLASH_BLOCKSIZE 64
#define ERASE_FLASH_BLOCKSIZE 64
#define END_FLASH 0x10000
/**
Section: Flash Module APIs
*/
/**
@Summary
Reads a data byte from Flash
@Description
This routine reads a data byte from given Flash address
@Preconditions
None
@Param
flashAddr - Flash program memory location from which data has to be read
@Returns
Data byte read from given Flash address
@Example
<code>
uint8_t readByte;
uint32_t flashAddr = 0x7D00;
readByte = FLASH_ReadByte(flashAddr);
</code>
*/
uint8_t FLASH_ReadByte(uint32_t flashAddr);
/**
@Summary
Reads a data word from Flash
@Description
This routine reads a data word from given Flash address
@Preconditions
None
@Param
flashAddr - Flash program memory location from which data has to be read
@Returns
Data word read from given Flash address
@Example
<code>
uint16_t readWord;
uint32_t flashAddr = 0x7D00;
readWord = FLASH_ReadWord(flashAddr);
</code>
*/
uint16_t FLASH_ReadWord(uint32_t flashAddr);
/**
@Summary
Writes a data byte into Flash
@Description
This routine writes the given data byte into mentioned Flash address.
This routine intially reads block of data (from Flash) into RAM, updates
data values in RAM, and writes back updated values to Flash.
@Preconditions
None
@Param
flashAddr - Flash program memory location to which data has to be written
*flashRdBufPtr - Pointer to RAM buffer of size 'ERASE_FLASH_BLOCKSIZE' at least
byte - Data byte to be written in Flash
@Returns
None
@Example
<code>
uint8_t writeData = 0xAA;
uint32_t flashAddr = 0x7D00;
uint8_t Buf[ERASE_FLASH_BLOCKSIZE];
FLASH_WriteWord(flashAddr, Buf, writeData);
</code>
*/
void FLASH_WriteByte(uint32_t flashAddr, uint8_t *flashRdBufPtr, uint8_t byte);
/**
@Summary
Writes data to complete block of Flash
@Description
This routine writes data bytes to complete block in Flash program memory
@Preconditions
None
@Param
writeAddr - A valid block starting address in Flash
*flashWrBufPtr - Pointer to an array of size 'WRITE_FLASH_BLOCKSIZE' at least
@Returns
-1, if the given address is not a valid block starting address of Flash
0, in case of valid block starting address
@Example
<code>
#define FLASH_ROW_ADDRESS 0x7D00
uint8_t wrBlockData[] =
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F
};
// write to Flash memory block
FLASH_WriteBlock((uint32_t)FLASH_ROW_ADDRESS, (uint8_t *)wrBlockData);
</code>
*/
int8_t FLASH_WriteBlock(uint32_t writeAddr, uint8_t *flashWrBufPtr);
/**
@Summary
Erases complete Flash program memory block
@Description
This routine erases complete Flash program memory block
@Preconditions
None
@Param
baseAddr - A valid block starting address in Flash program memory
@Returns
None
@Example
<code>
uint32_t flashBlockStartAddr = 0x7D00;
FLASH_EraseBlock(flashBlockStartAddr);
</code>
*/
void FLASH_EraseBlock(uint32_t baseAddr);
/**
Section: Data EEPROM Module APIs
*/
/**
@Summary
Writes a data byte to Data EEPROM
@Description
This routine writes a data byte to given Data EEPROM location
@Preconditions
None
@Param
bAdd - Data EEPROM location to which data to be written
bData - Data to be written to Data EEPROM location
@Returns
None
@Example
<code>
uint16_t dataeeAddr = 0x10;
uint8_t dataeeData = 0x55;
DATAEE_WriteByte(dataeeAddr, dataeeData);
</code>
*/
void DATAEE_WriteByte(uint16_t bAdd, uint8_t bData);
/**
@Summary
Reads a data byte from Data EEPROM
@Description
This routine reads a data byte from given Data EEPROM location
@Preconditions
None
@Param
bAdd - Data EEPROM location from which data has to be read
@Returns
Data byte read from given Data EEPROM location
@Example
<code>
uint16_t dataeeAddr = 0x10;
uint8_t readData;
readData = DATAEE_ReadByte(dataeeAddr);
</code>
*/
uint8_t DATAEE_ReadByte(uint16_t bAdd);
void MEMORY_Tasks(void);
#ifdef __cplusplus // Provide C++ Compatibility
}
#endif
#endif // MEMORY_H
/**
End of File
*/