-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlash_Sim_Demo.cpp
57 lines (38 loc) · 1.38 KB
/
Flash_Sim_Demo.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
#include "Flash_Sim_Demo.h"
#include "Flash/spi_flash.h"
#ifdef __cplusplus
extern "C" {
#endif
void Flash_Sim_Demo() {
//
// -------------------------------------------------------------------------
// flash testing for Exercise 3b
// -------------------------------------------------------------------------
//
// initialize SPI Flash
sFLASH_Init();
#ifdef is_spi_flash_simulation
uint32_t UsingFlashAddress = 0x1000;
uint32_t MaxFlashTestSize = 0x1FFF;
// when writing NULL during simulation, the parameters are actually setup for stating address and max size
sFLASH_WriteBuffer(NULL, UsingFlashAddress, MaxFlashTestSize);
#endif
// setup some data
uint8_t someData = 42;
uint8_t someOtherData = 0x55;
uint8_t* otherData = &someOtherData;
uint8_t* thisFlashData = &someData;
uint32_t thisFlashAddress = 0x1234;
uint32_t thisFlashTestSize = 1;
// sample write
sFLASH_WriteBuffer(thisFlashData, thisFlashAddress, thisFlashTestSize);
// sample read
sFLASH_ReadBuffer(otherData, thisFlashAddress, thisFlashTestSize);
// sample erase
sFLASH_EraseBulk();
// sample read after erase
sFLASH_ReadBuffer(thisFlashData, thisFlashAddress, thisFlashTestSize);
}
#ifdef __cplusplus
}
#endif