Skip to content

Commit

Permalink
matlab: allow to set and get current active channel through bladeRF_XCVR
Browse files Browse the repository at this point in the history
  • Loading branch information
rghilduta committed Aug 29, 2019
1 parent 37674cc commit a49ac5c
Showing 1 changed file with 48 additions and 7 deletions.
55 changes: 48 additions & 7 deletions host/libraries/libbladeRF_bindings/matlab/bladeRF_XCVR.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
lna % RX LNA gain. Values: { 'BYPASS', 'MID', 'MAX' }
xb200_filter % XB200 Filter selection. Only valid when an XB200 is attached. Options are: '50M', '144M', '222M', 'AUTO_1DB', 'AUTO_3DB', 'CUSTOM'
mux % FPGA sample FIFO mux mode. Only valid for RX, with options 'BASEBAND_LMS', '12BIT_COUNTER', '32BIT_COUNTER', 'DIGITAL_LOOPBACK'
channel % Channel number
end

properties(SetAccess = immutable, Hidden=true)
Expand All @@ -59,6 +60,10 @@
xb200_attached; % Modify behavior due to XB200 being attached
end

properties(SetAccess = private, Hidden=true)
current_channel % Current active channel
end

properties(SetAccess = private)
running % Denotes whether or not the module is enabled to stream samples.
timestamp % Provides a coarse readback of the timestamp counter.
Expand Down Expand Up @@ -207,6 +212,44 @@
%fprintf('Read %s gain: %d\n', obj.direction, val);
end

% Configures active channel setting
function set.channel(obj, val)
if (strcmpi(val,'RX') == true || strcmpi(val, 'RX1') || strcmp(val, 'BLADERF_CHANNEL_RX1'))
channel = 'BLADERF_CHANNEL_RX1';
elseif (strcmpi(val, 'RX2') || strcmp(val, 'BLADERF_CHANNEL_RX2'))
channel = 'BLADERF_CHANNEL_RX2';
elseif (strcmpi(val,'TX') == true || strcmpi(val, 'TX1') || strcmp(val, 'BLADERF_CHANNEL_TX1'))
channel = 'BLADERF_CHANNEL_TX1';
elseif (strcmpi(val, 'TX2') || strcmp(val, 'BLADERF_CHANNEL_TX2'))
channel = 'BLADERF_CHANNEL_TX2';
end

obj.current_channel = channel;

if obj.running
[status, ~] = calllib('libbladeRF', 'bladerf_enable_module', ...
obj.bladerf.device, ...
obj.current_channel, ...
false);

bladeRF.check_status('bladerf_enable_module', status);


[status, ~] = calllib('libbladeRF', 'bladerf_enable_module', ...
obj.bladerf.device, ...
channel, ...
true);

bladeRF.check_status('bladerf_enable_module', status);
end

end

% Reads the current active channel setting
function val = get.channel(obj)
val = obj.current_channel
end

% Configures the universal gain
function set.gain(obj, val)
if strcmpi(obj.direction,'RX') == true && strcmpi(obj.agc,'manual') == 0
Expand Down Expand Up @@ -484,11 +527,9 @@
% Set the direction of the transceiver
obj.direction = dir;
obj.bladerf = dev;
if strcmpi(dir,'RX') == true
obj.module = 'BLADERF_MODULE_RX';
else
obj.module = 'BLADERF_MODULE_TX';
end

obj.channel = dir;
obj.module = obj.current_channel;

if strcmpi(xb, 'XB200') == true
obj.min_frequency = 0;
Expand Down Expand Up @@ -583,7 +624,7 @@ function start(obj)
% Enable the module
[status, ~] = calllib('libbladeRF', 'bladerf_enable_module', ...
obj.bladerf.device, ...
obj.module, ...
obj.current_channel, ...
true);

bladeRF.check_status('bladerf_enable_module', status);
Expand Down Expand Up @@ -620,7 +661,7 @@ function stop(obj)
% Disable the module
[status, ~] = calllib('libbladeRF', 'bladerf_enable_module', ...
obj.bladerf.device, ...
obj.module, ...
obj.current_channel, ...
false);

bladeRF.check_status('bladerf_enable_module', status);
Expand Down

0 comments on commit a49ac5c

Please sign in to comment.