aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/transport/nirio/niriok_proxy_impl_v2.cpp
blob: 4e88b8a6ee0218d7e15ac260a55e2825fd470618 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
//
// Copyright 2013-2014 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//


#include <uhd/transport/nirio/niriok_proxy_impl_v2.h>
#include <cstring>

// "push" and "pop" introduced in GCC 4.6; works with all clang
#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5)
    #pragma GCC diagnostic push
#endif
#if defined(__clang__) || defined(__GNUC__)
    #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif

#define IOCTL_TRANSPORT_GET32                       IOCTL(0, 0, IOCTL_ACCESS_READ)
#define IOCTL_TRANSPORT_SET32                       IOCTL(0, 1, IOCTL_ACCESS_WRITE)
#define IOCTL_TRANSPORT_GET_STRING                  IOCTL(0, 2, IOCTL_ACCESS_READ)
#define IOCTL_TRANSPORT_SET_STRING                  IOCTL(0, 3, IOCTL_ACCESS_WRITE)
#define IOCTL_TRANSPORT_RESET                       IOCTL(1, 1, IOCTL_ACCESS_WRITE)
#define IOCTL_TRANSPORT_ADD_INPUT_FIFO_RESOURCE     IOCTL(2, 0, IOCTL_ACCESS_ANY)
#define IOCTL_TRANSPORT_ADD_OUTPUT_FIFO_RESOURCE    IOCTL(2, 1, IOCTL_ACCESS_ANY)
#define IOCTL_TRANSPORT_SET_DEVICE_CONFIG           IOCTL(2, 3, IOCTL_ACCESS_WRITE)
#define IOCTL_TRANSPORT_FIFO_CONFIG                 IOCTL(4, 0, IOCTL_ACCESS_ANY)
#define IOCTL_TRANSPORT_FIFO_START                  IOCTL(4, 1, IOCTL_ACCESS_ANY)
#define IOCTL_TRANSPORT_FIFO_STOP                   IOCTL(4, 2, IOCTL_ACCESS_ANY)
#define IOCTL_TRANSPORT_FIFO_READ                   IOCTL(4, 3, IOCTL_ACCESS_READ)
#define IOCTL_TRANSPORT_FIFO_WRITE                  IOCTL(4, 4, IOCTL_ACCESS_WRITE)
#define IOCTL_TRANSPORT_FIFO_WAIT                   IOCTL(4, 5, IOCTL_ACCESS_ANY)
#define IOCTL_TRANSPORT_FIFO_GRANT                  IOCTL(4, 6, IOCTL_ACCESS_ANY)
#define IOCTL_TRANSPORT_FIFO_STOP_ALL               IOCTL(4, 7, IOCTL_ACCESS_ANY)
#define IOCTL_TRANSPORT_PEEK64                      IOCTL(5, 2, IOCTL_ACCESS_READ)
#define IOCTL_TRANSPORT_PEEK32                      IOCTL(5, 3, IOCTL_ACCESS_READ)
#define IOCTL_TRANSPORT_POKE64                      IOCTL(5, 6, IOCTL_ACCESS_WRITE)
#define IOCTL_TRANSPORT_POKE32                      IOCTL(5, 7, IOCTL_ACCESS_WRITE)
#define IOCTL_TRANSPORT_POST_OPEN                   IOCTL(8, 0, IOCTL_ACCESS_ANY)
#define IOCTL_TRANSPORT_PRE_CLOSE                   IOCTL(8, 1, IOCTL_ACCESS_ANY)

namespace uhd { namespace niusrprio
{
    //-------------------------------------------------------
    // ioctl param typedefs
    //-------------------------------------------------------
    typedef struct {
       nirio_scalar_type_t scalarType;
       nirio_u32_t     bitWidth;
       nirio_i32_t     integerWordLength;
    } nirio_fifo_data_type_t;

    typedef struct in_transport_get32
    {
       nirio_device_attribute32_t attribute;
       int32_t status;
    } in_transport_get32_t;
    typedef struct out_transport_get32
    {
       uint32_t retVal__;
       int32_t status;
    } out_transport_get32_t;
    typedef struct in_transport_set32
    {
       nirio_device_attribute32_t attribute;
       uint32_t value;
       int32_t status;
    } in_transport_set32_t;
    typedef struct out_transport_set32
    {
       int32_t status;
    } out_transport_set32_t;
    typedef struct out_transport_get_string
    {
       uint32_t  stringLen;
       int32_t status;
    } out_transport_get_string_t;
    typedef struct out_transport_set_string
    {
       int32_t status;
    } out_transport_set_string_t;
    typedef struct in_transport_reset
    {
       int32_t status;
    } in_transport_reset_t;
    typedef struct out_transport_reset
    {
       int32_t status;
    } out_transport_reset_t;
    typedef struct in_transport_add_input_fifo_resource
    {
       uint32_t channel;
       uint32_t baseAddress;
       uint32_t depthInSamples;
       nirio_fifo_data_type_t dataType;
       uint32_t version;
       int32_t status;
    } in_transport_add_input_fifo_resource_t;
    typedef struct out_transport_addInputFifo_resource
    {
       int32_t status;
    } out_transport_add_input_fifo_resource_t;
    typedef struct in_transport_addOutputFifo_resource
    {
       uint32_t channel;
       uint32_t baseAddress;
       uint32_t depthInSamples;
       nirio_fifo_data_type_t dataType;
       uint32_t version;
       int32_t status;
    } in_transport_add_output_fifo_resource_t;
    typedef struct out_transport_addOutputFifo_resource
    {
       int32_t status;
    } out_transport_add_output_fifo_resource_t;
    typedef struct in_transport_setDevice_config
    {
       uint32_t attribute;
       int32_t status;
    } in_transport_set_device_config_t;
    typedef struct out_transport_setDevice_config
    {
       int32_t status;
    } out_transport_set_device_config_t;
    typedef struct in_transport_fifo_config
    {
       uint32_t channel;
       aligned_uint64_t requestedDepth;
       int32_t status;
    } in_transport_fifo_config_t;
    typedef struct out_transport_fifo_config
    {
       aligned_uint64_t  actualDepth;
       aligned_uint64_t  actualSize;
       int32_t status;
    } out_transport_fifo_config_t;
    typedef struct in_transport_fifo_start
    {
       uint32_t channel;
       int32_t status;
    } in_transport_fifo_start_t;
    typedef struct out_transport_fifo_start
    {
       int32_t status;
    } out_transport_fifo_start_t;
    typedef struct in_transport_fifo_stop
    {
       uint32_t channel;
       int32_t status;
    } in_transport_fifo_stop_t;
    typedef struct out_transport_fifo_stop
    {
       int32_t status;
    } out_transport_fifo_stop_t;
    typedef struct in_transport_fifo_read
    {
       uint32_t channel;
       aligned_uint64_t buf;
       uint32_t numberElements;
       nirio_fifo_data_type_t dataType;
       uint32_t timeout;
       int32_t status;
    } in_transport_fifo_read_t;
    typedef struct out_transport_fifo_read
    {
       uint32_t  read;
       uint32_t  remaining;
       int32_t status;
    } out_transport_fifo_read_t;
    typedef struct in_transport_fifo_write
    {
       uint32_t channel;
       aligned_uint64_t buf;
       uint32_t numberElements;
       nirio_fifo_data_type_t dataType;
       uint32_t timeout;
       int32_t status;
    } in_transport_fifo_write_t;
    typedef struct out_transport_fifo_write
    {
       uint32_t  remaining;
       int32_t status;
    } out_transport_fifo_write_t;
    typedef struct in_transport_fifo_wait
    {
       uint32_t channel;
       aligned_uint64_t elementsRequested;
       nirio_fifo_data_type_t dataType;
       bool output;
       uint32_t timeout;
       int32_t status;
    } in_transport_fifo_wait_t;
    typedef struct out_transport_fifo_wait
    {
       aligned_uint64_t  elements;
       aligned_uint64_t  elementsAcquired;
       aligned_uint64_t  elementsRemaining;
       int32_t status;
    } out_transport_fifo_wait_t;
    typedef struct in_transport_fifo_grant
    {
       uint32_t channel;
       aligned_uint64_t elements;
       int32_t status;
    } in_transport_fifo_grant_t;
    typedef struct out_transport_fifo_grant
    {
       int32_t status;
    } out_transport_fifo_grant_t;
    typedef struct in_transport_fifoStop_all
    {
       int32_t status;
    } in_transport_fifo_stop_all_t;
    typedef struct out_transport_fifoStop_all
    {
       int32_t status;
    } out_transport_fifo_stop_all_t;
    typedef struct in_transport_peek64
    {
       uint32_t offset;
       int32_t status;
    } in_transport_peek64_t;
    typedef struct out_transport_peek64
    {
       aligned_uint64_t retVal__;
       int32_t status;
    } out_transport_peek64_t;
    typedef struct in_transport_peek32
    {
       uint32_t offset;
       int32_t status;
    } in_transport_peek32_t;
    typedef struct out_transport_peek32
    {
       uint32_t retVal__;
       int32_t status;
    } out_transport_peek32_t;
    typedef struct in_transport_poke64
    {
       uint32_t offset;
       aligned_uint64_t value;
       int32_t status;
    } in_transport_poke64_t;
    typedef struct out_transport_poke64
    {
       int32_t status;
    } out_transport_poke64_t;
    typedef struct in_transport_poke32
    {
       uint32_t offset;
       uint32_t value;
       int32_t status;
    } in_transport_poke32_t;
    typedef struct out_transport_poke32
    {
       int32_t status;
    } out_transport_poke32_t;
    typedef struct in_transport_post_open
    {
       int32_t status;
    } in_transport_post_open_t;
    typedef struct out_transport_post_open
    {
       int32_t status;
    } out_transport_post_open_t;
    typedef struct in_transport_pre_close
    {
       int32_t status;
    } in_transport_pre_close_t;
    typedef struct out_transport_pre_close
    {
       int32_t status;
    } out_transport_pre_close_t;

    //-------------------------------------------------------
    // niriok_proxy_impl_v2
    //-------------------------------------------------------
    niriok_proxy_impl_v2::niriok_proxy_impl_v2()
    {
    }

    niriok_proxy_impl_v2::~niriok_proxy_impl_v2()
    {
        close();
    }

    nirio_status niriok_proxy_impl_v2::open(const std::string& interface_path)
    {
        WRITER_LOCK

        if (interface_path.empty()) return NiRio_Status_ResourceNotFound;

        //close if already open.
        // use non-locking _close since we already have the lock
        _close();

        in_transport_post_open_t in = {};
        out_transport_post_open_t out = {};

        in.status = NiRio_Status_Success;

        nirio_status status = NiRio_Status_Success;
        nirio_status_chain(nirio_driver_iface::rio_open(
        interface_path, _device_handle), status);
        if (nirio_status_not_fatal(status)) 
        {
            nirio_status_chain(nirio_driver_iface::rio_ioctl(_device_handle,
                                        IOCTL_TRANSPORT_POST_OPEN,
                                        &in, sizeof(in), &out, sizeof(out)), status);
            if (nirio_status_fatal(status)) _close();
        }
        return status;
    }

    void niriok_proxy_impl_v2::close(void)
    {
       WRITER_LOCK

       _close();
    }

    // this protected _close doesn't acquire the lock, so it can be used in methods 
    // that already have the lock
    void niriok_proxy_impl_v2::_close()
    {
        if(nirio_driver_iface::rio_isopen(_device_handle))
        {
            in_transport_pre_close_t in = {};
            out_transport_pre_close_t out = {};

            in.status = NiRio_Status_Success;

            nirio_driver_iface::rio_ioctl(
            _device_handle, IOCTL_TRANSPORT_PRE_CLOSE, &in, sizeof(in), &out, sizeof(out));
            nirio_driver_iface::rio_close(_device_handle);
       }
    }

    nirio_status niriok_proxy_impl_v2::reset()
    {
        READER_LOCK

        in_transport_reset_t in = {};
        out_transport_reset_t out = {};

        in.status = NiRio_Status_Success;

        nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle,
                                    IOCTL_TRANSPORT_RESET,
                                    &in, sizeof(in), &out, sizeof(out));
        if (nirio_status_fatal(ioctl_status)) return ioctl_status;

        return out.status;
    }

    nirio_status niriok_proxy_impl_v2::get_version(
        nirio_version_t type,
        uint32_t& major,
        uint32_t& upgrade,
        uint32_t& maintenance,
        char& phase,
        uint32_t& build)
    {
        nirio_device_attribute32_t version_attr = (type==CURRENT)?RIO_CURRENT_VERSION:RIO_OLDEST_COMPATIBLE_VERSION;
        uint32_t raw_version = 0;
        nirio_status status = get_attribute(version_attr, raw_version);

        major       = (raw_version & VERSION_MAJOR_MASK) >> VERSION_MAJOR_SHIFT;
        upgrade     = (raw_version & VERSION_UPGRD_MASK) >> VERSION_UPGRD_SHIFT;
        maintenance = (raw_version & VERSION_MAINT_MASK) >> VERSION_MAINT_SHIFT;
        build       = (raw_version & VERSION_BUILD_MASK) >> VERSION_BUILD_SHIFT;

        uint32_t phase_num = (raw_version & VERSION_PHASE_MASK) >> VERSION_PHASE_SHIFT;
        switch (phase_num) {
            case 0: phase = 'd'; break;
            case 1: phase = 'a'; break;
            case 2: phase = 'b'; break;
            case 3: phase = 'f'; break;
        }

        return status;
    }

    nirio_status niriok_proxy_impl_v2::get_attribute(
        const nirio_device_attribute32_t attribute,
        uint32_t& attrValue)
    {
        READER_LOCK

        in_transport_get32_t in = {};
        out_transport_get32_t out = {};

        in.attribute = attribute;
        in.status = NiRio_Status_Success;

        nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle,
                                 IOCTL_TRANSPORT_GET32,
                                 &in, sizeof(in),
                                 &out, sizeof(out));
        if (nirio_status_fatal(ioctl_status)) return ioctl_status;

        attrValue = out.retVal__;

        return out.status;
    }

    nirio_status niriok_proxy_impl_v2::set_attribute(
        const nirio_device_attribute32_t attribute,
        const uint32_t value)
    {
        READER_LOCK

        in_transport_set32_t in = {};
        out_transport_set32_t out = {};

        in.attribute = attribute;
        in.value  = value;
        in.status = NiRio_Status_Success;

        nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle,
                                 IOCTL_TRANSPORT_SET32,
                                 &in, sizeof(in),
                                 &out, sizeof(out));
        if (nirio_status_fatal(ioctl_status)) return ioctl_status;

        return out.status;
    }

    nirio_status niriok_proxy_impl_v2::peek(uint32_t offset, uint32_t& value)
    {
        READER_LOCK

        if (offset % 4 != 0) return NiRio_Status_MisalignedAccess;
        
        in_transport_peek32_t in = {};
        out_transport_peek32_t out = {};
                
        in.offset = offset;
        in.status = NiRio_Status_Success;

        nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle,
                                    IOCTL_TRANSPORT_PEEK32,
                                    &in, sizeof(in),
                                    &out, sizeof(out));
        if (nirio_status_fatal(ioctl_status)) return ioctl_status;

        value = out.retVal__;

        return out.status;
    }

    nirio_status niriok_proxy_impl_v2::peek(uint32_t offset, uint64_t& value)
    {
        READER_LOCK

        if (offset % 8 != 0) return NiRio_Status_MisalignedAccess;
        in_transport_peek64_t in = {};
        out_transport_peek64_t out = {};

        in.offset = offset;
        in.status = NiRio_Status_Success;

        nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle,
                                    IOCTL_TRANSPORT_PEEK64,
                                    &in, sizeof(in),
                                    &out, sizeof(out));
        if (nirio_status_fatal(ioctl_status)) return ioctl_status;

        value = out.retVal__;

        return out.status;
    }

    nirio_status niriok_proxy_impl_v2::poke(uint32_t offset, const uint32_t& value)
    {
        READER_LOCK

        if (offset % 4 != 0) return NiRio_Status_MisalignedAccess;

        in_transport_poke32_t in = {};
        out_transport_poke32_t out = {};

        in.offset = offset;
        in.value = value;
        in.status = NiRio_Status_Success;

        nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle,
                                    IOCTL_TRANSPORT_POKE32,
                                    &in, sizeof(in),
                                    &out, sizeof(out));
        if (nirio_status_fatal(ioctl_status)) return ioctl_status;

        return out.status;
    }

    nirio_status niriok_proxy_impl_v2::poke(uint32_t offset, const uint64_t& value)
    {
        READER_LOCK

        if (offset % 8 != 0) return NiRio_Status_MisalignedAccess;

        in_transport_poke64_t in = {};
        out_transport_poke64_t out = {};

        in.offset = offset;
        in.value = value;
        in.status = NiRio_Status_Success;

        nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle,
                                    IOCTL_TRANSPORT_POKE64,
                                    &in, sizeof(in),
                                    &out, sizeof(out));
        if (nirio_status_fatal(ioctl_status)) return ioctl_status;

        return out.status;
    }

    nirio_status niriok_proxy_impl_v2::map_fifo_memory(
        uint32_t fifo_instance,
        size_t size,
        nirio_driver_iface::rio_mmap_t& map)
    {
        READER_LOCK

        return nirio_driver_iface::rio_mmap(_device_handle,
                GET_FIFO_MEMORY_TYPE(fifo_instance),
                size, true, map);
    }

    nirio_status niriok_proxy_impl_v2::unmap_fifo_memory(
        nirio_driver_iface::rio_mmap_t& map)
    {
        READER_LOCK

        return nirio_driver_iface::rio_munmap(map);
    }

    nirio_status niriok_proxy_impl_v2::stop_all_fifos()
    {
        READER_LOCK

        nirio_status ioctl_status = NiRio_Status_Success;
        in_transport_fifo_stop_all_t in = {};
        out_transport_fifo_stop_all_t out = {};

        in.status = NiRio_Status_Success;

        ioctl_status = 
           nirio_driver_iface::rio_ioctl(
               _device_handle,
               IOCTL_TRANSPORT_FIFO_STOP_ALL,
               &in,
               sizeof(in),
               &out,
               sizeof(out));
        if (nirio_status_fatal(ioctl_status)) return ioctl_status;

        return out.status;
    }

   nirio_status niriok_proxy_impl_v2::add_fifo_resource(const nirio_fifo_info_t& fifo_info)
   {
      READER_LOCK

      nirio_status status = NiRio_Status_Success;
      nirio_status ioctl_status = NiRio_Status_Success;

      switch(fifo_info.direction)
      {
         case INPUT_FIFO:
         {
            in_transport_add_input_fifo_resource_t in = {};
            out_transport_add_input_fifo_resource_t out = {};

            in.channel = fifo_info.channel;
            in.baseAddress = fifo_info.base_addr;
            in.depthInSamples = fifo_info.depth;
            in.dataType.scalarType = fifo_info.scalar_type;
            in.dataType.bitWidth = fifo_info.bitWidth;
            in.dataType.integerWordLength = fifo_info.integerWordLength; 
            in.version = fifo_info.version;
            in.status = NiRio_Status_Success;

            ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle,
                                    IOCTL_TRANSPORT_ADD_INPUT_FIFO_RESOURCE,
                                    &in, sizeof(in),
                                    &out, sizeof(out));

            status = nirio_status_fatal(ioctl_status) ? ioctl_status : out.status;
            break;
         }
         case OUTPUT_FIFO:
         {
            in_transport_add_output_fifo_resource_t in = {};
            out_transport_add_output_fifo_resource_t out = {};

            in.channel = fifo_info.channel;
            in.baseAddress = fifo_info.base_addr;
            in.depthInSamples = fifo_info.depth;
            in.dataType.scalarType = fifo_info.scalar_type;
            in.dataType.bitWidth = fifo_info.bitWidth;
            in.dataType.integerWordLength = fifo_info.integerWordLength;
            in.version = fifo_info.version;
            in.status = NiRio_Status_Success;
           
            ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle,
                                    IOCTL_TRANSPORT_ADD_OUTPUT_FIFO_RESOURCE,
                                    &in, sizeof(in),
                                    &out, sizeof(out));

            status = nirio_status_fatal(ioctl_status) ? ioctl_status : out.status;
            break;
         }
         default:
            status = NiRio_Status_SoftwareFault;
         }
         
         return status;
    }

   nirio_status niriok_proxy_impl_v2::set_device_config()
   {
      READER_LOCK

      nirio_status ioctl_status = NiRio_Status_Success;

      in_transport_set_device_config_t in = {};
      out_transport_set_device_config_t out = {};

      in.attribute = 0;  //this is unused in the kernel
      in.status = NiRio_Status_Success;

      ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle,
                              IOCTL_TRANSPORT_SET_DEVICE_CONFIG,
                              &in, sizeof(in),
                              &out, sizeof(out));

      return nirio_status_fatal(ioctl_status) ? ioctl_status : out.status;
   }

    nirio_status niriok_proxy_impl_v2::start_fifo(
       uint32_t channel)
    {
        READER_LOCK

        nirio_status ioctl_status = NiRio_Status_Success;
        in_transport_fifo_start_t in = {};
        out_transport_fifo_start_t out = {};

        in.channel = channel;
        in.status = NiRio_Status_Success;

        ioctl_status = 
           nirio_driver_iface::rio_ioctl(
               _device_handle,
               IOCTL_TRANSPORT_FIFO_START,
               &in,
               sizeof(in),
               &out,
               sizeof(out));
        if (nirio_status_fatal(ioctl_status)) return ioctl_status;

        return out.status;
    }

    nirio_status niriok_proxy_impl_v2::stop_fifo(
        uint32_t channel)
    {
        READER_LOCK

        nirio_status ioctl_status = NiRio_Status_Success;
        in_transport_fifo_stop_t in = {};
        out_transport_fifo_stop_t out = {};

        in.channel = channel;
        in.status = NiRio_Status_Success;

        ioctl_status = 
           nirio_driver_iface::rio_ioctl(
               _device_handle,
               IOCTL_TRANSPORT_FIFO_STOP,
               &in,
               sizeof(in),
               &out,
               sizeof(out));
        if (nirio_status_fatal(ioctl_status)) return ioctl_status;

        return out.status;
    }

    nirio_status niriok_proxy_impl_v2::configure_fifo(
       uint32_t channel,
       uint32_t requested_depth,
       uint8_t /*requires_actuals*/, //Unused
       uint32_t& actual_depth,
       uint32_t& actual_size)
    {
        READER_LOCK

        nirio_status ioctl_status = NiRio_Status_Success;
        in_transport_fifo_config_t in = {};
        out_transport_fifo_config_t out = {};

        in.channel = channel;
        in.requestedDepth = requested_depth;
        in.status = NiRio_Status_Success;

        ioctl_status = 
           nirio_driver_iface::rio_ioctl(
               _device_handle,
               IOCTL_TRANSPORT_FIFO_CONFIG,
               &in,
               sizeof(in),
               &out,
               sizeof(out));
        if (nirio_status_fatal(ioctl_status)) return ioctl_status;

        UHD_ASSERT_THROW(out.actualDepth <= std::numeric_limits<uint32_t>::max());
        actual_depth = static_cast<uint32_t>(out.actualDepth);
        UHD_ASSERT_THROW(out.actualSize <= std::numeric_limits<uint32_t>::max());
        actual_size = static_cast<uint32_t>(out.actualSize);
        return out.status;
    }

    nirio_status niriok_proxy_impl_v2::wait_on_fifo(
        uint32_t channel,
        uint32_t elements_requested,
        uint32_t scalar_type,
        uint32_t bit_width,
        uint32_t timeout,
        uint8_t output,
        void*& data_pointer,
        uint32_t& elements_acquired,
        uint32_t& elements_remaining)
    {
        READER_LOCK

        nirio_status ioctl_status = NiRio_Status_Success;
        in_transport_fifo_wait_t in = {};
        out_transport_fifo_wait_t out = {};

        in.channel = channel;
        in.elementsRequested = elements_requested;
        in.dataType.scalarType = map_int_to_scalar_type(scalar_type);
        in.dataType.bitWidth = bit_width;
        in.dataType.integerWordLength = bit_width; // same as bit_width for all types except fixed point, which is not supported
        in.output = (output != 0);
        in.timeout = timeout;
        in.status = NiRio_Status_Success;

           ioctl_status =
           nirio_driver_iface::rio_ioctl(
              _device_handle,
              IOCTL_TRANSPORT_FIFO_WAIT,
              &in,
              sizeof(in),
              &out,
              sizeof(out));
        if (nirio_status_fatal(ioctl_status)) return ioctl_status;

        data_pointer = reinterpret_cast<void*>(out.elements);
        UHD_ASSERT_THROW(out.elementsAcquired <= std::numeric_limits<uint32_t>::max());
        elements_acquired = static_cast<uint32_t>(out.elementsAcquired);
        UHD_ASSERT_THROW(out.elementsRemaining <= std::numeric_limits<uint32_t>::max());
        elements_remaining = static_cast<uint32_t>(out.elementsRemaining);
        return out.status;
    }

    nirio_status niriok_proxy_impl_v2::grant_fifo(
       uint32_t channel,
       uint32_t elements_to_grant)
    {
        READER_LOCK

        nirio_status ioctl_status = NiRio_Status_Success;
        in_transport_fifo_grant_t in = {};
        out_transport_fifo_grant_t out = {};

        in.channel = channel;
        in.elements = elements_to_grant;
        in.status = NiRio_Status_Success;

        ioctl_status = 
           nirio_driver_iface::rio_ioctl(
               _device_handle,
               IOCTL_TRANSPORT_FIFO_GRANT,
               &in,
               sizeof(in),
               &out,
               sizeof(out));
        if (nirio_status_fatal(ioctl_status)) return ioctl_status;

        return out.status;
    }

    nirio_status niriok_proxy_impl_v2::read_fifo(
        uint32_t channel,
        uint32_t elements_to_read,
        void* buffer,
        uint32_t /*buffer_datatype_width*/, //Unused
        uint32_t scalar_type,
        uint32_t bit_width,
        uint32_t timeout,
        uint32_t& number_read,
        uint32_t& number_remaining)
    {
        READER_LOCK

        nirio_status ioctl_status = NiRio_Status_Success;
        in_transport_fifo_read_t in = {};
        out_transport_fifo_read_t out = {};

        in.channel = channel;
        in.buf = reinterpret_cast<aligned_uint64_t>(buffer);
        in.numberElements = elements_to_read;
        in.dataType.scalarType = map_int_to_scalar_type(scalar_type);
        in.dataType.bitWidth = bit_width;
        in.dataType.integerWordLength = bit_width; // same as bit_width for all types except fixed point, which is not supported
        in.timeout = timeout;
        in.status = NiRio_Status_Success;

        ioctl_status = 
           nirio_driver_iface::rio_ioctl(
               _device_handle,
               IOCTL_TRANSPORT_FIFO_READ,
               &in,
               sizeof(in),
               &out,
               sizeof(out));
        if (nirio_status_fatal(ioctl_status)) return ioctl_status;

        number_read = out.read;
        number_remaining = out.remaining;
        return out.status;
    }

    nirio_status niriok_proxy_impl_v2::write_fifo(
        uint32_t channel,
        uint32_t elements_to_write,
        void* buffer,
        uint32_t /*buffer_datatype_width*/, //Unused
        uint32_t scalar_type,
        uint32_t bit_width,
        uint32_t timeout,
        uint32_t& number_remaining)
    {
        READER_LOCK

        nirio_status ioctl_status = NiRio_Status_Success;
        in_transport_fifo_write_t in = {};
        out_transport_fifo_write_t out = {};

        in.channel = channel;
        in.buf = reinterpret_cast<aligned_uint64_t>(buffer);
        in.numberElements = elements_to_write;
        in.dataType.scalarType = map_int_to_scalar_type(scalar_type);
        in.dataType.bitWidth = bit_width;
        in.dataType.integerWordLength = bit_width; // same as bit_width for all types except fixed point, which is not supported
        in.timeout = timeout;
        in.status = NiRio_Status_Success;

        ioctl_status = 
           nirio_driver_iface::rio_ioctl(
               _device_handle,
               IOCTL_TRANSPORT_FIFO_WRITE,
               &in,
               sizeof(in),
               &out,
               sizeof(out));
        if (nirio_status_fatal(ioctl_status)) return ioctl_status;

        number_remaining = out.remaining;
        return out.status;
    }

}}

#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5)
    #pragma GCC diagnostic pop
#endif