File: 0001-Si5351C-Extract-low-level-driver-code.patch

package info (click to toggle)
hackrf 2015.07.2-11
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 69,764 kB
  • ctags: 9,327
  • sloc: ansic: 13,907; python: 696; vhdl: 218; sh: 32; makefile: 15
file content (270 lines) | stat: -rw-r--r-- 7,999 bytes parent folder | download | duplicates (2)
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
From 0bf84d974e94d4f612a1287b0a8901af4f729503 Mon Sep 17 00:00:00 2001
From: Jared Boone <jboone@earfeast.com>
Date: Tue, 4 Nov 2014 09:58:31 -0800
Subject: [PATCH 01/68] Si5351C: Extract low-level driver code.

---
 firmware/common/hackrf_core.c          |  1 +
 firmware/common/si5351c.c              | 50 +----------------------
 firmware/common/si5351c.h              |  5 ---
 firmware/common/si5351c_drv.c          | 74 ++++++++++++++++++++++++++++++++++
 firmware/common/si5351c_drv.h          | 41 +++++++++++++++++++
 firmware/hackrf-common.cmake           |  1 +
 firmware/hackrf_usb/usb_api_register.c |  2 +-
 7 files changed, 120 insertions(+), 54 deletions(-)
 create mode 100644 firmware/common/si5351c_drv.c
 create mode 100644 firmware/common/si5351c_drv.h

diff --git a/firmware/common/hackrf_core.c b/firmware/common/hackrf_core.c
index b862ba4..cd1c800 100644
--- a/firmware/common/hackrf_core.c
+++ b/firmware/common/hackrf_core.c
@@ -23,6 +23,7 @@
 
 #include "hackrf_core.h"
 #include "si5351c.h"
+#include "si5351c_drv.h"
 #include "max2837.h"
 #include "rffc5071.h"
 #include "sgpio.h"
diff --git a/firmware/common/si5351c.c b/firmware/common/si5351c.c
index 58b614d..3be5041 100644
--- a/firmware/common/si5351c.c
+++ b/firmware/common/si5351c.c
@@ -21,56 +21,10 @@
  */
 
 #include "si5351c.h"
-#include <libopencm3/lpc43xx/i2c.h>
 
-enum pll_sources active_clock_source;
-
-/* FIXME return i2c0 status from each function */
-
-/* write to single register */
-void si5351c_write_single(uint8_t reg, uint8_t val)
-{
-	i2c0_tx_start();
-	i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_WRITE);
-	i2c0_tx_byte(reg);
-	i2c0_tx_byte(val);
-	i2c0_stop();
-}
-
-/* read single register */
-uint8_t si5351c_read_single(uint8_t reg)
-{
-	uint8_t val;
-
-	/* set register address with write */
-	i2c0_tx_start();
-	i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_WRITE);
-	i2c0_tx_byte(reg);
-
-	/* read the value */
-	i2c0_tx_start();
-	i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_READ);
-	val = i2c0_rx_byte();
-	i2c0_stop();
+#include "si5351c_drv.h"
 
-	return val;
-}
-
-/*
- * Write to one or more contiguous registers. data[0] should be the first
- * register number, one or more values follow.
- */
-void si5351c_write(uint8_t* const data, const uint_fast8_t data_count)
-{
-	uint_fast8_t i;
-
-	i2c0_tx_start();
-	i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_WRITE);
-	
-	for (i = 0; i < data_count; i++)
-		i2c0_tx_byte(data[i]);
-	i2c0_stop();
-}
+enum pll_sources active_clock_source;
 
 /* Disable all CLKx outputs. */
 void si5351c_disable_all_outputs()
diff --git a/firmware/common/si5351c.h b/firmware/common/si5351c.h
index b62279d..fcc2d2b 100644
--- a/firmware/common/si5351c.h
+++ b/firmware/common/si5351c.h
@@ -31,7 +31,6 @@ extern "C"
 #include <stdint.h>
 
 #define SI_INTDIV(x)  (x*128-512)
-#define SI5351C_I2C_ADDR (0x60 << 1)
 
 #define SI5351C_CLK_POWERDOWN	(1<<7)
 #define SI5351C_CLK_INT_MODE	(1<<6)
@@ -76,10 +75,6 @@ void si5351c_configure_multisynth(const uint_fast8_t ms_number,
 void si5351c_configure_clock_control(const enum pll_sources source);
 void si5351c_enable_clock_outputs();
 void si5351c_set_int_mode(const uint_fast8_t ms_number, const uint_fast8_t on);
-
-void si5351c_write_single(uint8_t reg, uint8_t val);
-uint8_t si5351c_read_single(uint8_t reg);
-void si5351c_write(uint8_t* const data, const uint_fast8_t data_count);
 void si5351c_set_clock_source(const enum pll_sources source);
 void si5351c_activate_best_clock_source(void);
 
diff --git a/firmware/common/si5351c_drv.c b/firmware/common/si5351c_drv.c
new file mode 100644
index 0000000..e63912c
--- /dev/null
+++ b/firmware/common/si5351c_drv.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2012 Michael Ossmann <mike@ossmann.com>
+ * Copyright 2012 Jared Boone <jared@sharebrained.com>
+ *
+ * This file is part of HackRF.
+ *
+ * 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 2, 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; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "si5351c_drv.h"
+
+#include <libopencm3/lpc43xx/i2c.h>
+
+#define SI5351C_I2C_ADDR (0x60 << 1)
+
+/* FIXME return i2c0 status from each function */
+
+/* write to single register */
+void si5351c_write_single(uint8_t reg, uint8_t val)
+{
+	i2c0_tx_start();
+	i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_WRITE);
+	i2c0_tx_byte(reg);
+	i2c0_tx_byte(val);
+	i2c0_stop();
+}
+
+/* read single register */
+uint8_t si5351c_read_single(uint8_t reg)
+{
+	uint8_t val;
+
+	/* set register address with write */
+	i2c0_tx_start();
+	i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_WRITE);
+	i2c0_tx_byte(reg);
+
+	/* read the value */
+	i2c0_tx_start();
+	i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_READ);
+	val = i2c0_rx_byte();
+	i2c0_stop();
+
+	return val;
+}
+
+/*
+ * Write to one or more contiguous registers. data[0] should be the first
+ * register number, one or more values follow.
+ */
+void si5351c_write(uint8_t* const data, const uint_fast8_t data_count)
+{
+	uint_fast8_t i;
+
+	i2c0_tx_start();
+	i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_WRITE);
+	
+	for (i = 0; i < data_count; i++)
+		i2c0_tx_byte(data[i]);
+	i2c0_stop();
+}
diff --git a/firmware/common/si5351c_drv.h b/firmware/common/si5351c_drv.h
new file mode 100644
index 0000000..501b221
--- /dev/null
+++ b/firmware/common/si5351c_drv.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2012 Michael Ossmann <mike@ossmann.com>
+ * Copyright 2012 Jared Boone <jared@sharebrained.com>
+ *
+ * This file is part of HackRF.
+ *
+ * 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 2, 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; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __SI5351C_DRV_H
+#define __SI5351C_DRV_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+
+void si5351c_write_single(uint8_t reg, uint8_t val);
+uint8_t si5351c_read_single(uint8_t reg);
+void si5351c_write(uint8_t* const data, const uint_fast8_t data_count);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SI5351C_DRV_H */
diff --git a/firmware/hackrf-common.cmake b/firmware/hackrf-common.cmake
index df5d5c9..9b4fb9a 100644
--- a/firmware/hackrf-common.cmake
+++ b/firmware/hackrf-common.cmake
@@ -134,6 +134,7 @@ macro(DeclareTargets)
 		${PATH_HACKRF_FIRMWARE_COMMON}/sgpio.c
 		${PATH_HACKRF_FIRMWARE_COMMON}/rf_path.c
 		${PATH_HACKRF_FIRMWARE_COMMON}/si5351c.c
+		${PATH_HACKRF_FIRMWARE_COMMON}/si5351c_drv.c
 		${PATH_HACKRF_FIRMWARE_COMMON}/max2837.c
 		${PATH_HACKRF_FIRMWARE_COMMON}/max5864.c
 		${PATH_HACKRF_FIRMWARE_COMMON}/rffc5071.c
diff --git a/firmware/hackrf_usb/usb_api_register.c b/firmware/hackrf_usb/usb_api_register.c
index d822c92..9478e7c 100644
--- a/firmware/hackrf_usb/usb_api_register.c
+++ b/firmware/hackrf_usb/usb_api_register.c
@@ -24,7 +24,7 @@
 
 #include <usb_queue.h>
 #include <max2837.h>
-#include <si5351c.h>
+#include <si5351c_drv.h>
 #include <rffc5071.h>
 
 #include <stddef.h>
-- 
2.1.4