Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 7 files changed
  • 0 comments
  • 1 contributor
4  software/bios/main.c
@@ -498,13 +498,13 @@ static void boot_sequence(void)
498 498
 {
499 499
 	if(test_user_abort()) {
500 500
 		if(rescue) {
501  
-			netboot();
502 501
 			serialboot();
  502
+			netboot();
503 503
 			flashboot();
504 504
 		} else {
505 505
 			flashboot();
506  
-			netboot();
507 506
 			serialboot();
  507
+			netboot();
508 508
 		}
509 509
 		printf("No boot medium found\n");
510 510
 	}
35  software/include/hw/dvisampler.h
... ...
@@ -0,0 +1,35 @@
  1
+#ifndef __HW_DVISAMPLER_H
  2
+#define __HW_DVISAMPLER_H
  3
+
  4
+#include <hw/common.h>
  5
+#include <csrbase.h>
  6
+
  7
+#define DVISAMPLER0_CSR(x)		MMPTR(DVISAMPLER0_BASE+(x))
  8
+
  9
+#define CSR_DVISAMPLER0_PLL_RESET	DVISAMPLER0_CSR(0x00)
  10
+#define CSR_DVISAMPLER0_PLL_LOCKED	DVISAMPLER0_CSR(0x04)
  11
+
  12
+#define CSR_DVISAMPLER0_D0_DELAY_CTL	DVISAMPLER0_CSR(0x08)
  13
+#define CSR_DVISAMPLER0_D0_DELAY_BUSY	DVISAMPLER0_CSR(0x0C)
  14
+#define CSR_DVISAMPLER0_D0_PHASE	DVISAMPLER0_CSR(0x10)
  15
+#define CSR_DVISAMPLER0_D0_PHASE_RESET	DVISAMPLER0_CSR(0x14)
  16
+
  17
+#define CSR_DVISAMPLER0_D1_DELAY_CTL	DVISAMPLER0_CSR(0x18)
  18
+#define CSR_DVISAMPLER0_D1_DELAY_BUSY	DVISAMPLER0_CSR(0x1C)
  19
+#define CSR_DVISAMPLER0_D1_PHASE	DVISAMPLER0_CSR(0x20)
  20
+#define CSR_DVISAMPLER0_D1_PHASE_RESET	DVISAMPLER0_CSR(0x24)
  21
+
  22
+#define CSR_DVISAMPLER0_D2_DELAY_CTL	DVISAMPLER0_CSR(0x28)
  23
+#define CSR_DVISAMPLER0_D2_DELAY_BUSY	DVISAMPLER0_CSR(0x2C)
  24
+#define CSR_DVISAMPLER0_D2_PHASE	DVISAMPLER0_CSR(0x30)
  25
+#define CSR_DVISAMPLER0_D2_PHASE_RESET	DVISAMPLER0_CSR(0x34)
  26
+
  27
+#define DVISAMPLER_DELAY_CAL		0x01
  28
+#define DVISAMPLER_DELAY_RST		0x02
  29
+#define DVISAMPLER_DELAY_INC		0x04
  30
+#define DVISAMPLER_DELAY_DEC		0x08
  31
+
  32
+#define DVISAMPLER_TOO_LATE		0x01
  33
+#define DVISAMPLER_TOO_EARLY		0x02
  34
+
  35
+#endif /* __HW_DVISAMPLER_H */
44  software/videomixer/Makefile
... ...
@@ -0,0 +1,44 @@
  1
+M2DIR=../..
  2
+include $(M2DIR)/software/common.mak
  3
+
  4
+OBJECTS=crt0.o isr.o main.o
  5
+
  6
+all: videomixer.bin
  7
+
  8
+# pull in dependency info for *existing* .o files
  9
+-include $(OBJECTS:.o=.d)
  10
+
  11
+%.bin: %.elf
  12
+	$(OBJCOPY) -O binary $< $@
  13
+	chmod -x $@
  14
+
  15
+videomixer.elf: linker.ld $(OBJECTS) libs
  16
+
  17
+%.elf:
  18
+	$(LD) $(LDFLAGS) -T $< -N -o $@ $(OBJECTS) \
  19
+		-L$(M2DIR)/software/libbase \
  20
+		-L$(M2DIR)/software/libcompiler-rt \
  21
+		-lbase -lcompiler-rt
  22
+	chmod -x $@
  23
+
  24
+main.o: main.c
  25
+	$(compile-dep)
  26
+
  27
+%.o: %.c
  28
+	$(compile-dep)
  29
+
  30
+%.o: %.S
  31
+	$(assemble)
  32
+
  33
+libs:
  34
+	make -C $(M2DIR)/software/libcompiler-rt
  35
+	make -C $(M2DIR)/software/libbase
  36
+
  37
+load: videomixer.bin
  38
+	make -C $(M2DIR)/tools
  39
+	$(M2DIR)/tools/flterm --port /dev/ttyUSB0 --kernel videomixer.bin
  40
+
  41
+clean:
  42
+	rm -f $(OBJECTS) $(OBJECTS:.o=.d) videomixer.elf videomixer.bin .*~ *~
  43
+
  44
+.PHONY: main.o clean libs load
167  software/videomixer/crt0.S
... ...
@@ -0,0 +1,167 @@
  1
+/*
  2
+ * LatticeMico32 C startup code.
  3
+ *
  4
+ * Redistribution and use in source and binary forms, with or without
  5
+ * modification, are permitted provided that the following conditions
  6
+ * are met:
  7
+ * 1. Redistributions of source code must retain the above copyright
  8
+ * notice, this list of conditions and the following disclaimer.
  9
+ * 2. Redistributions in binary form must reproduce the above copyright
  10
+ * notice, this list of conditions and the following disclaimer in the
  11
+ * documentation and/or other materials provided with the distribution.
  12
+ *
  13
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  14
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  17
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  19
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  20
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  23
+ * SUCH DAMAGE.
  24
+ */
  25
+
  26
+/* Exception handlers - Must be 32 bytes long. */
  27
+.section    .text, "ax", @progbits
  28
+.global     _start
  29
+_start:
  30
+_reset_handler:
  31
+	xor	r0, r0, r0
  32
+	wcsr	IE, r0
  33
+	mvhi	r1, hi(_reset_handler)
  34
+	ori	r1, r1, lo(_reset_handler)
  35
+	wcsr	EBA, r1
  36
+	bi	_crt0
  37
+	nop
  38
+	nop
  39
+
  40
+_breakpoint_handler:
  41
+	bi _breakpoint_handler
  42
+	nop
  43
+	nop
  44
+	nop
  45
+	nop
  46
+	nop
  47
+	nop
  48
+	nop
  49
+
  50
+_instruction_bus_error_handler:
  51
+	bi _instruction_bus_error_handler
  52
+	nop
  53
+	nop
  54
+	nop
  55
+	nop
  56
+	nop
  57
+	nop
  58
+	nop
  59
+
  60
+_watchpoint_hander:
  61
+	bi _watchpoint_hander
  62
+	nop
  63
+	nop
  64
+	nop
  65
+	nop
  66
+	nop
  67
+	nop
  68
+	nop
  69
+
  70
+_data_bus_error_handler:
  71
+	bi _data_bus_error_handler
  72
+	nop
  73
+	nop
  74
+	nop
  75
+	nop
  76
+	nop
  77
+	nop
  78
+	nop
  79
+
  80
+_divide_by_zero_handler:
  81
+	bi _divide_by_zero_handler
  82
+	nop
  83
+	nop
  84
+	nop
  85
+	nop
  86
+	nop
  87
+	nop
  88
+	nop
  89
+
  90
+_interrupt_handler:
  91
+	sw      (sp+0), ra
  92
+	calli   .save_all
  93
+	calli   isr
  94
+	bi      .restore_all_and_eret
  95
+	nop
  96
+	nop
  97
+	nop
  98
+	nop
  99
+
  100
+macaddress:
  101
+	.byte 0x10
  102
+	.byte 0xe2
  103
+	.byte 0xd5
  104
+	.byte 0x00
  105
+	.byte 0x00
  106
+	.byte 0x00
  107
+
  108
+	/* padding to align to a 32-bit boundary */
  109
+	.byte 0x00
  110
+	.byte 0x00
  111
+
  112
+_crt0:
  113
+	/* Setup stack and global pointer */
  114
+	mvhi    sp, hi(_fstack)
  115
+	ori     sp, sp, lo(_fstack)
  116
+	mvhi    gp, hi(_gp)
  117
+	ori     gp, gp, lo(_gp)
  118
+
  119
+	/* Clear BSS */
  120
+	mvhi    r1, hi(_fbss)
  121
+	ori     r1, r1, lo(_fbss)
  122
+	mvhi    r3, hi(_ebss)
  123
+	ori     r3, r3, lo(_ebss)
  124
+.clearBSS:
  125
+	be      r1, r3, .callMain
  126
+	sw      (r1+0), r0
  127
+	addi    r1, r1, 4
  128
+	bi      .clearBSS
  129
+
  130
+.callMain:
  131
+	bi      main
  132
+
  133
+.save_all:
  134
+	addi    sp, sp, -56
  135
+	sw      (sp+4), r1
  136
+	sw      (sp+8), r2
  137
+	sw      (sp+12), r3
  138
+	sw      (sp+16), r4
  139
+	sw      (sp+20), r5
  140
+	sw      (sp+24), r6
  141
+	sw      (sp+28), r7
  142
+	sw      (sp+32), r8
  143
+	sw      (sp+36), r9
  144
+	sw      (sp+40), r10
  145
+	sw      (sp+48), ea
  146
+	sw      (sp+52), ba
  147
+	/* ra needs to be moved from initial stack location */
  148
+	lw      r1, (sp+56)
  149
+	sw      (sp+44), r1
  150
+	ret
  151
+
  152
+.restore_all_and_eret:
  153
+	lw      r1, (sp+4)
  154
+	lw      r2, (sp+8)
  155
+	lw      r3, (sp+12)
  156
+	lw      r4, (sp+16)
  157
+	lw      r5, (sp+20)
  158
+	lw      r6, (sp+24)
  159
+	lw      r7, (sp+28)
  160
+	lw      r8, (sp+32)
  161
+	lw      r9, (sp+36)
  162
+	lw      r10, (sp+40)
  163
+	lw      ra, (sp+44)
  164
+	lw      ea, (sp+48)
  165
+	lw      ba, (sp+52)
  166
+	addi    sp, sp, 56
  167
+	eret
15  software/videomixer/isr.c
... ...
@@ -0,0 +1,15 @@
  1
+#include <hw/uart.h>
  2
+#include <interrupt.h>
  3
+#include <irq.h>
  4
+#include <uart.h>
  5
+
  6
+void isr(void);
  7
+void isr(void)
  8
+{
  9
+	unsigned int irqs;
  10
+	
  11
+	irqs = irq_pending() & irq_getmask();
  12
+	
  13
+	if(irqs & (1 << UART_INTERRUPT))
  14
+		uart_isr();
  15
+}
56  software/videomixer/linker.ld
... ...
@@ -0,0 +1,56 @@
  1
+OUTPUT_FORMAT("elf32-lm32")
  2
+ENTRY(_start)
  3
+
  4
+__DYNAMIC = 0;
  5
+
  6
+MEMORY {
  7
+	sdram  : ORIGIN = 0x40000000, LENGTH = 0x08000000 /* 128M */
  8
+}
  9
+
  10
+SECTIONS
  11
+{
  12
+	.text :
  13
+	{
  14
+		_ftext = .;
  15
+		*(.text .stub .text.* .gnu.linkonce.t.*)
  16
+		_etext = .;
  17
+	} > sdram
  18
+
  19
+	.rodata :
  20
+	{
  21
+		. = ALIGN(4);
  22
+		_frodata = .;
  23
+		*(.rodata .rodata.* .gnu.linkonce.r.*)
  24
+		*(.rodata1)
  25
+		_erodata = .;
  26
+	} > sdram
  27
+
  28
+	.data :
  29
+	{
  30
+		. = ALIGN(4);
  31
+		_fdata = .;
  32
+		*(.data .data.* .gnu.linkonce.d.*)
  33
+		*(.data1)
  34
+		_gp = ALIGN(16);
  35
+		*(.sdata .sdata.* .gnu.linkonce.s.*)
  36
+		_edata = .;
  37
+	} > sdram
  38
+
  39
+	.bss :
  40
+	{
  41
+		. = ALIGN(4);
  42
+		_fbss = .;
  43
+		*(.dynsbss)
  44
+		*(.sbss .sbss.* .gnu.linkonce.sb.*)
  45
+		*(.scommon)
  46
+		*(.dynbss)
  47
+		*(.bss .bss.* .gnu.linkonce.b.*)
  48
+		*(COMMON)
  49
+		. = ALIGN(4);
  50
+		_ebss = .;
  51
+		. = ALIGN(8);
  52
+		_heapstart = .;
  53
+	} > sdram
  54
+}
  55
+
  56
+PROVIDE(_fstack = ORIGIN(sdram) + LENGTH(sdram) - 4);
99  software/videomixer/main.c
... ...
@@ -0,0 +1,99 @@
  1
+#include <stdio.h>
  2
+
  3
+#include <irq.h>
  4
+#include <uart.h>
  5
+#include <hw/dvisampler.h>
  6
+
  7
+static int d0, d1, d2;
  8
+
  9
+static void calibrate_delays(void)
  10
+{
  11
+	CSR_DVISAMPLER0_D0_DELAY_CTL = DVISAMPLER_DELAY_CAL;
  12
+	CSR_DVISAMPLER0_D1_DELAY_CTL = DVISAMPLER_DELAY_CAL;
  13
+	CSR_DVISAMPLER0_D2_DELAY_CTL = DVISAMPLER_DELAY_CAL;
  14
+	while(CSR_DVISAMPLER0_D0_DELAY_BUSY || CSR_DVISAMPLER0_D1_DELAY_BUSY || CSR_DVISAMPLER0_D2_DELAY_BUSY);
  15
+	CSR_DVISAMPLER0_D0_DELAY_CTL = DVISAMPLER_DELAY_RST;
  16
+	CSR_DVISAMPLER0_D1_DELAY_CTL = DVISAMPLER_DELAY_RST;
  17
+	CSR_DVISAMPLER0_D2_DELAY_CTL = DVISAMPLER_DELAY_RST;
  18
+	CSR_DVISAMPLER0_D0_PHASE_RESET = 1;
  19
+	CSR_DVISAMPLER0_D1_PHASE_RESET = 1;
  20
+	CSR_DVISAMPLER0_D2_PHASE_RESET = 1;
  21
+	d0 = d1 = d2 = 0;
  22
+	printf("Delays calibrated\n");
  23
+}
  24
+
  25
+static void adjust_phase(void)
  26
+{
  27
+	switch(CSR_DVISAMPLER0_D0_PHASE) {
  28
+		case DVISAMPLER_TOO_LATE:
  29
+			CSR_DVISAMPLER0_D0_DELAY_CTL = DVISAMPLER_DELAY_DEC;
  30
+			d0--;
  31
+			CSR_DVISAMPLER0_D0_PHASE_RESET = 1;
  32
+			break;
  33
+		case DVISAMPLER_TOO_EARLY:
  34
+			CSR_DVISAMPLER0_D0_DELAY_CTL = DVISAMPLER_DELAY_INC;
  35
+			d0++;
  36
+			CSR_DVISAMPLER0_D0_PHASE_RESET = 1;
  37
+			break;
  38
+	}
  39
+	switch(CSR_DVISAMPLER0_D1_PHASE) {
  40
+		case DVISAMPLER_TOO_LATE:
  41
+			CSR_DVISAMPLER0_D1_DELAY_CTL = DVISAMPLER_DELAY_DEC;
  42
+			d1--;
  43
+			CSR_DVISAMPLER0_D1_PHASE_RESET = 1;
  44
+			break;
  45
+		case DVISAMPLER_TOO_EARLY:
  46
+			CSR_DVISAMPLER0_D1_DELAY_CTL = DVISAMPLER_DELAY_INC;
  47
+			d1++;
  48
+			CSR_DVISAMPLER0_D1_PHASE_RESET = 1;
  49
+			break;
  50
+	}
  51
+	switch(CSR_DVISAMPLER0_D2_PHASE) {
  52
+		case DVISAMPLER_TOO_LATE:
  53
+			CSR_DVISAMPLER0_D2_DELAY_CTL = DVISAMPLER_DELAY_DEC;
  54
+			d2--;
  55
+			CSR_DVISAMPLER0_D2_PHASE_RESET = 1;
  56
+			break;
  57
+		case DVISAMPLER_TOO_EARLY:
  58
+			CSR_DVISAMPLER0_D2_DELAY_CTL = DVISAMPLER_DELAY_INC;
  59
+			d2++;
  60
+			CSR_DVISAMPLER0_D2_PHASE_RESET = 1;
  61
+			break;
  62
+	}
  63
+	//printf("Ph: %4d %4d %4d\n", d0, d1, d2);
  64
+}
  65
+
  66
+static void vmix(void)
  67
+{
  68
+	unsigned int counter;
  69
+
  70
+	while(1) {
  71
+		while(!CSR_DVISAMPLER0_PLL_LOCKED);
  72
+		printf("PLL locked\n");
  73
+		calibrate_delays();
  74
+		adjust_phase();
  75
+
  76
+		counter = 0;
  77
+		while(CSR_DVISAMPLER0_PLL_LOCKED) {
  78
+			counter++;
  79
+			if(counter == 200000) {
  80
+				adjust_phase();
  81
+				counter = 0;
  82
+			}
  83
+		}
  84
+		printf("PLL unlocked\n");
  85
+	}
  86
+}
  87
+
  88
+int main(void)
  89
+{
  90
+	irq_setmask(0);
  91
+	irq_setie(1);
  92
+	uart_init();
  93
+	
  94
+	puts("Minimal video mixer software built "__DATE__" "__TIME__"\n");
  95
+	
  96
+	vmix();
  97
+	
  98
+	return 0;
  99
+}

No commit comments for this range

Something went wrong with that request. Please try again.