-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflash.cpp
73 lines (62 loc) · 1.21 KB
/
flash.cpp
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
#include "mbed.h"
#include "flash.h"
FlashIAP flash;
/*
* Description:
* Initialize Flash IAP instance. It shall be called once after creating Flash Instance
*/
int Flash_init()
{
return flash.init();
}
/*
* Description:
* Erase the specific Flash Sector
* address - sector address
* size - size of bytes to be erased. Shall be multiple of sector size.
*/
int Flash_erase(uint64_t address, uint64_t size)
{
return flash.erase(address, size);
}
/*
* Description:
* Write Data into Flash Region
* psrc - pointer to source buffer
* addess - destination address in flash
* ndat - size of bytes to be written
*/
int Flash_write(uint8_t* psrc, uint64_t address, uint64_t ndat)
{
return flash.program(psrc, address, ndat);
}
/*
* Description:
* Read data from Flash Memory
* pbuf - pointer of buffer
* addess - destination address in flash
* ndat - size of bytes to be read
*/
int Flash_read(uint8_t* pbuf, uint64_t address, uint64_t ndat)
{
uint8_t* psrc;
int ret = 0;
if (pbuf != NULL)
{
psrc = (uint8_t*)address;
while (ndat--)
{
*pbuf++ = *psrc++;
}
ret = 1;
}
return ret;
}
/*
* Description:
* Deinitialize Flash IAP instance.
*/
int Flash_deinit()
{
return flash.deinit();
}