Commit 4a5c76e1 authored by Francisco Barranco's avatar Francisco Barranco

Stereo disparity gradient-based version

parent 20e87cd3
/* channels.hch
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#include "channels.hch"
// ***************************************************************
// Channels implemented using signals
// ***************************************************************
/*
% Channel - Send data through this channel
% Input - Data to be sent through the channel
%
% DESCRIPTION
% This function sends Input through Channel.
% Channels are structs declared
% in channels.hcc file
%
% RETURN
%
*/
macro proc Send(Channel, Input)
{
//register indicating that the procedure has completed
unsigned 1 done;
//do this at least once
do
{
par
{
//set the transfer wires to the input value
Channel.DataTransfer = Input;
//indicate that the send process is ready
Channel.SendReady = 1;
//set the done register if the read process is ready
done = Channel.ReadReady;
}
}while(!done); //until the transfer is complete
}
/*
% Channel - Send signed data through this channel
% Input - Data to be sent through the channel
%
% DESCRIPTION
% This function safely sends Input through Channel: to work, there must be
% a channel reading in the other side. It waits until the ready signal is activated
% and then sends the correct data. Otherwise, it is sending 0.
% Channels are structs declared in channels.hcc file
%
% RETURN
%
*/
macro proc SignedSecureSend(Channel, Input)
{
signed auxInput;
if (Read_Ready(Channel))
Send(Channel, Input);
else
{
auxInput=Input;
Send(Channel, auxInput);
}
}
/*
% Channel - Send unsigned data through this channel
% Input - Data to be sent through the channel
%
% DESCRIPTION
% This function safely sends Input through Channel: to work, there must be
% a channel reading in the other side. It waits until the ready signal is activated
% and then sends the correct data. Otherwise, it is sending 0.
% Channels are structs declared in channels.hcc file
%
% RETURN
%
*/
macro proc UnsignedSecureSend(Channel, Input)
{
unsigned auxInput;
if (Read_Ready(Channel))
Send(Channel, Input);
else
{
auxInput=Input;
Send(Channel, auxInput);
}
}
/*
% Channel - Receive data coming through this channel
% Output - Data to be received through the channel
%
% DESCRIPTION
% This function safely receives Output through Channel.
% It waits until the ready signal is activated (meaning that
% the sending part is ready) and then receives the data.
% This function is blocked until the reception of the first
% transference.
% Channels are structs declared in channels.hcc file
%
% RETURN
%
*/
macro proc Receive(Channel, Output)
{
//register indicating that the procedure has completed
unsigned 1 done;
//do this at least once
do
{
par
{
//is the send process is ready
if (Channel.SendReady)
{
//ready the value on the data transfer wires
Output = Channel.DataTransfer;
}
else
delay;
//indicate that the receive process is ready
Channel.ReadReady = 1;
//set the done register if the send process is ready
done = Channel.SendReady;
}
}while(!done); //until the transfer is complete
}
/*
% Channel - Channel
%
% DESCRIPTION
% This function checks whether the sender is ready or not.
% Channels are structs declared in channels.hcc file
%
% RETURN
%
% SendReady - Signal that is active if the sender is ready to transmit data
%
*/
macro expr Send_Ready(Channel) = Channel.SendReady;
/*
% Channel - Channel
%
% DESCRIPTION
% This function checks whether the receiver is ready or not.
% Channels are structs declared in channels.hcc file
%
% RETURN
%
% ReadReady - Signal that is active if the receiver is ready to receive data
%
*/
macro expr Read_Ready(Channel) = Channel.ReadReady;
\ No newline at end of file
/* channels.hch
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#ifndef __CHANNELS__
#define __CHANNELS__
#include "stdlib.hch"
// Channels implemented using signals
// ***************************************************************
struct unsignedchannel
{
signal unsigned 1 ReadReady;
signal unsigned 1 SendReady;
signal unsigned DataTransfer;
};
struct signedchannel
{
signal unsigned 1 ReadReady;
signal unsigned 1 SendReady;
signal signed DataTransfer;
};
// Definition of a channel with default values of 0
#define UNSIGNED_CHANNEL static struct unsignedchannel
#define SIGNED_CHANNEL static struct signedchannel
// Example channel declaration: declare a variable MyChannel
// as channel structure with default value of zero
// UNSIGNED_CHANNEL MyChannel;
macro proc Send(Channel, Input);
macro proc SignedSecureSend(Channel, Input);
macro proc UnsignedSecureSend(Channel, Input);
macro proc Receive(Channel, Output);
// These expressions allow the user to implement non-blocking channels:
// This channel structure has the readiness of the send and
// receive process exposed as signals, allowing the user to check
// the status of a channel. This can be simply expressed as
// expressions in Handel-C thus:
//Check whether the sender is ready
macro expr Send_Ready(Channel);
//Check whether the receiver is ready
macro expr Read_Ready(Channel);
#endif
/* cores.hcc
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#include "cores.hch"
// Interfaces for the top and core projects
// ***************************************************************
/*
% InputL - Input channel for the left image of the stereo system
% InputR - Input channel for the right image of the stereo system
% Output - Disparity estimation (unsigned 12 bits)
% Control - Control word with the different parameters:
% * Control[41:32] - Number of columns of the input images
% * Control[31:28] -
% * Control[27:20] - Threshold for minimum energy (gradient-based method)
% * Control[19:13] - Threshold for the minimum disparity between left and right image
% * Control[12:0] - Latency cycles of the pipeline
% ImSize - Size of the input images
%
% DESCRIPTION
% Interface for the disparity estimation core (used in the main.hcc)
%
% RETURN
%
*/
macro proc InterfaceTopDisparityLK(InputL, InputR, Output, Control, ImSize)
{
macro expr InWidth=8; // InputL and InputR of 8 b
macro expr OutWidth=12; //D --> 12
interface CoreDisparity( signal OutWidth Out, signal unsigned 1 OutSendReady, signal unsigned 1 InLReadReady, signal unsigned 1 InRReadReady)
MyCore( unsigned 1 clk=__clock, signal InWidth InL=InputL.DataTransfer,
signal unsigned 1 InLSendReady=InputL.SendReady, signal InWidth InR=InputR.DataTransfer, signal unsigned imSize=ImSize,
signal unsigned 1 InRSendReady=InputR.SendReady, signal unsigned 1 OutReadReady=Output.ReadReady, unsigned cmd=Control)with{retime=0};
while(1)
{
par
{
Output.DataTransfer=MyCore.Out;
Output.SendReady=MyCore.OutSendReady;
InputL.ReadReady=MyCore.InLReadReady;
InputR.ReadReady=MyCore.InRReadReady;
}
}
}
/*
% InputL - Input channel for the left image of the stereo system
% InputR - Input channel for the right image of the stereo system
% Output - Disparity estimation (unsigned 12 bits)
% Control - Control word with the different parameters:
% * Control[41:32] - Number of columns of the input images
% * Control[31:28] -
% * Control[27:20] - Threshold for minimum energy (gradient-based method)
% * Control[19:13] - Threshold for the minimum disparity between left and right image
% * Control[12:0] - Latency cycles of the pipeline
% ImSize - Size of the input images
%
% DESCRIPTION
% Interface for a top architecture to interface with the disparity estimation core
%
% RETURN
%
*/
// Interface for a top architecture
macro proc InterfaceCoreDisparityLK(InputL, InputR, Output, Control, ImSize)
{
#if CORE==1
// Outcoming data
interface port_out() OutData(signal Out = Output.DataTransfer)with{retime=0};
interface port_out() OutSendStatus(signal unsigned 1 OutSendReady = Output.SendReady)with{retime=0};
interface port_in(signal unsigned 1 OutReadReady) OutReadStatus()with{retime=0} ;
// Incoming data Left
interface port_in(signal unsigned imSize) CimSize()with{retime=0};
interface port_in(signal InL) InDataL()with{retime=0};
interface port_in(signal unsigned 1 InLSendReady) InLSendStatus()with{retime=0};
interface port_out() InLReadStatus(signal unsigned 1 InLReadReady = InputL.ReadReady)with{retime=0};
// Incoming data Right
interface port_in(signal InR) InDataR()with{retime=0};
interface port_in(signal unsigned 1 InRSendReady) InRSendStatus()with{retime=0};
interface port_out() InRReadStatus(signal unsigned 1 InRReadReady = InputR.ReadReady)with{retime=0};
// Control & Commands
interface port_in(unsigned cmd) Control_Commands()with{retime=0};
#else
// Outcoming data
interface bus_out() OutData(signal Out = Output.DataTransfer)with{retime=0};
interface bus_out() OutSendStatus(signal unsigned 1 OutSendReady = Output.SendReady)with{retime=0};
interface bus_in(signal unsigned 1 OutReadReady) OutReadStatus()with{retime=0} ;
// Incoming data Left
interface port_in(signal unsigned imSize) CimSize()with{retime=0};
interface bus_in(signal InL) InDataL()with{retime=0};
interface bus_in(signal unsigned 1 InLSendReady) InLSendStatus()with{retime=0};
interface bus_out() InLReadStatus(signal unsigned 1 InLReadReady = InputL.ReadReady)with{retime=0};
// Incoming data Right
interface bus_in(signal InR) InDataR()with{retime=0};
interface bus_in(signal unsigned 1 InRSendReady) InRSendStatus()with{retime=0};
interface bus_out() InRReadStatus(signal unsigned 1 InRReadReady = InputR.ReadReady)with{retime=0};
// Control & Commands
interface bus_in(unsigned cmd) Control_Commands()with{retime=0};
#endif
while(1)
{
par
{
Output.ReadReady=OutReadStatus.OutReadReady;
InputL.DataTransfer=InDataL.InL;
InputR.DataTransfer=InDataR.InR;
InputL.SendReady=InLSendStatus.InLSendReady;
InputR.SendReady=InRSendStatus.InRSendReady;
Control=Control_Commands.cmd;
ImSize=CimSize.imSize;
}
}
}
/* cores.hch
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#ifndef __CORES__
#define __CORES__
#include "stdlib.hch"
#include "channels.hch"
//#include "xircav4_lib.hch" Platform-dependent
#define CORE 1 // 0 for sub-circuit test, 1 for core calls
macro proc InterfaceTopDisparityLK(InputL, InputR, Output, Control, ImSize);
macro proc InterfaceCoreDisparityLK(InputL, InputR, Output, Control, ImSize);
#endif
\ No newline at end of file
/* generic.hcc
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#include "generic.hch"
// Pipeline synchronization delays
/*
% DelayCycles - Number of cycles of the delay
%
% DESCRIPTION
% This function sequentially generates the number of cycles that
% is passed in DelayCycles. It can be used for synchronization.
%
% RETURN
%
*/
macro proc PipelineDelay(DelayCycles)
{
seq(t=0;t<(DelayCycles);t++)
{
delay;
}
}
/*
% input - Input data
%
% DESCRIPTION
% This function creates a NaN valid. The value will depend on
% the width of the input. It will be 1 followed by as many zeros
% as the size of input minus 1.
%
% RETURN
% The NaN value for the width of input.
%
*/
macro expr SetNAN(input) = 1<<(width(input)-1);
/* generic.hch
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#ifndef __GENERIC_HCH__
#define __GENERIC_HCH__
#include "stdlib.hch"
#include "parameters.hch"
#include "cores.hch"
// Pipeline synchronization delays
macro proc PipelineDelay(DelayCycles);
#endif
\ No newline at end of file
This diff is collapsed.
/* lklib.hch
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#ifndef __LKLIB__
#define __LKLIB__
#include "stdlib.hch"
#include "Generic.hch"
#define XYTDERIVATIVESIZE 9
#define PIXELSIZE 8
#define DIVIDER_INPUT 22 //Input size of the divider core
#define DIVIDER_LATENCY DIVIDER_INPUT+4+1 //Latency of the divider core
macro proc Prefilter5Taps(buffer,Out);
macro proc Prefilter3Taps(buffer,Out);
macro proc Prefilter2Taps(buffer,Out);
macro proc Diff5Taps(buffer,Out);
macro proc Diff3Taps(buffer,Out);
macro proc Diff2Taps(buffer,Out);
macro proc Weighting(buffer,Out);
macro proc SpatialConvolutions_disp(Input,Output,KernelX,KernelY, ColumnLength);
macro proc WeightingMatrix_disp(Input0, Input1,Output, ColumnLength);
macro proc TemporalDerivative_disp(DataIn, dt, st);
macro proc FIXPOINTftu_disp(FractionalShift, detTH, Axx, Axt, VxOut);
macro proc division_core(Num, Den, quot);
#endif
\ No newline at end of file
/* parameters.hch
% Copyright (C) 2014 Francisco Barranco, 09/02/2014, University of Granada-University of Maryland.
% License, GNU GPL, free software, without any warranty.
*/
#ifndef __PARAMETERS__
#define __PARAMETERS__
// Number of cameras (1 for single camera, 2 for stereo system)
//#define NCAMERAS 2
// Max image resolution
#define MAX_RES_X 1024
#define MAX_RES_Y 1024
#define MAX_IMSIZE (MAX_RES_X*MAX_RES_Y)
//Number of frames we are using
#define NFRAMES 2
#endif
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#ifndef __LKLIB__
#define __LKLIB__
#define XYTDERIVATIVESIZE 9
#define PIXELSIZE 8
//extern unsigned 3 CONTROL;
#include "stdlib.hch"
#include "Generic.hch"
//#include "float_pipe.hch" // Celoxica library
// Custom floating point hardware library
#include "float.hch"
#define EXP 7 // 8 // Standard Simple Precission
#define MANTISSA 11 // 23 // Sign Mantissa exponente
#define FLOATDATALENGTH (EXP+MANTISSA+1) // 1 23 8
typedef FLOAT(EXP, MANTISSA) CUSTOMFLOAT;
#define DIVIDER_INPUT 22//25//40//18
#define DIVIDER_LATENCY DIVIDER_INPUT+4+1//1//DIVIDER_INPUT+4 // is +4 if divider has clks/div==1
// Unit macros
// --------------------------------------------------------------
macro proc Prefilter5Taps(buffer,Out);
macro proc Prefilter3Taps(buffer,Out);
macro proc Prefilter2Taps(buffer,Out);
macro proc Diff5Taps(buffer,Out);
macro proc Diff3Taps(buffer,Out);
macro proc Diff2Taps(buffer,Out);
macro proc Weighting(buffer,Out);
macro proc Gaussian17Taps(buffer,Out);
macro proc DiffGaussian17Taps(buffer,Out);
macro proc Gaussian2D(ChanInput, ChanOutput, ColumnLength);
macro proc SpatialConvolutions(Input,Output,KernelX,KernelY, ColumnLength);
macro proc SpatialConvolutions_last(Input,Output,KernelX,KernelY, ColumnLength);
macro proc WeightingMatrix(Input0, Input1,Output, ColumnLength);
macro proc WeightingMatrix_last(Input0, Input1,Output, ColumnLength);
macro proc TemporalDiff5Taps( ChanInput, ChanOutput, ColumnLength, RowLength, RAMdirE,
RAMdatE, RAMdirL, RAMdatL, GlobalPipeDelay);
//New TemporalDiff5Taps with memory accesses included
//macro proc TemporalDerivative(MyCallbackData, DataIn, DataOut, ImSize, Latency, MemOffset);
macro proc TemporalDerivative(MyCallbackData, DataIn, DataOut, ImSize, Latency, MemOffset, MemChan, BankNum);
macro proc TemporalDerivativeNoMemAccess(DataIn, DataOut);
macro proc TemporalDerivative_last(DataIn, dt, st);
macro proc Customftu(FractionalShift, detTH, Axx, Axy, Ayy, Axt, Ayt, Vx, Vy);
macro proc FIXPOINTftu_old(FractionalShift, detTH, Axx, Axy, Ayy, Axt, Ayt, VxOut, VyOut);
macro proc FIXPOINTftu(FractionalShift, detTH, Axx, Axy, Ayy, Axt, Ayt, VxOut, VyOut);
macro proc FIXPOINTftu_disp(FractionalShift, detTH, Axx, Axt, VxOut);
macro proc division_core(Num, Den, quot);
macro proc GenericConvolution(Input, Output, X_FIR, Y_FIR, NTaps, NTapsMinus1, ColumnLength);
macro proc GenericConvolutionOld(Input, Output, X_FIR, Y_FIR, NTaps, ColumnLength); // --> testearlas!!!
macro proc Median(Input, Output, ColumnLength);
// Old fpu units and test
macro proc testdiv(FractionalShift, Axx, Ayy, Vx);
macro proc ftu(Threshold, Axx, Axy, Ayy, Axt, Ayt, Vx, Vy);
macro proc Pipeftu(FractionalShift, Axx, Axy, Ayy, Axt, Ayt, Att, Vx, Vy, Confidence);
macro proc RecursiveTempCconvolution( Input, Output, ColumnLength, RowLength, RAMdirE,
RAMdatE, RAMdirL, RAMdatL, GlobalPipeDelay);
#endif
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment