1 /** @file blockDetailsLookup.c
3 Copyright 2008 Fred Cooke
5 This file holds the single function lookupBlockDetails() which
6 functions as a sort of address book for logical blocks of memory.
8 This file is part of the FreeEMS project.
10 FreeEMS software is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
15 FreeEMS software is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with any FreeEMS software. If not, see http://www.gnu.org/licenses/
23 We ask that if you make any changes to this file you email them upstream to
24 us at admin(at)diyefi(dot)org or, even better, fork the code on github.com!
26 Thank you for choosing FreeEMS to run your engine! */
29 #define BLOCK_DETAILS_LOOKUP_C
30 #include "inc/freeEMS.h"
31 #include "inc/interrupts.h"
32 #include "inc/pagedLocationBuffers.h"
33 #include "inc/blockDetailsLookup.h"
36 /** Lookup Block Details
38 * Flash only blocks leave the ram address and page values
39 * set to zero. ID's that don't exist leave all set to zero.
40 * Error handling is to be done externally based on that.
44 * @note This function is an exception to the style rule switch statement
45 * blocks of using a {} pair for each case statement. Readability is better
46 * without them in this case.
48 * @param locationID is the ID of the memory location for which details are required.
49 * @param details is a pointer to the blockDetails struct to populate with the details.
51 * @return An error code. Zero means success, anything else is a failure.
53 unsigned short lookupBlockDetails(unsigned short locationID
, blockDetails
* details
){
54 /* Initialise the four values needed for operations on memory at 0 for error checking */
56 details
->FlashPage
= 0;
57 details
->RAMAddress
= 0;
58 details
->FlashAddress
= 0;
60 /* Initialise the block size to 1024 to save code space and increase readability */
61 details
->size
= MAINTABLE_SIZE
;
63 /* Look up the locations and set non default sizes */
65 /* flash only fixed conf full blocks */
66 case FixedConfig1LocationID
:
67 details
->FlashPage
= PPAGE
;
68 details
->FlashAddress
= (void*)&fixedConfigs1
;
70 case FixedConfig2LocationID
:
71 details
->FlashPage
= PPAGE
;
72 details
->FlashAddress
= (void*)&fixedConfigs2
;
76 case IATTransferTableLocationID
:
77 details
->size
= TransferTableSize
;
78 details
->FlashPage
= LOOKUP_PPAGE
;
79 details
->FlashAddress
= IATTransferTableLocation
;
81 case CHTTransferTableLocationID
:
82 details
->size
= TransferTableSize
;
83 details
->FlashPage
= LOOKUP_PPAGE
;
84 details
->FlashAddress
= CHTTransferTableLocation
;
86 case MAFTransferTableLocationID
:
87 details
->size
= TransferTableSize
;
88 details
->FlashPage
= LOOKUP_PPAGE
;
89 details
->FlashAddress
= MAFTransferTableLocation
;
91 case TestTransferTableLocationID
:
92 details
->size
= TransferTableSize
;
93 details
->FlashPage
= LOOKUP_PPAGE
;
94 details
->FlashAddress
= TestTransferTableLocation
;
98 case VETableMainLocationID
:
99 details
->RAMPage
= RPAGE_FUEL_ONE
;
100 details
->FlashPage
= FUELTABLES_PPAGE
;
101 details
->RAMAddress
= (void*)&TablesA
;
102 details
->FlashAddress
= VETableMainFlashLocation
;
104 case VETableMain2LocationID
:
105 details
->RAMPage
= RPAGE_FUEL_TWO
;
106 details
->FlashPage
= FUELTABLES_PPAGE
;
107 details
->RAMAddress
= (void*)&TablesA
;
108 details
->FlashAddress
= VETableMainFlash2Location
;
110 case VETableSecondaryLocationID
:
111 details
->RAMPage
= RPAGE_FUEL_ONE
;
112 details
->FlashPage
= FUELTABLES_PPAGE
;
113 details
->RAMAddress
= (void*)&TablesB
;
114 details
->FlashAddress
= VETableSecondaryFlashLocation
;
116 case VETableSecondary2LocationID
:
117 details
->RAMPage
= RPAGE_FUEL_TWO
;
118 details
->FlashPage
= FUELTABLES_PPAGE
;
119 details
->RAMAddress
= (void*)&TablesB
;
120 details
->FlashAddress
= VETableSecondaryFlash2Location
;
122 case VETableTertiaryLocationID
:
123 details
->RAMPage
= RPAGE_FUEL_ONE
;
124 details
->FlashPage
= FUELTABLES_PPAGE
;
125 details
->RAMAddress
= (void*)&TablesC
;
126 details
->FlashAddress
= VETableTertiaryFlashLocation
;
128 case VETableTertiary2LocationID
:
129 details
->RAMPage
= RPAGE_FUEL_TWO
;
130 details
->FlashPage
= FUELTABLES_PPAGE
;
131 details
->RAMAddress
= (void*)&TablesC
;
132 details
->FlashAddress
= VETableTertiaryFlash2Location
;
134 case LambdaTableLocationID
:
135 details
->RAMPage
= RPAGE_FUEL_ONE
;
136 details
->FlashPage
= FUELTABLES_PPAGE
;
137 details
->RAMAddress
= (void*)&TablesD
;
138 details
->FlashAddress
= LambdaTableFlashLocation
;
140 case LambdaTable2LocationID
:
141 details
->RAMPage
= RPAGE_FUEL_TWO
;
142 details
->FlashPage
= FUELTABLES_PPAGE
;
143 details
->RAMAddress
= (void*)&TablesD
;
144 details
->FlashAddress
= LambdaTableFlash2Location
;
148 case IgnitionAdvanceTableMainLocationID
:
149 details
->RAMPage
= RPAGE_TIME_ONE
;
150 details
->FlashPage
= TIMETABLES_PPAGE
;
151 details
->RAMAddress
= (void*)&TablesA
;
152 details
->FlashAddress
= IgnitionAdvanceTableMainFlashLocation
;
154 case IgnitionAdvanceTableMain2LocationID
:
155 details
->RAMPage
= RPAGE_TIME_TWO
;
156 details
->FlashPage
= TIMETABLES_PPAGE
;
157 details
->RAMAddress
= (void*)&TablesA
;
158 details
->FlashAddress
= IgnitionAdvanceTableMainFlash2Location
;
160 case IgnitionAdvanceTableSecondaryLocationID
:
161 details
->RAMPage
= RPAGE_TIME_ONE
;
162 details
->FlashPage
= TIMETABLES_PPAGE
;
163 details
->RAMAddress
= (void*)&TablesB
;
164 details
->FlashAddress
= IgnitionAdvanceTableSecondaryFlashLocation
;
166 case IgnitionAdvanceTableSecondary2LocationID
:
167 details
->RAMPage
= RPAGE_TIME_TWO
;
168 details
->FlashPage
= TIMETABLES_PPAGE
;
169 details
->RAMAddress
= (void*)&TablesB
;
170 details
->FlashAddress
= IgnitionAdvanceTableSecondaryFlash2Location
;
172 case InjectionAdvanceTableMainLocationID
:
173 details
->RAMPage
= RPAGE_TIME_ONE
;
174 details
->FlashPage
= TIMETABLES_PPAGE
;
175 details
->RAMAddress
= (void*)&TablesC
;
176 details
->FlashAddress
= InjectionAdvanceTableMainFlashLocation
;
178 case InjectionAdvanceTableMain2LocationID
:
179 details
->RAMPage
= RPAGE_TIME_TWO
;
180 details
->FlashPage
= TIMETABLES_PPAGE
;
181 details
->RAMAddress
= (void*)&TablesC
;
182 details
->FlashAddress
= InjectionAdvanceTableMainFlash2Location
;
184 case InjectionAdvanceTableSecondaryLocationID
:
185 details
->RAMPage
= RPAGE_TIME_ONE
;
186 details
->FlashPage
= TIMETABLES_PPAGE
;
187 details
->RAMAddress
= (void*)&TablesD
;
188 details
->FlashAddress
= InjectionAdvanceTableSecondaryFlashLocation
;
190 case InjectionAdvanceTableSecondary2LocationID
:
191 details
->RAMPage
= RPAGE_TIME_TWO
;
192 details
->FlashPage
= TIMETABLES_PPAGE
;
193 details
->RAMAddress
= (void*)&TablesD
;
194 details
->FlashAddress
= InjectionAdvanceTableSecondaryFlash2Location
;
197 /* small table full blocks */
198 case SmallTablesALocationID
:
199 details
->RAMPage
= RPAGE_TUNE_ONE
;
200 details
->FlashPage
= TUNETABLES_PPAGE
;
201 details
->RAMAddress
= (void*)&TablesA
;
202 details
->FlashAddress
= SmallTablesAFlashLocation
;
204 case SmallTablesA2LocationID
:
205 details
->RAMPage
= RPAGE_TUNE_TWO
;
206 details
->FlashPage
= TUNETABLES_PPAGE
;
207 details
->RAMAddress
= (void*)&TablesA
;
208 details
->FlashAddress
= SmallTablesAFlash2Location
;
210 case SmallTablesBLocationID
:
211 details
->RAMPage
= RPAGE_TUNE_ONE
;
212 details
->FlashPage
= TUNETABLES_PPAGE
;
213 details
->RAMAddress
= (void*)&TablesB
;
214 details
->FlashAddress
= SmallTablesBFlashLocation
;
216 case SmallTablesB2LocationID
:
217 details
->RAMPage
= RPAGE_TUNE_TWO
;
218 details
->FlashPage
= TUNETABLES_PPAGE
;
219 details
->RAMAddress
= (void*)&TablesB
;
220 details
->FlashAddress
= SmallTablesBFlash2Location
;
222 case SmallTablesCLocationID
:
223 details
->RAMPage
= RPAGE_TUNE_ONE
;
224 details
->FlashPage
= TUNETABLES_PPAGE
;
225 details
->RAMAddress
= (void*)&TablesC
;
226 details
->FlashAddress
= SmallTablesCFlashLocation
;
228 case SmallTablesC2LocationID
:
229 details
->RAMPage
= RPAGE_TUNE_TWO
;
230 details
->FlashPage
= TUNETABLES_PPAGE
;
231 details
->RAMAddress
= (void*)&TablesC
;
232 details
->FlashAddress
= SmallTablesCFlash2Location
;
234 case SmallTablesDLocationID
:
235 details
->RAMPage
= RPAGE_TUNE_ONE
;
236 details
->FlashPage
= TUNETABLES_PPAGE
;
237 details
->RAMAddress
= (void*)&TablesD
;
238 details
->FlashAddress
= SmallTablesDFlashLocation
;
240 case SmallTablesD2LocationID
:
241 details
->RAMPage
= RPAGE_TUNE_TWO
;
242 details
->FlashPage
= TUNETABLES_PPAGE
;
243 details
->RAMAddress
= (void*)&TablesD
;
244 details
->FlashAddress
= SmallTablesDFlash2Location
;
247 /* TablesA small tables */
248 case dwellDesiredVersusVoltageTableLocationID
:
249 details
->size
= TWODTABLEUS_SIZE
;
250 details
->RAMPage
= RPAGE_TUNE_ONE
;
251 details
->FlashPage
= TUNETABLES_PPAGE
;
252 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.dwellDesiredVersusVoltageTable
;
253 details
->FlashAddress
= dwellDesiredVersusVoltageTableLocation
;
255 case dwellDesiredVersusVoltageTable2LocationID
:
256 details
->size
= TWODTABLEUS_SIZE
;
257 details
->RAMPage
= RPAGE_TUNE_TWO
;
258 details
->FlashPage
= TUNETABLES_PPAGE
;
259 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.dwellDesiredVersusVoltageTable
;
260 details
->FlashAddress
= dwellDesiredVersusVoltageTable2Location
;
262 case injectorDeadTimeTableLocationID
:
263 details
->size
= TWODTABLEUS_SIZE
;
264 details
->RAMPage
= RPAGE_TUNE_ONE
;
265 details
->FlashPage
= TUNETABLES_PPAGE
;
266 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.injectorDeadTimeTable
;
267 details
->FlashAddress
= injectorDeadTimeTableLocation
;
269 case injectorDeadTimeTable2LocationID
:
270 details
->size
= TWODTABLEUS_SIZE
;
271 details
->RAMPage
= RPAGE_TUNE_TWO
;
272 details
->FlashPage
= TUNETABLES_PPAGE
;
273 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.injectorDeadTimeTable
;
274 details
->FlashAddress
= injectorDeadTimeTable2Location
;
276 case postStartEnrichmentTableLocationID
:
277 details
->size
= TWODTABLEUS_SIZE
;
278 details
->RAMPage
= RPAGE_TUNE_ONE
;
279 details
->FlashPage
= TUNETABLES_PPAGE
;
280 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.postStartEnrichmentTable
;
281 details
->FlashAddress
= postStartEnrichmentTableLocation
;
283 case postStartEnrichmentTable2LocationID
:
284 details
->size
= TWODTABLEUS_SIZE
;
285 details
->RAMPage
= RPAGE_TUNE_TWO
;
286 details
->FlashPage
= TUNETABLES_PPAGE
;
287 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.postStartEnrichmentTable
;
288 details
->FlashAddress
= postStartEnrichmentTable2Location
;
290 case engineTempEnrichmentTableFixedLocationID
:
291 details
->size
= TWODTABLEUS_SIZE
;
292 details
->RAMPage
= RPAGE_TUNE_ONE
;
293 details
->FlashPage
= TUNETABLES_PPAGE
;
294 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.engineTempEnrichmentTableFixed
;
295 details
->FlashAddress
= engineTempEnrichmentTableFixedLocation
;
297 case engineTempEnrichmentTableFixed2LocationID
:
298 details
->size
= TWODTABLEUS_SIZE
;
299 details
->RAMPage
= RPAGE_TUNE_TWO
;
300 details
->FlashPage
= TUNETABLES_PPAGE
;
301 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.engineTempEnrichmentTableFixed
;
302 details
->FlashAddress
= engineTempEnrichmentTableFixed2Location
;
304 case primingVolumeTableLocationID
:
305 details
->size
= TWODTABLEUS_SIZE
;
306 details
->RAMPage
= RPAGE_TUNE_ONE
;
307 details
->FlashPage
= TUNETABLES_PPAGE
;
308 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.primingVolumeTable
;
309 details
->FlashAddress
= primingVolumeTableLocation
;
311 case primingVolumeTable2LocationID
:
312 details
->size
= TWODTABLEUS_SIZE
;
313 details
->RAMPage
= RPAGE_TUNE_TWO
;
314 details
->FlashPage
= TUNETABLES_PPAGE
;
315 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.primingVolumeTable
;
316 details
->FlashAddress
= primingVolumeTable2Location
;
318 case engineTempEnrichmentTablePercentLocationID
:
319 details
->size
= TWODTABLEUS_SIZE
;
320 details
->RAMPage
= RPAGE_TUNE_ONE
;
321 details
->FlashPage
= TUNETABLES_PPAGE
;
322 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.engineTempEnrichmentTablePercent
;
323 details
->FlashAddress
= engineTempEnrichmentTablePercentLocation
;
325 case engineTempEnrichmentTablePercent2LocationID
:
326 details
->size
= TWODTABLEUS_SIZE
;
327 details
->RAMPage
= RPAGE_TUNE_TWO
;
328 details
->FlashPage
= TUNETABLES_PPAGE
;
329 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.engineTempEnrichmentTablePercent
;
330 details
->FlashAddress
= engineTempEnrichmentTablePercent2Location
;
332 case dwellMaxVersusRPMTableLocationID
:
333 details
->size
= TWODTABLEUS_SIZE
;
334 details
->RAMPage
= RPAGE_TUNE_ONE
;
335 details
->FlashPage
= TUNETABLES_PPAGE
;
336 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.dwellMaxVersusRPMTable
;
337 details
->FlashAddress
= dwellMaxVersusRPMTableLocation
;
339 case dwellMaxVersusRPMTable2LocationID
:
340 details
->size
= TWODTABLEUS_SIZE
;
341 details
->RAMPage
= RPAGE_TUNE_TWO
;
342 details
->FlashPage
= TUNETABLES_PPAGE
;
343 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.dwellMaxVersusRPMTable
;
344 details
->FlashAddress
= dwellMaxVersusRPMTable2Location
;
347 /* TablesB small tables */
348 case perCylinderFuelTrimsLocationID
:
350 details
->RAMPage
= RPAGE_TUNE_ONE
;
351 details
->FlashPage
= TUNETABLES_PPAGE
;
352 details
->RAMAddress
= (void*)&TablesB
.SmallTablesB
.perCylinderFuelTrims
;
353 details
->FlashAddress
= perCylinderFuelTrimsLocation
;
355 case perCylinderFuelTrims2LocationID
:
357 details
->RAMPage
= RPAGE_TUNE_TWO
;
358 details
->FlashPage
= TUNETABLES_PPAGE
;
359 details
->RAMAddress
= (void*)&TablesB
.SmallTablesB
.perCylinderFuelTrims
;
360 details
->FlashAddress
= perCylinderFuelTrims2Location
;
363 /* TablesC small tables */
364 // TODO add data chunks from TablesC when some are put in
366 /* TablesD small tables */
367 // TODO add data chunks from TablesD when some are put in
369 /* filler block entries */
370 case fillerALocationID
:
372 details
->RAMPage
= RPAGE_TUNE_ONE
;
373 details
->FlashPage
= TUNETABLES_PPAGE
;
374 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.filler
;
375 details
->FlashAddress
= fillerALocation
;
377 case fillerA2LocationID
:
379 details
->RAMPage
= RPAGE_TUNE_TWO
;
380 details
->FlashPage
= TUNETABLES_PPAGE
;
381 details
->RAMAddress
= (void*)&TablesA
.SmallTablesA
.filler
;
382 details
->FlashAddress
= fillerA2Location
;
384 case fillerBLocationID
:
385 details
->size
= 1012;
386 details
->RAMPage
= RPAGE_TUNE_ONE
;
387 details
->FlashPage
= TUNETABLES_PPAGE
;
388 details
->RAMAddress
= (void*)&TablesB
.SmallTablesB
.filler
;
389 details
->FlashAddress
= fillerBLocation
;
391 case fillerB2LocationID
:
392 details
->size
= 1012;
393 details
->RAMPage
= RPAGE_TUNE_TWO
;
394 details
->FlashPage
= TUNETABLES_PPAGE
;
395 details
->RAMAddress
= (void*)&TablesB
.SmallTablesB
.filler
;
396 details
->FlashAddress
= fillerB2Location
;
398 case fillerCLocationID
:
399 details
->size
= 1024;
400 details
->RAMPage
= RPAGE_TUNE_ONE
;
401 details
->FlashPage
= TUNETABLES_PPAGE
;
402 details
->RAMAddress
= (void*)&TablesC
.SmallTablesC
.filler
;
403 details
->FlashAddress
= fillerCLocation
;
405 case fillerC2LocationID
:
406 details
->size
= 1024;
407 details
->RAMPage
= RPAGE_TUNE_TWO
;
408 details
->FlashPage
= TUNETABLES_PPAGE
;
409 details
->RAMAddress
= (void*)&TablesC
.SmallTablesC
.filler
;
410 details
->FlashAddress
= fillerC2Location
;
412 case fillerDLocationID
:
413 details
->size
= 1024;
414 details
->RAMPage
= RPAGE_TUNE_ONE
;
415 details
->FlashPage
= TUNETABLES_PPAGE
;
416 details
->RAMAddress
= (void*)&TablesD
.SmallTablesD
.filler
;
417 details
->FlashAddress
= fillerDLocation
;
420 case fillerD2LocationID
:
421 details
->size
= 1024;
422 details
->RAMPage
= RPAGE_TUNE_TWO
;
423 details
->FlashPage
= TUNETABLES_PPAGE
;
424 details
->RAMAddress
= (void*)&TablesD
.SmallTablesD
.filler
;
425 details
->FlashAddress
= fillerD2Location
;
428 /** @todo TODO (add) Fixed config small blocks */
429 /// @note NOTE these are in linear space so we can get the addresses directly.
432 /* Return early if locationID is not valid. */
433 return locationIDNotFound
;
436 /* Fall through to not return error */