-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit 5939a6c.
- Loading branch information
Alexey Kaygorodov
committed
Apr 18, 2018
1 parent
64c7b9e
commit 0759d71
Showing
143 changed files
with
3,771 additions
and
3,632 deletions.
There are no files selected for viewing
Submodule Applications
updated
from 15fbd0 to b50f24
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Simple C gpio test application shows how to export/unexport different pins and | ||
set direction on exported pins. | ||
|
||
Requierment for using sysfs gpio interface for working with gpios is to load appropriate fpga bitstream | ||
/opt/redpitaya/fpga/classic/fpga.bit and /opt/redpitaya/mercury/fpga.bit fit that requierments. | ||
You can load bitstream using "cat /opt/redpitaya/fpga/classic/fpga.bit > /dev/xdevcfg" command. | ||
|
||
Usaly exporting and setting direction to pins is done in external script that sets up all | ||
required gpio in this example that is done using "system" call(same can also be achived using calls to functions open read and write). | ||
|
||
Actual read and writes on /sys/class/gpio/gpio_PIN_NO_/value (where _PIN_NO_ represents pin number of | ||
exported pin) is done with simple open, read and write comands. | ||
|
||
If you connect pins DIO0_N to DIO0_P using jumper wire, value read from PIN DIO0_P | ||
should match value written to POUT DIO0_P. | ||
|
||
Documentation related to numbering of GPIO pins on redpitaya board is available at: | ||
https://github.com/RedPitaya/RedPitaya/blob/master/doc/developerGuide/gpio/gpio.rst | ||
|
||
General documentation related to gpio/sysfs interface is available at: | ||
https://github.com/RedPitaya/linux-xlnx/blob/master/Documentation/gpio/sysfs.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
#define IN 0 | ||
#define OUT 1 | ||
|
||
#define LOW 0 | ||
#define HIGH 1 | ||
|
||
#define PIN 976 | ||
#define POUT 968 | ||
|
||
#define VALUE_MAX 30 | ||
#define BUFFER_MAX 3 | ||
|
||
#define MAX_PATH 64 | ||
|
||
|
||
static int pin_export(int pin) | ||
{ | ||
char shell[MAX_PATH]; | ||
sprintf(shell,"echo %d > /sys/class/gpio/export", pin); | ||
system(shell); | ||
return 0; | ||
} | ||
|
||
static int pin_unexport(int pin) | ||
{ | ||
char shell[MAX_PATH]; | ||
sprintf(shell,"echo %d > /sys/class/gpio/unexport", pin); | ||
system(shell); | ||
|
||
return 0; | ||
} | ||
|
||
static int pin_direction(int pin, int dir){ | ||
|
||
char shell[MAX_PATH]; | ||
snprintf(shell, MAX_PATH, "echo %s > /sys/class/gpio/gpio%d/direction",((dir==IN)?"in":"out"),pin); | ||
system(shell); | ||
|
||
return 0; | ||
} | ||
|
||
static int pin_read(int pin){ | ||
|
||
char path[VALUE_MAX]; | ||
char value_str[3]; | ||
int fd; | ||
|
||
snprintf(path, VALUE_MAX, "/sys/class/gpio/gpio%d/value", pin); | ||
|
||
// get pin file descriptor for reading its state | ||
fd = open(path, O_RDONLY); | ||
if (-1 == fd) { | ||
fprintf(stderr, "Unable to open gpio sysfs pin value file %s for reading\n",path); | ||
return -1; | ||
} | ||
|
||
// read value | ||
if (-1 == read(fd, value_str, 3)) { | ||
fprintf(stderr, "Unable to read value\n"); | ||
return -1; | ||
} | ||
|
||
// close file | ||
close(fd); | ||
|
||
// return integar value | ||
return atoi(value_str); | ||
} | ||
|
||
static int pin_write(int pin, int value) | ||
{ | ||
char path[VALUE_MAX]; | ||
int fd; | ||
|
||
snprintf(path, VALUE_MAX, "/sys/class/gpio/gpio%d/value", pin); | ||
// get pin value file descrptor | ||
fd = open(path, O_WRONLY); | ||
if (-1 == fd) { | ||
fprintf(stderr, "Unable to to open sysfs pins value file %s for writing\n",path); | ||
return -1; | ||
} | ||
if(value==LOW){ | ||
//write low | ||
if (1 != write(fd, "0", 1)) { | ||
fprintf(stderr, "Unable to write value\n"); | ||
return -1; | ||
} | ||
} | ||
else if(value==HIGH){ | ||
//write high | ||
if (1 != write(fd, "1", 1)) { | ||
fprintf(stderr, "Unable to write value\n"); | ||
return -1; | ||
} | ||
}else fprintf(stderr, "Nonvalid pin value requested\n"); | ||
|
||
//close file | ||
close(fd); | ||
return 0; | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
// apply required fpga bitstream mercury or classic | ||
// system("cat /opt/redpitaya/fpga/fpga_classic.bit > /dev/xdevcfg"); | ||
|
||
int repeat = 10; | ||
if (argc==2) | ||
repeat=atoi(argv[1]); | ||
// export pins | ||
if (-1 == pin_export(POUT) || -1 == pin_export(PIN)) return 1; | ||
|
||
// set pin direction | ||
if (-1 == pin_direction(POUT, OUT) || -1 == pin_direction(PIN, IN)) return 2; | ||
int i; | ||
for (i = 1; i <= repeat; i++){ | ||
// set pin value | ||
if (-1 == pin_write( POUT, i % 2)) return 3; | ||
printf("Setting pin %d to %d\n", POUT,i % 2); | ||
// read and printout pin value | ||
printf("Reading pin %d got %d\n", PIN,pin_read(PIN)); | ||
usleep(10000); | ||
} | ||
// unexport pins on exit | ||
if (-1 == pin_unexport(POUT) || -1 == pin_unexport(PIN)) | ||
return 4; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,77 @@ | ||
% %% Define Red Pitaya as TCP/IP object | ||
clc | ||
close all | ||
IP= '192.168.178.103'; % Input IP of your Red Pitaya... | ||
% IP= '192.168.101.108'; % IP of your Red Pitaya... | ||
IP= 'rp-f01b63.local'; % rp-MAC.local MAC are the last 6 characters of your Red Pitaya | ||
port = 5000; % If you are using WiFi then IP is: | ||
RP=tcpip(IP, port,'OutputBufferSize',32784*5); % 192.168.128.1 | ||
|
||
RP=tcpip(IP, port,'OutputBufferSize',32784*5); | ||
fopen(RP); | ||
RP.Terminator = 'CR/LF'; | ||
|
||
%% Prepare an arbitrary waveform | ||
% Values of arbitrary waveform must be in range from -1 to 1. | ||
length = 2^14; | ||
|
||
% select data transmittion BIN/ASCII (0 - binary, any other value - ASCII) | ||
bin=1; | ||
% select buffer length (max = 2^14) | ||
length = 2^3; | ||
% STEMlab 14 - 1 sign + 13 data bits | ||
bitsize= 0; | ||
|
||
% generates x axis in range 0 to 6 with length number of points | ||
X0=0; | ||
XN=6; | ||
XN=length-1; | ||
x = X0:(XN-X0)/(length-1):XN ; | ||
% Values of arbitrary waveform must be in range from -1 to 1. | ||
y1 = 0.8 * sin(x); % the first sinus signal with the amplitude 0.8 | ||
y2 = 0.2 * sin(21*x); % the second sinus signal with a frequency 20 times higher than the first one and the amplitude of 0.2 | ||
y_sum = y1+y2; | ||
% y2 = 0.2 * sin(5*x); % the second sinus signal with a frequency 20 times higher than the first one and the amplitude of 0.2 | ||
y_sum = x; | ||
|
||
% plot(x,y_sum); | ||
% uncomment the following line to show the plot of the arbitrary function | ||
plot(x,y_sum); | ||
|
||
%% transmit data and configure genertor | ||
|
||
%%% transmit data in binary format | ||
% binary write still needs to be debuged | ||
% disp(y_sum) | ||
% binblockwrite(RP, y_sum,'int16','SOURce1:TRACe:DATA:RAW '); | ||
% fprintf(RP,'\n'); | ||
|
||
%%% transmit data in ascii format | ||
% convert float to string | ||
waveform_ch_1_0 = num2str(y_sum,'%1.5f,'); | ||
% remove the last “,”. | ||
waveform_ch_1 = waveform_ch_1_0(1,1: size(waveform_ch_1_0,2)-3); | ||
|
||
% set output amplitude and offset | ||
fprintf(RP,'SOURce1:VOLTage:IMMediate:AMPlitude 1'); | ||
fprintf(RP,'SOURce1:VOLTage:IMMediate:OFFSet 0'); | ||
|
||
% # specify peridic mode, sinusoidal waveform and 1kHZ frequency | ||
% specify peridic mode | ||
fprintf(RP,'SOURce1:MODE PERiodic'); | ||
|
||
fprintf(RP,['SOURce1:TRACe:DATA:DATA ' waveform_ch_1]); | ||
fprintf(RP,'SOURce1:FREQuency:FIXed 1000'); | ||
% | ||
% # reset and start state machine | ||
%%% transmit arbitrary waveform in either BINARY or ASCII format | ||
if bin | ||
disp('INFO: Sending data in BINARY format'); | ||
binblockwrite(RP, y_sum * (2^bitsize),'int16','SOURce1:TRACe:DATA:RAW '); | ||
fprintf(RP,''); %binblockwrite does not complete with /n, hence one is added here | ||
|
||
y_sum * (2^bitsize) | ||
fprintf(RP,'SOURce1:TRACe:DATA:RAW? 8 '); | ||
data1 = binblockread(RP,'int16') | ||
else | ||
disp('INFO: Sending data in ASCII format'); | ||
% convert float to string | ||
waveform_ch_1_0 = num2str(y_sum,'%1.5f,'); | ||
% remove the last “,”. | ||
waveform_ch_1 = waveform_ch_1_0(1,1: size(waveform_ch_1_0,2)-1); | ||
fprintf(RP,['SOURce1:TRACe:DATA:DATA ' waveform_ch_1]); | ||
end | ||
|
||
% set 1kHZ frequency | ||
fprintf(RP,'SOURce1:FREQuency:FIXed 2000'); | ||
|
||
% reset and start state machine | ||
fprintf(RP,'SOURce1:RESET'); | ||
fprintf(RP,'SOURce1:START'); | ||
% | ||
|
||
% # enable output | ||
fprintf(RP,'OUTPUT1:STATe ON'); | ||
% | ||
|
||
% # trigger state machine | ||
fprintf(RP,'SOURce1:TRIGger'); | ||
|
||
% RA = binblockread(RP,'int16'); | ||
|
||
%% Close connection to the Red Pitaya | ||
fclose(RP); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.