00001 /* FreeEMS - the open source engine management system 00002 * 00003 * Copyright 2008, 2009 Fred Cooke 00004 * 00005 * This file is part of the FreeEMS project. 00006 * 00007 * FreeEMS software is free software: you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation, either version 3 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * FreeEMS software is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with any FreeEMS software. If not, see http://www.gnu.org/licenses/ 00019 * 00020 * We ask that if you make any changes to this file you email them upstream to 00021 * us at admin(at)diyefi(dot)org or, even better, fork the code on github.com! 00022 * 00023 * Thank you for choosing FreeEMS to run your engine! 00024 */ 00025 00026 00039 #define BLOCK_DETAILS_LOOKUP_C 00040 #include "inc/freeEMS.h" 00041 #include "inc/interrupts.h" 00042 #include "inc/pagedLocationBuffers.h" 00043 #include "inc/blockDetailsLookup.h" 00044 00045 00063 unsigned short lookupBlockDetails(unsigned short locationID, blockDetails* details){ 00064 /* Initialise the four values needed for operations on memory at 0 for error checking */ 00065 details->RAMPage = 0; 00066 details->FlashPage = 0; 00067 details->RAMAddress = 0; 00068 details->FlashAddress = 0; 00069 00070 /* Initialise the block size to 1024 to save code space and increase readability */ 00071 details->size = MAINTABLE_SIZE; 00072 00073 /* Look up the locations and set non default sizes */ 00074 switch (locationID) { 00075 /* flash only fixed conf full blocks */ 00076 case FixedConfig1LocationID: 00077 details->FlashPage = PPAGE; 00078 details->FlashAddress = (void*)&fixedConfigs1; 00079 break; 00080 case FixedConfig2LocationID: 00081 details->FlashPage = PPAGE; 00082 details->FlashAddress = (void*)&fixedConfigs2; 00083 break; 00084 00085 /* lookup tables */ 00086 case IATTransferTableLocationID: 00087 details->size = TransferTableSize; 00088 details->FlashPage = LOOKUP_PPAGE; 00089 details->FlashAddress = IATTransferTableLocation; 00090 break; 00091 case CHTTransferTableLocationID: 00092 details->size = TransferTableSize; 00093 details->FlashPage = LOOKUP_PPAGE; 00094 details->FlashAddress = CHTTransferTableLocation; 00095 break; 00096 case MAFTransferTableLocationID: 00097 details->size = TransferTableSize; 00098 details->FlashPage = LOOKUP_PPAGE; 00099 details->FlashAddress = MAFTransferTableLocation; 00100 break; 00101 case TestTransferTableLocationID: 00102 details->size = TransferTableSize; 00103 details->FlashPage = LOOKUP_PPAGE; 00104 details->FlashAddress = TestTransferTableLocation; 00105 break; 00106 00107 /* fuel tables */ 00108 case VETableMainLocationID: 00109 details->RAMPage = RPAGE_FUEL_ONE; 00110 details->FlashPage = FUELTABLES_PPAGE; 00111 details->RAMAddress = (void*)&TablesA; 00112 details->FlashAddress = VETableMainFlashLocation; 00113 break; 00114 case VETableMain2LocationID: 00115 details->RAMPage = RPAGE_FUEL_TWO; 00116 details->FlashPage = FUELTABLES_PPAGE; 00117 details->RAMAddress = (void*)&TablesA; 00118 details->FlashAddress = VETableMainFlash2Location; 00119 break; 00120 case VETableSecondaryLocationID: 00121 details->RAMPage = RPAGE_FUEL_ONE; 00122 details->FlashPage = FUELTABLES_PPAGE; 00123 details->RAMAddress = (void*)&TablesB; 00124 details->FlashAddress = VETableSecondaryFlashLocation; 00125 break; 00126 case VETableSecondary2LocationID: 00127 details->RAMPage = RPAGE_FUEL_TWO; 00128 details->FlashPage = FUELTABLES_PPAGE; 00129 details->RAMAddress = (void*)&TablesB; 00130 details->FlashAddress = VETableSecondaryFlash2Location; 00131 break; 00132 case VETableTertiaryLocationID: 00133 details->RAMPage = RPAGE_FUEL_ONE; 00134 details->FlashPage = FUELTABLES_PPAGE; 00135 details->RAMAddress = (void*)&TablesC; 00136 details->FlashAddress = VETableTertiaryFlashLocation; 00137 break; 00138 case VETableTertiary2LocationID: 00139 details->RAMPage = RPAGE_FUEL_TWO; 00140 details->FlashPage = FUELTABLES_PPAGE; 00141 details->RAMAddress = (void*)&TablesC; 00142 details->FlashAddress = VETableTertiaryFlash2Location; 00143 break; 00144 case LambdaTableLocationID: 00145 details->RAMPage = RPAGE_FUEL_ONE; 00146 details->FlashPage = FUELTABLES_PPAGE; 00147 details->RAMAddress = (void*)&TablesD; 00148 details->FlashAddress = LambdaTableFlashLocation; 00149 break; 00150 case LambdaTable2LocationID: 00151 details->RAMPage = RPAGE_FUEL_TWO; 00152 details->FlashPage = FUELTABLES_PPAGE; 00153 details->RAMAddress = (void*)&TablesD; 00154 details->FlashAddress = LambdaTableFlash2Location; 00155 break; 00156 00157 /* timing tables */ 00158 case IgnitionAdvanceTableMainLocationID: 00159 details->RAMPage = RPAGE_TIME_ONE; 00160 details->FlashPage = TIMETABLES_PPAGE; 00161 details->RAMAddress = (void*)&TablesA; 00162 details->FlashAddress = IgnitionAdvanceTableMainFlashLocation; 00163 break; 00164 case IgnitionAdvanceTableMain2LocationID: 00165 details->RAMPage = RPAGE_TIME_TWO; 00166 details->FlashPage = TIMETABLES_PPAGE; 00167 details->RAMAddress = (void*)&TablesA; 00168 details->FlashAddress = IgnitionAdvanceTableMainFlash2Location; 00169 break; 00170 case IgnitionAdvanceTableSecondaryLocationID: 00171 details->RAMPage = RPAGE_TIME_ONE; 00172 details->FlashPage = TIMETABLES_PPAGE; 00173 details->RAMAddress = (void*)&TablesB; 00174 details->FlashAddress = IgnitionAdvanceTableSecondaryFlashLocation; 00175 break; 00176 case IgnitionAdvanceTableSecondary2LocationID: 00177 details->RAMPage = RPAGE_TIME_TWO; 00178 details->FlashPage = TIMETABLES_PPAGE; 00179 details->RAMAddress = (void*)&TablesB; 00180 details->FlashAddress = IgnitionAdvanceTableSecondaryFlash2Location; 00181 break; 00182 case InjectionAdvanceTableMainLocationID: 00183 details->RAMPage = RPAGE_TIME_ONE; 00184 details->FlashPage = TIMETABLES_PPAGE; 00185 details->RAMAddress = (void*)&TablesC; 00186 details->FlashAddress = InjectionAdvanceTableMainFlashLocation; 00187 break; 00188 case InjectionAdvanceTableMain2LocationID: 00189 details->RAMPage = RPAGE_TIME_TWO; 00190 details->FlashPage = TIMETABLES_PPAGE; 00191 details->RAMAddress = (void*)&TablesC; 00192 details->FlashAddress = InjectionAdvanceTableMainFlash2Location; 00193 break; 00194 case InjectionAdvanceTableSecondaryLocationID: 00195 details->RAMPage = RPAGE_TIME_ONE; 00196 details->FlashPage = TIMETABLES_PPAGE; 00197 details->RAMAddress = (void*)&TablesD; 00198 details->FlashAddress = InjectionAdvanceTableSecondaryFlashLocation; 00199 break; 00200 case InjectionAdvanceTableSecondary2LocationID: 00201 details->RAMPage = RPAGE_TIME_TWO; 00202 details->FlashPage = TIMETABLES_PPAGE; 00203 details->RAMAddress = (void*)&TablesD; 00204 details->FlashAddress = InjectionAdvanceTableSecondaryFlash2Location; 00205 break; 00206 00207 /* small table full blocks */ 00208 case SmallTablesALocationID: 00209 details->RAMPage = RPAGE_TUNE_ONE; 00210 details->FlashPage = TUNETABLES_PPAGE; 00211 details->RAMAddress = (void*)&TablesA; 00212 details->FlashAddress = SmallTablesAFlashLocation; 00213 break; 00214 case SmallTablesA2LocationID: 00215 details->RAMPage = RPAGE_TUNE_TWO; 00216 details->FlashPage = TUNETABLES_PPAGE; 00217 details->RAMAddress = (void*)&TablesA; 00218 details->FlashAddress = SmallTablesAFlash2Location; 00219 break; 00220 case SmallTablesBLocationID: 00221 details->RAMPage = RPAGE_TUNE_ONE; 00222 details->FlashPage = TUNETABLES_PPAGE; 00223 details->RAMAddress = (void*)&TablesB; 00224 details->FlashAddress = SmallTablesBFlashLocation; 00225 break; 00226 case SmallTablesB2LocationID: 00227 details->RAMPage = RPAGE_TUNE_TWO; 00228 details->FlashPage = TUNETABLES_PPAGE; 00229 details->RAMAddress = (void*)&TablesB; 00230 details->FlashAddress = SmallTablesBFlash2Location; 00231 break; 00232 case SmallTablesCLocationID: 00233 details->RAMPage = RPAGE_TUNE_ONE; 00234 details->FlashPage = TUNETABLES_PPAGE; 00235 details->RAMAddress = (void*)&TablesC; 00236 details->FlashAddress = SmallTablesCFlashLocation; 00237 break; 00238 case SmallTablesC2LocationID: 00239 details->RAMPage = RPAGE_TUNE_TWO; 00240 details->FlashPage = TUNETABLES_PPAGE; 00241 details->RAMAddress = (void*)&TablesC; 00242 details->FlashAddress = SmallTablesCFlash2Location; 00243 break; 00244 case SmallTablesDLocationID: 00245 details->RAMPage = RPAGE_TUNE_ONE; 00246 details->FlashPage = TUNETABLES_PPAGE; 00247 details->RAMAddress = (void*)&TablesD; 00248 details->FlashAddress = SmallTablesDFlashLocation; 00249 break; 00250 case SmallTablesD2LocationID: 00251 details->RAMPage = RPAGE_TUNE_TWO; 00252 details->FlashPage = TUNETABLES_PPAGE; 00253 details->RAMAddress = (void*)&TablesD; 00254 details->FlashAddress = SmallTablesDFlash2Location; 00255 break; 00256 00257 /* TablesA small tables */ 00258 case dwellDesiredVersusVoltageTableLocationID: 00259 details->size = TWODTABLEUS_SIZE; 00260 details->RAMPage = RPAGE_TUNE_ONE; 00261 details->FlashPage = TUNETABLES_PPAGE; 00262 details->RAMAddress = (void*)&TablesA.SmallTablesA.dwellDesiredVersusVoltageTable; 00263 details->FlashAddress = dwellDesiredVersusVoltageTableLocation; 00264 break; 00265 case dwellDesiredVersusVoltageTable2LocationID: 00266 details->size = TWODTABLEUS_SIZE; 00267 details->RAMPage = RPAGE_TUNE_TWO; 00268 details->FlashPage = TUNETABLES_PPAGE; 00269 details->RAMAddress = (void*)&TablesA.SmallTablesA.dwellDesiredVersusVoltageTable; 00270 details->FlashAddress = dwellDesiredVersusVoltageTable2Location; 00271 break; 00272 case injectorDeadTimeTableLocationID: 00273 details->size = TWODTABLEUS_SIZE; 00274 details->RAMPage = RPAGE_TUNE_ONE; 00275 details->FlashPage = TUNETABLES_PPAGE; 00276 details->RAMAddress = (void*)&TablesA.SmallTablesA.injectorDeadTimeTable; 00277 details->FlashAddress = injectorDeadTimeTableLocation; 00278 break; 00279 case injectorDeadTimeTable2LocationID: 00280 details->size = TWODTABLEUS_SIZE; 00281 details->RAMPage = RPAGE_TUNE_TWO; 00282 details->FlashPage = TUNETABLES_PPAGE; 00283 details->RAMAddress = (void*)&TablesA.SmallTablesA.injectorDeadTimeTable; 00284 details->FlashAddress = injectorDeadTimeTable2Location; 00285 break; 00286 case postStartEnrichmentTableLocationID: 00287 details->size = TWODTABLEUS_SIZE; 00288 details->RAMPage = RPAGE_TUNE_ONE; 00289 details->FlashPage = TUNETABLES_PPAGE; 00290 details->RAMAddress = (void*)&TablesA.SmallTablesA.postStartEnrichmentTable; 00291 details->FlashAddress = postStartEnrichmentTableLocation; 00292 break; 00293 case postStartEnrichmentTable2LocationID: 00294 details->size = TWODTABLEUS_SIZE; 00295 details->RAMPage = RPAGE_TUNE_TWO; 00296 details->FlashPage = TUNETABLES_PPAGE; 00297 details->RAMAddress = (void*)&TablesA.SmallTablesA.postStartEnrichmentTable; 00298 details->FlashAddress = postStartEnrichmentTable2Location; 00299 break; 00300 case engineTempEnrichmentTableFixedLocationID: 00301 details->size = TWODTABLEUS_SIZE; 00302 details->RAMPage = RPAGE_TUNE_ONE; 00303 details->FlashPage = TUNETABLES_PPAGE; 00304 details->RAMAddress = (void*)&TablesA.SmallTablesA.engineTempEnrichmentTableFixed; 00305 details->FlashAddress = engineTempEnrichmentTableFixedLocation; 00306 break; 00307 case engineTempEnrichmentTableFixed2LocationID: 00308 details->size = TWODTABLEUS_SIZE; 00309 details->RAMPage = RPAGE_TUNE_TWO; 00310 details->FlashPage = TUNETABLES_PPAGE; 00311 details->RAMAddress = (void*)&TablesA.SmallTablesA.engineTempEnrichmentTableFixed; 00312 details->FlashAddress = engineTempEnrichmentTableFixed2Location; 00313 break; 00314 case primingVolumeTableLocationID: 00315 details->size = TWODTABLEUS_SIZE; 00316 details->RAMPage = RPAGE_TUNE_ONE; 00317 details->FlashPage = TUNETABLES_PPAGE; 00318 details->RAMAddress = (void*)&TablesA.SmallTablesA.primingVolumeTable; 00319 details->FlashAddress = primingVolumeTableLocation; 00320 break; 00321 case primingVolumeTable2LocationID: 00322 details->size = TWODTABLEUS_SIZE; 00323 details->RAMPage = RPAGE_TUNE_TWO; 00324 details->FlashPage = TUNETABLES_PPAGE; 00325 details->RAMAddress = (void*)&TablesA.SmallTablesA.primingVolumeTable; 00326 details->FlashAddress = primingVolumeTable2Location; 00327 break; 00328 case engineTempEnrichmentTablePercentLocationID: 00329 details->size = TWODTABLEUS_SIZE; 00330 details->RAMPage = RPAGE_TUNE_ONE; 00331 details->FlashPage = TUNETABLES_PPAGE; 00332 details->RAMAddress = (void*)&TablesA.SmallTablesA.engineTempEnrichmentTablePercent; 00333 details->FlashAddress = engineTempEnrichmentTablePercentLocation; 00334 break; 00335 case engineTempEnrichmentTablePercent2LocationID: 00336 details->size = TWODTABLEUS_SIZE; 00337 details->RAMPage = RPAGE_TUNE_TWO; 00338 details->FlashPage = TUNETABLES_PPAGE; 00339 details->RAMAddress = (void*)&TablesA.SmallTablesA.engineTempEnrichmentTablePercent; 00340 details->FlashAddress = engineTempEnrichmentTablePercent2Location; 00341 break; 00342 case dwellMaxVersusRPMTableLocationID: 00343 details->size = TWODTABLEUS_SIZE; 00344 details->RAMPage = RPAGE_TUNE_ONE; 00345 details->FlashPage = TUNETABLES_PPAGE; 00346 details->RAMAddress = (void*)&TablesA.SmallTablesA.dwellMaxVersusRPMTable; 00347 details->FlashAddress = dwellMaxVersusRPMTableLocation; 00348 break; 00349 case dwellMaxVersusRPMTable2LocationID: 00350 details->size = TWODTABLEUS_SIZE; 00351 details->RAMPage = RPAGE_TUNE_TWO; 00352 details->FlashPage = TUNETABLES_PPAGE; 00353 details->RAMAddress = (void*)&TablesA.SmallTablesA.dwellMaxVersusRPMTable; 00354 details->FlashAddress = dwellMaxVersusRPMTable2Location; 00355 break; 00356 00357 /* TablesB small tables */ 00358 case perCylinderFuelTrimsLocationID: 00359 details->size = 12; 00360 details->RAMPage = RPAGE_TUNE_ONE; 00361 details->FlashPage = TUNETABLES_PPAGE; 00362 details->RAMAddress = (void*)&TablesB.SmallTablesB.perCylinderFuelTrims; 00363 details->FlashAddress = perCylinderFuelTrimsLocation; 00364 break; 00365 case perCylinderFuelTrims2LocationID: 00366 details->size = 12; 00367 details->RAMPage = RPAGE_TUNE_TWO; 00368 details->FlashPage = TUNETABLES_PPAGE; 00369 details->RAMAddress = (void*)&TablesB.SmallTablesB.perCylinderFuelTrims; 00370 details->FlashAddress = perCylinderFuelTrims2Location; 00371 break; 00372 00373 /* TablesC small tables */ 00374 // TODO add data chunks from TablesC when some are put in 00375 00376 /* TablesD small tables */ 00377 // TODO add data chunks from TablesD when some are put in 00378 00379 /* filler block entries */ 00380 case fillerALocationID: 00381 details->size = 576; 00382 details->RAMPage = RPAGE_TUNE_ONE; 00383 details->FlashPage = TUNETABLES_PPAGE; 00384 details->RAMAddress = (void*)&TablesA.SmallTablesA.filler; 00385 details->FlashAddress = fillerALocation; 00386 break; 00387 case fillerA2LocationID: 00388 details->size = 576; 00389 details->RAMPage = RPAGE_TUNE_TWO; 00390 details->FlashPage = TUNETABLES_PPAGE; 00391 details->RAMAddress = (void*)&TablesA.SmallTablesA.filler; 00392 details->FlashAddress = fillerA2Location; 00393 break; 00394 case fillerBLocationID: 00395 details->size = 1012; 00396 details->RAMPage = RPAGE_TUNE_ONE; 00397 details->FlashPage = TUNETABLES_PPAGE; 00398 details->RAMAddress = (void*)&TablesB.SmallTablesB.filler; 00399 details->FlashAddress = fillerBLocation; 00400 break; 00401 case fillerB2LocationID: 00402 details->size = 1012; 00403 details->RAMPage = RPAGE_TUNE_TWO; 00404 details->FlashPage = TUNETABLES_PPAGE; 00405 details->RAMAddress = (void*)&TablesB.SmallTablesB.filler; 00406 details->FlashAddress = fillerB2Location; 00407 break; 00408 case fillerCLocationID: 00409 details->size = 1024; 00410 details->RAMPage = RPAGE_TUNE_ONE; 00411 details->FlashPage = TUNETABLES_PPAGE; 00412 details->RAMAddress = (void*)&TablesC.SmallTablesC.filler; 00413 details->FlashAddress = fillerCLocation; 00414 break; 00415 case fillerC2LocationID: 00416 details->size = 1024; 00417 details->RAMPage = RPAGE_TUNE_TWO; 00418 details->FlashPage = TUNETABLES_PPAGE; 00419 details->RAMAddress = (void*)&TablesC.SmallTablesC.filler; 00420 details->FlashAddress = fillerC2Location; 00421 break; 00422 case fillerDLocationID: 00423 details->size = 1024; 00424 details->RAMPage = RPAGE_TUNE_ONE; 00425 details->FlashPage = TUNETABLES_PPAGE; 00426 details->RAMAddress = (void*)&TablesD.SmallTablesD.filler; 00427 details->FlashAddress = fillerDLocation; 00428 break; 00429 case fillerD2LocationID: 00430 details->size = 1024; 00431 details->RAMPage = RPAGE_TUNE_TWO; 00432 details->FlashPage = TUNETABLES_PPAGE; 00433 details->RAMAddress = (void*)&TablesD.SmallTablesD.filler; 00434 details->FlashAddress = fillerD2Location; 00435 break; 00436 00437 /* Fixed conf 1 small chunks */ 00438 case engineSettingsLocationID: 00439 details->size = ENGINE_SETTINGS_SIZE; 00440 details->FlashPage = PPAGE; 00441 details->FlashAddress = (void*)&(fixedConfigs1.engineSettings); 00442 break; 00443 case serialSettingsLocationID: 00444 details->size = SERIAL_SETTINGS_SIZE; 00445 details->FlashPage = PPAGE; 00446 details->FlashAddress = (void*)&(fixedConfigs1.serialSettings); 00447 break; 00448 case tachoSettingsLocationID: 00449 details->size = TACHO_SETTINGS_SIZE; 00450 details->FlashPage = PPAGE; 00451 details->FlashAddress = (void*)&(fixedConfigs1.tachoSettings); 00452 break; 00453 case coreSettingsALocationID: 00454 details->size = 2; 00455 details->FlashPage = PPAGE; 00456 details->FlashAddress = (void*)&(fixedConfigs1.coreSettingsA); 00457 break; 00458 case userTextFieldLocationID: 00459 details->size = userTextFieldArrayLength1; 00460 details->FlashPage = PPAGE; 00461 details->FlashAddress = (void*)&(fixedConfigs1.userTextField); 00462 break; 00463 00464 /* Fixed conf 2 small chunks */ 00465 case sensorRangesLocationID: 00466 details->size = SENSOR_RANGES_SIZE; 00467 details->FlashPage = PPAGE; 00468 details->FlashAddress = (void*)&(fixedConfigs2.sensorRanges); 00469 break; 00470 case sensorPresetsLocationID: 00471 details->size = SENSOR_PRESETS_SIZE; 00472 details->FlashPage = PPAGE; 00473 details->FlashAddress = (void*)&(fixedConfigs2.sensorPresets); 00474 break; 00475 case sensorSettingsLocationID: 00476 details->size = SENSOR_SETTINGS_SIZE; 00477 details->FlashPage = PPAGE; 00478 details->FlashAddress = (void*)&(fixedConfigs2.sensorSettings); 00479 break; 00480 case userTextField2LocationID: 00481 details->size = userTextFieldArrayLength2; 00482 details->FlashPage = PPAGE; 00483 details->FlashAddress = (void*)&(fixedConfigs2.userTextField2); 00484 break; 00485 00486 default: 00487 /* Return early if locationID is not valid. */ 00488 return locationIDNotFound; 00489 } 00490 00491 /* Fall through to not return error */ 00492 return 0; 00493 }