mirror of https://github.com/contiki-ng/mspsim
made CPU more configurable
This commit is contained in:
parent
487880797a
commit
d7a36abbfb
|
|
@ -35,8 +35,13 @@
|
|||
|
||||
package se.sics.mspsim.config;
|
||||
|
||||
import se.sics.mspsim.core.DMA;
|
||||
import se.sics.mspsim.core.IOUnit;
|
||||
import se.sics.mspsim.core.InterruptMultiplexer;
|
||||
import se.sics.mspsim.core.MSP430Config;
|
||||
import se.sics.mspsim.core.MSP430Core;
|
||||
import se.sics.mspsim.core.Timer;
|
||||
import se.sics.mspsim.core.USART;
|
||||
|
||||
public class MSP430f1611Config extends MSP430Config {
|
||||
|
||||
|
|
@ -49,4 +54,44 @@ public class MSP430f1611Config extends MSP430Config {
|
|||
TimerConfig timerB = new TimerConfig(13, 12, 7, 0x180, Timer.TIMER_Bx149, "TimerB");
|
||||
timerConfig = new TimerConfig[] {timerA, timerB};
|
||||
}
|
||||
|
||||
|
||||
public int setup(MSP430Core cpu, IOUnit[] ioUnits, int ioPos) {
|
||||
System.out.println("*** Setting up f1611 IO!");
|
||||
|
||||
USART usart0 = new USART(cpu, 0, cpu.memory, 0x70);
|
||||
USART usart1 = new USART(cpu, 1, cpu.memory, 0x78);
|
||||
|
||||
for (int i = 0, n = 8; i < n; i++) {
|
||||
cpu.memOut[0x70 + i] = usart0;
|
||||
cpu.memIn[0x70 + i] = usart0;
|
||||
|
||||
cpu.memOut[0x78 + i] = usart1;
|
||||
cpu.memIn[0x78 + i] = usart1;
|
||||
}
|
||||
|
||||
// Usarts
|
||||
ioUnits[ioPos] = usart0;
|
||||
ioUnits[ioPos + 1] = usart1;
|
||||
|
||||
DMA dma = new DMA("dma", cpu.memory, 0, cpu);
|
||||
for (int i = 0, n = 24; i < n; i++) {
|
||||
cpu.memOut[0x1E0 + i] = dma;
|
||||
cpu.memIn[0x1E0 + i] = dma;
|
||||
}
|
||||
|
||||
/* DMA Ctl */
|
||||
cpu.memOut[0x122] = dma;
|
||||
cpu.memIn[0x124] = dma;
|
||||
|
||||
/* configure the DMA */
|
||||
dma.setDMATrigger(DMA.URXIFG0, usart0, 0);
|
||||
dma.setDMATrigger(DMA.UTXIFG0, usart0, 1);
|
||||
dma.setDMATrigger(DMA.URXIFG1, usart1, 0);
|
||||
dma.setDMATrigger(DMA.UTXIFG1, usart1, 1);
|
||||
dma.setInterruptMultiplexer(new InterruptMultiplexer(cpu, 0));
|
||||
|
||||
ioUnits[ioPos + 2] = dma;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,9 @@
|
|||
|
||||
package se.sics.mspsim.config;
|
||||
|
||||
import se.sics.mspsim.core.IOUnit;
|
||||
import se.sics.mspsim.core.MSP430Config;
|
||||
import se.sics.mspsim.core.MSP430Core;
|
||||
import se.sics.mspsim.core.Timer;
|
||||
|
||||
public class MSP430f2617Config extends MSP430Config {
|
||||
|
|
@ -51,4 +53,9 @@ public class MSP430f2617Config extends MSP430Config {
|
|||
TimerConfig timerB = new TimerConfig(29, 28, 7, 0x180, Timer.TIMER_Bx149, "TimerB");
|
||||
timerConfig = new TimerConfig[] {timerA, timerB};
|
||||
}
|
||||
|
||||
public int setup(MSP430Core cpu, IOUnit[] ioUnits, int ioPos) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package se.sics.mspsim.core;
|
||||
|
||||
public class MSP430Config {
|
||||
public abstract class MSP430Config {
|
||||
|
||||
public class TimerConfig {
|
||||
int ccr0Vector;
|
||||
|
|
@ -29,6 +29,5 @@ public class MSP430Config {
|
|||
public int maxInterruptVector = 15;
|
||||
public boolean MSP430XArch = false;
|
||||
|
||||
public void setup() {
|
||||
}
|
||||
public abstract int setup(MSP430Core cpu, IOUnit[] ioUnits, int ioPos);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,17 +199,6 @@ public class MSP430Core extends Chip implements MSP430Constants {
|
|||
memIn[i] = mp;
|
||||
}
|
||||
|
||||
USART usart0 = new USART(this, 0, memory, 0x70);
|
||||
USART usart1 = new USART(this, 1, memory, 0x78);
|
||||
|
||||
for (int i = 0, n = 8; i < n; i++) {
|
||||
memOut[0x70 + i] = usart0;
|
||||
memIn[0x70 + i] = usart0;
|
||||
|
||||
memOut[0x78 + i] = usart1;
|
||||
memIn[0x78 + i] = usart1;
|
||||
}
|
||||
|
||||
|
||||
// Add port 1,2 with interrupt capability!
|
||||
ioUnits[0] = new IOPort(this, 1, 4, memory, 0x20);
|
||||
|
|
@ -240,9 +229,7 @@ public class MSP430Core extends Chip implements MSP430Constants {
|
|||
ioUnits[passIO++] = sfr;
|
||||
ioUnits[passIO++] = bcs;
|
||||
|
||||
// Usarts
|
||||
ioUnits[passIO++] = usart0;
|
||||
ioUnits[passIO++] = usart1;
|
||||
passIO += config.setup(this, ioUnits, passIO);
|
||||
|
||||
// Add the timers
|
||||
ioUnits[passIO++] = ta;
|
||||
|
|
@ -266,26 +253,7 @@ public class MSP430Core extends Chip implements MSP430Constants {
|
|||
memIn[0x1A0 + i] = adc12;
|
||||
}
|
||||
|
||||
|
||||
DMA dma = new DMA("dma", memory, 0, this);
|
||||
for (int i = 0, n = 24; i < n; i++) {
|
||||
memOut[0x1E0 + i] = dma;
|
||||
memIn[0x1E0 + i] = dma;
|
||||
}
|
||||
/* DMA Ctl */
|
||||
memOut[0x122] = dma;
|
||||
memIn[0x124] = dma;
|
||||
|
||||
/* configure the DMA */
|
||||
dma.setDMATrigger(DMA.URXIFG0, usart0, 0);
|
||||
dma.setDMATrigger(DMA.UTXIFG0, usart0, 1);
|
||||
dma.setDMATrigger(DMA.URXIFG1, usart1, 0);
|
||||
dma.setDMATrigger(DMA.UTXIFG1, usart1, 1);
|
||||
|
||||
dma.setInterruptMultiplexer(new InterruptMultiplexer(this, 0));
|
||||
|
||||
ioUnits[passIO++] = dma;
|
||||
|
||||
|
||||
if (DEBUG) System.out.println("Number of passive: " + passIO);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import java.io.IOException;
|
|||
import se.sics.mspsim.chip.Beeper;
|
||||
import se.sics.mspsim.chip.Leds;
|
||||
import se.sics.mspsim.chip.TR1001;
|
||||
import se.sics.mspsim.config.MSP430f1611Config;
|
||||
import se.sics.mspsim.core.IOPort;
|
||||
import se.sics.mspsim.core.IOUnit;
|
||||
import se.sics.mspsim.core.MSP430;
|
||||
|
|
@ -92,7 +93,7 @@ public class ESBNode extends GenericNode implements PortListener {
|
|||
*/
|
||||
public ESBNode() {
|
||||
/* this should be a config for the MSP430f149 */
|
||||
super("ESB", new MSP430Config());
|
||||
super("ESB", new MSP430f1611Config());
|
||||
}
|
||||
|
||||
public Leds getLeds() {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package se.sics.mspsim.platform.sky;
|
|||
import se.sics.mspsim.chip.CC2420;
|
||||
import se.sics.mspsim.chip.DS2411;
|
||||
import se.sics.mspsim.chip.PacketListener;
|
||||
import se.sics.mspsim.config.MSP430f1611Config;
|
||||
import se.sics.mspsim.core.IOPort;
|
||||
import se.sics.mspsim.core.IOUnit;
|
||||
import se.sics.mspsim.core.MSP430;
|
||||
|
|
@ -49,7 +50,7 @@ public abstract class CC2420Node extends GenericNode implements PortListener, US
|
|||
|
||||
public CC2420Node(String id) {
|
||||
/* this should be a config for the MSP430x1611 */
|
||||
super(id, new MSP430Config());
|
||||
super(id, new MSP430f1611Config());
|
||||
}
|
||||
|
||||
public void setDebug(boolean debug) {
|
||||
|
|
|
|||
|
|
@ -2,27 +2,72 @@ package se.sics.mspsim.platform.z1;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import se.sics.mspsim.chip.CC2420;
|
||||
import se.sics.mspsim.chip.FileM25P80;
|
||||
import se.sics.mspsim.chip.M25P80;
|
||||
import se.sics.mspsim.config.MSP430f2617Config;
|
||||
import se.sics.mspsim.core.IOPort;
|
||||
import se.sics.mspsim.core.IOUnit;
|
||||
import se.sics.mspsim.core.PortListener;
|
||||
import se.sics.mspsim.core.USART;
|
||||
import se.sics.mspsim.core.USARTListener;
|
||||
import se.sics.mspsim.platform.GenericNode;
|
||||
import se.sics.mspsim.ui.SerialMon;
|
||||
import se.sics.mspsim.util.ArgumentManager;
|
||||
|
||||
public class Z1Node extends GenericNode implements PortListener {
|
||||
public class Z1Node extends GenericNode implements PortListener, USARTListener {
|
||||
|
||||
/* P1.2 - Input: FIFOP from CC2420 */
|
||||
/* P1.3 - Input: FIFO from CC2420 */
|
||||
/* P1.4 - Input: CCA from CC2420 */
|
||||
public static final int CC2420_FIFOP = 2;
|
||||
public static final int CC2420_FIFO = 3;
|
||||
public static final int CC2420_CCA = 4;
|
||||
|
||||
/* P4.1 - Input: SFD from CC2420 */
|
||||
/* P4.5 - Output: VREG_EN to CC2420 */
|
||||
/* P3.0 - Output: SPI Chip Select (CS_N) */
|
||||
public static final int CC2420_SFD = 1;
|
||||
public static final int CC2420_VREG = (1 << 5);
|
||||
public static final int CC2420_CHIP_SELECT = 0x01;
|
||||
|
||||
|
||||
IOPort port1;
|
||||
IOPort port3;
|
||||
IOPort port4;
|
||||
IOPort port5;
|
||||
|
||||
|
||||
public static final int LEDS_CONF_RED = 0x10;
|
||||
public static final int LEDS_CONF_GREEN = 0x40;
|
||||
public static final int LEDS_CONF_YELLOW = 0x20;
|
||||
|
||||
private M25P80 flash;
|
||||
private String flashFile;
|
||||
public CC2420 radio;
|
||||
|
||||
|
||||
public Z1Node() {
|
||||
super("Z1", new MSP430f2617Config());
|
||||
}
|
||||
|
||||
public M25P80 getFlash() {
|
||||
return flash;
|
||||
}
|
||||
|
||||
public void setFlash(M25P80 flash) {
|
||||
this.flash = flash;
|
||||
registry.registerComponent("xmem", flash);
|
||||
}
|
||||
|
||||
public void dataReceived(USART source, int data) {
|
||||
radio.dataReceived(source, data);
|
||||
flash.dataReceived(source, data);
|
||||
/* if nothing selected, just write back a random byte to these devs */
|
||||
if (!radio.getChipSelect() && !flash.getChipSelect()) {
|
||||
source.byteReceived(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void portWrite(IOPort source, int data) {
|
||||
System.out.println("Write to port: " + source + " => " + data);
|
||||
if (source == port5) {
|
||||
|
|
@ -30,23 +75,94 @@ public class Z1Node extends GenericNode implements PortListener {
|
|||
System.out.println("LEDS RED = " + ((data & LEDS_CONF_RED) > 0));
|
||||
System.out.println("LEDS YELLOW = " + ((data & LEDS_CONF_YELLOW) > 0));
|
||||
}
|
||||
if (source == port3) {
|
||||
radio.setChipSelect((data & CC2420_CHIP_SELECT) == 0);
|
||||
}
|
||||
if (source == port4) {
|
||||
// Chip select = active low...
|
||||
radio.setVRegOn((data & CC2420_VREG) != 0);
|
||||
//radio.portWrite(source, data);
|
||||
flash.portWrite(source, data);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupNodePorts() {
|
||||
if (flashFile != null) {
|
||||
setFlash(new FileM25P80(cpu, flashFile));
|
||||
}
|
||||
|
||||
IOUnit unit = cpu.getIOUnit("P1");
|
||||
if (unit instanceof IOPort) {
|
||||
port1 = (IOPort) unit;
|
||||
port1.setPortListener(this);
|
||||
}
|
||||
unit = cpu.getIOUnit("P3");
|
||||
if (unit instanceof IOPort) {
|
||||
port3 = (IOPort) unit;
|
||||
port3.setPortListener(this);
|
||||
}
|
||||
unit = cpu.getIOUnit("P4");
|
||||
if (unit instanceof IOPort) {
|
||||
port4 = (IOPort) unit;
|
||||
port4.setPortListener(this);
|
||||
}
|
||||
unit = cpu.getIOUnit("P5");
|
||||
if (unit instanceof IOPort) {
|
||||
port5 = (IOPort) unit;
|
||||
port5.setPortListener(this);
|
||||
}
|
||||
|
||||
IOUnit usart0 = cpu.getIOUnit("USART0");
|
||||
if (usart0 instanceof USART) {
|
||||
radio = new CC2420(cpu);
|
||||
radio.setCCAPort(port1, CC2420_CCA);
|
||||
radio.setFIFOPPort(port1, CC2420_FIFOP);
|
||||
radio.setFIFOPort(port1, CC2420_FIFO);
|
||||
|
||||
((USART) usart0).setUSARTListener(this);
|
||||
if (port4 != null) {
|
||||
radio.setSFDPort(port4, CC2420_SFD);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void setupNode() {
|
||||
// create a filename for the flash file
|
||||
// This should be possible to take from a config file later!
|
||||
String fileName = config.getProperty("flashfile");
|
||||
if (fileName == null) {
|
||||
fileName = firmwareFile;
|
||||
if (fileName != null) {
|
||||
int ix = fileName.lastIndexOf('.');
|
||||
if (ix > 0) {
|
||||
fileName = fileName.substring(0, ix);
|
||||
}
|
||||
fileName = fileName + ".flash";
|
||||
}
|
||||
}
|
||||
if (DEBUG) System.out.println("Using flash file: " + (fileName == null ? "no file" : fileName));
|
||||
|
||||
this.flashFile = fileName;
|
||||
|
||||
setupNodePorts();
|
||||
|
||||
if (!config.getPropertyAsBoolean("nogui", true)) {
|
||||
setupGUI();
|
||||
|
||||
// Add some windows for listening to serial output
|
||||
IOUnit usart = cpu.getIOUnit("USART1");
|
||||
if (usart instanceof USART) {
|
||||
SerialMon serial = new SerialMon((USART)usart, "USART1 Port Output");
|
||||
registry.registerComponent("serialgui", serial);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void setupGUI() {
|
||||
System.out.println("No gui for Z1 yet...");
|
||||
}
|
||||
|
||||
public int getModeMax() {
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@
|
|||
|
||||
package se.sics.mspsim.util;
|
||||
import java.io.*;
|
||||
|
||||
import se.sics.mspsim.config.MSP430f1611Config;
|
||||
import se.sics.mspsim.core.MSP430;
|
||||
import se.sics.mspsim.core.MSP430Config;
|
||||
|
||||
|
|
@ -139,7 +141,7 @@ public class IHexReader {
|
|||
// System.out.println("T ^ T => " + (true ^ true) +
|
||||
// " T ^ F => " + (false ^ true));
|
||||
|
||||
MSP430 cpu = new MSP430(0, new ComponentRegistry(), new MSP430Config());
|
||||
MSP430 cpu = new MSP430(0, new ComponentRegistry(), new MSP430f1611Config());
|
||||
int[] memory = cpu.getMemory();
|
||||
reader.readFile(memory, args[0]);
|
||||
cpu.reset();
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@
|
|||
package se.sics.mspsim.util;
|
||||
import java.io.IOException;
|
||||
|
||||
import se.sics.mspsim.config.MSP430f1611Config;
|
||||
import se.sics.mspsim.core.*;
|
||||
|
||||
/**
|
||||
|
|
@ -83,7 +84,7 @@ public class Test implements USARTListener {
|
|||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
MSP430 cpu = new MSP430(0, new ComponentRegistry(), new MSP430Config());
|
||||
MSP430 cpu = new MSP430(0, new ComponentRegistry(), new MSP430f1611Config());
|
||||
int index = 0;
|
||||
if (args[index].startsWith("-")) {
|
||||
// Flag
|
||||
|
|
|
|||
Loading…
Reference in New Issue