Something went wrong. Try again.
Completely reimplimented in zig (eventually)
Something went wrong. Try again.
6.3 kB · 156 lines
Java
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157package com.microchip.mplab.ipelib.device;
import com.microchip.crownking.Pair;import com.microchip.mplab.crownkingx.xMemoryPartition;import com.microchip.mplab.ipelib.common.SharedData;import com.microchip.mplab.mdbcore.OptSupport.NumberOptionValidator;import com.microchip.mplab.mdbcore.OptSupport.RuntimeProperties;import com.microchip.mplab.mdbcore.RealICETool.utils.RIUsefulFunctions;import java.util.ArrayList;import java.util.Properties;
public class PreservePGMRangeValidator extends NumberOptionValidator { RuntimeProperties rtp = null;
public String getHint() { String hint = ""; RuntimeProperties rtp = new RuntimeProperties(SharedData.getSingletonObject().getAssemblySession()); long Boundary = rtp.getProgramChunkSize(); return "Each range must be two hex numbers, representing the start and end addresses of the range, separated by a dash. Ranges must be separated by a comma(e.g. 0-ff, 200-2ff). Areas are reserved by reading them into MPLAB and then programming them back down when a program operation occurs. Thus the preserved areas must lie within a memory range that will be programmed. Ranges must be aligned on a 0x" + Long.toHexString(Boundary) + " address boundary."; }
public boolean isValid(String arg0) { boolean RetVal = false;
try { ArrayList<Pair<Long, Long>> Addrs = new ArrayList<>(); this.rtp = new RuntimeProperties(SharedData.getSingletonObject().getAssemblySession()); Properties Props = this.rtp.getAssembly().GetToolProperties(); if (Props != null && Props.getProperty("programoptions.preserveprogramrange", "false").equals("false")) { RetVal = true; } else { xMemoryPartition XMP = this.rtp.getPic().getMainPartition(); if (XMP != null) { Pair<Long, Long> P; if (XMP.hasSPIFlashMemory()) { P = XMP.getSPIFlashRange(); } else { P = XMP.getInstRange(); }
if ((Long)P.second != 0L) { Addrs.add(new Pair(P.first, (Long)P.second - 1L)); } }
XMP = (xMemoryPartition)this.rtp.getPic().getIDOntoPartition().get("first"); if (XMP != null && (Long)XMP.getInstRange().second != 0L) { Addrs.add(new Pair(XMP.getInstRange().first, (Long)XMP.getInstRange().second - 1L)); }
XMP = (xMemoryPartition)this.rtp.getPic().getIDOntoPartition().get("second"); if (XMP != null && (Long)XMP.getInstRange().second != 0L) { Addrs.add(new Pair(XMP.getInstRange().first, (Long)XMP.getInstRange().second - 1L)); }
XMP = (xMemoryPartition)this.rtp.getPic().getIDOntoPartition().get("only"); if (XMP != null && (Long)XMP.getInstRange().second != 0L) { Addrs.add(new Pair(XMP.getInstRange().first, (Long)XMP.getInstRange().second - 1L)); }
RetVal = this.ValidateReserveRange(arg0, Props.getProperty("memories.programmemory.ranges", ""), Addrs, this.rtp.getProgramChunkSize()); } } catch (Exception var7) { RetVal = false; }
return RetVal; }
protected boolean ValidateReserveRange(String ReserveStr, String PgmRangeStr, ArrayList<Pair<Long, Long>> Addresses, long Boundary) { boolean RetVal = true;
try { RIUsefulFunctions UF = new RIUsefulFunctions(); ArrayList<Pair<Long, Long>> PgmAddrs = null; ArrayList<Pair<Long, Long>> ReserveAddrs = null; boolean InRange = false; if (ReserveStr.isEmpty()) { throw new Exception("Address field is empty"); }
ReserveAddrs = UF.GetAddressFromString(ReserveStr); if (ReserveAddrs.isEmpty()) { throw new Exception("Invalid address"); }
if (!PgmRangeStr.isEmpty()) { PgmAddrs = UF.GetAddressFromString(PgmRangeStr); }
ArrayList<Pair<Long, Long>> TempReserves = new ArrayList<>(); ArrayList<Pair<Long, Long>> RemoveList = new ArrayList<>();
for (Pair<Long, Long> P : ReserveAddrs) { TempReserves.add(P); }
for (Pair<Long, Long> P : Addresses) { RemoveList.clear();
for (Pair<Long, Long> RP : TempReserves) { if ((Long)RP.first >= (Long)P.first && (Long)RP.second <= (Long)P.second) { if ((Long)RP.second % Boundary != Boundary - 1L && (Long)RP.second != (Long)P.second) { throw new Exception("Invalid boundry address"); }
RemoveList.add(RP); }
if ((Long)RP.first % Boundary != 0L) { throw new Exception("Preserve start address is not boundry aligned"); } }
for (Pair<Long, Long> Remove : RemoveList) { TempReserves.remove(Remove); } }
if (!TempReserves.isEmpty()) { throw new Exception("Preserve range is not valid for this address"); }
this.rtp = new RuntimeProperties(SharedData.getSingletonObject().getAssemblySession()); String Auto = this.rtp.getAssembly().GetToolProperties().getProperty("AutoSelectMemRanges"); if (PgmAddrs != null && !PgmAddrs.isEmpty()) { for (Pair<Long, Long> RP : ReserveAddrs) { InRange = false;
for (Pair<Long, Long> P : PgmAddrs) { if ((Long)RP.first >= (Long)P.first && (Long)RP.second <= (Long)P.second) { InRange = true; break; } }
if (!InRange) { throw new Exception(); } } } } catch (Exception var18) { RetVal = false; this.why = var18.getMessage(); if (this.why == null) { this.why = "The Preserve Program memory range falls outside of what will be programmed " + PgmRangeStr + "The given Preserve address range should either be within or equal to the Program memory range."; } }
return RetVal; }}