-
Notifications
You must be signed in to change notification settings - Fork 10
/
flash.h
66 lines (45 loc) · 2.01 KB
/
flash.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
//---------------------------------------------------------------------------
#pragma once
#include <stddef.h>
#include <stdint.h>
//---------------------------------------------------------------------------
class Console;
//---------------------------------------------------------------------------
class Flash {
public:
static bool IsUpdating() { return instance.target != nullptr; }
// Sets all bits in the region to 1.
static void EraseBlock(const void *target, size_t size);
static bool IsErased(const void *target, size_t size) {
return !RequiresErase(target, size);
}
static void WriteBlock(const void *target, const void *data, size_t size);
static void Write(const void *target, const void *data, size_t size);
static const size_t BLOCK_SIZE = 4096;
static void PrintInfo();
static void BeginWriteBinding(void *context, const char *commandLine);
static void WriteBinding(void *context, const char *commandLine);
static void EndWriteBinding(void *context, const char *commandLine);
static void AddConsoleCommands(Console &console);
bool IsScriptMemory(const void *start, const void *end);
private:
static bool RequiresErase(const void *target, size_t size);
static bool RequiresErase(const void *target, const void *data, size_t size);
static bool RequiresProgram(const void *target, const void *data,
size_t size);
static void EraseBlockInternal(const void *target, size_t size);
static void WriteBlockInternal(const void *target, const void *data,
size_t size);
void BeginWrite(const uint8_t *address);
void AddData(const uint8_t *data, size_t length);
void WriteRemaining();
static const size_t WRITE_DATA_BUFFER_SIZE = BLOCK_SIZE;
size_t erasedBytes;
size_t programmedBytes;
size_t reprogrammedBytes;
const uint8_t *target;
const void *writeStart;
uint8_t buffer[WRITE_DATA_BUFFER_SIZE];
static Flash instance;
};
//---------------------------------------------------------------------------