Merge pull request #59 from nfi/minor-code-cleanup

Minor code cleanup
This commit is contained in:
Joakim Eriksson 2022-05-18 16:41:58 +02:00 committed by GitHub
commit 9a752cdac0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 37 additions and 49 deletions

View File

@ -830,16 +830,16 @@ public class CC1120 extends Radio802154 implements USARTListener {
}
private void printRXFIFO() {
System.out.print(String.format("RXFIFO[%03d]: ", rxfifo.size()));
System.out.printf("RXFIFO[%03d]: ", rxfifo.size());
for (int i = 0; i < rxfifo.size(); i++) {
System.out.print(String.format("%02x", rxfifo.get(i)));
System.out.printf("%02x", rxfifo.get(i));
}
System.out.println();
}
private void printTXFIFO() {
System.out.print(String.format("TXFIFO[%03d]: ", txfifo.size()));
System.out.printf("TXFIFO[%03d]: ", txfifo.size());
for (int i = 0; i < txfifo.size(); i++) {
System.out.print(String.format("%02x", txfifo.get(i)));
System.out.printf("%02x", txfifo.get(i));
}
System.out.println();
}

View File

@ -147,6 +147,9 @@ public class CC2420 extends Radio802154 implements USARTListener {
public static final int SFDMUX = 0x3E0;
public static final int CCAMUX = 0x1F;
public static final int SFDMUX_SHIFT = 5;
public static final int CCAMUX_SHIFT = 0;
// CCAMUX values
public static final int CCAMUX_CCA = 0;
public static final int CCAMUX_XOSC16M_STABLE = 24;
@ -741,8 +744,8 @@ public class CC2420 extends Radio802154 implements USARTListener {
case REG_IOCFG1:
if (logLevel > INFO)
log("IOCFG1: SFDMUX "
+ ((registers[address] & SFDMUX) >> SFDMUX)
+ " CCAMUX: " + (registers[address] & CCAMUX));
+ ((registers[address] & SFDMUX) >> SFDMUX_SHIFT)
+ " CCAMUX: " + ((registers[address] & CCAMUX) >> CCAMUX_SHIFT));
updateCCA();
break;
case REG_MDMCTRL0:

View File

@ -55,7 +55,7 @@ public abstract class I2CUnit implements USARTListener {
*
* @author Víctor Ariño <victor.arino@tado.com>
*/
public class I2CData {
public static class I2CData {
/**
* Several mask for messages. This may not implement a real i2c but is

View File

@ -41,6 +41,8 @@
package se.sics.mspsim.chip;
import java.io.IOException;
import java.util.Arrays;
import se.sics.mspsim.core.*;
import se.sics.mspsim.core.EmulationLogger.WarningType;
import se.sics.mspsim.util.Utils;
@ -170,9 +172,7 @@ public class M25P80 extends ExternalFlash implements USARTListener, PortListener
pos++;
if (pos == 3) {
// Clear buffer
for (int i = 0; i < buffer.length; i++) {
buffer[i] = (byte) 0xff;
}
Arrays.fill(buffer, (byte) 0xff);
blockWriteAddress = readAddress & 0xfff00;
if (DEBUG) {
log("programming at $" + Integer.toHexString(readAddress));
@ -356,9 +356,7 @@ public class M25P80 extends ExternalFlash implements USARTListener, PortListener
writeStatus(SECTOR_ERASE_MILLIS);
int sectorAddress = address & 0xf0000;
loadedAddress = -1;
for (int i = 0; i < buffer.length; i++) {
buffer[i] = (byte)0xff;
}
Arrays.fill(buffer, (byte) 0xff);
// Erase a complete sector
blockWriteAddress = sectorAddress;
for (int i = 0; i < 0x100; i++) {

View File

@ -86,7 +86,7 @@ public class CRC16 extends IOUnit {
*
* @author Víctor Ariño <victor.arino@tado.com>
*/
private class CRC16Java {
private static class CRC16Java {
private int crc = CCITTSeed;
private int polynomial = 0x1021; // 0001 0000 0010 0001 (0, 5, 12)

View File

@ -630,14 +630,14 @@ public class DisAsm implements MSP430Constants {
}
private static String dumpMem(int pc, int size, int[] memory) {
String output = "";
StringBuilder output = new StringBuilder();
for (int i = 0, n = size; i < n; i++) {
if (size > i) {
output += Utils.hex8(memory[pc + i]) + " ";
output.append(Utils.hex8(memory[pc + i])).append(" ");
} else {
output += " ";
output.append(" ");
}
}
return output;
return output.toString();
}
}

View File

@ -38,6 +38,7 @@
package se.sics.mspsim.core;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import se.sics.mspsim.core.EmulationLogger.WarningType;
import se.sics.mspsim.core.Memory.AccessMode;
@ -267,9 +268,7 @@ public class MSP430Core extends Chip implements MSP430Constants {
config.setup(this, ioUnits);
/* timers after ports ? */
for (int i = 0; i < timers.length; i++) {
ioUnits.add(timers[i]);
}
ioUnits.addAll(Arrays.asList(timers));
watchdog = new Watchdog(this, config.watchdogOffset);
ioSegment.setIORange(config.watchdogOffset, 1, watchdog);
@ -662,7 +661,7 @@ public class MSP430Core extends Chip implements MSP430Constants {
/**
* Schedules a new Time event using the cycles counter
* @param event
* @param time
* @param cycles
*/
public void scheduleCycleEvent(TimeEvent event, long cycles) {
long currentNext = cycleEventQueue.nextTime;
@ -703,7 +702,7 @@ public class MSP430Core extends Chip implements MSP430Constants {
/**
* Schedules a new Time event msec milliseconds in the future
* @param event
* @param time
* @param msec
*/
public long scheduleTimeEventMillis(TimeEvent event, double msec) {
/* System.out.println("MAX_DCO " + bcs.getMaxDCOFrequency());*/

View File

@ -77,7 +77,7 @@ public class DwarfReader implements ELFDebug {
ELF elfFile;
/* Address ranges */
class Arange {
static class Arange {
int length;
int version;
int offset;
@ -85,7 +85,7 @@ public class DwarfReader implements ELFDebug {
int segmentSize;
}
class LineEntry {
static class LineEntry {
int address;
int line;
int file;
@ -96,7 +96,7 @@ public class DwarfReader implements ELFDebug {
}
}
/* Line number lookup data */
class LineData {
static class LineData {
String[] includeDirs;
String[] sourceFiles;
LineEntry[] lineEntries;

View File

@ -130,7 +130,7 @@ public class StabFile {
}
public String toString() {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append("File: " + path + file + " starts at: " + startAddress + "\n");
for (int i = 0; i < functions.size(); i++) {
sb.append(" ").append(functions.get(i)).append("\n");

View File

@ -21,7 +21,7 @@ public class StabFunction {
}
public String toString() {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append("Function: " + name);
if (params != null) {
sb.append("(");
@ -36,7 +36,7 @@ public class StabFunction {
return sb.toString();
}
class Param {
static class Param {
String name;
Param(String name) {
this.name = name;

View File

@ -264,7 +264,7 @@ public class LineNumberedBorder extends AbstractBorder {
* @return the line number for drawing
*/
private static String padLabel(int lineNumber, int length, boolean addSpace) {
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
buffer.append(lineNumber);
for (int count = (length - buffer.length()); count > 0; count--) {
buffer.insert(0, ' ');

View File

@ -15,7 +15,7 @@ public class TextScanner extends Scanner {
+ "7333333333333333333333333337777473333333333333333333333333377771";
static final byte[] kinds = new byte[cs.length()];
{
static {
for (int i = 0; i < cs.length(); i++) {
kinds[i] = (byte) (cs.charAt(i) - '0');
}

View File

@ -297,10 +297,6 @@ public abstract class GenericNode extends Chip implements Runnable {
}
public ELF loadFirmware(URL url) throws IOException {
return loadFirmware(url, cpu.memory);
}
@Deprecated public ELF loadFirmware(URL url, int[] memory) throws IOException {
DataInputStream inputStream = new DataInputStream(url.openStream());
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
byte[] firmwareData = new byte[2048];
@ -311,27 +307,19 @@ public abstract class GenericNode extends Chip implements Runnable {
inputStream.close();
ELF elf = new ELF(byteStream.toByteArray());
elf.readAll();
return loadFirmware(elf, memory);
return loadFirmware(elf);
}
public ELF loadFirmware(String name) throws IOException {
return loadFirmware(name, cpu.memory);
}
@Deprecated public ELF loadFirmware(String name, int[] memory) throws IOException {
return loadFirmware(ELF.readELF(firmwareFile = name), memory);
return loadFirmware(ELF.readELF(firmwareFile = name));
}
public ELF loadFirmware(ELF elf) {
return loadFirmware(elf, cpu.memory);
}
@Deprecated public ELF loadFirmware(ELF elf, int[] memory) {
if (cpu.isRunning()) {
stop();
}
this.elf = elf;
elf.loadPrograms(memory);
elf.loadPrograms(cpu.memory);
MapTable map = elf.getMap();
cpu.getDisAsm().setMap(map);
cpu.setMap(map);

View File

@ -78,7 +78,7 @@ public class DebugUI extends JPanel {
listModel = new DbgListModel();
disList = new JList<DbgInstruction>(listModel);
disList.setFont(new Font("courier", 0, 12));
disList.setFont(new Font("courier", Font.PLAIN, 12));
disList.setCellRenderer(new MyCellRenderer());
disList.setPreferredSize(new Dimension(500, 350));
add(disList, BorderLayout.CENTER);

View File

@ -180,7 +180,7 @@ public class DotDiagram extends JComponent {
// names = new String[diagrams];
// }
// names[index] = name;
// StringBuffer sb = new StringBuffer();
// StringBuilder sb = new StringBuilder();
// for (int i = 0, n = names.length; i < n; i++) {
// // Setup JLables...
// }

View File

@ -201,7 +201,7 @@ public class GDBStubs implements Runnable {
public static String stringToHex(String base)
{
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
int intValue;
for(int x = 0; x < base.length(); x++)
{