Как получить доступ к входу переключателя в коде сборки - PullRequest
0 голосов
/ 19 мая 2019

Я делаю домашнее задание в школе, это проект, который отображает рисунок змеи на светодиодах платы FPGA, и мы должны заполнить код процессора MIPS (аппаратная часть) и код сборки (программная часть).
Одна частьВ проекте добавлен переключатель, который будет контролировать направление движения змеи.Например, змея движется вперед, если переключатель равен 0, и назад, когда переключатель равен 1.

В руководстве сказано: «Это более сложная задача из-за ограниченного числа инструкций, которые могут быть выполнены в нашем процессоре MIPS. Вам также нужно будет изменить иерархию верхнего уровня, чтобы добавить регистр для передачи значения этого нового переключателя. '

###   I/O addresses Reference
###  compatible to the compact modelling
###  0x00007FF0   LED output

#0x001e8484 original delay
.data
pattern: .word 0x00200000,0x00004000,0x00000080,0x00000001,0x00000002,0x00000004,0x00000008,0x00000400,0x00020000,0x01000000,0x02000000,0x04000000
loopcnt: .word 1200000

.text
   lw $t3, loopcnt    # initialize a  large loopcounter (so that the snake does not crawl SUPERFAST)
   addi $t5,$0,48       # initialize the length of the display pattern (in bytes)

restart:   
   addi $t4,$0,0

forward:
   beq $t5,$t4, restart
   lw $t0,0($t4)
   sw  $t0, 0x7ff0($0) # send the value to the display

   addi $t4, $t4, 4 # increment to the next address
   addi $t2, $0, 0 # clear $t2 counter
   lw $t6, 0x7ff4($0)
   addi $t6, $t6, 1

wait:
   beq $t2,$t3,forward  
   add  $t2, $t2, $t6     # increment counter
   j wait

Выше приведен ассемблерный код. Моя идея состоит в том, что, когда switch равен 1 (snake backward), мы уменьшаем до предыдущего адреса, то есть addi $ t4, $ t4, -4.
Но я запутался, как получить доступ к значению switch , именно то, что было сказано в руководстве 'Вам также нужно будет изменить иерархию верхнего уровня, чтобы добавить регистр для передачи значения этогоновый выключатель.Какие дополнительные аппаратные / архитектурные изменения необходимы в верхнем модуле (файл top.v) для реализации этого ' Я не знаю, как это сделать, к какой части должен подключиться этот регистр, чтобы я мог получить к нему доступ в своей сборкекод?

module top(
           input            FPGACLK,
           // TODO PART II for Lab 8           
           // add input port to read the switch value for speed control of the snake
           input [1:0]      SWITCHES,
           input            RESET,
           output [6:0]     LED,
           output reg [3:0] AN
           );

   // Define internal signals
   wire                     CLK;                 // The output of the clock divider 10 MHz Clock

   // MIPS interface
   wire [31:0]              IOWriteData;
   wire [3:0]               IOAddr;
   wire                     IOWriteEn;
   wire [31:0]              IOReadData;
   // Signals for driving the LED, note all are 'reg'
   reg [27:0]               DispReg;        // Register that holds the number
   reg [6:0]                DispDigit;      // Present 4bit value to drive the 
   reg [15:0]               DispCount;     // Simple counter to go through all options
   // The counter is large to allow enough time
   // for each LED to fully light up. 
   // we could probably increase it a bit further

   // Signals for composing the input
   wire [1:0]               IOin;           // output of the multiplexer


   // Instantiate an internal clock divider that will 
   // take the 50 MHz FPGA clock and divide it by 5 so that
   // We will have a simple 10 MHz clock internally
   clockdiv ClockDiv (
                      .clk(FPGACLK), 
                      .rst(RESET), 
                      .clk_en(CLK)
                      );

   // Counter for the display refresh
   always @ (posedge CLK, posedge RESET)
     if (RESET) DispCount = 0;
     else       DispCount = DispCount + 1;

   // Simple Way to determine the outputs, use a combinational process
   // Use the MSB of the Disp count so that each digit lights up for
   // 1.6ms  == 65536/4 * 100ns
   always @ ( * )  // combinational process
     begin
        case (DispCount[15:14])
          2'b00:   begin AN = 4'b1110; DispDigit = DispReg[6:0];  end   // LSB
          2'b01:   begin AN = 4'b1101; DispDigit = DispReg[13:7];  end   // 2nd digit
          2'b10:   begin AN = 4'b1011; DispDigit = DispReg[20:14]; end   // 3rd digit
          2'b11:   begin AN = 4'b0111; DispDigit = DispReg[27:21];end   // MSB, default
        endcase  
     end

   // Instantiate the 7segment Display Driver
   // led_driver sevendriver ( .S(DispDigit), .D(LED) );  // Instantiate the driver
   assign LED = ~DispDigit;


   // TODO for Part II of Lab 8
   // The speed of the snake must be read as input and sent to the MIPS processor.
   // Create the 32 bit IOReadData based on IOAddr value. Remember IOAddr is a 4-bit
   // value.

   //assign IOReadData = (IOAddr == 1'h4)? {{30{1'b0}}, SWITCHES} : 32'h0;
   // For some reason the above check never succeeds even though it should.
   // Therefore we just assign it directly always, which works fine in our specific case.
   assign IOReadData = {{30{1'b0}}, SWITCHES};

   // Register to save the 28-bit Value
   always @ (posedge CLK, posedge RESET)
     if      (RESET)     DispReg = 28'h0;          // Funny default value 
     else if (IOWriteEn)                              // Only when IOWrite 
       DispReg = IOWriteData[27:0];           // only the lower half


   // Instantiate the processor
   MIPS processor (
                   .CLK(CLK), 
                   .RESET(RESET), 
                   .IOWriteData(IOWriteData), 
                   .IOAddr(IOAddr), 
                   .IOWriteEn(IOWriteEn), 
                   .IOReadData(IOReadData)
                   );



endmodule
...