Your Name 3 주 전
커밋
f3e804db95
39개의 변경된 파일2709개의 추가작업 그리고 0개의 파일을 삭제
  1. 59 0
      Makefile
  2. 36 0
      README.md
  3. 73 0
      acquire_4ch_trigger_software.c
  4. 209 0
      acquire_signal_check.c
  5. 63 0
      acquire_trigger_posedge.c
  6. 80 0
      acquire_trigger_software.c
  7. 28 0
      analog_inputs.c
  8. 42 0
      analog_outputs.c
  9. BIN
      axi
  10. 113 0
      axi.c
  11. 149 0
      axi_4ch.c
  12. BIN
      axi_gen
  13. 140 0
      axi_gen.c
  14. BIN
      axi_service
  15. BIN
      axi_service]
  16. 76 0
      calibration_api.c
  17. 52 0
      can_loopback.c
  18. 81 0
      can_pass.c
  19. 37 0
      digital_led_bar.c
  20. 38 0
      digital_led_blink.c
  21. 32 0
      digital_push_button.c
  22. 54 0
      generate_arbitrary_waveform.c
  23. 34 0
      generate_burst_trigger_external.c
  24. 38 0
      generate_burst_trigger_software.c
  25. 40 0
      generate_continuous.c
  26. 48 0
      generate_two_burst_trigger_software.c
  27. 32 0
      generate_two_trigger_software_sync.c
  28. 216 0
      i2c.c
  29. 64 0
      i2c_eeprom_read_calib.c
  30. 63 0
      i2c_switch_max7311.c
  31. 116 0
      period
  32. 1 0
      rp-test-pub
  33. BIN
      rp.tar
  34. 94 0
      rp_client.py
  35. 188 0
      spi.c
  36. 81 0
      spi_loopback.c
  37. 99 0
      test_e_module.c
  38. 177 0
      uart.c
  39. 56 0
      uart_loopback.c

+ 59 - 0
Makefile

@@ -0,0 +1,59 @@
+CFLAGS  = -std=gnu11 -Wall ## -Werror
+CFLAGS += -I/opt/redpitaya/include
+LDFLAGS = -L/opt/redpitaya/lib
+LDLIBS = -static -lrp-hw-can -lrp -lrp-hw-calib -lrp-hw-profiles
+
+INCLUDE += -I/opt/redpitaya/include/api250-12
+LDLIBS += -lrp-gpio -lrp-i2c
+LDLIBS += -lrp-hw -lm -lstdc++ -lpthread -li2c -lsocketcan
+
+
+# List of compiled object files (not yet linked to executable)
+
+PRGS =  analog_inputs \
+		analog_outputs \
+		digital_led_bar \
+		digital_led_blink \
+		digital_push_button \
+		i2c \
+		spi \
+		spi_loopback \
+		test_e_module \
+		uart \
+		uart_loopback \
+		can_pass \
+		can_loopback \
+		calibration_api \
+		axi_gen
+
+PRGS += acquire_trigger_software \
+		acquire_trigger_posedge \
+		acquire_signal_check \
+		generate_arbitrary_waveform \
+		generate_burst_trigger_external \
+		generate_burst_trigger_software \
+		generate_continuous \
+		generate_two_burst_trigger_software \
+		generate_two_trigger_software_sync \
+		axi \
+		axi_4ch
+
+PRGS += i2c_eeprom_read_calib
+PRGS += acquire_4ch_trigger_software
+PRGS += i2c_switch_max7311
+
+OBJS := $(patsubst %,%.o,$(PRGS))
+SRC := $(patsubst %,%.c,$(PRGS))
+
+all: $(PRGS)
+
+$(PRGS): %: %.c
+	$(CC) $< $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@
+
+clean:
+	$(RM) *.o
+	$(RM) $(OBJS)
+
+clean_all: clean
+	$(RM) $(PRGS)
+

+ 36 - 0
README.md

@@ -0,0 +1,36 @@
+# Compiling and running on target
+
+When compiling on the target no special preparations are needed. A native toolchain is available directly on the Debian system.
+
+First connect to your board over SSH (replace the IP, the default password is `root`).
+```bash
+ssh root@192.168.0.100
+```
+
+Now on the target, make a clone of the Red Pitaya Git repository and enter the project directory.
+```bash
+git clone https://github.com/RedPitaya/RedPitaya.git
+cd RedPitaya
+```
+
+To compile one example just use the source file name without the `.c` extension.
+```bash
+cd Examples/C
+make digital_led_blink
+```
+
+```bash
+cd Examples/C
+make acquire_signal_check
+```
+
+
+Applications based on the API require a specific FPGA image to be loaded:
+```bash
+overlay.sh v0.94
+```
+
+Execute the application. The path to Red Pitaya shared libraries must be provided explicitly. Some applications run in a continuous loop, press `CTRL+C` to stop them.
+```bash
+LD_LIBRARY_PATH=/opt/redpitaya/lib ./digital_led_blink
+```

+ 73 - 0
acquire_4ch_trigger_software.c

@@ -0,0 +1,73 @@
+/* Red Pitaya C API example Acquiring a signal from a buffer
+ * This application acquires a signal on a specific channel */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "rp.h"
+#include "rp_hw-profiles.h"
+
+
+int main(int argc, char **argv){
+
+        uint8_t c = 0;
+        if (rp_HPGetFastADCChannelsCount(&c) != RP_HP_OK){
+                fprintf(stderr,"[Error] Can't get fast ADC channels count\n");
+                return 1;
+        }
+
+        if (c!= 4){
+                fprintf(stderr,"[Error] The number of channels is wrong\n");
+                return 1;
+        }
+
+        /* Print error, if rp_Init() function failed */
+        if(rp_Init() != RP_OK){
+                fprintf(stderr, "Rp api init failed!\n");
+        }
+
+        uint32_t buff_size = 16384;
+
+        rp_AcqReset();
+        rp_AcqSetDecimation(RP_DEC_8);
+        rp_AcqSetTriggerDelay(0);
+
+        rp_AcqStart();
+
+        /* After acquisition is started some time delay is needed in order to acquire fresh samples in to buffer*/
+        /* Here we have used time delay of one second but you can calculate exact value taking in to account buffer*/
+        /*length and smaling rate*/
+
+        sleep(1);
+        rp_AcqSetTriggerSrc(RP_TRIG_SRC_NOW);
+        rp_acq_trig_state_t state = RP_TRIG_STATE_TRIGGERED;
+
+        while(1){
+                rp_AcqGetTriggerState(&state);
+                if(state == RP_TRIG_STATE_TRIGGERED){
+                sleep(1);
+                break;
+                }
+        }
+
+        bool fillState = false;
+        while(!fillState){
+		rp_AcqGetBufferFillState(&fillState);
+	}
+
+        uint32_t pos = 0;
+	rp_AcqGetWritePointerAtTrig(&pos);
+        buffers_t *b = rp_createBuffer(4,buff_size,false,false,true);
+
+        rp_AcqGetData(pos, b);
+
+        int i;
+        for(i = 0; i < buff_size; i++){
+                printf("%f %f %f %f\n", b->ch_f[0][i],b->ch_f[1][i],b->ch_f[2][i],b->ch_f[3][i]);
+        }
+        /* Releasing resources */
+        rp_deleteBuffer(b);
+        rp_Release();
+
+        return 0;
+}

+ 209 - 0
acquire_signal_check.c

@@ -0,0 +1,209 @@
+/* Red Pitaya C API example Acquiring a signal from a buffer and check it
+ * This application acquires a signal on a specific channel */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <math.h>
+#include <string.h>
+
+#include "rp_hw-profiles.h"
+#include "rp.h"
+
+#define EPS 0.05
+#define EPS_F 100
+
+
+uint32_t getADCRate(){
+    uint32_t c = 0;
+    if (rp_HPGetBaseFastADCSpeedHz(&c) != RP_HP_OK){
+        fprintf(stderr,"[Error] Can't get fast ADC channels count\n");
+    }
+    return c;
+}
+
+#define c_osc_fpga_smpl_freq  getADCRate()
+#define c_meas_time_thr  (ADC_BUFFER_SIZE / (1000000000 / getADCRate()))
+const float c_meas_freq_thr = 0.05;
+const float c_min_period = 19.6e-9; // 51 MHz
+
+void filterBuffer(float *_buffer,int _size){
+    float *n_b = malloc(_size * sizeof(float));
+    memcpy(n_b,_buffer,_size);
+    float core[] = { 1.0 / 8.0 , 1.0 / 4.0 , 1.0 / 4.0 , 1.0 / 4.0 , 1.0 / 8.0};
+    for(int i = 2 ; i < _size - 2 ; i++ ){
+        float sum = 0;
+        for (int j = -2 ; j <= 2 ; j++ ){
+            sum += core[j + 2] * _buffer [i + j];
+        }
+        n_b[i] = sum;
+    }
+    memcpy(_buffer,n_b,_size);
+    free(n_b);
+}
+
+bool checkAmplitudeAndFreq(float *_buff, uint32_t _size,float _nominal,float *min, float *max,float *frequency){
+        int trig_t[2] = { 0, 0 };
+        int trig_cnt = 0;
+        int state = 0;
+        if (_size > 0){
+                *min = _buff[0];
+                *max = _buff[0];
+                for (int i = 1 ; i < _size ; ++i){
+                        if (*min > _buff[i]) *min = _buff[i];
+                        if (*max < _buff[i]) *max = _buff[i];
+                }
+
+                uint32_t dec_factor = 1;
+                rp_AcqGetDecimationFactor(&dec_factor);
+
+                float acq_dur=(float)(_size)/((float) c_osc_fpga_smpl_freq) * (float) dec_factor;
+                float cen = (*max + *min) / 2;
+                float thr1 = cen + 0.2 * (*min - cen);
+                float thr2 = cen + 0.2 * (*max - cen);
+                float res_period = 0;
+                for(int i = 0; i < _size; i++) {
+                        float sa = _buff[i];
+                        if((state == 0) && (sa < thr1)) {
+                                state = 1;
+                        }
+                        if((state == 1) && (sa >= thr2) ) {
+                                state = 0;
+                                if (trig_cnt++ == 0) {
+                                trig_t[0] = i;
+                                } else {
+                                trig_t[1] = i;
+                                }
+                        }
+                        if ((trig_t[1] - trig_t[0]) > c_meas_time_thr) {
+                                break;
+                        }
+                }
+                if(trig_cnt >= 2) {
+                        res_period = (float)(trig_t[1] - trig_t[0]) /
+                                ((float)c_osc_fpga_smpl_freq * (trig_cnt - 1)) * dec_factor;
+                }
+
+                if( ((thr2 - thr1) < c_meas_freq_thr) ||
+                        (res_period * 3 >= acq_dur)   ||
+                        (res_period < c_min_period) ){
+                        res_period = 0;
+                }
+                float period = res_period * 1000.f;
+                period = (period == 0.f) ?  0.000001f : period;
+                *frequency = (float) (1 / (period / 1000.0));
+                if ((fabs(*min + _nominal) < EPS) && (fabs(*max - _nominal) < EPS))
+                        return true;
+                return false;
+        }
+        return false;
+}
+
+float trapezoidalApprox(double *data, float T, int size){
+    double result = 0;
+    for(int i = 0; i < size - 1; i++){
+        result += data[i] + data[i+1];
+    }
+    result = ((T / 2.0) * result);
+    return result;
+}
+
+bool isSineTester(float *data, uint32_t size)
+{
+        uint32_t dec_factor = 1;
+        rp_AcqGetDecimationFactor(&dec_factor);
+        double T = (dec_factor / getADCRate());
+        double ch_rms[size];
+        double ch_avr[size];
+        for(int i = 0; i < size; i++) {
+                ch_rms[i] = data[i] * data[i];
+                ch_avr[i] = fabs(data[i]);
+        }
+        double K0 = sqrtf(T * size * trapezoidalApprox(ch_rms, T, size)) / trapezoidalApprox(ch_avr, T, size);
+        return ((K0 > 1.10) && (K0 < 1.12));
+}
+
+
+int main(int argc, char **argv){
+
+        bool fillState = false;
+	int  counter=100;
+        /* Print error, if rp_Init() function failed */
+        if(rp_Init() != RP_OK){
+                fprintf(stderr, "Rp api init failed!\n");
+        }
+
+        rp_GenReset();
+        rp_GenFreq(RP_CH_1, 20000.0);
+        rp_GenAmp(RP_CH_1, 1.0);
+        rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
+        rp_GenOutEnable(RP_CH_1);
+
+
+        uint32_t buff_size = 16384;
+        float *buff = (float *)malloc(buff_size * sizeof(float));
+
+        rp_AcqReset();
+        rp_AcqSetDecimation(RP_DEC_8);
+        rp_AcqSetTriggerLevel(RP_CH_1, 0);
+        rp_AcqSetTriggerDelay(ADC_BUFFER_SIZE/2.0);
+
+        while(counter--){
+                fillState = false;
+                rp_AcqStart();
+
+                /* After acquisition is started some time delay is needed in order to acquire fresh samples in to buffer*/
+                /* Here we have used time delay of one second but you can calculate exact value taking in to account buffer*/
+                /*length and smaling rate*/
+
+                sleep(1);
+                rp_AcqSetTriggerSrc(RP_TRIG_SRC_CHA_PE);
+                rp_acq_trig_state_t state = RP_TRIG_STATE_TRIGGERED;
+
+                while(1){
+                        rp_AcqGetTriggerState(&state);
+                        if(state == RP_TRIG_STATE_TRIGGERED){
+                        break;
+                        }
+                }
+
+                while(!fillState){
+                        rp_AcqGetBufferFillState(&fillState);
+                }
+
+                rp_AcqStop();
+                rp_AcqGetOldestDataV(RP_CH_1, &buff_size, buff);
+                filterBuffer(buff,buff_size);
+                printf("Acquiring Done\n");
+                float min = 0;
+                float max = 0;
+                float frequency = 0;
+                bool  isBrokenSignal = false;
+                if (checkAmplitudeAndFreq(buff,buff_size,1.0, &min , &max , &frequency)) {
+                        printf("\tAmplitude is correct MIN = %0.4f , MAX = %0.4f\n",min,max);
+                }else{
+                        printf("\tAmplitude is not correct MIN = %0.4f , MAX = %0.4f\n",min,max);
+                        isBrokenSignal = true;
+                }
+                if (fabs(frequency - 20000.0) < EPS_F) {
+                        printf("\tFrequency is correct %0.4f\n",frequency);
+                }else{
+                        printf("\tFrequency is not correct %0.4f\n",frequency);
+                        isBrokenSignal = true;
+                }
+
+                if (isSineTester(buff,buff_size)){
+                        printf("\tSignal form is sine\n");
+                }else{
+                        printf("\tSignal form is not sine\n");
+                        isBrokenSignal = true;
+                }
+
+                printf("Signal is %s\n\n",isBrokenSignal ? "not correct" : "correct");
+        }
+
+        /* Releasing resources */
+        free(buff);
+        rp_Release();
+        return 0;
+}

+ 63 - 0
acquire_trigger_posedge.c

@@ -0,0 +1,63 @@
+/* Red Pitaya C API example Acquiring a signal from a buffer
+ * This application acquires a signal on a specific channel */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "rp.h"
+
+int main(int argc, char **argv){
+
+        /* Print error, if rp_Init() function failed */
+        if(rp_Init() != RP_OK){
+                fprintf(stderr, "Rp api init failed!\n");
+        }
+
+        /*LOOB BACK FROM OUTPUT 2 - ONLY FOR TESTING*/
+        rp_GenReset();
+        rp_GenFreq(RP_CH_1, 20000.0);
+        rp_GenAmp(RP_CH_1, 1.0);
+        rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
+        rp_GenOutEnable(RP_CH_1);
+        rp_GenTriggerOnly(RP_CH_1);
+
+        uint32_t buff_size = 16384;
+        float *buff = (float *)malloc(buff_size * sizeof(float));
+
+        rp_AcqReset();
+        rp_AcqSetDecimation(RP_DEC_8);
+        rp_AcqSetTriggerLevel(RP_CH_1, 0.1);
+        rp_AcqSetTriggerDelay(0);
+
+        rp_AcqStart();
+
+        /* After acquisition is started some time delay is needed in order to acquire fresh samples in to buffer*/
+        /* Here we have used time delay of one second but you can calculate exact value taking in to account buffer*/
+        /*length and smaling rate*/
+
+        sleep(1);
+        rp_AcqSetTriggerSrc(RP_TRIG_SRC_CHA_PE);
+        rp_acq_trig_state_t state = RP_TRIG_STATE_TRIGGERED;
+
+        while(1){
+                rp_AcqGetTriggerState(&state);
+                if(state == RP_TRIG_STATE_TRIGGERED){
+                break;
+                }
+        }
+
+        bool fillState = false;
+        while(!fillState){
+		rp_AcqGetBufferFillState(&fillState);
+	}
+
+        rp_AcqGetOldestDataV(RP_CH_1, &buff_size, buff);
+        int i;
+        for(i = 0; i < buff_size; i++){
+                printf("%f\n", buff[i]);
+        }
+        /* Releasing resources */
+        free(buff);
+        rp_Release();
+        return 0;
+}

+ 80 - 0
acquire_trigger_software.c

@@ -0,0 +1,80 @@
+/* Red Pitaya C API example Acquiring a signal from a buffer
+ * This application acquires a signal on a specific channel */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "rp.h"
+
+int main(int argc, char **argv){
+
+        /* Print error, if rp_Init() function failed */
+        if(rp_InitReset(false) != RP_OK){
+                fprintf(stderr, "Rp api init failed!\n");
+        }
+
+        /*LOOB BACK FROM OUTPUT 2 - ONLY FOR TESTING*/
+        rp_EnableDebugReg();
+        rp_GenReset();
+        rp_GenFreq(RP_CH_1, 1000.0);
+        rp_GenAmp(RP_CH_1, 1.0);
+        rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
+        rp_GenOutEnable(RP_CH_1);
+        rp_GenTriggerOnly(RP_CH_1);
+
+        uint32_t buff_size = 20;
+        float *buff = (float *)malloc(buff_size * sizeof(float));
+
+        rp_AcqReset();
+        rp_AcqSetDecimation(RP_DEC_1024);
+        rp_AcqSetTriggerDelay(0);
+
+        rp_AcqStart();
+
+        /* After acquisition is started some time delay is needed in order to acquire fresh samples in to buffer*/
+        /* Here we have used time delay of one second but you can calculate exact value taking in to account buffer*/
+        /*length and smaling rate*/
+        int z = 5;
+
+        while(z){
+                uint32_t c;
+                rp_AcqGetPreTriggerCounter(&c);
+                sleep(1);
+                z--;
+                printf("Pre counter %d\n",c);
+        }
+
+
+        sleep(1);
+
+        rp_AcqSetTriggerSrc(RP_TRIG_SRC_NOW);
+        rp_acq_trig_state_t state = RP_TRIG_STATE_TRIGGERED;
+
+        while(1){
+                rp_AcqGetTriggerState(&state);
+                if(state == RP_TRIG_STATE_TRIGGERED){
+                sleep(1);
+                break;
+                }
+        }
+
+        bool fillState = false;
+        while(!fillState){
+		rp_AcqGetBufferFillState(&fillState);
+	}
+
+        rp_AcqStop();
+
+        rp_AcqGetOldestDataV(RP_CH_1, &buff_size, buff);
+
+        int i;
+        for(i = 0; i < buff_size; i++){
+                printf("%f\n", buff[i]);
+        }
+        /* Releasing resources */
+        free(buff);
+        rp_Release();
+
+        return 0;
+}
+

+ 28 - 0
analog_inputs.c

@@ -0,0 +1,28 @@
+/* Read analog voltage on slow analog input */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "rp.h"
+
+int main (int argc, char **argv) {
+    float value [4];
+    uint32_t raw [4];
+
+    // Initialization of API
+    if (rp_Init() != RP_OK) {
+        fprintf(stderr, "Red Pitaya API init failed!\n");
+        return EXIT_FAILURE;
+    }
+
+    // Measure each XADC input voltage
+    for (int i=0; i<4; i++) {
+        rp_AIpinGetValue(i, &value[i],&raw[i]);
+        printf("Measured voltage on AI[%i] = %1.2fV\n", i, value[i]);
+    }
+
+    // Releasing resources
+    rp_Release();
+
+    return EXIT_SUCCESS;
+}

+ 42 - 0
analog_outputs.c

@@ -0,0 +1,42 @@
+/* Set analog voltage on slow analog output */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "rp.h"
+
+int main (int argc, char **argv) {
+    float value [4];
+
+    // Voltages can be provided as an argument (default is 1V)
+    for (int i=0; i<4; i++) {
+        if (argc > (1+i)) {
+            value [i] = atof(argv[1+i]);
+        } else {
+            value [i] = 1.0;
+        }
+        printf("Voltage setting for AO[%i] = %1.1fV\n", i, value [i]);
+    }
+
+    // Initialization of API
+    if (rp_Init() != RP_OK) {
+        fprintf(stderr, "Red Pitaya API init failed!\n");
+        return EXIT_FAILURE;
+    }
+
+    // Setting a voltage for each ananlog output
+    for (int i=0; i<4; i++) {
+        int status = rp_AOpinSetValue(i, value[i]);
+        if (status != RP_OK) {
+            printf("Could not set AO[%i] voltage.\n", i);
+        }
+    }
+
+    // wait for user input
+    getchar();
+
+    // Releasing resources
+    rp_Release();
+
+    return EXIT_SUCCESS;
+}

BIN
axi


+ 113 - 0
axi.c

@@ -0,0 +1,113 @@
+/* Red Pitaya C API example Acquiring a signal from a buffer
+ * This application acquires a signal on a specific channel */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "rp.h"
+
+#define DATA_SIZE 64
+
+int main(int argc, char **argv)
+{
+    int dsize = DATA_SIZE;
+    uint32_t dec = 1;
+    if (argc >= 3){
+        dsize = atoi(argv[1]);
+        dec = atoi(argv[2]);
+    }
+
+    /* Print error, if rp_Init() function failed */
+    if (rp_InitReset(false) != RP_OK) {
+        fprintf(stderr, "Rp api init failed!\n");
+        return -1;
+    }
+
+    uint32_t g_adc_axi_start,g_adc_axi_size;
+    rp_AcqAxiGetMemoryRegion(&g_adc_axi_start,&g_adc_axi_size);
+
+    printf("Reserved memory start 0x%X size 0x%X\n",g_adc_axi_start,g_adc_axi_size);
+//    rp_AcqResetFpga();
+
+    if (rp_AcqAxiSetDecimationFactor(dec) != RP_OK) {
+        fprintf(stderr, "rp_AcqAxiSetDecimationFactor failed!\n");
+        return -1;
+    }
+    if (rp_AcqAxiSetTriggerDelay(RP_CH_1, dsize  )  != RP_OK) {
+        fprintf(stderr, "rp_AcqAxiSetTriggerDelay RP_CH_1 failed!\n");
+        return -1;
+    }
+    if (rp_AcqAxiSetTriggerDelay(RP_CH_2, dsize  ) != RP_OK) {
+        fprintf(stderr, "rp_AcqAxiSetTriggerDelay RP_CH_2 failed!\n");
+        return -1;
+    }
+    if (rp_AcqAxiSetBufferSamples(RP_CH_1, g_adc_axi_start, dsize) != RP_OK) {
+        fprintf(stderr, "rp_AcqAxiSetBuffer RP_CH_1 failed!\n");
+        return -1;
+    }
+    if (rp_AcqAxiSetBufferSamples(RP_CH_2, g_adc_axi_start + g_adc_axi_size / 2, dsize) != RP_OK) {
+        fprintf(stderr, "rp_AcqAxiSetBuffer RP_CH_2 failed!\n");
+        return -1;
+    }
+    if (rp_AcqAxiEnable(RP_CH_1, true)) {
+        fprintf(stderr, "rp_AcqAxiEnable RP_CH_1 failed!\n");
+        return -1;
+    }
+    if (rp_AcqAxiEnable(RP_CH_2, true)) {
+        fprintf(stderr, "rp_AcqAxiEnable RP_CH_2 failed!\n");
+        return -1;
+    }
+
+    rp_AcqSetTriggerLevel(RP_T_CH_1,0);
+
+    if (rp_AcqStart() != RP_OK) {
+        fprintf(stderr, "rp_AcqStart failed!\n");
+        return -1;
+    }
+
+    rp_AcqSetTriggerSrc(RP_TRIG_SRC_CHA_PE);
+    rp_acq_trig_state_t state = RP_TRIG_STATE_TRIGGERED;
+
+    while(1){
+        rp_AcqGetTriggerState(&state);
+        if(state == RP_TRIG_STATE_TRIGGERED){
+            sleep(1);
+            break;
+        }
+    }
+
+    bool fillState = false;
+    while (!fillState) {
+        if (rp_AcqAxiGetBufferFillState(RP_CH_1, &fillState) != RP_OK) {
+            fprintf(stderr, "rp_AcqAxiGetBufferFillState RP_CH_1 failed!\n");
+            return -1;
+        }
+    }
+    rp_AcqStop();
+
+    uint32_t posChA,posChB;
+    rp_AcqAxiGetWritePointerAtTrig(RP_CH_1,&posChA);
+    rp_AcqAxiGetWritePointerAtTrig(RP_CH_2,&posChB);
+
+    fprintf(stderr,"Tr pos1: 0x%X pos2: 0x%X\n",posChA,posChB);
+
+    int16_t *buff1 = (int16_t *)malloc(dsize * sizeof(int16_t));
+    int16_t *buff2 = (int16_t *)malloc(dsize * sizeof(int16_t));
+
+    uint32_t size1 = dsize;
+    uint32_t size2 = dsize;
+    rp_AcqAxiGetDataRaw(RP_CH_1, posChA, &size1, buff1);
+    rp_AcqAxiGetDataRaw(RP_CH_2, posChB, &size2, buff2);
+
+    for (int i = 0; i < dsize; i++) {
+        printf("[%d]\t%d\t%d\n",i,buff1[i], buff2[i]);
+    }
+
+    /* Releasing resources */
+    rp_AcqAxiEnable(RP_CH_1, false);
+    rp_AcqAxiEnable(RP_CH_2, false);
+    rp_Release();
+    free(buff1);
+    free(buff2);
+    return 0;
+}

+ 149 - 0
axi_4ch.c

@@ -0,0 +1,149 @@
+/* Red Pitaya C API example Acquiring a signal from a buffer
+ * This application acquires a signal on a specific channel */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "rp.h"
+
+#define DATA_SIZE 1024
+
+int main(int argc, char **argv)
+{
+    /* Print error, if rp_Init() function failed */
+    if (rp_InitReset(false) != RP_OK) {
+        fprintf(stderr, "Rp api init failed!\n");
+        return -1;
+    }
+
+    uint32_t g_adc_axi_start,g_adc_axi_size;
+    rp_AcqAxiGetMemoryRegion(&g_adc_axi_start,&g_adc_axi_size);
+
+    printf("Reserved memory start 0x%X size 0x%X\n",g_adc_axi_start,g_adc_axi_size);
+//    rp_AcqResetFpga();
+
+    if (rp_AcqAxiSetDecimationFactor(RP_DEC_1) != RP_OK) {
+        fprintf(stderr, "rp_AcqAxiSetDecimationFactor failed!\n");
+        return -1;
+    }
+    if (rp_AcqAxiSetTriggerDelay(RP_CH_1, DATA_SIZE  )  != RP_OK) {
+        fprintf(stderr, "rp_AcqAxiSetTriggerDelay RP_CH_1 failed!\n");
+        return -1;
+    }
+    if (rp_AcqAxiSetTriggerDelay(RP_CH_2, DATA_SIZE  ) != RP_OK) {
+        fprintf(stderr, "rp_AcqAxiSetTriggerDelay RP_CH_2 failed!\n");
+        return -1;
+    }
+    if (rp_AcqAxiSetTriggerDelay(RP_CH_3, DATA_SIZE  ) != RP_OK) {
+        fprintf(stderr, "rp_AcqAxiSetTriggerDelay RP_CH_3 failed!\n");
+        return -1;
+    }
+    if (rp_AcqAxiSetTriggerDelay(RP_CH_4, DATA_SIZE  ) != RP_OK) {
+        fprintf(stderr, "rp_AcqAxiSetTriggerDelay RP_CH_4 failed!\n");
+        return -1;
+    }
+
+    if (rp_AcqAxiSetBufferSamples(RP_CH_1, g_adc_axi_start, DATA_SIZE) != RP_OK) {
+        fprintf(stderr, "rp_AcqAxiSetBuffer RP_CH_1 failed!\n");
+        return -1;
+    }
+    if (rp_AcqAxiSetBufferSamples(RP_CH_2, g_adc_axi_start + g_adc_axi_size / 4, DATA_SIZE) != RP_OK) {
+        fprintf(stderr, "rp_AcqAxiSetBuffer RP_CH_2 failed!\n");
+        return -1;
+    }
+
+    if (rp_AcqAxiSetBufferSamples(RP_CH_3, g_adc_axi_start + g_adc_axi_size / 4 * 2, DATA_SIZE) != RP_OK) {
+        fprintf(stderr, "rp_AcqAxiSetBuffer RP_CH_3 failed!\n");
+        return -1;
+    }
+
+    if (rp_AcqAxiSetBufferSamples(RP_CH_4, g_adc_axi_start + g_adc_axi_size / 4 * 3, DATA_SIZE) != RP_OK) {
+        fprintf(stderr, "rp_AcqAxiSetBuffer RP_CH_4 failed!\n");
+        return -1;
+    }
+
+    if (rp_AcqAxiEnable(RP_CH_1, true)) {
+        fprintf(stderr, "rp_AcqAxiEnable RP_CH_1 failed!\n");
+        return -1;
+    }
+
+    if (rp_AcqAxiEnable(RP_CH_2, true)) {
+        fprintf(stderr, "rp_AcqAxiEnable RP_CH_2 failed!\n");
+        return -1;
+    }
+
+    if (rp_AcqAxiEnable(RP_CH_3, true)) {
+        fprintf(stderr, "rp_AcqAxiEnable RP_CH_3 failed!\n");
+        return -1;
+    }
+
+    if (rp_AcqAxiEnable(RP_CH_4, true)) {
+        fprintf(stderr, "rp_AcqAxiEnable RP_CH_4 failed!\n");
+        return -1;
+    }
+
+    rp_AcqSetTriggerLevel(RP_T_CH_1,0);
+
+    if (rp_AcqStart() != RP_OK) {
+        fprintf(stderr, "rp_AcqStart failed!\n");
+        return -1;
+    }
+
+    rp_AcqSetTriggerSrc(RP_TRIG_SRC_CHA_PE);
+    rp_acq_trig_state_t state = RP_TRIG_STATE_TRIGGERED;
+
+    while(1){
+        rp_AcqGetTriggerState(&state);
+        if(state == RP_TRIG_STATE_TRIGGERED){
+            sleep(1);
+            break;
+        }
+    }
+
+    bool fillState = false;
+    while (!fillState) {
+        if (rp_AcqAxiGetBufferFillState(RP_CH_1, &fillState) != RP_OK) {
+            fprintf(stderr, "rp_AcqAxiGetBufferFillState RP_CH_1 failed!\n");
+            return -1;
+        }
+    }
+    rp_AcqStop();
+
+    uint32_t posChA,posChB,posChC,posChD;
+    rp_AcqAxiGetWritePointerAtTrig(RP_CH_1,&posChA);
+    rp_AcqAxiGetWritePointerAtTrig(RP_CH_2,&posChB);
+    rp_AcqAxiGetWritePointerAtTrig(RP_CH_3,&posChC);
+    rp_AcqAxiGetWritePointerAtTrig(RP_CH_4,&posChD);
+
+    fprintf(stderr,"Tr pos1: 0x%X pos2: 0x%X pos3: 0x%X pos4: 0x%X\n",posChA,posChB,posChC,posChD);
+
+    int16_t *buff1 = (int16_t *)malloc(DATA_SIZE * sizeof(int16_t));
+    int16_t *buff2 = (int16_t *)malloc(DATA_SIZE * sizeof(int16_t));
+    int16_t *buff3 = (int16_t *)malloc(DATA_SIZE * sizeof(int16_t));
+    int16_t *buff4 = (int16_t *)malloc(DATA_SIZE * sizeof(int16_t));
+
+    uint32_t size1 = DATA_SIZE;
+    uint32_t size2 = DATA_SIZE;
+    uint32_t size3 = DATA_SIZE;
+    uint32_t size4 = DATA_SIZE;
+    rp_AcqAxiGetDataRaw(RP_CH_1, posChA, &size1, buff1);
+    rp_AcqAxiGetDataRaw(RP_CH_2, posChB, &size2, buff2);
+    rp_AcqAxiGetDataRaw(RP_CH_3, posChC, &size3, buff3);
+    rp_AcqAxiGetDataRaw(RP_CH_4, posChD, &size4, buff4);
+
+    for (int i = 0; i < DATA_SIZE; i++) {
+        printf("%d\t%d\t%d\t%d\n", buff1[i], buff2[i], buff3[i], buff4[i]);
+    }
+
+    /* Releasing resources */
+    rp_AcqAxiEnable(RP_CH_1, false);
+    rp_AcqAxiEnable(RP_CH_2, false);
+    rp_AcqAxiEnable(RP_CH_3, false);
+    rp_AcqAxiEnable(RP_CH_4, false);
+    rp_Release();
+    free(buff1);
+    free(buff2);
+    free(buff3);
+    free(buff4);
+    return 0;
+}

BIN
axi_gen


+ 140 - 0
axi_gen.c

@@ -0,0 +1,140 @@
+#include <math.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "rp.h"
+#include "rp_asg_axi.h"
+
+// g++ axi_gen.c -std=c++20 -Wall  -I/opt/redpitaya/include -L/opt/redpitaya/lib -static -lrp-hw-can -lrp -lrp-hw-calib -lrp-hw-profiles -lrp-gpio -lrp-i2c -lrp-hw -lm -lstdc++ -lpthread -li2c -lsocketcan -o axi_gen
+
+int main(int argc, char **argv) {
+
+    // Select channel
+    rp_channel_t channel = RP_CH_1;
+
+    if(argc < 3)
+    {
+    	fprintf(stderr, "Invalid args!");
+	return -1;
+    }
+
+    // Data size in samples (16 bit)
+
+    uint32_t bufferSize = 4096;
+    uint32_t freq = 3000000;
+
+    if(argv[0] != nullptr)
+    {
+    	bufferSize = atoi(argv[1]);    // Should be twice the actual number of samples
+    }
+    uint32_t dec_factor = 1;
+    uint32_t num_buffers = 1;
+    if(argv[1] != nullptr)
+    {
+    	freq = atoi(argv[2]);
+    }
+    uint32_t ncyc = 1;
+    uint32_t nor = 1;
+    uint32_t period = 100;
+
+    // Start addresses of buffers must be multiple of 4096 (DDR page size)
+    uint32_t min_addr_diff = 4096;
+
+    // Initialize the interface
+    if (rp_Init() != RP_OK) {
+        fprintf(stderr, "Rp api init failed!\n");
+        return 1;
+    }
+
+    // Reset generator
+    rp_GenReset();
+
+    /* Setting up the Deep Memory Generation (DMG) */
+    uint32_t dac_axi_start, dac_axi_size;
+
+    // Get the reserved memory region start and size
+    if (rp_AcqAxiGetMemoryRegion(&dac_axi_start, &dac_axi_size) != RP_OK) {
+        fprintf(stderr, "Error get memory!\n");
+        return 1;
+    }
+
+    // Lower the buffer size to the available memory size (if needed)
+    uint32_t dmg_min_size = (uint32_t) (ceil((float) bufferSize / (float) min_addr_diff) * (float) min_addr_diff * (float) num_buffers);
+    printf("Buffer size: %d\n", bufferSize);
+    printf("Minimum size: %d\n", dmg_min_size);
+
+    if (dmg_min_size > dac_axi_size) {
+        printf("Buffer size is too large, reducing to available memory size\n");
+        bufferSize = dac_axi_size / num_buffers;
+        printf("Buffer size reduced to %d\n", bufferSize);
+    }
+
+    // Calculate the start address
+    uint32_t gen1_start_addr = dac_axi_start;
+
+    // Reserve memory for the generator
+    printf("Reserved memory for OUT1 Start: %x Size: %x End: %x\n", gen1_start_addr, bufferSize, gen1_start_addr + bufferSize);
+
+    if (rp_GenAxiReserveMemory(channel, gen1_start_addr, gen1_start_addr + bufferSize) != RP_OK) {
+        fprintf(stderr, "Error setting address for DMG mode for OUT1\n");
+        return 1;
+    }
+
+    // Set decimation factor
+    if (rp_GenAxiSetDecimationFactor(channel, dec_factor) != RP_OK) {
+        fprintf(stderr, "Error setting decimation for generator OUT1\n");
+        return 1;
+    }
+
+    // Enable DMG mode
+    if (rp_GenAxiSetEnable(channel, true) != RP_OK) {
+        fprintf(stderr, "Error enable axi mode for OUT1\n");
+        return 1;
+    }
+
+    // Define output waveform for both channels
+    bufferSize /= 2;                // Samples are float32 which is 4 bytes, int16 is 2 bytes
+
+
+    float *t = (float *)malloc(bufferSize * sizeof(float));
+    float *x = (float *)malloc(bufferSize * sizeof(float));
+
+    for (uint32_t i = 1; i < bufferSize; i++) {
+        t[i] = t[i-1] + 0.000000008f;
+    }
+
+    for (uint32_t i = 0; i < bufferSize; ++i) {
+	// x[i] = sin(t[i] * freq * 2 * M_PI) * ((1.0f * (bufferSize - i)) / bufferSize);
+    	if(i > 512 && i < 3576)
+	{
+	    x[i] = 1.0f;
+	}
+	else
+	{
+	    x[i] = 0.0f;
+	}
+    }
+
+    // Configure calibration and offset
+    rp_GenSetAmplitudeAndOffsetOrigin(channel);
+
+    // Set burst parameters
+    rp_GenMode(channel, RP_GEN_MODE_BURST);
+    rp_GenBurstCount(channel, ncyc);
+    rp_GenBurstRepetitions(channel, nor);
+    rp_GenBurstPeriod(channel, period);
+    rp_GenAxiWriteWaveform(channel, x, bufferSize);
+
+    rp_GenOutEnable(channel);
+    rp_GenTriggerOnly(channel);
+
+    // Release resources
+    free(t);
+    free(x);
+
+    rp_Release();
+
+    return 0;
+}

BIN
axi_service


BIN
axi_service]


+ 76 - 0
calibration_api.c

@@ -0,0 +1,76 @@
+/* @brief This is a simple application for testing calibration api
+* (c) Red Pitaya  http://www.redpitaya.com
+*
+* This part of code is written in C programming language.
+* Please visit http://en.wikipedia.org/wiki/C_(programming_language)
+* for more details on the language used herein.
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "rp_hw-calib.h"
+
+
+int main(int argc, char *argv[]){
+
+    // Read calibrations from EEPROM to RAM
+    int res = rp_CalibInit();
+    printf("Init result: %d\n",res);
+
+    // Backup current calibrations
+    rp_calib_params_t current_calib = rp_GetCalibrationSettings();
+
+    // Retrieves calibration coefficients
+    double gain;
+    int32_t offset;
+    res = rp_CalibGetFastADCCalibValue(RP_CH_1_CALIB,RP_DC_CALIB,&gain,&offset);
+    printf("Calibration factors for channel 1 GAIN %f OFFSET %d result = %d\n",gain,offset,res);
+    res = rp_CalibGetFastADCCalibValue(RP_CH_2_CALIB,RP_DC_CALIB,&gain,&offset);
+    printf("Calibration factors for channel 2 GAIN %f OFFSET %d result = %d\n",gain,offset,res);
+
+    printf("\nCurrent calibration in user space\n");
+    rp_CalibPrint(&current_calib);
+
+    // Returns the default calibration for the current board version. It may be different on different boards.
+    rp_calib_params_t def_calib = rp_GetDefaultCalibrationSettings();
+    printf("\nDefailt calibration\n");
+    rp_CalibPrint(&def_calib);
+
+    // Write default calibration in EEPROM user space.
+    // The previously loaded in RAM calibration will not change.
+    rp_CalibrationWriteParams(def_calib,false);
+
+    // Sets calibration parameters into RAM.
+    rp_CalibrationSetParams(def_calib);
+
+    res = rp_CalibGetFastADCCalibValue(RP_CH_1_CALIB,RP_DC_CALIB,&gain,&offset);
+    printf("Calibration factors for channel 1 GAIN %f OFFSET %d result = %d\n",gain,offset,res);
+    res = rp_CalibGetFastADCCalibValue(RP_CH_2_CALIB,RP_DC_CALIB,&gain,&offset);
+    printf("Calibration factors for channel 2 GAIN %f OFFSET %d result = %d\n",gain,offset,res);
+
+    // Resets calibration values in EEPROM
+    rp_CalibrationWriteParams(current_calib,false);
+
+    // Read calibrations from EEPROM to RAM
+    res = rp_CalibInit();
+    printf("\nRestored calibration\n");
+    res = rp_CalibGetFastADCCalibValue(RP_CH_1_CALIB,RP_DC_CALIB,&gain,&offset);
+    printf("Calibration factors for channel 1 GAIN %f OFFSET %d result = %d\n",gain,offset,res);
+    res = rp_CalibGetFastADCCalibValue(RP_CH_2_CALIB,RP_DC_CALIB,&gain,&offset);
+    printf("Calibration factors for channel 2 GAIN %f OFFSET %d result = %d\n",gain,offset,res);
+
+    // Read calibration direct from eeprom
+    uint8_t *data = NULL;
+    uint16_t size;
+    rp_calib_params_t eeprom_calib;
+    rp_CalibGetEEPROM(&data,&size,false);
+    // Convert bytes to rp_calib_params_t
+    rp_CalibConvertEEPROM(data,size,&eeprom_calib);
+    printf("\nCalibration read directly\n");
+    rp_CalibPrint(&eeprom_calib);
+
+    return 0;
+}

+ 52 - 0
can_loopback.c

@@ -0,0 +1,52 @@
+/* @brief This is a simple application for testing CAN communication on a RedPitaya
+*
+* (c) Red Pitaya  http://www.redpitaya.com
+*
+* This part of code is written in C programming language.
+* Please visit http://en.wikipedia.org/wiki/C_(programming_language)
+* for more details on the language used herein.
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "rp_hw_can.h"
+
+
+int main(int argc, char *argv[]){
+
+    int res = rp_CanSetFPGAEnable(true); // init can in fpga for pass can controller to GPIO (N7,P7) 
+    printf("Init result: %d\n",res);
+    
+    res = rp_CanStop(RP_CAN_0); // set can0 interface to DOWN  for configure
+    printf("Stop can0: %d\n",res);
+    
+    res = rp_CanSetBitrate(RP_CAN_0,200000); // set can0 bitrate
+    printf("Set bitrate: %d\n",res);
+
+    res = rp_CanSetControllerMode(RP_CAN_0,RP_CAN_MODE_LOOPBACK,true); // set loopback mode
+    printf("Set loopback mode ON: %d\n",res);
+
+    res = rp_CanStart(RP_CAN_0); // set can0 interface to UP
+    printf("Start can0: %d\n",res);
+
+    res = rp_CanOpen(RP_CAN_0); // open socket for can0
+    printf("Open socket: %d\n",res);
+
+    unsigned char tx_buffer[8];
+    tx_buffer[0] = 1;
+    tx_buffer[1] = 2;
+    tx_buffer[2] = 3;
+    res = rp_CanSend(RP_CAN_0,123, tx_buffer,3,false,false,0); // write buffer to can0
+    printf("Write result: %d\n",res);
+
+    rp_can_frame_t frame;
+    res = rp_CanRead(RP_CAN_0,2000, &frame); // read frame from can0
+    printf("Read result: %d\n",res);   
+    printf("Can ID: %d data: %d,%d,%d\n",frame.can_id,frame.data[0],frame.data[1],frame.data[2]);
+
+    res = rp_CanClose(RP_CAN_0); // close socket for can0
+    printf("Close can0 result: %d\n",res);
+    return 0;
+}

+ 81 - 0
can_pass.c

@@ -0,0 +1,81 @@
+/* @brief This is a simple application for testing CAN communication on a RedPitaya
+*
+* (c) Red Pitaya  http://www.redpitaya.com
+*
+* This part of code is written in C programming language.
+* Please visit http://en.wikipedia.org/wiki/C_(programming_language)
+* for more details on the language used herein.
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "rp_hw_can.h"
+
+
+int main(int argc, char *argv[]){
+
+    int res = rp_CanSetFPGAEnable(true); // init can in fpga for pass can controller to GPIO (N7,P7) 
+    printf("Init result: %d\n",res);
+    
+    res = rp_CanStop(RP_CAN_0); // set can0 interface to DOWN  for configure
+    printf("Stop can0: %d\n",res);
+    
+    res = rp_CanSetBitrate(RP_CAN_0,200000); // set can0 bitrate
+    printf("Set bitrate: %d\n",res);
+
+    res = rp_CanSetControllerMode(RP_CAN_0,RP_CAN_MODE_LOOPBACK,false); // set loopback mode
+    printf("Set loopback mode OFF: %d\n",res);
+    
+    res = rp_CanStop(RP_CAN_1); // set can1 interface to DOWN  for configure
+    printf("Stop can1: %d\n",res);
+    
+    res = rp_CanSetBitrate(RP_CAN_1,200000); // set can1 bitrate
+    printf("Set bitrate: %d\n",res);
+
+    res = rp_CanSetControllerMode(RP_CAN_1,RP_CAN_MODE_LOOPBACK,false); // set loopback mode
+    printf("Set loopback mode OFF: %d\n",res);
+
+    res = rp_CanStart(RP_CAN_0); // set can0 interface to UP
+    printf("Start can0: %d\n",res);
+
+    res = rp_CanOpen(RP_CAN_0); // open socket for can0
+    printf("Open socket: %d\n",res);
+
+    res = rp_CanStart(RP_CAN_1); // set can1 interface to UP
+    printf("Start can1: %d\n",res);
+
+    res = rp_CanOpen(RP_CAN_1); // open socket for can1
+    printf("Open socket: %d\n",res);
+
+    unsigned char tx_buffer[8];
+    tx_buffer[0] = 1;
+    tx_buffer[1] = 2;
+    tx_buffer[2] = 3;
+    tx_buffer[3] = 4;
+    tx_buffer[4] = 5;
+
+    res = rp_CanSend(RP_CAN_0,123, tx_buffer,3,false,false,0); // write buffer to can0
+    printf("Write result: %d\n",res);
+
+    res = rp_CanSend(RP_CAN_0,321, tx_buffer,5,true,false,0); // write buffer to can0
+    printf("Write result: %d\n",res);
+
+    rp_can_frame_t frame;
+    res = rp_CanRead(RP_CAN_1,2000, &frame); // read frame from can1
+    printf("Read result: %d\n",res);   
+    printf("Can ID: %d data: %d,%d,%d\n",frame.can_id,frame.data[0],frame.data[1],frame.data[2]);
+
+    res = rp_CanRead(RP_CAN_1,0, &frame); // read frame from can1 without timeout
+    printf("Read result: %d\n",res);   
+    printf("Can ID: %d data: %d,%d,%d,%d,%d\n",frame.can_id,frame.data[0],frame.data[1],frame.data[2],frame.data[3],frame.data[4]);
+
+    res = rp_CanClose(RP_CAN_0); // close socket for can0
+    printf("Close can0 result: %d\n",res);
+
+    res = rp_CanClose(RP_CAN_1); // close socket for can1
+    printf("Close can1 result: %d\n",res);
+
+    return 0;
+}

+ 37 - 0
digital_led_bar.c

@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "rp.h"
+
+int main (int argc, char **argv) {
+    float percent;
+
+    // percentage can be provided as an argument
+    if (argc > 1) {
+        percent = atof(argv[1]);
+    } else {
+        percent = 50.0;
+    }
+    printf("Bar showing %.1f%%\n", percent);
+
+    // Initialization of API
+    if (rp_Init() != RP_OK) {
+        fprintf(stderr, "Red Pitaya API init failed!\n");
+        return EXIT_FAILURE;
+    }
+
+    // Turning on leds based on parameter percent
+    for (int i=0; i<8; i++) {
+        if (percent > (i*(100.0/8))) {
+            rp_DpinSetState(i+RP_LED0, RP_HIGH);
+        } else {
+            rp_DpinSetState(i+RP_LED0, RP_LOW);
+        }
+    }
+
+    // Releasing resources
+    rp_Release();
+
+    return EXIT_SUCCESS;
+}

+ 38 - 0
digital_led_blink.c

@@ -0,0 +1,38 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "rp.h"
+
+int main (int argc, char **argv) {
+    int unsigned period = 1000000; // uS
+    int unsigned led;
+
+    // index of blinking LED can be provided as an argument
+    if (argc > 1) {
+        led = atoi(argv[1]);
+    // otherwise LED 0 will blink
+    } else {
+        led = 0;
+    }
+    printf("Blinking LED[%u]\n", led);
+    led += RP_LED0;
+
+    // Initialization of API
+    if (rp_Init() != RP_OK) {
+        fprintf(stderr, "Red Pitaya API init failed!\n");
+        return EXIT_FAILURE;
+    }
+
+    int unsigned retries = 1000;
+    while (retries--){
+        rp_DpinSetState(led, RP_HIGH);
+        usleep(period/2);
+        rp_DpinSetState(led, RP_LOW);
+        usleep(period/2);
+    }
+
+    // Releasing resources
+    rp_Release();
+
+    return EXIT_SUCCESS;
+}

+ 32 - 0
digital_push_button.c

@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "rp.h"
+
+int main (int argc, char **argv) {
+    rp_pinState_t state;
+
+    // Initialization of API
+    if (rp_Init() != RP_OK) {
+        fprintf(stderr, "Red Pitaya API init failed!\n");
+        return EXIT_FAILURE;
+    }
+
+    // configure DIO[0:7]_N to inputs
+    for (int i=0; i<8; i++) {
+        rp_DpinSetDirection (i+RP_DIO0_N, RP_IN);
+    }
+
+    // transfer each input state to the corresponding LED state
+    while (1) {
+        for (int i=0; i<8; i++) {
+            rp_DpinGetState (i+RP_DIO0_N, &state);
+            rp_DpinSetState (i+RP_LED0, state);
+        }
+    }
+
+    // Releasing resources
+    rp_Release();
+
+    return EXIT_SUCCESS;
+}

+ 54 - 0
generate_arbitrary_waveform.c

@@ -0,0 +1,54 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "rp.h"
+
+#define M_PI 3.14159265358979323846
+
+int main(int argc, char **argv){
+
+	int i;
+	int buff_size = 16384;
+
+	/* Print error, if rp_Init() function failed */
+	if(rp_Init() != RP_OK){
+		fprintf(stderr, "Rp api init failed!\n");
+	}
+
+	float *t = (float *)malloc(buff_size * sizeof(float));
+	float *x = (float *)malloc(buff_size * sizeof(float));
+	float *y = (float *)malloc(buff_size * sizeof(float));
+
+	for(i = 1; i < buff_size; i++){
+		t[i] = (2 * M_PI) / buff_size * i;
+	}
+
+	for (int i = 0; i < buff_size; ++i){
+		x[i] = sin(t[i]) + ((1.0/3.0) * sin(t[i] * 3));
+		y[i] = (1.0/2.0) * sin(t[i]) + (1.0/4.0) * sin(t[i] * 4);
+	}
+
+	rp_GenWaveform(RP_CH_1, RP_WAVEFORM_ARBITRARY);
+	rp_GenWaveform(RP_CH_2, RP_WAVEFORM_ARBITRARY);
+
+	rp_GenArbWaveform(RP_CH_1, x, buff_size);
+	rp_GenArbWaveform(RP_CH_2, y, buff_size);
+
+	rp_GenAmp(RP_CH_1, 0.7);
+	rp_GenAmp(RP_CH_2, 1.0);
+
+	rp_GenFreq(RP_CH_1, 4000.0);
+	rp_GenFreq(RP_CH_2, 4000.0);
+
+	rp_GenOutEnable(RP_CH_1);
+	rp_GenOutEnable(RP_CH_2);
+	rp_GenSynchronise();
+
+	/* Releasing resources */
+	free(y);
+	free(x);
+	free(t);
+	rp_Release();
+}

+ 34 - 0
generate_burst_trigger_external.c

@@ -0,0 +1,34 @@
+/* Red Pitaya external trigger pulse generation Example */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "rp.h"
+
+
+int main(int argc, char **argv){
+
+	/* Print error, if rp_Init() function failed */
+	if(rp_Init() != RP_OK){
+		fprintf(stderr, "Rp api init failed!\n");
+	}
+
+	rp_GenReset();
+	
+	rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
+	rp_GenFreq(RP_CH_1, 200);
+	rp_GenAmp(RP_CH_1, 1);
+
+	rp_GenBurstCount(RP_CH_1, 1);
+	rp_GenMode(RP_CH_1, RP_GEN_MODE_BURST);
+	rp_GenTriggerSource(RP_CH_1, RP_GEN_TRIG_SRC_EXT_PE);
+
+	rp_GenOutEnable(RP_CH_1);
+	rp_GenTriggerOnly(RP_CH_1);
+
+	/* Release rp resources */
+	rp_Release();
+
+	return 0;
+}

+ 38 - 0
generate_burst_trigger_software.c

@@ -0,0 +1,38 @@
+/* Red Pitaya C API example Generating signal pulse on an external trigger 
+ * This application generates a specific signal */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "rp.h"
+
+int main(int argc, char **argv){
+
+        /* Burst count */
+
+
+        /* Print error, if rp_Init() function failed */
+        if(rp_Init() != RP_OK){
+                fprintf(stderr, "Rp api init failed!\n");
+        }
+
+        rp_GenReset();
+
+        rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
+        rp_GenFreq(RP_CH_1, 1000);
+        rp_GenAmp(RP_CH_1, 1.0);
+
+        rp_GenMode(RP_CH_1, RP_GEN_MODE_BURST);
+        rp_GenBurstCount(RP_CH_1, 1);
+        rp_GenBurstRepetitions(RP_CH_1, 10000);
+        rp_GenBurstPeriod(RP_CH_1, 5000);
+
+        rp_GenOutEnable(RP_CH_1);
+        rp_GenTriggerOnly(RP_CH_1);
+
+        rp_Release();
+}
+
+
+

+ 40 - 0
generate_continuous.c

@@ -0,0 +1,40 @@
+/* Red Pitaya C API example Generating continuous signal  
+ * This application generates a specific signal */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "rp.h"
+
+int main(int argc, char **argv){
+
+	/* Print error, if rp_Init() function failed */
+	if(rp_Init() != RP_OK){
+		fprintf(stderr, "Rp api init failed!\n");
+	}
+
+	/* Reset generator */
+	rp_GenReset();
+
+	/* Generating wave form */
+	rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
+
+	/* Generating frequency */
+	rp_GenFreq(RP_CH_1, 10000.0);
+
+	/* Generating amplitude */
+	rp_GenAmp(RP_CH_1, 1.0);
+
+	/* Enable channel */
+	rp_GenOutEnable(RP_CH_1);
+
+	/* Generating trigger */
+	rp_GenTriggerOnly(RP_CH_1);
+
+	/* Releasing resources */
+	rp_Release();
+
+	return 0;
+}

+ 48 - 0
generate_two_burst_trigger_software.c

@@ -0,0 +1,48 @@
+/* Red Pitaya C API example Generating signal pulse on an external trigger
+ * This application generates a specific signal */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "rp.h"
+
+int main(int argc, char **argv) {
+
+        /* Print error, if rp_Init() function failed */
+        if(rp_Init() != RP_OK) {
+                fprintf(stderr, "Rp api init failed!\n");
+        }
+
+        rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
+        rp_GenFreq(RP_CH_1, 4);
+        rp_GenAmp(RP_CH_1, 1.0);
+
+         rp_GenWaveform(RP_CH_2, RP_WAVEFORM_SINE);
+        rp_GenFreq(RP_CH_2, 4);
+        rp_GenAmp(RP_CH_2, 1.0);
+
+        rp_GenMode(RP_CH_1, RP_GEN_MODE_BURST);
+        rp_GenBurstCount(RP_CH_1, 2);
+        rp_GenBurstRepetitions(RP_CH_1, 1);
+        rp_GenBurstPeriod(RP_CH_1, 5000);
+
+        rp_GenMode(RP_CH_2, RP_GEN_MODE_BURST);
+        rp_GenBurstCount(RP_CH_2, 2);
+        rp_GenBurstRepetitions(RP_CH_2, 1);
+        rp_GenBurstPeriod(RP_CH_2, 5000);
+
+        rp_GenOutEnableSync(true);
+	rp_GenSynchronise();
+        sleep(2);
+	rp_GenTriggerOnly(RP_CH_1);
+        sleep(2);
+	rp_GenTriggerOnly(RP_CH_2);
+        sleep(1);
+	rp_GenSynchronise();
+
+        rp_Release();
+}
+
+
+

+ 32 - 0
generate_two_trigger_software_sync.c

@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "rp.h"
+
+
+int main(int argc, char **argv) {
+
+	/* Print error, if rp_Init() function failed */
+	if(rp_Init() != RP_OK) {
+		fprintf(stderr, "Rp api init failed!\n");
+	}
+
+	rp_GenSynchronise();
+
+	rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
+	rp_GenFreq(RP_CH_1, 2000);
+	rp_GenAmp(RP_CH_1, 1);
+
+	rp_GenWaveform(RP_CH_2, RP_WAVEFORM_SINE);
+	rp_GenFreq(RP_CH_2, 2000);
+	rp_GenAmp(RP_CH_2, 1);
+
+	rp_GenOutEnableSync(true);
+	rp_GenSynchronise();
+
+	/* Release rp resources */
+	rp_Release();
+
+	return 0;
+}

+ 216 - 0
i2c.c

@@ -0,0 +1,216 @@
+/* @brief This is a simple application for testing IIC communication on a RedPitaya
+* @Author Luka Golinar <luka.golinar@redpitaya.com>
+*
+* (c) Red Pitaya  http://www.redpitaya.com
+*
+* This part of code is written in C programming language.
+* Please visit http://en.wikipedia.org/wiki/C_(programming_language)
+* for more details on the language used herein.
+*/
+
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <linux/ioctl.h>
+#include <sys/ioctl.h>
+#include <linux/i2c-dev.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdint.h>
+
+
+#define I2C_SLAVE_FORCE                0x0706
+#define I2C_SLAVE                              0x0703    /* Change slave address            */
+#define I2C_FUNCS                              0x0705    /* Get the adapter functionality */
+#define I2C_RDWR                               0x0707    /* Combined R/W transfer (one stop only)*/
+
+
+#define EEPROM_ADDR                    0x50
+
+/*
+* Page size of the EEPROM. This depends on the type of the EEPROM available
+* on board.
+*/
+#define PAGESIZE                   32
+/* eeprom size on a redpitaya */
+#define EEPROMSIZE                 64*1024/8
+
+
+/* Inline functions definition */
+static int iic_read(char *buffer, int offset, int size);
+static int iic_write(char *data, int offset, int size);
+
+/*
+* File descriptors
+*/
+int fd;
+
+int main(int argc, char *argv[])
+{
+    int status;
+
+    /* Read buffer to hold the data */
+    char *buffer = (char *)malloc(EEPROMSIZE * sizeof(char));
+
+    char data[] = "THIS IS A TEST MESSAGE FOR THE I2C PROTOCOL COMMUNICATION WITH A EEPROM. IT WAS WRITTEN FOR A REDPITAYA MEASURMENT TOOL.";
+    size_t size = strlen(data);
+
+    /* Sample offset inside an eeprom */
+    int offset = 0x100;
+
+    /*
+    * Open the device.
+    */
+    fd = open("/dev/i2c-0", O_RDWR);
+
+    if(fd < 0)
+    {
+        printf("Cannot open the IIC device\n");
+        return 1;
+    }
+
+    status = ioctl(fd, I2C_SLAVE_FORCE, EEPROM_ADDR);
+    if(status < 0)
+    {
+        printf("Unable to set the EEPROM address\n");
+        return -1;
+    }
+
+    /* Write to redpitaya eeprom */
+    status = iic_write((char *)data, offset, size);
+    if(status){
+        fprintf(stderr, "Cannot Write to EEPROM\n");
+        close(fd);
+        return -1;
+    }
+
+    /* Read from redpitaya eeprom */
+    status = iic_read(buffer, EEPROM_ADDR, EEPROMSIZE);
+    if (status)
+    {
+        printf("Cannot Read from EEPROM \n");
+        close(fd);
+        return 1;
+    }
+
+    printf("eerprom test successfull.\n");
+
+    /* Release allocations */
+    close(fd);
+    free(buffer);
+
+    return 0;
+}
+
+/* Read the data from the EEPROM.
+*
+*  @param    read buffer -- input buffer for data storage
+*  @param    off set     -- eeprom memory space offset
+*  @param    size        -- size of read data
+*  @return   iicRead status
+*
+*  @note     None. */
+
+static int iic_read(char *buffer, int offset, int size)
+{
+    ssize_t bytes_written;
+    ssize_t bytes_read;
+    uint8_t write_buffer[2];
+
+    /*
+    * Load the offset address inside EEPROM where data need to be written.
+    * Supported for BigEndian and LittleEndian CPU's
+    */
+    write_buffer[0] = (uint8_t)(offset >> 8);
+    write_buffer[1] = (uint8_t)(offset);
+
+    /* Write the bytes onto the bus */
+    bytes_written = write(fd, write_buffer, 2);
+    if(bytes_written < 0){
+        fprintf(stderr, "EEPROM write address error.\n");
+        return -1;
+    }
+
+    /*
+    * Read the bytes.
+    */
+    printf ("Performing Read operation.\n");
+
+    /* Read bytes from the bus */
+    bytes_read = read(fd, buffer, size);
+    if(bytes_read < 0){
+        fprintf(stderr, "EEPROM read error.\n");
+        return -1;
+    }
+
+    printf("Read EEPROM Succesful\n");
+
+    return 0;
+}
+
+
+static int iic_write(char *data, int offset, int size){
+
+    /* variable declaration */
+    int bytes_written;
+    int write_bytes;
+    int index;
+
+    /* Check for limits */
+    if(size > PAGESIZE){
+        write_bytes = PAGESIZE;
+    }else{
+        write_bytes = size;
+    }
+
+    /* Number of needed loops to send all the data.
+    * Limit data size per transmission is PAGESIZE */
+    int loop = 0;
+
+    while(size > 0){
+
+        /* buffer size is PAGESIZE per transmission */
+        uint8_t write_buffer[32 + 2];
+
+        /*
+        * Load the offset address inside EEPROM where data need to be written.
+        * Supported for BigEndian and LittleEndian CPU's
+        */
+        write_buffer[0] = (uint8_t)(offset >> 8);
+        write_buffer[1] = (uint8_t)(offset);
+
+        for(index = 0; index < PAGESIZE; index++){
+            write_buffer[index + 2] = data[index + (PAGESIZE * loop)];
+        }
+
+        /* Write the bytes onto the bus */
+        bytes_written = write(fd, write_buffer, write_bytes + 2);
+        /* Wait till the EEPROM internally completes the write cycle */
+        sleep(2);
+
+        if(bytes_written != write_bytes+2){
+            fprintf(stderr, "Failed to write to EEPROM\n");
+            return -1;
+        }
+
+        /* written bytes minus the offset addres of two */
+        size -= bytes_written - 2;
+        /* Increment offset */
+        offset += PAGESIZE;
+
+        /* Check for limits for the new message */
+        if(size > PAGESIZE){
+            write_bytes = PAGESIZE;
+        }else{
+            write_bytes = size;
+        }
+
+        loop++;
+    }
+
+    printf("\nWrite EEPROM Succesful\n");
+
+    return 0;
+}

+ 64 - 0
i2c_eeprom_read_calib.c

@@ -0,0 +1,64 @@
+/* @brief This is a simple application for testing I2C communication on a RedPitaya
+*
+* (c) Red Pitaya  http://www.redpitaya.com
+*
+* This part of code is written in C programming language.
+* Please visit http://en.wikipedia.org/wiki/C_(programming_language)
+* for more details on the language used herein.
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "rp_hw.h"
+#include "rp_hw-calib.h"
+
+
+int main(int argc, char *argv[]){
+
+    // This example shows how to work with EEPROM via I2C
+
+    int res = rp_I2C_InitDevice("/dev/i2c-0",0x50); // Init i2c api.
+    printf("Init result: %d\n",res);
+
+    res = rp_I2C_setForceMode(true); // Set force mode.
+    printf("Set force mode: %d\n",res);
+
+    uint8_t wb[2] = {0,0};
+    res = rp_I2C_IOCTL_WriteBuffer(wb,2); // Write position for reading.
+    printf("Write 2 bytes: %d\n",res);
+
+    usleep(100000);
+
+    uint8_t rb[1];
+
+    res = rp_I2C_IOCTL_ReadBuffer(rb,1); // Read 1 byte from I2C
+    printf("Read 1 byte: %d\n",res);
+    uint8_t df = rb[0];
+    printf("Data format %d\n",df);
+    res = rp_I2C_IOCTL_WriteBuffer(wb,2); // Write position for reading.
+    printf("Write 2 bytes: %d\n",res);
+    usleep(100000);
+
+    rp_calib_params_t calib;
+
+    if (df == 5){
+        rp_calib_params_universal_t data;
+        uint16_t size = sizeof(data);
+        res = rp_I2C_IOCTL_ReadBuffer((uint8_t*)&data,size);
+        printf("Read %d byte: %d\n",size,res);
+        res = rp_CalibConvertEEPROM((uint8_t*)&data,size,&calib);
+        printf("Convert calib: %d\n",res);
+    }else{
+        rp_eepromWpData_t data;
+        uint16_t size = sizeof(data);
+        res = rp_I2C_IOCTL_ReadBuffer((uint8_t*)&data,size);
+        printf("Read %d byte: %d\n",size,res);
+        res = rp_CalibConvertEEPROM((uint8_t*)&data,size,&calib);
+        printf("Convert calib: %d\n",res);
+    }
+    rp_CalibPrint(&calib);
+    return 0;
+}

+ 63 - 0
i2c_switch_max7311.c

@@ -0,0 +1,63 @@
+/* @brief This is a simple application for testing I2C communication on a RedPitaya
+*
+* (c) Red Pitaya  http://www.redpitaya.com
+*
+* This part of code is written in C programming language.
+* Please visit http://en.wikipedia.org/wiki/C_(programming_language)
+* for more details on the language used herein.
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "rp_hw.h"
+
+
+int main(int argc, char *argv[]){
+
+
+    int res = rp_I2C_InitDevice("/dev/i2c-0",0x21); // Init i2c api.
+    printf("Init result: %d\n",res);
+
+    res = rp_I2C_setForceMode(true); // Set force mode.
+    printf("Set force mode: %d\n",res);
+    
+    printf("Turn on AC/DC ch1 & ch2\n");
+
+    uint16_t value = 0x0055;
+
+    res = rp_I2C_SMBUS_WriteWord(0x02,value);
+    printf("Write 2 bytes: %d\n",res);
+
+    usleep(1000000);
+
+    value = value & ~ 0x000F;
+
+    res = rp_I2C_SMBUS_WriteWord(0x02,value);
+    printf("Write 2 bytes: %d\n",res);
+
+    usleep(3000000);
+
+    printf("Turn off AC/DC ch1 & ch2\n");
+
+    value = 0x00AA;
+
+    res = rp_I2C_SMBUS_WriteWord(0x02,value);
+    printf("Write 2 bytes: %d\n",res);
+
+    usleep(1000000);
+
+    value = value & ~ 0x000F;
+
+    res = rp_I2C_SMBUS_WriteWord(0x02,value);
+    printf("Write 2 bytes: %d\n",res);
+
+    uint16_t read_value = 0;
+
+    res = rp_I2C_SMBUS_ReadWord(0x02,&read_value);
+    printf("Read 2 bytes: 0x%x (res: %d)\n",read_value, res);
+
+    return 0;
+}

+ 116 - 0
period

@@ -0,0 +1,116 @@
+#include <math.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "rp.h"
+#include "rp_asg_axi.h"
+
+// g++ axi_gen.c -std=c++20 -Wall  -I/opt/redpitaya/include -L/opt/redpitaya/lib -static -lrp-hw-can -lrp -lrp-hw-calib -lrp-hw-profiles -lrp-gpio -lrp-i2c -lrp-hw -lm -lstdc++ -lpthread -li2c -lsocketcan -o axi_gen
+
+int main(int argc, char **argv) {
+
+    // Select channel
+    rp_channel_t channel = RP_CH_1;
+
+    // Data size in samples (16 bit)
+    uint32_t bufferSize = 10;             // Should be twice the actual number of samples
+    uint32_t dec_factor = 1;
+    uint32_t num_buffers = 1;
+
+    uint32_t ncyc = 3;
+    uint32_t nor = 3;
+    uint32_t period = 100;
+
+    // Start addresses of buffers must be multiple of 4096 (DDR page size)
+    uint32_t min_addr_diff = 4096;
+
+    // Initialize the interface
+    if (rp_Init() != RP_OK) {
+        fprintf(stderr, "Rp api init failed!\n");
+        return 1;
+    }
+
+    // Reset generator
+    rp_GenReset();
+
+    /* Setting up the Deep Memory Generation (DMG) */
+    uint32_t dac_axi_start, dac_axi_size;
+
+    // Get the reserved memory region start and size
+    if (rp_AcqAxiGetMemoryRegion(&dac_axi_start, &dac_axi_size) != RP_OK) {
+        fprintf(stderr, "Error get memory!\n");
+        return 1;
+    }
+
+    // Lower the buffer size to the available memory size (if needed)
+    uint32_t dmg_min_size = (uint32_t) (ceil((float) bufferSize / (float) min_addr_diff) * (float) min_addr_diff * (float) num_buffers);
+    printf("Buffer size: %d\n", bufferSize);
+    printf("Minimum size: %d\n", dmg_min_size);
+
+    if (dmg_min_size > dac_axi_size) {
+        printf("Buffer size is too large, reducing to available memory size\n");
+        bufferSize = dac_axi_size / num_buffers;
+        printf("Buffer size reduced to %d\n", bufferSize);
+    }
+
+    // Calculate the start address
+    uint32_t gen1_start_addr = dac_axi_start;
+
+    // Reserve memory for the generator
+    printf("Reserved memory for OUT1 Start: %x Size: %x End: %x\n", gen1_start_addr, bufferSize, gen1_start_addr + bufferSize);
+
+    if (rp_GenAxiReserveMemory(channel, gen1_start_addr, gen1_start_addr + bufferSize) != RP_OK) {
+        fprintf(stderr, "Error setting address for DMG mode for OUT1\n");
+        return 1;
+    }
+
+    // Set decimation factor
+    if (rp_GenAxiSetDecimationFactor(channel, dec_factor) != RP_OK) {
+        fprintf(stderr, "Error setting decimation for generator OUT1\n");
+        return 1;
+    }
+
+    // Enable DMG mode
+    if (rp_GenAxiSetEnable(channel, true) != RP_OK) {
+        fprintf(stderr, "Error enable axi mode for OUT1\n");
+        return 1;
+    }
+
+    // Define output waveform for both channels
+    bufferSize /= 2;                // Samples are float32 which is 4 bytes, int16 is 2 byte
+
+
+    float *t = (float *)malloc(bufferSize * sizeof(float));
+    float *x = (float *)malloc(bufferSize * sizeof(float));
+
+    for (uint32_t i = 1; i < bufferSize; i++) {
+        t[i] = (2 * M_PI) / bufferSize * i;
+    }
+
+    for (uint32_t i = 0; i < bufferSize; ++i) {
+        x[i] = sin(t[i]) + ((1.0 / 3.0) * sin(t[i] * 3));
+    }
+
+    // Configure calibration and offset
+    rp_GenSetAmplitudeAndOffsetOrigin(channel);
+
+    // Set burst parameters
+    rp_GenMode(channel, RP_GEN_MODE_BURST);
+    rp_GenBurstCount(channel, ncyc);
+    rp_GenBurstRepetitions(channel, nor);
+    rp_GenBurstPeriod(channel, period);
+    rp_GenAxiWriteWaveform(channel, x, bufferSize);
+
+    rp_GenOutEnable(channel);
+    rp_GenTriggerOnly(channel);
+
+    // Release resources
+    free(t);
+    free(x);
+
+    rp_Release();
+
+    return 0;
+}

+ 1 - 0
rp-test-pub

@@ -0,0 +1 @@
+Subproject commit c7e01d44ca2b0fd6ca9de25d51729a3d8a5cc9d7

BIN
rp.tar


+ 94 - 0
rp_client.py

@@ -0,0 +1,94 @@
+from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QCheckBox, QBoxLayout
+import sys
+import struct
+import socket
+from QtPyNetwork.client import TCPClient
+
+def setPinout(pinout):
+    pass
+
+class Window(QWidget):
+    def __init__(self):
+        QWidget.__init__(self)
+        self.setWindowTitle('Magnetometer Control Client')
+
+        layout = QBoxLayout(QBoxLayout.TopToBottom)
+        self.setLayout(layout)
+
+        label_layout = QBoxLayout(QBoxLayout.LeftToRight)
+        self.label = QLabel('Magnetometer Controller')
+        label_layout.addWidget(self.label, 0)
+        layout.addLayout(label_layout)
+
+        button_layout = QBoxLayout(QBoxLayout.LeftToRight)
+        self.check1 = QCheckBox('PIN1')
+        self.check1.setEnabled(False)
+        self.check1.toggled.connect(self.toggleChecks)
+        button_layout.addWidget(self.check1)
+        self.check2 = QCheckBox('PIN2')
+        self.check2.setEnabled(False)
+        self.check2.toggled.connect(self.toggleChecks)
+        button_layout.addWidget(self.check2)
+        self.check3 = QCheckBox('PIN3')
+        self.check3.setEnabled(False)
+        self.check3.toggled.connect(self.toggleChecks)
+        button_layout.addWidget(self.check3)
+        self.check4 = QCheckBox('PIN4')
+        self.check4.setEnabled(False)
+        self.check4.toggled.connect(self.toggleChecks)
+        button_layout.addWidget(self.check4)
+        layout.addLayout(button_layout)
+
+        control_layout = QBoxLayout(QBoxLayout.LeftToRight)
+        self.connected = False
+        self.buttonCon = QPushButton('Connect')
+        self.buttonCon.clicked.connect(self.connectPressed)
+        control_layout.addWidget(self.buttonCon)
+        layout.addLayout(control_layout)
+
+        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    
+    @Slot()
+    def toggleChecks(self):
+        pinout = 0b00000000
+
+        if(self.check1.isChecked()):
+            pinout = pinout | 0b00000001
+
+        if(self.check2.isChecked()):
+            pinout = pinout | 0b00000010
+
+        if(self.check3.isChecked()):
+            pinout = pinout | 0b00000100
+        
+        if(self.check4.isChecked()):
+            pinout = pinout | 0b00001000
+
+        data = struct.pack('<BB', 0x02, pinout)
+        self.socket.sendall(data)
+        data = self.sock.recv(1024)
+
+    @Slot()
+    def connectPressed(self):
+        if(self.connected):
+            self.check1.setEnabled(False)
+            self.check2.setEnabled(False)
+            self.check3.setEnabled(False)
+            self.check4.setEnabled(False)
+            self.sock.close()
+            self.buttonCon.setText('Connect')
+        else:
+            self.check1.setEnabled(True)
+            self.check2.setEnabled(True)
+            self.check3.setEnabled(True)
+            self.check4.setEnabled(True)
+            self.sock.connect(('rp-f082cf.local', 5005))
+            self.buttonCon.setText('Disconnect')
+        
+
+
+app = QApplication(sys.argv)
+win = Window()
+win.show()
+
+sys.exit(app.exec())

+ 188 - 0
spi.c

@@ -0,0 +1,188 @@
+/* @brief This is a simple application for testing SPI communication on a RedPitaya
+* @Author Luka Golinar <luka.golinar@redpitaya.com>
+*
+* (c) Red Pitaya  http://www.redpitaya.com
+*
+* This part of code is written in C programming language.
+* Please visit http://en.wikipedia.org/wiki/C_(programming_language)
+* for more details on the language used herein.
+*/
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <string.h>
+#include <linux/spi/spidev.h>
+#include <linux/types.h>
+
+/* Inline functions definition */
+static int init_spi();
+static int release_spi();
+static int read_flash_id(int fd);
+static int write_spi(char *write_data, int size);
+
+/* Constants definition */
+int spi_fd = -1;
+
+int main(void){
+
+    /* Sample data */
+    char *data = "REDPITAYA SPI TEST";
+
+    /* Init the spi resources */
+    if(init_spi() < 0){
+        printf("Initialization of SPI failed. Error: %s\n", strerror(errno));
+        return -1;
+    }
+
+    /* Write some sample data */
+    if(write_spi(data, strlen(data)) < 0){
+        printf("Write to SPI failed. Error: %s\n", strerror(errno));
+        return -1;
+    }
+
+    /* Read flash ID and some sample loopback data */
+    if(read_flash_id(spi_fd) < 0){
+        printf("Error reading from SPI bus : %s\n", strerror(errno));
+        return -1;
+    }
+
+    /* Release resources */
+    if(release_spi() < 0){
+        printf("Relase of SPI resources failed, Error: %s\n", strerror(errno));
+        return -1;
+    }
+
+    return 0;
+}
+
+static int init_spi(){
+
+    /* MODES: mode |= SPI_LOOP;
+    *        mode |= SPI_CPHA;
+    *        mode |= SPI_CPOL;
+    *                 mode |= SPI_LSB_FIRST;
+    *        mode |= SPI_CS_HIGH;
+    *        mode |= SPI_3WIRE;
+    *        mode |= SPI_NO_CS;
+    *        mode |= SPI_READY;
+    *
+    * multiple possibilities possible using | */
+    int mode = 0;
+
+    /* Opening file stream */
+    spi_fd = open("/dev/spidev1.0", O_RDWR | O_NOCTTY);
+
+    if(spi_fd < 0){
+        printf("Error opening spidev0.1. Error: %s\n", strerror(errno));
+        return -1;
+    }
+
+    /* Setting mode (CPHA, CPOL) */
+    if(ioctl(spi_fd, SPI_IOC_WR_MODE, &mode) < 0){
+        printf("Error setting SPI_IOC_RD_MODE. Error: %s\n", strerror(errno));
+        return -1;
+    }
+
+    /* Setting SPI bus speed */
+    int spi_speed = 1000000;
+
+    if(ioctl(spi_fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi_speed) < 0){
+        printf("Error setting SPI_IOC_WR_MAX_SPEED_HZ. Error: %s\n", strerror(errno));
+        return -1;
+    }
+
+    return 0;
+}
+
+static int release_spi(){
+
+    /* Release the spi resources */
+    close(spi_fd);
+
+    return 0;
+}
+
+/* Read data from the SPI bus */
+static int read_flash_id(int fd){
+
+    int size = 2;
+
+    /*struct spi_ioc_transfer {
+        __u64           tx_buf;
+        __u64           rx_buf;
+
+        __u32           len;
+        __u32           speed_hz;
+
+        __u16           delay_usecs;
+        __u8            bits_per_word;
+        __u8            cs_change;
+        __u32           pad;
+    }*/
+    /* If the contents of 'struct spi_ioc_transfer' ever change
+    * incompatibly, then the ioctl number (currently 0) must change;
+    * ioctls with constant size fields get a bit more in the way of
+    * error checking than ones (like this) where that field varies.
+    *
+    * NOTE: struct layout is the same in 64bit and 32bit userspace.*/
+    struct spi_ioc_transfer xfer[size];
+
+    unsigned char           buf0[1];
+    unsigned char           buf1[3];
+    int                     status;
+
+    memset(xfer, 0, sizeof xfer);
+
+    /* RDID command */
+    buf0[0] = 0x9f;
+    /* Some sample data */
+    buf1[0] = 0x01;
+    buf1[1] = 0x23;
+    buf1[2] = 0x45;
+
+    /* RDID buffer */
+    xfer[0].tx_buf = (__u64)((__u32)buf0);
+    xfer[0].rx_buf = (__u64)((__u32)buf0);
+    xfer[0].len = 1;
+
+    /* Sample loopback buffer */
+    xfer[1].tx_buf = (__u64)((__u32)buf1);
+    xfer[1].rx_buf = (__u64)((__u32)buf1);
+    xfer[1].len = 3;
+
+    /* ioctl function arguments
+    * arg[0] - file descriptor
+    * arg[1] - message number
+    * arg[2] - spi_ioc_transfer structure
+    */
+    status = ioctl(fd, SPI_IOC_MESSAGE(2), xfer);
+    if (status < 0) {
+        perror("SPI_IOC_MESSAGE");
+        return -1;
+    }
+
+    /* Print read buffer */
+    for(int i = 0; i < 3; i++){
+        printf("Buffer: %d\n", buf1[i]);
+    }
+
+    return 0;
+}
+
+/* Write data to the SPI bus */
+static int write_spi(char *write_buffer, int size){
+
+    int write_spi = write(spi_fd, write_buffer, strlen(write_buffer));
+
+    if(write_spi < 0){
+        printf("Failed to write to SPI. Error: %s\n", strerror(errno));
+        return -1;
+    }
+
+    return 0;
+}

+ 81 - 0
spi_loopback.c

@@ -0,0 +1,81 @@
+/* @brief This is a simple application for testing SPI communication on a RedPitaya
+*
+* (c) Red Pitaya  http://www.redpitaya.com
+*
+* This part of code is written in C programming language.
+* Please visit http://en.wikipedia.org/wiki/C_(programming_language)
+* for more details on the language used herein.
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "rp_hw.h"
+
+
+int main(int argc, char *argv[]){
+
+    char *buffer = "TEST string";
+    char rx_buf[255];
+    memset(rx_buf,0,255);
+
+    int res = rp_SPI_InitDevice("/dev/spidev1.0"); // Init spi api.
+    printf("Init result: %d\n",res);
+
+    res = rp_SPI_SetDefaultSettings(); // Set default settings.
+    printf("Set default settings: %d\n",res);
+
+    res = rp_SPI_GetSettings(); // Get uart speed.
+    printf("Get current settings of spi: %d\n",res);
+
+    rp_spi_mode_t mode;
+    res = rp_SPI_GetMode(&mode);
+    printf("Get mode: %d ret: %d\n",mode,res);
+
+    res = rp_SPI_SetMode(RP_SPI_MODE_LIST); // Set SPI mode: Low idle level, sample on trailing edge.
+    printf("Set mode: %d\n",res);
+
+    rp_spi_cs_mode_t cs_mode;
+    res = rp_SPI_GetCSMode(&cs_mode);
+    printf("Get CS mode: %d ret: %d\n",cs_mode,res);
+
+    int speed;
+    res = rp_SPI_GetSpeed(&speed);
+    printf("Get speed: %d ret: %d\n",speed,res);
+
+    res = rp_SPI_SetSpeed(50000000); // Set SPI speed.
+    printf("Set speed: %d\n",res);
+
+    res = rp_SPI_SetWordLen(8); // Set word bit size.
+    printf("Set word length: %d\n",res);
+
+    res = rp_SPI_SetSettings(); // Apply settings to SPI.
+    printf("Set settings: %d\n",res);
+
+    res = rp_SPI_CreateMessage(2); // Create 2 message.
+    printf("Set settings: %d\n",res);
+
+    res = rp_SPI_SetBufferForMessage(0,(uint8_t*)buffer,true,strlen(buffer),false); // Set buffer for first message and create RX buffer.
+    printf("Set buffers for first msg: %d\n",res);
+
+    res = rp_SPI_SetBufferForMessage(1,0,true,100,false); // Create RX buffer.
+    printf("Set buffers for second msg: %d\n",res);
+
+    res = rp_SPI_ReadWrite(); // Pass message to SPI.
+    printf("Read/Write to spi: %d\n",res);
+
+    const uint8_t *rx_buffer = 0;
+    size_t rx_size = 0;
+    res = rp_SPI_GetRxBuffer(0,&rx_buffer,&rx_size); // Get pointer to rx buffer. No need free buffer. Api itself destroy buffer.
+
+    if (rx_buffer)
+        printf("Read message: %s (res %d)\n",rx_buffer,res);
+
+    res = rp_SPI_DestoryMessage();
+
+    res = rp_SPI_Release(); // Close spi api.
+    printf("UnInit result: %d\n",res);
+
+    return 0;
+}

+ 99 - 0
test_e_module.c

@@ -0,0 +1,99 @@
+/* @brief This is a simple application for testing IIC communication on a RedPitaya
+ * @Author Luka Golinar <luka.golinar@redpitaya.com>
+ * 
+ * (c) Red Pitaya  http://www.redpitaya.com
+ *
+ * This part of code is written in C programming language.
+ * Please visit http://en.wikipedia.org/wiki/C_(programming_language)
+ * for more details on the language used herein.
+ */
+
+ 
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <linux/ioctl.h>
+#include <sys/ioctl.h>
+#include <linux/i2c-dev.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdint.h>
+ #include <math.h>
+#define I2C_SLAVE_FORCE            0x0706
+#define EXPANDER_ADDR                  0x20
+ 
+
+int main(int argc, char *argv[])
+{
+//int main(){
+//int k;
+
+//for (k=0;k<=5;k++)
+//{
+ 
+sleep(3);
+//printf("%i\n", k );
+    
+    int  dat;
+    int  fd; 
+    int  status;
+    char str [1+2*11];
+
+    //parse input arguments
+    dat = (int)strtol(argv[1], NULL, 0);
+
+    dat = (1<<dat);
+
+    // Open the device.
+    fd = open("/dev/i2c-0", O_RDWR);
+    if (fd < 0) {
+        printf("Cannot open the IIC device\n");
+        return 1;
+    }
+
+    // set slave address
+    status = ioctl(fd, I2C_SLAVE_FORCE, EXPANDER_ADDR);
+    if (status < 0) {
+        printf("Unable to set the I2C address\n");
+        return -1;
+    }
+
+    // Write to expander
+    str [0] = 0; // set address to 0
+    str [1+0x00] = 0x00; // IODIRA - set all to output
+    str [1+0x01] = 0x00; // IODIRB - set all to output
+    str [1+0x02] = 0x00; // IPOLA
+    str [1+0x03] = 0x00; // IPOLB
+    str [1+0x04] = 0x00; // GPINTENA
+    str [1+0x05] = 0x00; // GPINTENB
+    str [1+0x06] = 0x00; // DEFVALA
+    str [1+0x07] = 0x00; // DEFVALB
+    str [1+0x08] = 0x00; // INTCONA
+    str [1+0x09] = 0x00; // INTCONB
+    str [1+0x0A] = 0x00; // IOCON
+    str [1+0x0B] = 0x00; // IOCON
+    str [1+0x0C] = 0x00; // GPPUA
+    str [1+0x0D] = 0x00; // GPPUB
+    str [1+0x0E] = 0x00; // INTFA
+    str [1+0x0F] = 0x00; // INTFB
+    str [1+0x10] = 0x00; // INTCAPA
+    str [1+0x11] = 0x00; // INTCAPB
+    str [1+0x12] = (dat >> 0) & 0xff; // GPIOA
+    str [1+0x13] = (dat >> 8) & 0xff; // GPIOB
+    str [1+0x14] = (dat >> 0) & 0xff; // OLATA
+    str [1+0x15] = (dat >> 8) & 0xff; // OLATB
+    status = write(fd, str, 1+2*11);
+
+    //printf("Resistor data write = 0x%04x.\n", dat);
+   // if (status)  printf("Resistor write => %.1f\n", powf(10.0,(float)k+1));
+    //else         
+     //   printf("Error write\n");
+    
+
+    close(fd);
+
+//}
+    return 0;
+
+}

+ 177 - 0
uart.c

@@ -0,0 +1,177 @@
+/* @brief This is a simple application for testing UART communication on a RedPitaya
+* @Author Luka Golinar <luka.golinar@redpitaya.com>
+*
+* (c) Red Pitaya  http://www.redpitaya.com
+*
+* This part of code is written in C programming language.
+* Please visit http://en.wikipedia.org/wiki/C_(programming_language)
+* for more details on the language used herein.
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>                 //Used for UART
+#include <fcntl.h>                  //Used for UART
+#include <termios.h>                //Used for UART
+#include <errno.h>
+
+
+/* Inline function definition */
+static int uart_init();
+static int release();
+static int uart_read(int size);
+static int uart_write();
+
+/* File descriptor definition */
+int uart_fd = -1;
+
+static int uart_init(){
+
+    uart_fd = open("/dev/ttyPS1", O_RDWR | O_NOCTTY | O_NDELAY);
+
+    if(uart_fd == -1){
+        fprintf(stderr, "Failed to open uart.\n");
+        return -1;
+    }
+
+    struct termios settings;
+    tcgetattr(uart_fd, &settings);
+
+    /*  CONFIGURE THE UART
+    *  The flags (defined in /usr/include/termios.h - see http://pubs.opengroup.org/onlinepubs/007908799/xsh/termios.h.html):
+    *       Baud rate:- B1200, B2400, B4800, B9600, B19200, B38400, B57600, B115200, B230400, B460800, B500000, B576000, B921600, B1000000, B1152000, B1500000, B2000000, B2500000, B3000000, B3500000, B4000000
+    *       CSIZE:- CS5, CS6, CS7, CS8
+    *       CLOCAL - Ignore modem status lines
+    *       CREAD - Enable receiver
+    *       IGNPAR = Ignore characters with parity errors
+    *       ICRNL - Map CR to NL on input (Use for ASCII comms where you want to auto correct end of line characters - don't use for bianry comms!)
+    *       PARENB - Parity enable
+    *       PARODD - Odd parity (else even) */
+
+    /* Set baud rate - default set to 9600Hz */
+    speed_t baud_rate = B9600;
+
+    /* Baud rate fuctions
+    * cfsetospeed - Set output speed
+    * cfsetispeed - Set input speed
+    * cfsetspeed  - Set both output and input speed */
+
+    cfsetspeed(&settings, baud_rate);
+
+    settings.c_cflag &= ~PARENB; /* no parity */
+    settings.c_cflag &= ~CSTOPB; /* 1 stop bit */
+    settings.c_cflag &= ~CSIZE;
+    settings.c_cflag |= CS8 | CLOCAL; /* 8 bits */
+    settings.c_lflag = ICANON; /* canonical mode */
+    settings.c_oflag &= ~OPOST; /* raw output */
+
+    /* Setting attributes */
+    tcflush(uart_fd, TCIFLUSH);
+    tcsetattr(uart_fd, TCSANOW, &settings);
+
+    return 0;
+}
+
+static int uart_read(int size){
+
+    /* Read some sample data from RX UART */
+
+    /* Don't block serial read */
+    fcntl(uart_fd, F_SETFL, FNDELAY);
+
+    while(1){
+        if(uart_fd == -1){
+            fprintf(stderr, "Failed to read from UART.\n");
+            return -1;
+        }
+
+        unsigned char rx_buffer[size];
+
+        int rx_length = read(uart_fd, (void*)rx_buffer, size);
+
+        if (rx_length < 0){
+
+            /* No data yet avaliable, check again */
+            if(errno == EAGAIN){
+                fprintf(stderr, "AGAIN!\n");
+                continue;
+            /* Error differs */
+            }else{
+                fprintf(stderr, "Error!\n");
+                return -1;
+            }
+
+        }else if (rx_length == 0){
+            fprintf(stderr, "No data waiting\n");
+        /* Print data and exit while loop */
+        }else{
+            rx_buffer[rx_length] = '\0';
+            printf("%i bytes read : %s\n", rx_length, rx_buffer);
+            break;
+
+        }
+    }
+
+    return 0;
+}
+
+static int uart_write(char *data){
+
+    /* Write some sample data into UART */
+    /* ----- TX BYTES ----- */
+    int msg_len = strlen(data);
+
+    int count = 0;
+    char tx_buffer[msg_len+1];
+
+    strncpy(tx_buffer, data, msg_len);
+    tx_buffer[msg_len++] = 0x0a; //New line numerical value
+
+    if(uart_fd != -1){
+        count = write(uart_fd, &tx_buffer, (msg_len));
+    }
+    if(count < 0){
+        fprintf(stderr, "UART TX error.\n");
+        return -1;
+    }
+
+    return 0;
+}
+
+static int release(){
+
+    tcflush(uart_fd, TCIFLUSH);
+    close(uart_fd);
+
+    return 0;
+}
+
+int main(int argc, char *argv[]){
+
+    char *data = "HELLO WOLRD!";
+
+    /* uart init */
+    if(uart_init() < 0){
+        printf("Uart init error.\n");
+        return -1;
+    }
+
+    /* Sample write */
+    if(uart_write(data) < 0){
+        printf("Uart write error\n");
+        return -1;
+    }
+
+    /* Sample read */
+    if(uart_read(strlen(data)) < 0){
+        printf("Uart read error\n");
+        return -1;
+    }
+
+    /* CLOSING UART */
+    release();
+
+    return 0;
+}

+ 56 - 0
uart_loopback.c

@@ -0,0 +1,56 @@
+/* @brief This is a simple application for testing UART communication on a RedPitaya
+* @Author Luka Golinar <luka.golinar@redpitaya.com>
+*
+* (c) Red Pitaya  http://www.redpitaya.com
+*
+* This part of code is written in C programming language.
+* Please visit http://en.wikipedia.org/wiki/C_(programming_language)
+* for more details on the language used herein.
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "rp_hw.h"
+
+
+int main(int argc, char *argv[]){
+
+    char *buffer = "TEST string";
+    char rx_buf[255];
+    memset(rx_buf,0,255);
+    int size = 255;
+
+    int res = rp_UartInit(); // init uart api
+    printf("Init result: %d\n",res);
+    
+    res = rp_UartSetTimeout(10); // set timeout in 1/10 sec. 10 = 1 sec 
+    printf("Set timeout: %d\n",res);
+    
+    res = rp_UartSetSpeed(115200); // set uart speed
+    printf("Set speed: %d\n",res);
+
+    res = rp_UartSetBits(RP_UART_CS8); // set word size
+    printf("Set CS8: %d\n",res);
+
+    res = rp_UartSetStopBits(RP_UART_STOP2); // set stop bits
+    printf("Set Stop Bits 2: %d\n",res);
+
+    res = rp_UartSetParityMode(RP_UART_MARK); // set parity
+    printf("Set Parity Mode: %d\n",res);
+    
+    res = rp_UartSetSettings(); // apply settings to uart
+    printf("Set settings: %d\n",res);
+    
+    res = rp_UartWrite((unsigned char*)buffer,strlen(buffer)); // write buffer to uart
+    printf("Write result: %d\n",res);
+
+    res = rp_UartRead((unsigned char*)rx_buf,&size); // read from uart
+    printf("Read result: %d\n",res);   
+    printf("Size: %d (%s)\n",size,rx_buf);
+
+    res = rp_UartRelease(); // close uart api
+    printf("UnInit result: %d\n",res);
+    return 0;
+}