|
@@ -32,7 +32,8 @@
|
32
|
32
|
*
|
33
|
33
|
* The cache memory begins with a table at
|
34
|
34
|
* DL_CACHE_START: each table entry contains
|
35
|
|
- * an address and size for a cached DL slot.
|
|
35
|
+ * an address, size and used bytes for a cached
|
|
36
|
+ * DL slot.
|
36
|
37
|
*
|
37
|
38
|
* Immediately following the table is the
|
38
|
39
|
* DL_FREE_ADDR, which points to free cache
|
|
@@ -44,11 +45,14 @@
|
44
|
45
|
*
|
45
|
46
|
* DL_CACHE_START slot0_addr 4
|
46
|
47
|
* slot0_size 4
|
|
48
|
+ * slot0_used 4
|
47
|
49
|
* slot1_addr 4
|
48
|
50
|
* slot1_size 4
|
|
51
|
+ * slot1_used 4
|
49
|
52
|
* ...
|
50
|
53
|
* slotN_addr 4
|
51
|
54
|
* slotN_size 4
|
|
55
|
+ * slotN_used 4
|
52
|
56
|
* DL_FREE_ADDR dl_free_ptr 4
|
53
|
57
|
* cached data
|
54
|
58
|
* ...
|
|
@@ -57,7 +61,7 @@
|
57
|
61
|
*/
|
58
|
62
|
|
59
|
63
|
#define DL_CACHE_START MAP::RAM_G_SIZE - 0xFFFF
|
60
|
|
-#define DL_FREE_ADDR DL_CACHE_START + DL_CACHE_SLOTS * 8
|
|
64
|
+#define DL_FREE_ADDR DL_CACHE_START + DL_CACHE_SLOTS * 12
|
61
|
65
|
|
62
|
66
|
using namespace FTDI;
|
63
|
67
|
|
|
@@ -66,12 +70,12 @@ using namespace FTDI;
|
66
|
70
|
void DLCache::init() {
|
67
|
71
|
CLCD::mem_write_32(DL_FREE_ADDR, DL_FREE_ADDR + 4);
|
68
|
72
|
for(uint8_t slot = 0; slot < DL_CACHE_SLOTS; slot++) {
|
69
|
|
- save_slot(slot, 0, 0);
|
|
73
|
+ save_slot(slot, 0, 0, 0);
|
70
|
74
|
}
|
71
|
75
|
}
|
72
|
76
|
|
73
|
77
|
bool DLCache::has_data() {
|
74
|
|
- return dl_size != 0;
|
|
78
|
+ return dl_slot_size != 0;
|
75
|
79
|
}
|
76
|
80
|
|
77
|
81
|
bool DLCache::wait_until_idle() {
|
|
@@ -93,12 +97,12 @@ bool DLCache::wait_until_idle() {
|
93
|
97
|
* that it can be appended later. The memory is
|
94
|
98
|
* dynamically allocated following DL_FREE_ADDR.
|
95
|
99
|
*
|
96
|
|
- * If num_bytes is provided, then that many bytes
|
|
100
|
+ * If min_bytes is provided, then that many bytes
|
97
|
101
|
* will be reserved so that the cache may be re-written
|
98
|
102
|
* later with potentially a bigger DL.
|
99
|
103
|
*/
|
100
|
104
|
|
101
|
|
-bool DLCache::store(uint32_t num_bytes /* = 0*/) {
|
|
105
|
+bool DLCache::store(uint32_t min_bytes /* = 0*/) {
|
102
|
106
|
CLCD::CommandFifo cmd;
|
103
|
107
|
|
104
|
108
|
// Execute any commands already in the FIFO
|
|
@@ -107,67 +111,67 @@ bool DLCache::store(uint32_t num_bytes /* = 0*/) {
|
107
|
111
|
return false;
|
108
|
112
|
|
109
|
113
|
// Figure out how long the display list is
|
110
|
|
- uint32_t new_dl_size = CLCD::mem_read_32(REG::CMD_DL) & 0x1FFF;
|
111
|
|
- uint32_t free_space = 0;
|
112
|
|
- uint32_t dl_alloc = 0;
|
|
114
|
+ const uint32_t dl_size = CLCD::dl_size();
|
113
|
115
|
|
114
|
|
- if (dl_addr == 0) {
|
|
116
|
+ if (dl_slot_addr == 0) {
|
115
|
117
|
// If we are allocating new space...
|
116
|
|
- dl_addr = CLCD::mem_read_32(DL_FREE_ADDR);
|
117
|
|
- free_space = MAP::RAM_G_SIZE - dl_addr;
|
118
|
|
- dl_alloc = num_bytes ?: new_dl_size;
|
119
|
|
- dl_size = new_dl_size;
|
120
|
|
- } else {
|
121
|
|
- // Otherwise, we can only store as much space
|
122
|
|
- // as was previously allocated.
|
123
|
|
- free_space = num_bytes ?: dl_size;
|
124
|
|
- dl_alloc = 0;
|
125
|
|
- dl_size = new_dl_size;
|
|
118
|
+ dl_slot_addr = CLCD::mem_read_32(DL_FREE_ADDR);
|
|
119
|
+ dl_slot_size = max(dl_size, min_bytes);
|
|
120
|
+
|
|
121
|
+ const uint32_t free_space = MAP::RAM_G_SIZE - dl_slot_addr;
|
|
122
|
+ if(dl_slot_size <= free_space) {
|
|
123
|
+ CLCD::mem_write_32(DL_FREE_ADDR, dl_slot_addr + dl_slot_size);
|
|
124
|
+ } else {
|
|
125
|
+ dl_slot_addr = 0;
|
|
126
|
+ dl_slot_size = 0;
|
|
127
|
+ dl_slot_used = 0;
|
|
128
|
+ }
|
126
|
129
|
}
|
127
|
130
|
|
128
|
|
- if (dl_size > free_space) {
|
|
131
|
+ if (dl_size > dl_slot_size) {
|
129
|
132
|
// Not enough memory to cache the display list.
|
130
|
133
|
#if ENABLED(TOUCH_UI_DEBUG)
|
131
|
134
|
SERIAL_ECHO_START();
|
132
|
|
- SERIAL_ECHOPAIR ("Not enough space in GRAM to cache display list, free space: ", free_space);
|
|
135
|
+ SERIAL_ECHOPAIR ("Not enough space in GRAM to cache display list, free space: ", dl_slot_size);
|
133
|
136
|
SERIAL_ECHOLNPAIR(" Required: ", dl_size);
|
134
|
137
|
#endif
|
|
138
|
+ dl_slot_used = 0;
|
|
139
|
+ save_slot();
|
135
|
140
|
return false;
|
136
|
141
|
} else {
|
137
|
142
|
#if ENABLED(TOUCH_UI_DEBUG)
|
138
|
143
|
SERIAL_ECHO_START();
|
139
|
|
- SERIAL_ECHOPAIR ("Saving DL to RAMG cache, bytes: ", dl_size);
|
140
|
|
- SERIAL_ECHOLNPAIR(" Free space: ", free_space);
|
|
144
|
+ SERIAL_ECHOPAIR ("Saving DL to RAMG cache, bytes: ", dl_slot_used);
|
|
145
|
+ SERIAL_ECHOLNPAIR(" Free space: ", dl_slot_size);
|
141
|
146
|
#endif
|
142
|
|
- cmd.memcpy(dl_addr, MAP::RAM_DL, dl_size);
|
|
147
|
+ dl_slot_used = dl_size;
|
|
148
|
+ save_slot();
|
|
149
|
+ cmd.memcpy(dl_slot_addr, MAP::RAM_DL, dl_slot_used);
|
143
|
150
|
cmd.execute();
|
144
|
|
- save_slot(dl_slot, dl_addr, dl_size);
|
145
|
|
- if (dl_alloc > 0) {
|
146
|
|
- // If we allocated space dynamically, then adjust dl_free_addr.
|
147
|
|
- CLCD::mem_write_32(DL_FREE_ADDR, dl_addr + dl_alloc);
|
148
|
|
- }
|
149
|
151
|
return true;
|
150
|
152
|
}
|
151
|
153
|
}
|
152
|
154
|
|
153
|
|
-void DLCache::save_slot(uint8_t dl_slot, uint32_t dl_addr, uint32_t dl_size) {
|
154
|
|
- CLCD::mem_write_32(DL_CACHE_START + dl_slot * 8 + 0, dl_addr);
|
155
|
|
- CLCD::mem_write_32(DL_CACHE_START + dl_slot * 8 + 4, dl_size);
|
|
155
|
+void DLCache::save_slot(uint8_t indx, uint32_t addr, uint16_t size, uint16_t used) {
|
|
156
|
+ CLCD::mem_write_32(DL_CACHE_START + indx * 12 + 0, addr);
|
|
157
|
+ CLCD::mem_write_32(DL_CACHE_START + indx * 12 + 4, size);
|
|
158
|
+ CLCD::mem_write_32(DL_CACHE_START + indx * 12 + 8, used);
|
156
|
159
|
}
|
157
|
160
|
|
158
|
|
-void DLCache::load_slot() {
|
159
|
|
- dl_addr = CLCD::mem_read_32(DL_CACHE_START + dl_slot * 8 + 0);
|
160
|
|
- dl_size = CLCD::mem_read_32(DL_CACHE_START + dl_slot * 8 + 4);
|
|
161
|
+void DLCache::load_slot(uint8_t indx, uint32_t &addr, uint16_t &size, uint16_t &used) {
|
|
162
|
+ addr = CLCD::mem_read_32(DL_CACHE_START + indx * 12 + 0);
|
|
163
|
+ size = CLCD::mem_read_32(DL_CACHE_START + indx * 12 + 4);
|
|
164
|
+ used = CLCD::mem_read_32(DL_CACHE_START + indx * 12 + 8);
|
161
|
165
|
}
|
162
|
166
|
|
163
|
167
|
void DLCache::append() {
|
164
|
168
|
CLCD::CommandFifo cmd;
|
165
|
|
- cmd.append(dl_addr, dl_size);
|
|
169
|
+ cmd.append(dl_slot_addr, dl_slot_used);
|
166
|
170
|
#if ENABLED(TOUCH_UI_DEBUG)
|
167
|
171
|
cmd.execute();
|
168
|
172
|
wait_until_idle();
|
169
|
173
|
SERIAL_ECHO_START();
|
170
|
|
- SERIAL_ECHOPAIR ("Appending to DL from RAMG cache, bytes: ", dl_size);
|
|
174
|
+ SERIAL_ECHOPAIR ("Appending to DL from RAMG cache, bytes: ", dl_slot_used);
|
171
|
175
|
SERIAL_ECHOLNPAIR(" REG_CMD_DL: ", CLCD::mem_read_32(REG::CMD_DL));
|
172
|
176
|
#endif
|
173
|
177
|
}
|