Skip to content

Commit

Permalink
Merge branch 'master' into hid
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangfu committed Apr 16, 2012
2 parents 7696bf9 + a534e34 commit b5de0d0
Show file tree
Hide file tree
Showing 22 changed files with 206 additions and 108 deletions.
2 changes: 1 addition & 1 deletion boards/milkymist-one/rtl/system.v
Expand Up @@ -917,7 +917,7 @@ sysctl #(
.ninputs(7),
.noutputs(2),
.clk_freq(`CLOCK_FREQUENCY),
.systemid(32'h12004D31) /* 1.2.0 final (0) on M1 */
.systemid(32'h13004D31) /* 1.3.0 final (0) on M1 */
) sysctl (
.sys_clk(sys_clk),
.sys_rst(sys_rst),
Expand Down
13 changes: 10 additions & 3 deletions cores/softusb/rtl/softusb.v
Expand Up @@ -76,8 +76,11 @@ softusb_timer timer(
.io_do(io_dr_timer)
);

wire [pmem_width-1:0] dbg_pc;

softusb_hostif #(
.csr_addr(csr_addr)
.csr_addr(csr_addr),
.pmem_width(pmem_width)
) hostif (
.sys_clk(sys_clk),
.sys_rst(sys_rst),
Expand All @@ -93,7 +96,9 @@ softusb_hostif #(
.irq(irq),

.io_we(io_we),
.io_a(io_a)
.io_a(io_a),

.dbg_pc(dbg_pc)
);

softusb_sie sie(
Expand Down Expand Up @@ -178,7 +183,9 @@ softusb_navre #(
.io_we(io_we),
.io_a(io_a),
.io_do(io_dw),
.io_di(io_dr_sie|io_dr_timer)
.io_di(io_dr_sie|io_dr_timer),

.dbg_pc(dbg_pc)
);

endmodule
9 changes: 6 additions & 3 deletions cores/softusb/rtl/softusb_hostif.v
Expand Up @@ -16,7 +16,8 @@
*/

module softusb_hostif #(
parameter csr_addr = 4'h0
parameter csr_addr = 4'h0,
parameter pmem_width = 12
) (
input sys_clk,
input sys_rst,
Expand All @@ -32,7 +33,9 @@ module softusb_hostif #(
output irq,

input io_we,
input [5:0] io_a
input [5:0] io_a,

input [pmem_width-1:0] dbg_pc
);

wire csr_selected = csr_a[13:10] == csr_addr;
Expand All @@ -48,7 +51,7 @@ always @(posedge sys_clk) begin
if(csr_selected) begin
if(csr_we)
usb_rst0 <= csr_di[0];
csr_do <= usb_rst0;
csr_do <= { dbg_pc, 1'b0 };
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion cores/softusb/rtl/softusb_navre.v
Expand Up @@ -35,7 +35,9 @@ module softusb_navre #(
output reg io_we,
output [5:0] io_a,
output [7:0] io_do,
input [7:0] io_di
input [7:0] io_di,

output reg [pmem_width-1:0] dbg_pc
);

/* Register file */
Expand Down Expand Up @@ -195,6 +197,7 @@ always @(posedge clk) begin
PC_SEL_Z: PC <= pZ - 1;
endcase
end
dbg_pc <= PC;
end
reg pmem_selz;
assign pmem_a = rst ?
Expand Down
48 changes: 24 additions & 24 deletions cores/softusb/rtl/softusb_rx.v
Expand Up @@ -151,49 +151,49 @@ reg lastrx;
reg startrx;
always @(posedge usb_clk) begin
if(rxreset) begin
rx_active = 1'b0;
rx_valid = 1'b0;
rx_error = 1'b0;
rx_active <= 1'b0;
rx_valid <= 1'b0;
rx_error <= 1'b0;
end else begin
rx_valid = 1'b0;
rx_error = 1'b0;
rx_valid <= 1'b0;
rx_error <= 1'b0;
if(eop_detected)
rx_active = 1'b0;
rx_active <= 1'b0;
else if(dpll_ce) begin
if(rx_active & ~se0) begin
if(onecount == 3'd6) begin
/* skip stuffed bits */
onecount = 3'd0;
onecount <= 3'd0;
if((lastrx & rx_corrected)|(~lastrx & ~rx_corrected)) begin
/* no transition? bitstuff error */
rx_active = 1'b0;
rx_error = 1'b1;
rx_active <= 1'b0;
rx_error <= 1'b1;
end
lastrx = ~lastrx;
lastrx <= ~lastrx;
end else begin
if(rx_corrected) begin
rx_data = {lastrx, rx_data[7:1]};
rx_data <= {lastrx, rx_data[7:1]};
if(lastrx)
onecount = onecount + 3'd1;
onecount <= onecount + 3'd1;
else
onecount = 3'd0;
lastrx = 1'b1;
onecount <= 3'd0;
lastrx <= 1'b1;
end else begin
rx_data = {~lastrx, rx_data[7:1]};
rx_data <= {~lastrx, rx_data[7:1]};
if(~lastrx)
onecount = onecount + 3'd1;
onecount <= onecount + 3'd1;
else
onecount = 3'd0;
lastrx = 1'b0;
onecount <= 3'd0;
lastrx <= 1'b0;
end
rx_valid = bitcount == 3'd7;
bitcount = bitcount + 3'd1;
rx_valid <= bitcount == 3'd7;
bitcount <= bitcount + 3'd1;
end
end else if(startrx) begin
rx_active = 1'b1;
bitcount = 3'd0;
onecount = 3'd1;
lastrx = 1'b0;
rx_active <= 1'b1;
bitcount <= 3'd0;
onecount <= 3'd1;
lastrx <= 1'b0;
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions cores/softusb/rtl/softusb_timer.v
Expand Up @@ -33,12 +33,12 @@ always @(posedge usb_clk) begin
end else begin
io_do <= 32'd0;
case(io_a)
6'h11: io_do <= counter[7:0];
6'h12: io_do <= counter[15:8];
6'h13: io_do <= counter[23:16];
6'h14: io_do <= counter[31:24];
6'h20: io_do <= counter[7:0];
6'h21: io_do <= counter[15:8];
6'h22: io_do <= counter[23:16];
6'h23: io_do <= counter[31:24];
endcase
if(io_we & ((io_a == 6'h11)|(io_a == 6'h12)|(io_a == 6'h13)|(io_a == 6'h14)))
if(io_we & ((io_a == 6'h20)|(io_a == 6'h21)|(io_a == 6'h22)|(io_a == 6'h23)))
counter <= 32'd0;
else
counter <= counter + 32'd1;
Expand Down
15 changes: 12 additions & 3 deletions softusb-input/Makefile
@@ -1,10 +1,16 @@
SOURCES=crt0.S main.c debug.c crc.c libc.c
INCLUDES=comloc.h crc.h debug.h host.h io.h libc.h progmem.h sie.h timer.h

all: softusb-input.h
.PHONY: all install upload clean

all: softusb-input.h

softusb-input.elf: $(SOURCES) $(INCLUDES)
avr-gcc -o $@ -mmcu=avr2 -mno-interrupts -Wall -Os $(SOURCES) $(CFLAGS) -nostdlib -Wl,-T -Wl,navre.ld
avr-gcc -o $@ -mmcu=avr2 -mno-interrupts -Os \
-Wall -Wstrict-prototypes -Wmissing-prototypes \
-Wold-style-declaration -Wold-style-definition \
-Wno-char-subscripts \
$(SOURCES) $(CFLAGS) -nostdlib -Wl,-T -Wl,navre.ld

%.bin: %.elf
avr-objcopy -O binary $< $@
Expand All @@ -17,7 +23,10 @@ install: softusb-input.h
mkdir -p $(RTEMS_MAKEFILE_PATH)/lib/include
cp $< $(RTEMS_MAKEFILE_PATH)/lib/include

.PHONY: clean
upload: softusb-input.bin
@[ "$(MM_HOST)" ] && [ "$(MM_USER)" ] && [ "$(MM_PW)" ] || \
{ echo "please define MM_HOST, MM_USER, and MM_PW"; exit 1; }
ftp-upload --host $(MM_HOST) --user $(MM_USER) --password $(MM_PW) $<

clean:
rm -f softusb-input.elf softusb-input.bin softusb-input.h
5 changes: 2 additions & 3 deletions softusb-input/debug.c
Expand Up @@ -18,6 +18,7 @@
#include "progmem.h"
#include "host.h"
#include "comloc.h"
#include "debug.h"

void print_char(char c)
{
Expand Down Expand Up @@ -59,13 +60,11 @@ void dump_hex(unsigned char *buf, unsigned char len)
} else {
for(i=0;i<len;i++) {
print_hex(buf[i]);
if(((i & 0x0f) == 0) && (i != 0))
if((i & 0x0f) == 0xf)
print_char('\n');
else
print_char(' ');
}
if(i & 0x0f)
print_char('\n');
}
}

Expand Down

0 comments on commit b5de0d0

Please sign in to comment.