blob: 7ead5015dc438200ea7d68d3b3826a0abc4c4246 (
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
|
;;;
;;; Copyright 2010 Free Software Foundation, Inc.
;;;
;;; This file is part of GNU Radio
;;;
;;; GNU Radio 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, or (at your option)
;;; any later version.
;;;
;;; GNU Radio 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/>.
;;;
;;; Module that re-exports the usrp2_swig module and adds convenience functions
(define-module (gnuradio usrp2)
#:use-module (oop goops)
#:use-module (gnuradio export-safely)
#:use-module (gnuradio usrp2_swig)
#:duplicates (merge-generics replace check))
(re-export-all '(gnuradio usrp2_swig))
;; Utilities (guaranteed not to leak the allocated object)
(define (call-with-long-ptr fn)
(let ((ptr #f))
(dynamic-wind
(lambda () (set! ptr (gr:make-long-ptr)))
(lambda () (and (fn ptr) (gr:deref-long-ptr ptr)))
(lambda () (gr:free-long-ptr ptr)))))
(define (call-with-int-ptr fn)
(let ((ptr #f))
(dynamic-wind
(lambda () (set! ptr (gr:make-int-ptr)))
(lambda () (and (fn ptr) (gr:deref-int-ptr ptr)))
(lambda () (gr:free-int-ptr ptr)))))
(define (call-with-uint16-ptr fn)
(let ((ptr #f))
(dynamic-wind
(lambda () (set! ptr (gr:make-uint16-ptr)))
(lambda () (and (fn ptr) (gr:deref-uint16-ptr ptr)))
(lambda () (gr:free-uint16-ptr ptr)))))
;;; scheme-ish convenience functions
(define-method (gr:set-center-freq self freq)
(let ((tr (make <tune-result>)))
(if (gr:-real-set-center-freq self freq tr)
tr
#f)))
(define-method (gr:fpga-master-clock-freq self)
(call-with-long-ptr (lambda (ptr) (gr:-real-fpga-master-clock-freq self ptr))))
(define-method (gr:adc-rate self)
(call-with-long-ptr (lambda (ptr) (gr:-real-adc-rate self ptr))))
(define-method (gr:dac-rate self)
(call-with-long-ptr (lambda (ptr) (gr:-real-dac-rate self ptr))))
(define-method (gr:daughterboard-id self)
(call-with-int-ptr (lambda (ptr) (gr:-real-daugherboard-id self ptr))))
;; (define-method (gr:default-tx-scale-iq self) ...) FIXME
(define-method (gr:read-gpio self)
(call-with-uint16-ptr (lambda (ptr) (gr:-real-read-gpio self ptr))))
;; Export them
(export-safely gr:set-center-freq gr:fpga-master-clock-freq gr:adc-rate gr:dac-rate gr:daughterboard-id gr:read-gpio)
|