Bläddra i källkod

Add Button mailbox. Start implementing SW btn handling logic.

Signed-off-by: Jakub Duchniewicz <j.duchniewicz@gmail.com>
Jakub Duchniewicz 4 dagar sedan
förälder
incheckning
a09fa0b998

+ 36 - 0
projects/riscv_usb/fw/buttons.h

@@ -0,0 +1,36 @@
+// TODO: add copyright
+//
+//
+
+#include <stdint.h>
+
+#include "config.h"
+
+typedef struct {
+    uint32_t inc_f1;
+    uint32_t dec_f1;
+    uint32_t inc_d1;
+    uint32_t dec_d1;
+    uint32_t inc_d2;
+    uint32_t dec_d2;
+    uint32_t inc_ph2;
+    uint32_t dec_ph2;
+    uint32_t inc_f3;
+    uint32_t dec_f3;
+    uint32_t inc_d3;
+    uint32_t dec_d3;
+    uint32_t inc_ph3;
+    uint32_t dec_ph3;
+    uint32_t inc_n3;
+    uint32_t dec_n3;
+} button_regs_t __attribute__((packed,aligned(4)));
+
+typedef struct {
+    union {
+        uint32_t data[16];
+        button_regs_t regs;
+    };
+} wb_mailbox_button_regs_t __attribute__((packed,aligned(4)));
+
+// READONLY
+static volatile wb_mailbox_button_regs_t * const mailbox_button_regs = (void*)(MAILBOX_BUTTONS_BASE);

+ 5 - 4
projects/riscv_usb/fw/config.h

@@ -23,7 +23,8 @@
 
 #pragma once
 
-#define UART_BASE	 0x81000000
-#define SPI_BASE	 0x82000000
-#define LED_BASE	 0x83000000
-#define MAILBOX_BASE 0x84000000
+#define UART_BASE	         0x81000000
+#define SPI_BASE	         0x82000000
+#define LED_BASE	         0x83000000
+#define MAILBOX_REGS_BASE    0x84000000
+#define MAILBOX_BUTTONS_BASE 0x84000000

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

@@ -41,6 +41,18 @@ float kupa;
 
 static uint32_t copy_array[16];
 
+/* Timer fuction */
+static bool timer_expired()
+{
+
+}
+
+/* three signal generation params */
+static void update_three_signal_values()
+{
+
+}
+
 static void print_mailbox_contents()
 {
     int i = 0;
@@ -210,6 +222,10 @@ void main()
 	/* Main loop */
 	while (1)
 	{
+        /* Run the timer for button updates periodically */
+        if (timer_expired())
+            update_three_signal_values();
+
 		/* Prompt ? */
 		if (cmd >= 0)
 			printf("Command> ");

+ 9 - 2
projects/riscv_usb/fw/registers.h

@@ -16,7 +16,8 @@ typedef struct {
     uint32_t npuls3;
     uint32_t odd_train_flag;
     uint32_t ena_odd_out3;
-    uint64_t reserved;
+    uint32_t write_flash;
+    uint32_t reserved[4];
 } three_signal_regs_t __attribute__((packed,aligned(4)));
 
 typedef struct {
@@ -26,4 +27,10 @@ typedef struct {
     };
 } wb_mailbox_regs_t __attribute__((packed,aligned(4)));
 
-static volatile wb_mailbox_regs_t * const mailbox_regs = (void*)(MAILBOX_BASE);
+static volatile wb_mailbox_regs_t * const mailbox_regs = (void*)(MAILBOX_REGS_BASE);
+// TOOD: we need deafults somewhere
+//static const wb_mailbox_regs_t mailbox_defaults = {
+//    .regs = {
+//        .period1 = 10
+//    }
+//};

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

@@ -50,7 +50,7 @@ module top (
 );
 
 	localparam integer SPRAM_AW = 14; /* 14 => 64k, 15 => 128k */
-	localparam integer WB_N  =  5; // TODO: Reduce
+	localparam integer WB_N  =  6;
 
 	localparam integer WB_DW = 32;
 	localparam integer WB_AW = 16;
@@ -61,6 +61,8 @@ module top (
     localparam integer PULSE_COUNTER_WIDTH = 8;
     localparam integer SLOW_PWM_WIDTH = 14;
 
+    localparam integer BUTTON_COUNTER_WIDTH = 5;
+
 	genvar i;
 
 
@@ -97,9 +99,29 @@ module top (
     wire [PULSE_COUNTER_WIDTH-1:0] npuls3;
     wire [1:0] odd_train_flag;
     wire ena_odd_out3;
+    wire write_flash;
+
+    // Buttons
+    wire [BUTTON_COUNTER_WIDTH-1:0] inc_f1;
+    wire [BUTTON_COUNTER_WIDTH-1:0] dec_f1;
+    wire [BUTTON_COUNTER_WIDTH-1:0] inc_d1;
+    wire [BUTTON_COUNTER_WIDTH-1:0] dec_d1;
+    wire [BUTTON_COUNTER_WIDTH-1:0] inc_d2;
+    wire [BUTTON_COUNTER_WIDTH-1:0] dec_d2;
+    wire [BUTTON_COUNTER_WIDTH-1:0] inc_ph2;
+    wire [BUTTON_COUNTER_WIDTH-1:0] dec_ph2;
+    wire [BUTTON_COUNTER_WIDTH-1:0] inc_f3;
+    wire [BUTTON_COUNTER_WIDTH-1:0] dec_f3;
+    wire [BUTTON_COUNTER_WIDTH-1:0] inc_d3;
+    wire [BUTTON_COUNTER_WIDTH-1:0] dec_d3;
+    wire [BUTTON_COUNTER_WIDTH-1:0] inc_ph3;
+    wire [BUTTON_COUNTER_WIDTH-1:0] dec_ph3;
+    wire [BUTTON_COUNTER_WIDTH-1:0] inc_n3;
+    wire [BUTTON_COUNTER_WIDTH-1:0] dec_n3;
 
 	// Mailbox signal wires
     wire [16*16-1:0] mailbox_regs_flat;  // Flattened register array (16 registers of 16 bits each)
+    wire [16*16-1:0] mailbox_btns_flat;
 
 	// SoC
 	// ---
@@ -196,12 +218,12 @@ module top (
 		.rst        (rst)
 	);
 
-	// WB Mailbox [4]
+	// WB Register Mailbox [4]
 	// ----------
 	mailbox_wb #(
 		.AW(4),
 		.DW(WB_DW)
-	) mailbox_I (
+	) mailbox_regs_I (
 		.clk(clk_24m),
 		.rst(rst),
 		.wb_addr(wb_addr[3:0]),
@@ -225,6 +247,7 @@ module top (
     assign npuls3 = mailbox_regs_flat[127:112];      // Next 16 bits for npuls3
     assign odd_train_flag = mailbox_regs_flat[143:128]; // Next 16 bits for odd_train_flag
     assign ena_odd_out3 = mailbox_regs_flat[159:144]; // Next 16 bits for ena_odd_out3
+    assign write_flash = mailbox_regs_flat[175:160]; // Next 16 bits for write_flash (triggered from keyboard)
 
     three_signal #(
         .FAST_PWM_WIDTH(FAST_PWM_WIDTH),
@@ -248,6 +271,42 @@ module top (
         .Out3(out3)
     );
 
+	// WB Button Mailbox [5]
+	// ----------
+	mailbox_wb #(
+		.AW(4),
+		.DW(WB_DW)
+	) mailbox_btns_I (
+		.clk(clk_24m),
+		.rst(rst),
+		.wb_addr(wb_addr[3:0]),
+		.wb_wdata(wb_wdata),
+		.wb_rdata(wb_rdata[5]),
+		.wb_we(wb_we),
+		.wb_cyc(wb_cyc[5]),
+		.wb_ack(wb_ack[5]),
+		.registers_flat(mailbox_btns_flat)
+	);
+
+
+    // Buttons
+    assign inc_f1 = mailbox_btns_flat[15:0];
+    assign dec_f1 = mailbox_btns_flat[31:16];
+    assign inc_d1 = mailbox_btns_flat[47:32];
+    assign dec_d1 = mailbox_btns_flat[63:48];
+    assign inc_d2 = mailbox_btns_flat[79:64];
+    assign dec_d2 = mailbox_btns_flat[95:80];
+    assign inc_ph2 = mailbox_btns_flat[111:96];
+    assign dec_ph2 = mailbox_btns_flat[127:112];
+    assign inc_f3 = mailbox_btns_flat[143:128];
+    assign dec_f3 = mailbox_btns_flat[159:144];
+    assign inc_d3 = mailbox_btns_flat[175:160];
+    assign dec_d3 = mailbox_btns_flat[191:176];
+    assign inc_ph3 = mailbox_btns_flat[207:192];
+    assign dec_ph3 = mailbox_btns_flat[223:208];
+    assign inc_n3 = mailbox_btns_flat[239:224];
+    assign dec_n3 = mailbox_btns_flat[255:240];
+
 	reg [31:0] pcount; //dummy variable + usage to make sure button will not be optimized out
 
 	button b1(