MIDI origin/HEAD origin/master
authorlekernel <sebastien.bourdeauducq@lekernel.net>
Sat, 3 Jul 2010 16:50:59 +0000 (18:50 +0200)
committerlekernel <sebastien.bourdeauducq@lekernel.net>
Sat, 3 Jul 2010 16:50:59 +0000 (18:50 +0200)
boards/milkymist-one/rtl/setup.v
boards/milkymist-one/rtl/system.v
software/demo/Makefile
software/demo/shell.c
software/include/hw/interrupts.h
software/include/hw/midi.h [new file with mode: 0644]

index 76ae147..6e849e4 100644 (file)
@@ -28,7 +28,7 @@
 `define ENABLE_ETHERNET
 `define ENABLE_FMLMETER
 //`define ENABLE_VIDEOIN
-//`define ENABLE_MIDI
+`define ENABLE_MIDI
 //`define ENABLE_DMX
 `define ENABLE_IR
 //`define ENABLE_USB
index 86079ef..0f5effe 100644 (file)
@@ -468,7 +468,8 @@ wire [31:0] csr_dr_uart,
                csr_dr_ethernet,
                csr_dr_fmlmeter,
                csr_dr_videoin,
-               csr_dr_ir;
+               csr_dr_ir,
+               csr_dr_midi;
 
 //------------------------------------------------------------------
 // FML master wires
@@ -622,6 +623,7 @@ csrbrg csrbrg(
                |csr_dr_fmlmeter
                |csr_dr_videoin
                |csr_dr_ir
+               |csr_dr_midi
        )
 );
 
@@ -683,7 +685,9 @@ wire videoin_irq;
 wire ir_irq;
 
 wire [31:0] cpu_interrupt;
-assign cpu_interrupt = {17'd0,
+assign cpu_interrupt = {15'd0,
+       miditx_irq,
+       midirx_irq,
        ir_irq,
        videoin_irq,
        ethernettx_irq,
@@ -1217,9 +1221,31 @@ assign videoin_sdc = 1'b0;
 // MIDI
 //---------------------------------------------------------------------------
 `ifdef ENABLE_MIDI
-// TODO
+wire midi_tx_n;
+uart #(
+       .csr_addr(4'hd),
+       .clk_freq(`CLOCK_FREQUENCY),
+       .baud(31250)
+) midi (
+       .sys_clk(sys_clk),
+       .sys_rst(sys_rst),
+
+       .csr_a(csr_a),
+       .csr_we(csr_we),
+       .csr_di(csr_dw),
+       .csr_do(csr_dr_midi),
+
+       .rx_irq(midirx_irq),
+       .tx_irq(miditx_irq),
+
+       .uart_rxd(midi_rx),
+       .uart_txd(midi_tx)
+);
 `else
-assign midi_tx = 1'b0;
+assign csr_dr_midi = 32'd0;
+assign midirx_irq = 1'b0;
+assign miditx_irq = 1'b0;
+assign midi_tx = 1'b1;
 `endif
 
 //---------------------------------------------------------------------------
index 509e7ef..2fcfc93 100644 (file)
@@ -92,7 +92,8 @@ memstats.o: ../../software/include/hw/common.h
 osd.o: ../../software/include/hal/vga.h ../../software/include/hal/tmu.h
 osd.o: ../../software/include/hw/tmu.h ../../software/include/hw/common.h
 osd.o: ../../software/include/hw/sysctl.h ../../software/include/hw/gpio.h
-osd.o: ../../software/include/base/math.h
+osd.o: ../../software/include/hw/rc5.h ../../software/include/hw/interrupts.h
+osd.o: ../../software/include/base/irq.h ../../software/include/base/math.h
 osd.o: ../../software/include/base/system.h
 osd.o: ../../software/include/base/string.h
 osd.o: ../../software/include/base/stdlib.h
@@ -132,12 +133,12 @@ shell.o: ../../software/include/hw/common.h ../../software/include/hw/tmu.h
 shell.o: ../../software/include/hw/sysctl.h ../../software/include/hw/gpio.h
 shell.o: ../../software/include/hw/interrupts.h
 shell.o: ../../software/include/hw/minimac.h
-shell.o: ../../software/include/hw/bt656cap.h
-shell.o: ../../software/include/hal/vga.h ../../software/include/hal/snd.h
-shell.o: ../../software/include/hw/ac97.h ../../software/include/hal/tmu.h
-shell.o: ../../software/include/hal/time.h ../../software/include/hal/brd.h
-shell.o: ../../software/include/hal/vin.h line.h wave.h rpipe.h cpustats.h
-shell.o: memstats.h shell.h renderer.h
+shell.o: ../../software/include/hw/bt656cap.h ../../software/include/hw/rc5.h
+shell.o: ../../software/include/hw/midi.h ../../software/include/hal/vga.h
+shell.o: ../../software/include/hal/snd.h ../../software/include/hw/ac97.h
+shell.o: ../../software/include/hal/tmu.h ../../software/include/hal/time.h
+shell.o: ../../software/include/hal/brd.h ../../software/include/hal/vin.h
+shell.o: line.h wave.h rpipe.h cpustats.h memstats.h shell.h renderer.h
 tick.o: ../../software/include/hal/time.h rpipe.h
 tick.o: ../../software/include/hal/tmu.h ../../software/include/hw/tmu.h
 tick.o: ../../software/include/hw/common.h cpustats.h memstats.h
index 6fff87a..5e0002d 100644 (file)
@@ -34,6 +34,7 @@
 #include <hw/minimac.h>
 #include <hw/bt656cap.h>
 #include <hw/rc5.h>
+#include <hw/midi.h>
 
 #include <hal/vga.h>
 #include <hal/snd.h>
@@ -626,6 +627,52 @@ static void irtest()
        }
 }
 
+static void midiprint()
+{
+       unsigned int r;
+       if(irq_pending() & IRQ_MIDIRX) {
+               r = CSR_MIDI_RXTX;
+               irq_ack(IRQ_MIDIRX);
+               printf("RX: %02x\n", r);
+       }
+}
+
+static void midirx()
+{
+       irq_ack(IRQ_MIDIRX);
+       while(!readchar_nonblock()) midiprint();
+}
+
+static void midisend(int c)
+{
+       printf("TX: %02x\n", c);
+       CSR_MIDI_RXTX = c;
+       while(!(irq_pending() & IRQ_MIDITX));
+       printf("TX done\n");
+       irq_ack(IRQ_MIDITX);
+       midiprint();
+}
+
+static void miditx(char *note)
+{
+       int note2;
+       char *c;
+       
+       if(*note == 0) {
+               printf("miditx <note>\n");
+               return;
+       }
+       note2 = (unsigned *)strtoul(note, &c, 0);
+       if(*c != 0) {
+               printf("incorrect note\n");
+               return;
+       }
+       
+       //midisend(0x90);
+       midisend(note2);
+       //midisend(0x22);
+}
+
 static char *get_token(char **str)
 {
        char *c, *d;
@@ -686,6 +733,8 @@ static void do_command(char *c)
                else if(strcmp(command, "readv") == 0) readv(param1);
                else if(strcmp(command, "writev") == 0) writev(param1, param2);
                else if(strcmp(command, "irtest") == 0) irtest();
+               else if(strcmp(command, "midirx") == 0) midirx();
+               else if(strcmp(command, "miditx") == 0) miditx(param1);
 
                else if(strcmp(command, "") != 0) printf("Command not found: '%s'\n", command);
        }
index bfd6ab6..0a492c3 100644 (file)
@@ -33,5 +33,7 @@
 #define IRQ_ETHTX              (0x00001000) /* 14 */
 #define IRQ_VIDEOIN            (0x00002000) /* 15 */
 #define IRQ_IR                 (0x00004000) /* 16 */
+#define IRQ_MIDIRX             (0x00008000) /* 17 */
+#define IRQ_MIDITX             (0x00010000) /* 18 */
 
 #endif /* __HW_INTERRUPTS_H */
diff --git a/software/include/hw/midi.h b/software/include/hw/midi.h
new file mode 100644 (file)
index 0000000..6faee8d
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HW_MIDI_H
+#define __HW_MIDI_H
+
+#include <hw/common.h>
+
+#define CSR_MIDI_RXTX          MMPTR(0x8000d000)
+#define CSR_MIDI_DIVISOR       MMPTR(0x8000d004)
+
+#endif /* __HW_MIDI_H */