Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Floating point pixel manipulation #270

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e4a71b9
Adding float16 mudules to gateware/csc
ssk1328 Jun 22, 2016
054b69e
Updates to rgb16f conversion
ssk1328 Jun 24, 2016
d1a9a81
Initial Commit/Adding float-mult.py
ssk1328 Jun 24, 2016
8245112
Fixed bugs
ssk1328 Jun 25, 2016
7b46268
Code cleanup-breaking in submodules
ssk1328 Jun 25, 2016
253778f
Multiplier module with test bench
ssk1328 Jun 26, 2016
99b0ae7
Fixed errors in mult output
ssk1328 Jun 26, 2016
64f22f1
Cleanup and Documentation
ssk1328 Jun 26, 2016
85b8f62
Adding model convert function
ssk1328 Jun 30, 2016
b680b78
Adding float CSR in opsis base
ssk1328 Jul 3, 2016
c4158d3
Added CSR functions in ci for testing
ssk1328 Jul 4, 2016
e750759
Added float Mult
ssk1328 Jul 11, 2016
694faa2
Adding CSR
ssk1328 Jul 18, 2016
30be831
merge branch 'csc-update' into float-arithmetic
ssk1328 Jul 20, 2016
aa54898
Added float16 modules to video pipeline
ssk1328 Jul 21, 2016
1406e11
Added modules to output pipeline
ssk1328 Jul 26, 2016
dcdd7c9
Defining multiple sinks for floatadd
ssk1328 Jul 27, 2016
a2379db
Fixed error in connecting floatadd layout
ssk1328 Jul 28, 2016
0d7ef23
Adding dynamic fade mix
ssk1328 Jul 29, 2016
8bfac7f
Added another DMA block
ssk1328 Aug 3, 2016
c66aa37
Updating block connections for HDMIOut
ssk1328 Aug 3, 2016
c2260e8
Chages in HDMIOUT PLL Clock
ssk1328 Aug 4, 2016
51700ec
Changes in Clock for single HDMI_OUT
ssk1328 Aug 4, 2016
ddc36cb
Updates in HDMI_OUT clocking
ssk1328 Aug 4, 2016
9e7cb75
Fixed HDMI_OUT MAP error
ssk1328 Aug 4, 2016
f6e5365
Combining two DMA streams before VTG
ssk1328 Aug 7, 2016
e46f5e4
Adding dynamic fade mix
ssk1328 Aug 8, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions firmware/lm32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ OBJECTS=isr.o \
processor.o \
hdmi_in0.o \
hdmi_in1.o \
mix.o\
hdmi_out0.o \
hdmi_out1.o \
pattern.o \
Expand Down
57 changes: 55 additions & 2 deletions firmware/lm32/ci.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <generated/sdram_phy.h>
#include <time.h>

#include "mix.h"
#include "config.h"
#include "fx2.h"
#include "hdmi_in0.h"
Expand Down Expand Up @@ -61,6 +62,16 @@ static void help_output0(void)
puts(" output0 on - enable output0");
puts(" output0 off - disable output0");
}

static void help_output0_mult_factor(void)
{
puts("output0 multfactor (alias: 'm0')");
puts(" set0 - set mult at input0");
puts(" set1 - set mult at input1");
puts(" val0 - mask values at mixer input0");
puts(" val1 - mask values at mixer input1");
}

#endif

#ifdef CSR_HDMI_OUT1_BASE
Expand All @@ -83,6 +94,14 @@ static void help_encoder(void)
}
#endif

static void help_floatmult(void)
{
puts("floatmult commands (alias: 'f')");
puts(" floatmult in1 val - set floatmult in1 equal val");
puts(" floatmult in2 val - set floatmult in2 equal val");
puts(" floatmult out - print floatmult out");
}

static void help_debug(void)
{
puts("debug commands (alias 'd')");
Expand Down Expand Up @@ -118,6 +137,8 @@ static void help(void)
#ifdef CSR_HDMI_OUT0_BASE
help_output0();
puts("");
help_output0_mult_factor();
puts("");
#endif
#ifdef CSR_HDMI_OUT1_BASE
help_output1();
Expand All @@ -127,6 +148,8 @@ static void help(void)
help_encoder();
puts("");
#endif
help_floatmult();
puts("");
help_debug();
}

Expand Down Expand Up @@ -495,7 +518,6 @@ static char *get_token(char **str)
return d;
}


void ci_prompt(void)
{
printf("HDMI2USB>");
Expand Down Expand Up @@ -637,6 +659,36 @@ void ci_service(void)
help_encoder();
}
#endif

else if((strcmp(token, "mix_mult") == 0) || (strcmp(token, "m0") == 0)) {
token = get_token(&str);

if (strcmp(token, "set0") == 0){
hdmi_out0_driver_mult_factor0_write(atoi(get_token(&str)));
printf("HDMI_OUT0 mult factor = %d\n", hdmi_out0_driver_mult_factor0_read());
printf("HDMI_OUT1 mult factor = %d\n", hdmi_out0_driver_mult_factor1_read());
}

else if (strcmp(token, "set1") == 0){
hdmi_out0_driver_mult_factor1_write(atoi(get_token(&str)));
printf("HDMI_OUT0 mult factor = %d\n", hdmi_out0_driver_mult_factor0_read());
printf("HDMI_OUT1 mult factor = %d\n", hdmi_out0_driver_mult_factor1_read());
}

else if(strcmp(token, "val0") == 0){
printf("HDMI_OUT0 mult factor = %d\n", hdmi_out0_driver_mult_factor0_read());
}

else if(strcmp(token, "val1") == 0){
printf("HDMI_OUT1 mult factor = %d\n", hdmi_out0_driver_mult_factor1_read());
}

else {
help_output0_mult_factor();
}

}

else if((strcmp(token, "status") == 0) || (strcmp(token, "s") == 0)) {
token = get_token(&str);
if(strcmp(token, "on") == 0)
Expand Down Expand Up @@ -757,4 +809,5 @@ void ci_service(void)
}

ci_prompt();
}

}
2 changes: 2 additions & 0 deletions firmware/lm32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "hdmi_out1.h"
#include "fx2.h"
#include "version.h"
#include "mix.h"

int main(void)
{
Expand Down Expand Up @@ -62,6 +63,7 @@ int main(void)
#endif
ci_prompt();
while(1) {
mult_service();
processor_service();
ci_service();

Expand Down
58 changes: 58 additions & 0 deletions firmware/lm32/mix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <generated/csr.h>
#include <generated/mem.h>
#include <hw/flags.h>
#include <system.h>
#include <time.h>
#include <stdbool.h>

#include "processor.h"
#include "hdmi_in0.h"
#include "hdmi_in1.h"
#include "pattern.h"
#include "mix.h"

static const unsigned int mult_bar[20] = {
0 ,
10854 ,
11878 ,
12493 ,
12902 ,
13312 ,
13517 ,
13722 ,
13926 ,
14131 ,
14336 ,
14438 ,
14541 ,
14643 ,
14746 ,
14848 ,
14950 ,
15053 ,
15155 ,
15258


};

#define FILL_RATE 20 // In Hertz, double the standard frame rate

void mult_service(void)
{
static int last_event;
static int counter;

// if (mix_status) {
if(elapsed(&last_event, identifier_frequency_read()/FILL_RATE)) {
counter = counter+1;
if(counter >= (FILL_RATE-1)) {
counter = 0;
}
}
// }

hdmi_out0_driver_mult_factor0_write(mult_bar[counter]);
hdmi_out0_driver_mult_factor1_write(mult_bar[20-1-counter]);

}
12 changes: 12 additions & 0 deletions firmware/lm32/mix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

#ifndef __MIX_H
#define __MIX_H

#include <stdbool.h>

static bool mix_status;
static const unsigned int mult_bar[20];

void mult_service(void);

#endif
20 changes: 13 additions & 7 deletions firmware/lm32/processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,15 +508,21 @@ void processor_update(void)
#ifdef CSR_HDMI_OUT0_BASE
/* hdmi_out0 */
#ifdef CSR_HDMI_IN0_BASE
if(processor_hdmi_out0_source == VIDEO_IN_HDMI_IN0)
if(processor_hdmi_out0_source == VIDEO_IN_HDMI_IN0) {
hdmi_out0_fi_base0_write(hdmi_in0_framebuffer_base(hdmi_in0_fb_index));
hdmi_out0_fi_base1_write(pattern_framebuffer_base());
}
#endif
#ifdef CSR_HDMI_IN1_BASE
if(processor_hdmi_out0_source == VIDEO_IN_HDMI_IN1)
if(processor_hdmi_out0_source == VIDEO_IN_HDMI_IN1) {
hdmi_out0_fi_base0_write(hdmi_in1_framebuffer_base(hdmi_in1_fb_index));
hdmi_out0_fi_base1_write(hdmi_in1_framebuffer_base(hdmi_in1_fb_index));
}
#endif
if(processor_hdmi_out0_source == VIDEO_IN_PATTERN)
if(processor_hdmi_out0_source == VIDEO_IN_PATTERN) {
hdmi_out0_fi_base0_write(pattern_framebuffer_base());
hdmi_out0_fi_base1_write(pattern_framebuffer_base());
}
#endif

#ifdef CSR_HDMI_OUT1_BASE
Expand All @@ -529,8 +535,8 @@ void processor_update(void)
if(processor_hdmi_out1_source == VIDEO_IN_HDMI_IN1)
hdmi_out1_fi_base0_write(hdmi_in1_framebuffer_base(hdmi_in1_fb_index));
#endif
if(processor_hdmi_out1_source == VIDEO_IN_PATTERN)
hdmi_out1_fi_base0_write(pattern_framebuffer_base());
// if(processor_hdmi_out1_source == VIDEO_IN_PATTERN)
// hdmi_out1_fi_base0_write(pattern_framebuffer_base());
#endif

#ifdef ENCODER_BASE
Expand All @@ -545,8 +551,8 @@ void processor_update(void)
encoder_reader_base_write((hdmi_in1_framebuffer_base(hdmi_in1_fb_index)));
}
#endif
if(processor_encoder_source == VIDEO_IN_PATTERN)
encoder_reader_base_write(pattern_framebuffer_base());
// if(processor_encoder_source == VIDEO_IN_PATTERN)
// encoder_reader_base_write(pattern_framebuffer_base());
#endif
}

Expand Down
10 changes: 9 additions & 1 deletion gateware/csc/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ def saturate(i, o, minimum, maximum):
def coef(value, cw=None):
return int(value * 2**cw) if cw is not None else value


def rgb_layout(dw):
return [("r", dw), ("g", dw), ("b", dw)]

def rgb16f_layout(dw):
return [("rf", dw), ("gf", dw), ("bf", dw)]

def ycbcr444_layout(dw):
return [("y", dw), ("cb", dw), ("cr", dw)]

def ycbcr422_layout(dw):
return [("y", dw), ("cb_cr", dw)]

def pix_layout(dw):
return [("pix", dw)]

def pixf_layout(dw):
return [("pixf", dw)]

73 changes: 73 additions & 0 deletions gateware/csc/rgb16f2rgb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# rgb16f2rgb

from migen.fhdl.std import *
from migen.genlib.record import *
from migen.flow.actor import *

from gateware.csc.common import *

@DecorateModule(InsertCE)
class PIXF2PIXDatapath(Module):
"""
Converts a 16 bit half precision floating point
number defined in the range [0-1] to 8 bit unsigned
int represented by a pixel in the range [0-255]
"""
latency = 2
def __init__(self, pixf_w, pix_w):
self.sink = sink = Record(pixf_layout(pixf_w))
self.source = source = Record(pix_layout(pix_w))

# # #

# delay pixf signals
pixf_delayed = [sink]
for i in range(self.latency):
pixf_n = Record(pixf_layout(pixf_w))
self.sync += getattr(pixf_n, "pixf").eq(getattr(pixf_delayed[-1], "pixf"))
pixf_delayed.append(pixf_n)


# Hardware implementation:

# Stage 1
# Unpack frac and exp components
# Correct exponent offset for shifting later
frac = Signal(11)
exp = Signal(5)
exp_offset = Signal((6,True))

self.sync += [

exp_offset.eq(15 - sink.pixf[10:15] -1),
frac[:10].eq(sink.pixf[:10]),
frac[10].eq(1),
]

# Stage 2
# Right shift frac by exp_offset
# Most significant 8 bits of frac assigned to uint8 pix
self.sync += [
If(exp_offset<0,
source.pix.eq(255)
).Else(
source.pix.eq((frac >> exp_offset)[3:]),
)
]


class RGB16f2RGB(PipelinedActor, Module):
def __init__(self, rgb16f_w=16, rgb_w=8, coef_w=8):
self.sink = sink = Sink(EndpointDescription(rgb16f_layout(rgb16f_w), packetized=True))
self.source = source = Source(EndpointDescription(rgb_layout(rgb_w), packetized=True))

# # #

for name in ["r", "g", "b"]:
self.submodules.datapath = PIXF2PIXDatapath(rgb16f_w, rgb_w)
PipelinedActor.__init__(self, self.datapath.latency)
self.comb += self.datapath.ce.eq(self.pipe_ce)
self.comb += getattr(self.datapath.sink, "pixf").eq(getattr(sink, name +"f"))
self.comb += getattr(source, name).eq(getattr(self.datapath.source, "pix"))

self.latency = self.datapath.latency
Loading