# migIo
migIo0 = migIo.MigIo(8,"IO")
-
+
# Trigger
term0 = trigger.Term(trig_width)
trigger0 = trigger.Trigger(TRIGGER_ADDR, trig_width, dat_width, [term0])
# Spi2Csr
spi2csr0 = spi2Csr.Spi2Csr(16,8)
-
+
# Csr Interconnect
csrcon0 = csr.Interconnect(spi2csr0.csr,
[
recorder0.trig_hit.eq(trigger0.hit)
]
-
+
# HouseKeeping
in_clk = Signal()
in_rst_n = Signal()
--- /dev/null
+/*
+ * spiFpga
+ * Copyright (C) 2012 by Florent Kermarrec <florent@enjoy-digital.fr>
+ * Copyright (C) 2011 by James Bowman <jamesb@excamera.com>
+ *
+ */
+
+#include "WProgram.h"
+#include <avr/pgmspace.h>
+#include <SPI.h>
+#include <spiFpga.h>
+
+SFClass SF;
+
+void SFClass::begin()
+{
+ pinMode(SS_PIN, OUTPUT);
+ SPI.begin();
+ SPI.setClockDivider(SPI_CLOCK_DIV2);
+ SPI.setBitOrder(MSBFIRST);
+ SPI.setDataMode(SPI_MODE0);
+ SPSR = (1 << SPI2X);
+ digitalWrite(SS_PIN, HIGH);
+}
+
+void SFClass::end() {
+}
+
+void SFClass::__start(unsigned int addr)
+{
+ digitalWrite(SS_PIN, LOW);
+ SPI.transfer(highByte(addr));
+ SPI.transfer(lowByte(addr));
+}
+
+void SFClass::__wstart(unsigned int addr)
+{
+ __start(0x8000|addr);
+}
+
+void SFClass::__end()
+{
+ digitalWrite(SS_PIN, HIGH);
+}
+
+char SFClass::rd(unsigned int addr)
+{
+ __start(addr);
+ char r = SPI.transfer(0);
+ __end();
+ return r;
+}
+
+void SFClass::wr(unsigned int addr, char v)
+{
+ __wstart(addr);
+ SPI.transfer(v);
+ __end();
+}
\ No newline at end of file
--- /dev/null
+/*
+ * spiFpga
+ * Copyright (C) 2012 by Florent Kermarrec <florent@enjoy-digital.fr>
+ * Copyright (C) 2011 by James Bowman <jamesb@excamera.com>
+ *
+ */
+
+#ifndef _SF_H_INCLUDED
+#define _SF_H_INCLUDED
+
+#ifndef SS_PIN
+#define SS_PIN 10
+#endif
+
+class SFClass {
+public:
+ static void begin();
+ static void end();
+ static void __start(unsigned int addr);
+ static void __wstart(unsigned int addr);
+ static void __end(void);
+ static char rd(unsigned int addr);
+ static void wr(unsigned int addr, char v);
+};
+
+extern SFClass SF;
+
+#endif
--- /dev/null
+/*
+ Uart2Spi
+ Copyright 2012 - Florent Kermarrec - florent@enjoy-digital.fr
+
+ Protocol:
+ -Write : 0x01 + 16b Addr + 8b Data
+ -Read : 0x02 + 16b Addr + 8b Don't Care
+
+ Todo:
+ Support Spi Burst Mode
+
+ */
+#include <SPI.h>
+#include <spiFpga.h>
+
+void setup() {
+ SF.begin();
+ SPI.setClockDivider(8);
+ Serial.begin(115200);
+}
+
+int cmd = 0;
+
+void loop()
+{
+ if (Serial.available() == 4)
+ {
+ cmd = Serial.read();
+ //Write Cmd
+ if (cmd == 0x01)
+ {
+ char addrMsb = Serial.read();
+ char addrLsb = Serial.read();
+ char data = Serial.read();
+ SF.wr(addrMsb<<8|addrLsb, data);
+ }
+ //Read Cmd
+ if (cmd == 0x02)
+ {
+ char addrMsb = Serial.read();
+ char addrLsb = Serial.read();
+ Serial.read();
+ char data;
+ data = SF.rd(addrMsb<<8|addrLsb);
+ Serial.print(data);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+import string
+import time
+import serial
+
+def write_ascii(uart, data):
+ uart.write(bytes("%c" % data, encoding="ascii"))
+
+class Uart2Spi:
+ def __init__(self, port, baudrate):
+ self.port = port
+ self.baudrate = baudrate
+ self.uart = serial.Serial(port, baudrate, timeout=0.01)
+
+ def read(self, addr):
+ while True:
+ write_ascii(self.uart, 0x02)
+ write_ascii(self.uart, (addr>>8)&0xFF)
+ write_ascii(self.uart, (addr&0xFF))
+ write_ascii(self.uart, 0x00)
+ read = self.uart.read()
+ if len(read) == 1:
+ break
+ return read[0]
+
+ def write(self, addr, data):
+ write_ascii(self.uart, 0x01)
+ write_ascii(self.uart, (addr>>8)&0xFF)
+ write_ascii(self.uart, (addr&0xFF))
+ write_ascii(self.uart, data)
+
+def main():
+ csr = Uart2Spi(1,115200)
+ for i in range(100):
+ csr.write(0x0000,i)
+ print(csr.read(0x0000))
+
+if __name__ == '__main__':
+ main()
\ No newline at end of file