Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 4 files changed
  • 0 comments
  • 1 contributor
4  milkymist/dvisampler/dma.py
@@ -31,7 +31,7 @@ def __init__(self, addr_bits, alignment_bits):
31 31
 
32 32
 class _SlotArray(Module, AutoCSR):
33 33
 	def __init__(self, nslots, addr_bits, alignment_bits):
34  
-		self.ev = EventManager()
  34
+		self.submodules.ev = EventManager()
35 35
 		self.address = Signal(addr_bits)
36 36
 		self.address_valid = Signal()
37 37
 		self.address_done = Signal()
@@ -46,7 +46,7 @@ def __init__(self, nslots, addr_bits, alignment_bits):
46 46
 
47 47
 		change_slot = Signal()
48 48
 		current_slot = Signal(max=nslots)
49  
-		self.sync += If(change_slot, [If(slot.address_valid, current_slot.eq(n)) for n, slot in enumerate(slots)])
  49
+		self.sync += If(change_slot, [If(slot.address_valid, current_slot.eq(n)) for n, slot in reversed(list(enumerate(slots)))])
50 50
 		self.comb += change_slot.eq(~self.address_valid | self.address_done)
51 51
 
52 52
 		self.comb += [
4  software/include/hw/flags.h
@@ -30,4 +30,8 @@
30 30
 #define DVISAMPLER_DELAY_INC	0x4
31 31
 #define DVISAMPLER_DELAY_DEC	0x8
32 32
 
  33
+#define DVISAMPLER_SLOT_EMPTY	0
  34
+#define DVISAMPLER_SLOT_LOADED	1
  35
+#define DVISAMPLER_SLOT_PENDING	2
  36
+
33 37
 #endif /* __HW_FLAGS_H */
4  software/videomixer/isr.c
@@ -2,6 +2,8 @@
2 2
 #include <irq.h>
3 3
 #include <uart.h>
4 4
 
  5
+void dvisampler0_isr(void); // FIXME
  6
+
5 7
 void isr(void);
6 8
 void isr(void)
7 9
 {
@@ -11,4 +13,6 @@ void isr(void)
11 13
 	
12 14
 	if(irqs & (1 << UART_INTERRUPT))
13 15
 		uart_isr();
  16
+	if(irqs & (1 << DVISAMPLER0_INTERRUPT))
  17
+		dvisampler0_isr();
14 18
 }
96  software/videomixer/main.c
@@ -7,12 +7,11 @@
7 7
 #include <hw/csr.h>
8 8
 #include <hw/flags.h>
9 9
 
10  
-static int d0, d1, d2;
11  
-static unsigned int framebuffer[640*480] __attribute__((aligned(16)));
  10
+static int dvisampler0_d0, dvisampler0_d1, dvisampler0_d2;
12 11
 
13 12
 static void print_status(void)
14 13
 {
15  
-	printf("Ph: %4d %4d %4d // %d%d%d [%d %d %d] // %d // %dx%d\n", d0, d1, d2,
  14
+	printf("dvisampler0 ph: %4d %4d %4d // %d%d%d [%d %d %d] // %d // %dx%d\n", dvisampler0_d0, dvisampler0_d1, dvisampler0_d2,
16 15
 		dvisampler0_data0_charsync_char_synced_read(),
17 16
 		dvisampler0_data1_charsync_char_synced_read(),
18 17
 		dvisampler0_data2_charsync_char_synced_read(),
@@ -24,17 +23,6 @@ static void print_status(void)
24 23
 		dvisampler0_resdetection_vres_read());
25 24
 }
26 25
 
27  
-static void capture_fb(void)
28  
-{
29  
-	dvisampler0_dma_frame_size_write(sizeof(framebuffer));
30  
-	dvisampler0_dma_slot0_address_write((unsigned int)framebuffer);
31  
-	dvisampler0_dma_slot0_status_write(1);
32  
-
33  
-	printf("waiting for DMA...");
34  
-	while(dvisampler0_dma_slot0_status_read() != 2);
35  
-	printf("done\n");
36  
-}
37  
-
38 26
 static void calibrate_delays(void)
39 27
 {
40 28
 	dvisampler0_data0_cap_dly_ctl_write(DVISAMPLER_DELAY_CAL);
@@ -49,7 +37,7 @@ static void calibrate_delays(void)
49 37
 	dvisampler0_data0_cap_phase_reset_write(1);
50 38
 	dvisampler0_data1_cap_phase_reset_write(1);
51 39
 	dvisampler0_data2_cap_phase_reset_write(1);
52  
-	d0 = d1 = d2 = 0;
  40
+	dvisampler0_d0 = dvisampler0_d1 = dvisampler0_d2 = 0;
53 41
 	printf("Delays calibrated\n");
54 42
 }
55 43
 
@@ -58,36 +46,36 @@ static void adjust_phase(void)
58 46
 	switch(dvisampler0_data0_cap_phase_read()) {
59 47
 		case DVISAMPLER_TOO_LATE:
60 48
 			dvisampler0_data0_cap_dly_ctl_write(DVISAMPLER_DELAY_DEC);
61  
-			d0--;
  49
+			dvisampler0_d0--;
62 50
 			dvisampler0_data0_cap_phase_reset_write(1);
63 51
 			break;
64 52
 		case DVISAMPLER_TOO_EARLY:
65 53
 			dvisampler0_data0_cap_dly_ctl_write(DVISAMPLER_DELAY_INC);
66  
-			d0++;
  54
+			dvisampler0_d0++;
67 55
 			dvisampler0_data0_cap_phase_reset_write(1);
68 56
 			break;
69 57
 	}
70 58
 	switch(dvisampler0_data1_cap_phase_read()) {
71 59
 		case DVISAMPLER_TOO_LATE:
72 60
 			dvisampler0_data1_cap_dly_ctl_write(DVISAMPLER_DELAY_DEC);
73  
-			d1--;
  61
+			dvisampler0_d1--;
74 62
 			dvisampler0_data1_cap_phase_reset_write(1);
75 63
 			break;
76 64
 		case DVISAMPLER_TOO_EARLY:
77 65
 			dvisampler0_data1_cap_dly_ctl_write(DVISAMPLER_DELAY_INC);
78  
-			d1++;
  66
+			dvisampler0_d1++;
79 67
 			dvisampler0_data1_cap_phase_reset_write(1);
80 68
 			break;
81 69
 	}
82 70
 	switch(dvisampler0_data2_cap_phase_read()) {
83 71
 		case DVISAMPLER_TOO_LATE:
84 72
 			dvisampler0_data2_cap_dly_ctl_write(DVISAMPLER_DELAY_DEC);
85  
-			d2--;
  73
+			dvisampler0_d2--;
86 74
 			dvisampler0_data2_cap_phase_reset_write(1);
87 75
 			break;
88 76
 		case DVISAMPLER_TOO_EARLY:
89 77
 			dvisampler0_data2_cap_dly_ctl_write(DVISAMPLER_DELAY_INC);
90  
-			d2++;
  78
+			dvisampler0_d2++;
91 79
 			dvisampler0_data2_cap_phase_reset_write(1);
92 80
 			break;
93 81
 	}
@@ -95,21 +83,73 @@ static void adjust_phase(void)
95 83
 
96 84
 static int init_phase(void)
97 85
 {
98  
-	int od0, od1, od2; 
  86
+	int o_d0, o_d1, o_d2; 
99 87
 	int i, j;
100 88
 
101 89
 	for(i=0;i<100;i++) {
102  
-		od0 = d0;
103  
-		od1 = d1;
104  
-		od2 = d2;
  90
+		o_d0 = dvisampler0_d0;
  91
+		o_d1 = dvisampler0_d1;
  92
+		o_d2 = dvisampler0_d2;
105 93
 		for(j=0;j<1000;j++)
106 94
 			adjust_phase();
107  
-		if((abs(d0 - od0) < 4) && (abs(d1 - od1) < 4) && (abs(d2 - od2) < 4))
  95
+		if((abs(dvisampler0_d0 - o_d0) < 4) && (abs(dvisampler0_d1 - o_d1) < 4) && (abs(dvisampler0_d2 - o_d2) < 4))
108 96
 			return 1;
109 97
 	}
110 98
 	return 0;
111 99
 }
112 100
 
  101
+#define FRAMEBUFFER_COUNT 4
  102
+#define FRAMEBUFFER_MASK (FRAMEBUFFER_COUNT - 1)
  103
+
  104
+static unsigned int dvisampler0_framebuffers[FRAMEBUFFER_COUNT][640*480] __attribute__((aligned(16)));
  105
+static int dvisampler0_fb_slot_indexes[2];
  106
+static int dvisampler0_next_fb_index;
  107
+
  108
+static void dvisampler0_init_video(void)
  109
+{
  110
+	unsigned int mask;
  111
+
  112
+	dvisampler0_dma_ev_pending_write(dvisampler0_dma_ev_pending_read());
  113
+	dvisampler0_dma_ev_enable_write(0x3);
  114
+	mask = irq_getmask();
  115
+	mask |= 1 << DVISAMPLER0_INTERRUPT;
  116
+	irq_setmask(mask);
  117
+
  118
+	dvisampler0_dma_frame_size_write(sizeof(dvisampler0_framebuffers[0]));
  119
+	dvisampler0_fb_slot_indexes[0] = 0;
  120
+	dvisampler0_dma_slot0_address_write((unsigned int)dvisampler0_framebuffers[0]);
  121
+	dvisampler0_dma_slot0_status_write(DVISAMPLER_SLOT_LOADED);
  122
+	dvisampler0_fb_slot_indexes[1] = 1;
  123
+	dvisampler0_dma_slot1_address_write((unsigned int)dvisampler0_framebuffers[1]);
  124
+	dvisampler0_dma_slot1_status_write(DVISAMPLER_SLOT_LOADED);
  125
+	dvisampler0_next_fb_index = 2;
  126
+
  127
+	fb_base_write((unsigned int)dvisampler0_framebuffers[0]);
  128
+}
  129
+
  130
+void dvisampler0_isr(void)
  131
+{
  132
+	int fb_index = -1;
  133
+
  134
+	if(dvisampler0_dma_slot0_status_read() == DVISAMPLER_SLOT_PENDING) {
  135
+		fb_index = dvisampler0_fb_slot_indexes[0];
  136
+		dvisampler0_fb_slot_indexes[0] = dvisampler0_next_fb_index;
  137
+		dvisampler0_dma_slot0_address_write((unsigned int)dvisampler0_framebuffers[dvisampler0_next_fb_index]);
  138
+		dvisampler0_dma_slot0_status_write(DVISAMPLER_SLOT_LOADED);
  139
+		dvisampler0_next_fb_index = (dvisampler0_next_fb_index + 1) & FRAMEBUFFER_MASK;
  140
+	}
  141
+	if(dvisampler0_dma_slot1_status_read() == DVISAMPLER_SLOT_PENDING) {
  142
+		fb_index = dvisampler0_fb_slot_indexes[1];
  143
+		dvisampler0_fb_slot_indexes[1] = dvisampler0_next_fb_index;
  144
+		dvisampler0_dma_slot1_address_write((unsigned int)dvisampler0_framebuffers[dvisampler0_next_fb_index]);
  145
+		dvisampler0_dma_slot1_status_write(DVISAMPLER_SLOT_LOADED);
  146
+		dvisampler0_next_fb_index = (dvisampler0_next_fb_index + 1) & FRAMEBUFFER_MASK;
  147
+	}
  148
+
  149
+	if(fb_index != -1)
  150
+		fb_base_write((unsigned int)dvisampler0_framebuffers[fb_index]);
  151
+}
  152
+
113 153
 static void vmix(void)
114 154
 {
115 155
 	unsigned int counter;
@@ -132,8 +172,6 @@ static void vmix(void)
132 172
 				adjust_phase();
133 173
 				counter = 0;
134 174
 			}
135  
-			if(readchar_nonblock() && (readchar() == 'c'))
136  
-				capture_fb();
137 175
 		}
138 176
 		printf("PLL unlocked\n");
139 177
 	}
@@ -147,7 +185,7 @@ int main(void)
147 185
 	
148 186
 	puts("Minimal video mixer software built "__DATE__" "__TIME__"\n");
149 187
 	
150  
-	fb_base_write((unsigned int)framebuffer);
  188
+	dvisampler0_init_video();
151 189
 	fb_enable_write(1);
152 190
 	vmix();
153 191
 	

No commit comments for this range

Something went wrong with that request. Please try again.