Exemplo n.º 1
0
 def test_writescanline(self):
     host = self.host
     yield from host.writeline([1] * host.laser_params['BITSINSCANLINE'])
     while (yield self.dut.empty) == 1:
         yield
     wordslaser = wordsinscanline(params(self.platform)['BITSINSCANLINE'])
     yield from self.instruction_ready(wordslaser)
Exemplo n.º 2
0
 def __init__(self, platform=None):
     if platform is None:
         from gpiozero import LED
         import spidev
         from smbus2 import SMBus
         self.platform = Firestarter()
         # IC bus used to set power laser
         self.bus = SMBus(self.platform.ic_dev_nr)
         # SPI to sent data to scanner
         self.spi = spidev.SpiDev()
         self.spi.open(0, 0)
         self.spi.mode = 1
         self.spi.max_speed_hz = round(1E6)
         self.chip_select = LED(8)
         self.init_steppers()
         self.enable = LED(self.platform.enable_pin)
         # TODO: generator syntax is no longer needed!
         self.generator = False
     else:
         self.platform = platform
         self.generator = True
     self.laser_params = lasers.params(self.platform)
     self._position = np.array([0] * self.platform.motors)
Exemplo n.º 3
0
 def elaborate(self, platform):
     m = Module()
     if platform and self.top:
         board_spi = platform.request("debug_spi")
         spi2 = synchronize(m, board_spi)
         m.d.comb += self.spi.connect(spi2)
     if self.platform:
         platform = self.platform
     spi = self.spi
     interf = SPICommandInterface(command_size=COMMAND_BYTES*8,
                                  word_size=WORD_BYTES*8)
     m.d.comb += interf.spi.connect(spi)
     m.submodules.interf = interf
     # FIFO connection
     fifo = TransactionalizedFIFO(width=MEMWIDTH,
                                  depth=platform.memdepth)
     if platform.name == 'Test':
         self.fifo = fifo
     m.submodules.fifo = fifo
     m.d.comb += [self.read_data.eq(fifo.read_data),
                  fifo.read_commit.eq(self.read_commit),
                  fifo.read_discard.eq(self.read_discard),
                  fifo.read_en.eq(self.read_en),
                  self.empty.eq(fifo.empty)]
     # Parser
     mtrcntr = Signal(range(platform.motors))
     wordsreceived = Signal(range(wordsinmove(platform.motors)+1))
     error = Signal()
     # Peripheral state
     state = Signal(8)
     m.d.sync += [state[STATE.PARSING].eq(self.execute),
                  state[STATE.FULL].eq(fifo.space_available <= 1),
                  state[STATE.ERROR].eq(self.dispatcherror | error)]
     # remember which word we are processing
     instruction = Signal(8)
     with m.FSM(reset='RESET', name='parser'):
         with m.State('RESET'):
             m.d.sync += [self.execute.eq(1), wordsreceived.eq(0),
                          error.eq(0)]
             m.next = 'WAIT_COMMAND'
         with m.State('WAIT_COMMAND'):
             with m.If(interf.command_ready):
                 word = Cat(state[::-1], self.pinstate[::-1])
                 with m.If(interf.command == COMMANDS.EMPTY):
                     m.next = 'WAIT_COMMAND'
                 with m.Elif(interf.command == COMMANDS.START):
                     m.next = 'WAIT_COMMAND'
                     m.d.sync += self.execute.eq(1)
                 with m.Elif(interf.command == COMMANDS.STOP):
                     m.next = 'WAIT_COMMAND'
                     m.d.sync += self.execute.eq(0)
                 with m.Elif(interf.command == COMMANDS.WRITE):
                     m.d.sync += interf.word_to_send.eq(word)
                     with m.If(state[STATE.FULL] == 0):
                         m.next = 'WAIT_WORD'
                     with m.Else():
                         m.next = 'WAIT_COMMAND'
                 with m.Elif(interf.command == COMMANDS.READ):
                     m.d.sync += interf.word_to_send.eq(word)
                     m.next = 'WAIT_COMMAND'
                 with m.Elif(interf.command == COMMANDS.POSITION):
                     # position is requested multiple times for multiple
                     # motors
                     with m.If(mtrcntr < platform.motors-1):
                         m.d.sync += mtrcntr.eq(mtrcntr+1)
                     with m.Else():
                         m.d.sync += mtrcntr.eq(0)
                     m.d.sync += interf.word_to_send.eq(
                                             self.position[mtrcntr])
                     m.next = 'WAIT_COMMAND'
         with m.State('WAIT_WORD'):
             with m.If(interf.word_complete):
                 byte0 = interf.word_received[:8]
                 with m.If(wordsreceived == 0):
                     with m.If((byte0 > 0) & (byte0 < 6)):
                         m.d.sync += [instruction.eq(byte0),
                                      fifo.write_en.eq(1),
                                      wordsreceived.eq(wordsreceived+1),
                                      fifo.write_data.eq(
                                          interf.word_received)]
                         m.next = 'WRITE'
                     with m.Else():
                         m.d.sync += error.eq(1)
                         m.next = 'WAIT_COMMAND'
                 with m.Else():
                     m.d.sync += [fifo.write_en.eq(1),
                                  wordsreceived.eq(wordsreceived+1),
                                  fifo.write_data.eq(interf.word_received)]
                     m.next = 'WRITE'
         with m.State('WRITE'):
             m.d.sync += fifo.write_en.eq(0)
             wordslaser = wordsinscanline(
                 params(platform)['BITSINSCANLINE'])
             wordsmotor = wordsinmove(platform.motors)
             with m.If(((instruction == INSTRUCTIONS.MOVE) &
                       (wordsreceived >= wordsmotor))
                       | (instruction == INSTRUCTIONS.WRITEPIN)
                       | (instruction == INSTRUCTIONS.LASTSCANLINE)
                       | ((instruction == INSTRUCTIONS.SCANLINE) &
                       (wordsreceived >= wordslaser)
                       )):
                 m.d.sync += [wordsreceived.eq(0),
                              fifo.write_commit.eq(1)]
                 m.next = 'COMMIT'
             with m.Else():
                 m.next = 'WAIT_COMMAND'
         with m.State('COMMIT'):
             m.d.sync += fifo.write_commit.eq(0)
             m.next = 'WAIT_COMMAND'
     return m