فهرست منبع

Add ability to flash LEDs over Wishbone on RTL side.

Signed-off-by: Jakub Duchniewicz <j.duchniewicz@gmail.com>
Jakub Duchniewicz 3 هفته پیش
والد
کامیت
561a0dfbd0

+ 2 - 0
projects/riscv_usb/fw/Makefile

@@ -19,6 +19,7 @@ HEADERS_common=\
 	mini-printf.h \
 	spi.h \
 	utils.h \
+	registers.h \
 	$(HEADERS_no2usb)
 
 SOURCES_common=\
@@ -28,6 +29,7 @@ SOURCES_common=\
 	mini-printf.c  \
 	spi.c \
 	utils.c \
+	registers.c \
 	$(SOURCES_no2usb)
 
 HEADERS_app=\

+ 1 - 0
projects/riscv_usb/fw/config.h

@@ -28,3 +28,4 @@
 #define LED_BASE	0x83000000
 #define USB_CORE_BASE	0x84000000
 #define USB_DATA_BASE	0x85000000
+#define MAILBOX_BASE 0x86000000

+ 34 - 0
projects/riscv_usb/fw/fw_app.c

@@ -32,6 +32,7 @@
 #include <no2usb/usb.h>
 #include <no2usb/usb_dfu_rt.h>
 #include "utils.h"
+#include "registers.h"
 
 
 extern const struct usb_stack_descriptors app_stack_desc;
@@ -49,6 +50,9 @@ serial_no_init()
 	flash_unique_id(buf);
 	printf("Flash Unique ID    : %s\n", hexstr(buf, 8, true));
 
+    // Print Mailbox contents just to be sure */
+    printf("Mailbox period1: %d\n", mailbox_regs->regs.period1);
+
 	/* Overwrite descriptor string */
 		/* In theory in rodata ... but nothing is ro here */
 	id = hexstr(buf, 8, false);
@@ -57,6 +61,27 @@ serial_no_init()
 		desc[2 + (i << 1)] = id[i];
 }
 
+static void write_period1()
+{
+    printf("Writing period1 0x1\n");
+    mailbox_regs->regs.period1 = 0x1;
+    printf("Done writing\n");
+}
+
+static void write_period1_2()
+{
+    printf("Writing period1 0x2\n");
+    mailbox_regs->regs.period1 = 0x2;
+    printf("Done writing\n");
+}
+
+static void clear_period1()
+{
+    printf("Clearing period1 current val: %d\n", mailbox_regs->regs.period1);
+    mailbox_regs->regs.period1 = 0x0;
+    printf("Done clearing\n");
+}
+
 static void
 boot_dfu(void)
 {
@@ -128,6 +153,15 @@ void main()
 			case 'd':
 				usb_disconnect();
 				break;
+            case 'w':
+                write_period1();
+                break;
+            case 'k':
+                clear_period1();
+                break;
+            case 'a':
+                write_period1_2();
+                break;
 			default:
 				break;
 			}

+ 4 - 0
projects/riscv_usb/fw/registers.c

@@ -0,0 +1,4 @@
+
+#pragma once
+
+#include "registers.h"

+ 29 - 0
projects/riscv_usb/fw/registers.h

@@ -0,0 +1,29 @@
+// TODO: add copyright
+//
+//
+
+#include <stdint.h>
+
+#include "config.h"
+
+typedef struct {
+    uint16_t period1;
+    uint16_t delay1;
+    uint16_t duty2;
+    uint16_t delay2;
+    uint16_t duty3;
+    uint16_t delay3;
+    uint16_t npuls3;
+    uint16_t odd_train_flag;
+    uint16_t ena_odd_out3;
+    uint64_t reserved;
+} three_signal_regs_t __attribute__((packed,aligned(4)));
+
+typedef struct {
+    union {
+        uint16_t data[16];
+        three_signal_regs_t regs;
+    };
+} wb_mailbox_regs_t __attribute__((packed,aligned(4)));
+
+static volatile wb_mailbox_regs_t * const mailbox_regs = (void*)(MAILBOX_BASE);

+ 19 - 3
projects/riscv_usb/rtl/top.v

@@ -99,7 +99,7 @@ module top (
     wire ena_odd_out3;
 
 	// Mailbox signal wires
-    wire [16*16-1:0] mailbox_regs_flat;  // Flattened register array (16 registers of 16 bits each)
+    wire [16*WB_DW-1:0] mailbox_regs_flat;  // Flattened register array (16 registers of 16 bits each)
 
 	// SoC
 	// ---
@@ -223,7 +223,7 @@ module top (
 	// ----------
 	mailbox_wb #(
 		.AW(4),
-		.DW(16)
+		.DW(32)
 	) mailbox_I (
 		.clk(clk_48m),
 		.rst(rst),
@@ -238,7 +238,7 @@ module top (
 
     // 3 Signal
     // --------
-    //assign period1 = mailbox_regs[0];
+    assign period1 = mailbox_regs_flat[15:0];
 	// TODO: rest of assignments
     //wire [SLOW_PWM_WIDTH-1:0] delay1;
     //wire [SLOW_PWM_WIDTH-1:0] duty2;
@@ -272,6 +272,22 @@ module top (
         .Out3(out3)
     );
 
+    // TODO: dummy led onoff when value has been written
+    always @(posedge clk_48m or posedge rst)
+        if (rst) begin
+            led[0] = 1'b0;
+            led[1] = 1'b0;
+        end else if (period1 == 1) begin
+            led[0] = 1'b1;
+            led[1] = 1'b0;
+        end else if (period1 == 2) begin
+            led[0] = 1'b0;
+            led[1] = 1'b1;
+        end else begin
+            led[0] = 1'b0;
+            led[1] = 1'b0;
+        end
+
 	// Warm Boot
 	// ---------