-
Notifications
You must be signed in to change notification settings - Fork 0
/
flash_win32.c
66 lines (53 loc) · 1.66 KB
/
flash_win32.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
/* FLASH_WIN32.c */
#include "flash_kinetis.h"
#include "instrument.h"
#include "status.h"
#include <stdint.h>
#include <assert.h>
#define FLASH_SECTOR_SIZE 0x1000
#define FLASH_TOTAL_SIZE 0x00100000
#define FLASH_BLOCK_SIZE 0x00080000
#define CONFIG_0_ADDR 0x000F5000
#define NUM_CONFIG 10
#define SAVED_CAL_SIZE_BYTES (SAVED_CAL_STRUCT_SIZE_LWORDS*sizeof(uint32_t))
static uint8_t simulatedFlash[FLASH_BLOCK_SIZE];
void ReadFlashWords(uint32_t* destBuffer, uint32_t startAddress, size_t numWords)
{
// Make sure start address in program flash block 2 (0x0008000 to 0x00FFFFF)
if (startAddress < 0x0008000 || startAddress >= 0x00FFFFF) {
RecordError(EXE_RECALL_FAILED);
}
// But the simulated flash starts at address 0
startAddress -= FLASH_BLOCK_SIZE;
memcpy(destBuffer, &simulatedFlash[startAddress], numWords * 4);
}
int WriteFlash(uint32_t* srcData, uint32_t destAddress, size_t numBytes)
{
// Make sure destAddress in program flash block 2 (0x0008000 to 0x00FFFFF)
if ((destAddress < 0x0008000) ||
(destAddress >= 0x00FFFFF) ||
(destAddress & 0x7 != 0)) {
return EXE_SAVE_FAILED;
}
// But the simulated flash starts at address 0
destAddress -= FLASH_BLOCK_SIZE;
memcpy(&simulatedFlash[destAddress], (uint8_t*)srcData, numBytes);
return 0;
}
uint32_t GetConfigAddress(int configNum)
{
int32_t address = CONFIG_0_ADDR + (configNum)*FLASH_SECTOR_SIZE;
assert(address < FLASH_TOTAL_SIZE);
return address;
}
uint32_t GetCalAddress(void)
{
// Cal data is stored 1 sector * before * config 0
uint32_t address = CONFIG_0_ADDR - FLASH_SECTOR_SIZE;
assert(address < FLASH_TOTAL_SIZE);
return address;
}
void CalculateFlashStartAddr(void)
{
// stub
}