Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions +adi/+AD9361/Base.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
classdef (Abstract, Hidden = true) Base < adi.common.Attribute & matlabshared.libiio.base & ...
matlab.system.mixin.CustomIcon
classdef (Abstract, Hidden = true) Base < adi.common.Attribute & ...
adi.common.DebugAttribute & ...
matlabshared.libiio.base & matlab.system.mixin.CustomIcon

%adi.AD9361.Base Class
% This class contains shared parameters and methods between TX and RX
% classes
Expand Down
13 changes: 11 additions & 2 deletions +adi/+AD9361/Rx.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
classdef Rx < adi.AD9361.Base & adi.common.Rx & matlab.system.mixin.SampleTime
classdef Rx < adi.AD9361.Base & adi.AD9361.TuneAGC & ...
adi.common.Rx & matlab.system.mixin.SampleTime
% adi.AD9361.Rx Receive data from the AD9361 transceiver
% The adi.AD9361.Rx System object is a signal source that can receive
% complex data from the AD9361.
Expand Down Expand Up @@ -215,7 +216,7 @@
obj.setAttributeLongLong(id,'sampling_frequency',value,true,4);
end
end
end
end
end

methods (Access=protected)
Expand Down Expand Up @@ -324,6 +325,14 @@ function setupInit(obj)
writeFilterFile(obj);
end

if (obj.CustomAGC)
% Initialize hardware to reflect debug attribute changes
obj.WriteDebugAttributes();
obj.setDebugAttributeLongLong();
obj.setDebugAttributeBool();
obj.WriteToRegisters();
end

end

end
Expand Down
288 changes: 288 additions & 0 deletions +adi/+AD9361/TuneAGC.m

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions +adi/+AD9371/Base.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
channelCount = 2;
end

properties (Nontunable, Logical)
%EnableCustomProfile Enable Custom Profile
% Enable use of custom Profile file to set SamplingRate,
% RFBandwidth, and FIR in datapaths
EnableCustomProfile = false;
end

properties (Nontunable)
%CustomProfileFileName Custom Profile File Name
% Path to custom Profile file created from profile wizard
CustomProfileFileName = '';
end

properties (Hidden, Constant)
%SamplingRate Sampling Rate
% Baseband sampling rate in Hz, specified as a scalar
Expand Down Expand Up @@ -72,6 +85,23 @@ function delete(~)
obj.setAttributeLongLong(id,'frequency',value,true);
end
end
% Check EnableCustomProfile
function set.EnableCustomProfile(obj, value)
validateattributes( value, { 'logical' }, ...
{ }, ...
'', 'EnableCustomProfile');
obj.EnableCustomProfile = value;
end
% Check CustomFilterFileName
function set.CustomProfileFileName(obj, value)
validateattributes( value, { 'char' }, ...
{ }, ...
'', 'CustomProfileFileName');
obj.CustomProfileFileName = value;
if obj.EnableCustomProfile && obj.ConnectedToDevice %#ok<MCSUP>
writeProfileFile(obj);
end
end
end

%% API Functions
Expand All @@ -80,6 +110,12 @@ function delete(~)
function icon = getIconImpl(obj)
icon = sprintf(['AD9371 ',obj.Type]);
end


function writeProfileFile(obj)
profle_data_str = fileread(obj.CustomProfileFileName);
obj.setDeviceAttributeRAW('profile_config',profle_data_str);
end

end

Expand Down
4 changes: 4 additions & 0 deletions +adi/+AD9371/Rx.m
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ function setupInit(obj)
id = sprintf('altvoltage%d',strcmp(obj.Type,'Tx'));
obj.setAttributeLongLong(id,'RX_LO_frequency',obj.CenterFrequency ,true);

if obj.EnableCustomProfile
writeProfileFile(obj);
end

if strcmp(obj.GainControlMode,'manual')
obj.setAttributeLongLong('voltage0','hardwaregain',obj.GainChannel0,false);
obj.setAttributeLongLong('voltage1','hardwaregain',obj.GainChannel1,false);
Expand Down
35 changes: 34 additions & 1 deletion +adi/+common/Attribute.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
classdef (Abstract) Attribute < matlabshared.libiio.base
% Attribute IIO attribute function calls

methods (Hidden, Access = protected)
methods (Hidden)

function setAttributeLongLong(obj,id,attr,value,isOutput,tol)
phydev = getDev(obj, obj.phyDevName);
Expand All @@ -22,6 +22,15 @@ function setAttributeLongLong(obj,id,attr,value,isOutput,tol)
end
end

function rValue = getAttributeLongLong(obj,id,attr,isOutput)
phydev = getDev(obj, obj.phyDevName);
chanPtr = iio_device_find_channel(obj,phydev,id,isOutput);%FIXME (INVERSION)
status = cPtrCheck(obj,chanPtr);
cstatus(obj,status,['Channel: ' id ' not found']);
[status, rValue] = iio_channel_attr_read_longlong(obj,chanPtr,attr);
cstatus(obj,status,['Error reading attribute: ' attr]);
end

function setAttributeBool(obj,id,attr,value,isOutput)
phydev = getDev(obj, obj.phyDevName);
chanPtr = iio_device_find_channel(obj,phydev,id,isOutput);%FIXME (INVERSION)
Expand All @@ -38,6 +47,15 @@ function setAttributeBool(obj,id,attr,value,isOutput)
end
end

function rValue = getAttributeBool(obj,id,attr,isOutput)
phydev = getDev(obj, obj.phyDevName);
chanPtr = iio_device_find_channel(obj,phydev,id,isOutput);%FIXME (INVERSION)
status = cPtrCheck(obj,chanPtr);
cstatus(obj,status,['Channel: ' id ' not found']);
[status, rValue] = iio_channel_attr_read_bool(obj,chanPtr,attr);
cstatus(obj,status,['Error reading attribute: ' attr]);
end

function setAttributeRAW(obj,id,attr,value,isOutput)
phydev = getDev(obj, obj.phyDevName);
chanPtr = iio_device_find_channel(obj,phydev,id,isOutput);%FIXME (INVERSION)
Expand All @@ -50,6 +68,15 @@ function setAttributeRAW(obj,id,attr,value,isOutput)
end
end

function rValue = getAttributeRAW(obj,id,attr,isOutput)
phydev = getDev(obj, obj.phyDevName);
chanPtr = iio_device_find_channel(obj,phydev,id,isOutput);%FIXME (INVERSION)
status = cPtrCheck(obj,chanPtr);
cstatus(obj,status,['Channel: ' id ' not found']);
[status, rValue] = iio_channel_attr_read(obj,chanPtr,attr);
cstatus(obj,status,['Error reading attribute: ' attr]);
end

function setDeviceAttributeRAW(obj,attr,value)
phydev = getDev(obj, obj.phyDevName);
bytes = iio_device_attr_write(obj,phydev,attr,value);
Expand All @@ -59,5 +86,11 @@ function setDeviceAttributeRAW(obj,attr,value)
end
end

function rValue = getDeviceAttributeRAW(obj,attr)
phydev = getDev(obj, obj.phyDevName);
[status, rValue] = iio_device_attr_read(obj,phydev,attr);
cstatus(obj,status,['Error reading attribute: ' attr]);
end

end
end
38 changes: 38 additions & 0 deletions +adi/+common/DebugAttribute.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
classdef (Abstract) DebugAttribute < matlabshared.libiio.base

methods (Hidden, Access = protected)
function setDebugAttributeLongLong(obj,attr,value)
phydev = getDev(obj, obj.phyDevName);
if (nargin == 1)
iio_device_debug_attr_write_longlong(obj,phydev, 'initialize',1);
return;
end
status = iio_device_debug_attr_write_longlong(obj,phydev,attr,value);
cstatus(obj,status,['Attribute write failed for : ' attr ' with value ' num2str(value)]);
% Check
[status, rValue] = iio_device_debug_attr_read_longlong(obj,phydev,attr);
cstatus(obj,status,['Error reading attribute: ' attr]);
if (value ~= rValue)
status = -1;
cstatus(obj,status,['Attribute ' attr ' return value ' num2str(rValue) ', expected ' num2str(value)]);
end
end

function setDebugAttributeBool(obj,attr,value)
phydev = getDev(obj, obj.phyDevName);
if (nargin == 1)
iio_device_debug_attr_write_bool(obj,phydev, 'initialize',1);
return;
end
status = iio_device_debug_attr_write_bool(obj,phydev,attr,value);
cstatus(obj,status,['Attribute write failed for : ' attr]);
% Check
[status, rValue] = iio_device_debug_attr_read_bool(obj,phydev,attr);
cstatus(obj,status,['Error reading attribute: ' attr]);
if value ~= rValue
status = -1;
cstatus(obj,status,['Attribute ' attr ' return value ' num2str(rValue) ', expected ' num2str(value)]);
end
end
end
end
40 changes: 40 additions & 0 deletions +adi/+common/RegisterReadWrite.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
classdef (Abstract) RegisterReadWrite < matlabshared.libiio.base

methods (Hidden, Access = protected)
function setRegister(obj, value, addr, mask_bin, bit_shift)
phydev = getDev(obj, obj.phyDevName);
if (nargin == 5)
value = value*2^(bit_shift);
end
addr_dec = hex2dec(addr);
mask_dec = bin2dec(mask_bin);
[status, curr_val] = iio_device_reg_read(obj,phydev,addr_dec);
cstatus(obj,status,['Error reading address: ' addr]);
new_val = bitxor(value, bitand(bitxor(value, curr_val), mask_dec));
status = iio_device_reg_write(obj,phydev,addr_dec,new_val);
cstatus(obj,status,['Address write failed for : ' addr ' with value ' num2str(value)]);
% Check
[status, rValue] = iio_device_reg_read(obj,phydev,addr_dec);
cstatus(obj,status,['Error reading address: ' addr]);
if (new_val ~= rValue)
status = -1;
cstatus(obj,status,['Address ' addr ' contents ' num2str(rValue) ', expected ' num2str(new_val)]);
end
end

function value = getRegister(obj, addr, mask_bin, bit_shift)
phydev = getDev(obj, obj.phyDevName);
addr_dec = hex2dec(addr);
% Check
[status, value] = iio_device_reg_read(obj,phydev,addr_dec);
if (nargin >= 3)
mask_dec = 255-bin2dec(mask_bin);
value = bitand(value, mask_dec);
if (nargin == 4)
value = value/2^(bit_shift);
end
end
cstatus(obj,status,['Error reading address: ' addr]);
end
end
end
7 changes: 7 additions & 0 deletions +adi/+common/RxTx.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
function flag = isInactivePropertyImpl(obj, prop)
flag = strcmpi(prop,'enIO');
% TX/RX
if isprop(obj,'EnableCustomProfile')
flag = flag || strcmpi(prop,'CustomProfileFileName') && ~obj.EnableCustomProfile;
if obj.EnableCustomProfile
flag = flag || strcmpi(prop,'RFBandwidth');
flag = flag || strcmpi(prop,'SamplingRate');
end
end
if isprop(obj,'EnableCustomFilter')
flag = flag || strcmpi(prop,'CustomFilterFileName') && ~obj.EnableCustomFilter;
if obj.EnableCustomFilter
Expand Down
20 changes: 20 additions & 0 deletions +adi/Version.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
classdef Version
%Version
% BSP Version information
properties(Constant)
HDL = 'hdl_2018_r1';
Vivado = '2017.4.1';
MATLAB = 'R2018b';
Release = '18.2';
end
properties(Dependent)
VivadoShort
end

methods
function value = get.VivadoShort(obj)
value = obj.Vivado(1:6);
end
end
end

Loading