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
|
From 4f3cae2e4192dcb17452fef32d10aa8b64ca2cf0 Mon Sep 17 00:00:00 2001
From: Jared Boone <jboone@earfeast.com>
Date: Tue, 4 Nov 2014 11:16:14 -0800
Subject: [PATCH 03/68] MAX2837: Extract hardware/bus dependent stuff into
separate layer.
Conflicts:
firmware/CMakeLists.txt
firmware/hackrf_usb/Makefile
firmware/mixertx/Makefile
firmware/sgpio/CMakeLists.txt
firmware/simpletx/Makefile
firmware/spiflash/CMakeLists.txt
firmware/startup/Makefile
firmware/startup_systick/Makefile
firmware/startup_systick_perfo/Makefile
---
firmware/common/max2837.c | 155 +++++++---------------------------------
firmware/common/max2837.h | 34 ++++++---
firmware/common/max2837_drv.c | 159 ++++++++++++++++++++++++++++++++++++++++++
firmware/common/max2837_drv.h | 45 ++++++++++++
firmware/hackrf-common.cmake | 1 +
5 files changed, 253 insertions(+), 141 deletions(-)
create mode 100644 firmware/common/max2837_drv.c
create mode 100644 firmware/common/max2837_drv.h
--- a/firmware/common/max2837.c
+++ b/firmware/common/max2837.c
@@ -1,4 +1,26 @@
/*
+ * Copyright 2012 Will Code? (TODO: Proper attribution)
+ * Copyright 2014 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.
+ */
+
+/*
* 'gcc -DTEST -DDEBUG -O2 -o test max2837.c' prints out what test
* program would do if it had a real spi library
*
@@ -9,6 +31,7 @@
#include <stdint.h>
#include <string.h>
#include "max2837.h"
+#include "max2837_drv.h"
#include "max2837_regs.def" // private register def macros
#if (defined DEBUG || defined BUS_PIRATE)
@@ -16,9 +39,6 @@
#define LOG printf
#else
#define LOG(x,...)
-#include <libopencm3/lpc43xx/ssp.h>
-#include <libopencm3/lpc43xx/scu.h>
-#include <libopencm3/lpc43xx/gpio.h>
#include "hackrf_core.h"
#endif
@@ -85,51 +105,7 @@
void max2837_setup(void)
{
LOG("# max2837_setup\n");
-#if !defined TEST
- /* Configure XCVR_CTL GPIO pins. */
-#ifdef JELLYBEAN
- scu_pinmux(SCU_XCVR_RXHP, SCU_GPIO_FAST);
- scu_pinmux(SCU_XCVR_B1, SCU_GPIO_FAST);
- scu_pinmux(SCU_XCVR_B2, SCU_GPIO_FAST);
- scu_pinmux(SCU_XCVR_B3, SCU_GPIO_FAST);
- scu_pinmux(SCU_XCVR_B4, SCU_GPIO_FAST);
- scu_pinmux(SCU_XCVR_B5, SCU_GPIO_FAST);
- scu_pinmux(SCU_XCVR_B6, SCU_GPIO_FAST);
- scu_pinmux(SCU_XCVR_B7, SCU_GPIO_FAST);
-#endif
- scu_pinmux(SCU_XCVR_ENABLE, SCU_GPIO_FAST);
- scu_pinmux(SCU_XCVR_RXENABLE, SCU_GPIO_FAST);
- scu_pinmux(SCU_XCVR_TXENABLE, SCU_GPIO_FAST);
-
- /* Set GPIO pins as outputs. */
- GPIO2_DIR |= (PIN_XCVR_ENABLE | PIN_XCVR_RXENABLE | PIN_XCVR_TXENABLE);
-#ifdef JELLYBEAN
- GPIO_DIR(PORT_XCVR_RXHP) |= PIN_XCVR_RXHP;
- GPIO_DIR(PORT_XCVR_B) |=
- PIN_XCVR_B1
- | PIN_XCVR_B2
- | PIN_XCVR_B3
- | PIN_XCVR_B4
- | PIN_XCVR_B5
- | PIN_XCVR_B6
- | PIN_XCVR_B7
- ;
-#endif
-
- max2837_mode_shutdown();
-#ifdef JELLYBEAN
- gpio_set(PORT_XCVR_RXHP, PIN_XCVR_RXHP);
- gpio_set(PORT_XCVR_B,
- PIN_XCVR_B1
- | PIN_XCVR_B2
- | PIN_XCVR_B3
- | PIN_XCVR_B4
- | PIN_XCVR_B5
- | PIN_XCVR_B6
- | PIN_XCVR_B7
- );
-#endif
-#endif
+ max2837_pin_config();
max2837_init();
LOG("# max2837_init done\n");
@@ -159,29 +135,6 @@
max2837_regs_commit();
}
-/* SPI register read. */
-uint16_t max2837_spi_read(uint8_t r) {
- gpio_clear(PORT_XCVR_CS, PIN_XCVR_CS);
- const uint16_t value = ssp_transfer(SSP1_NUM, (uint16_t)((1 << 15) | (r << 10)));
- gpio_set(PORT_XCVR_CS, PIN_XCVR_CS);
- return value & 0x3ff;
-}
-
-/* SPI register write */
-void max2837_spi_write(uint8_t r, uint16_t v) {
-
-#ifdef BUS_PIRATE
- LOG("{0x%02x 0x%02x]\n", 0x00 | ((uint16_t)r<<2) | ((v>>8) & 0x3),
- v & 0xff);
-#elif DEBUG
- LOG("0x%03x -> reg%d\n", v, r);
-#else
- gpio_clear(PORT_XCVR_CS, PIN_XCVR_CS);
- ssp_transfer(SSP1_NUM, (uint16_t)((r << 10) | (v & 0x3ff)));
- gpio_set(PORT_XCVR_CS, PIN_XCVR_CS);
-#endif
-}
-
uint16_t max2837_reg_read(uint8_t r)
{
if ((max2837_regs_dirty >> r) & 0x1) {
@@ -197,12 +150,6 @@
MAX2837_REG_SET_CLEAN(r);
}
-/* This functions should not be needed, and might be confusing. DELETE. */
-void max2837_regs_read(void)
-{
- ;
-}
-
static inline void max2837_reg_commit(uint8_t r)
{
max2837_reg_write(r,max2837_regs[r]);
@@ -218,60 +165,6 @@
}
}
-void max2837_mode_shutdown(void) {
- /* All circuit blocks are powered down, except the 4-wire serial bus
- * and its internal programmable registers.
- */
- gpio_clear(PORT_XCVR_ENABLE,
- (PIN_XCVR_ENABLE | PIN_XCVR_RXENABLE | PIN_XCVR_TXENABLE));
-}
-
-void max2837_mode_standby(void) {
- /* Used to enable the frequency synthesizer block while the rest of the
- * device is powered down. In this mode, PLL, VCO, and LO generator
- * are on, so that Tx or Rx modes can be quickly enabled from this mode.
- * These and other blocks can be selectively enabled in this mode.
- */
- gpio_clear(PORT_XCVR_ENABLE, (PIN_XCVR_RXENABLE | PIN_XCVR_TXENABLE));
- gpio_set(PORT_XCVR_ENABLE, PIN_XCVR_ENABLE);
-}
-
-void max2837_mode_tx(void) {
- /* All Tx circuit blocks are powered on. The external PA is powered on
- * after a programmable delay using the on-chip PA bias DAC. The slow-
- * charging Rx circuits are in a precharged “idle-off” state for fast
- * Tx-to-Rx turnaround time.
- */
- gpio_clear(PORT_XCVR_ENABLE, PIN_XCVR_RXENABLE);
- gpio_set(PORT_XCVR_ENABLE,
- (PIN_XCVR_ENABLE | PIN_XCVR_TXENABLE));
-}
-
-void max2837_mode_rx(void) {
- /* All Rx circuit blocks are powered on and active. Antenna signal is
- * applied; RF is downconverted, filtered, and buffered at Rx BB I and Q
- * outputs. The slow- charging Tx circuits are in a precharged “idle-off”
- * state for fast Rx-to-Tx turnaround time.
- */
- gpio_clear(PORT_XCVR_ENABLE, PIN_XCVR_TXENABLE);
- gpio_set(PORT_XCVR_ENABLE,
- (PIN_XCVR_ENABLE | PIN_XCVR_RXENABLE));
-}
-
-max2837_mode_t max2837_mode(void) {
- if( gpio_get(PORT_XCVR_ENABLE, PIN_XCVR_ENABLE) ) {
- if( gpio_get(PORT_XCVR_ENABLE, PIN_XCVR_TXENABLE) ) {
- return MAX2837_MODE_TX;
- } else if( gpio_get(PORT_XCVR_ENABLE, PIN_XCVR_RXENABLE) ) {
- return MAX2837_MODE_RX;
- } else {
- return MAX2837_MODE_STANDBY;
- }
- } else {
- return MAX2837_MODE_SHUTDOWN;
- }
-}
-
void max2837_set_mode(const max2837_mode_t new_mode) {
switch(new_mode) {
case MAX2837_MODE_SHUTDOWN:
--- a/firmware/common/max2837.h
+++ b/firmware/common/max2837.h
@@ -1,9 +1,33 @@
+/*
+ * Copyright 2012 Will Code? (TODO: Proper attribution)
+ * Copyright 2014 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 __MAX2837_H
#define __MAX2837_H
#include <stdint.h>
#include <stdbool.h>
+#include "max2837_drv.h"
+
/* TODO - make this a private header for max2837.c only, make new max2837.h */
/* 32 registers, each containing 10 bits of data. */
@@ -29,21 +53,11 @@
* clean. */
extern void max2837_reg_write(uint8_t r, uint16_t v);
-/* Read all registers from chip and copy to memory. Mark all clean. */
-extern void max2837_regs_read(void);
-
/* Write all dirty registers via SPI from memory. Mark all clean. Some
* operations require registers to be written in a certain order. Use
* provided routines for those operations. */
extern void max2837_regs_commit(void);
-typedef enum {
- MAX2837_MODE_SHUTDOWN,
- MAX2837_MODE_STANDBY,
- MAX2837_MODE_TX,
- MAX2837_MODE_RX
-} max2837_mode_t;
-
void max2837_mode_shutdown(void);
void max2837_mode_standby(void);
void max2837_mode_tx(void);
--- /dev/null
+++ b/firmware/common/max2837_drv.c
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2012 Will Code? (TODO: Proper attribution)
+ * Copyright 2014 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 "max2837_drv.h"
+
+#if (defined DEBUG || defined BUS_PIRATE)
+#include <stdio.h>
+#define LOG printf
+#else
+#define LOG(x,...)
+#include <libopencm3/lpc43xx/ssp.h>
+#include <libopencm3/lpc43xx/scu.h>
+#include <libopencm3/lpc43xx/gpio.h>
+#include "hackrf_core.h"
+#endif
+
+void max2837_pin_config(void) {
+#if !defined TEST
+ /* Configure XCVR_CTL GPIO pins. */
+#ifdef JELLYBEAN
+ scu_pinmux(SCU_XCVR_RXHP, SCU_GPIO_FAST);
+ scu_pinmux(SCU_XCVR_B1, SCU_GPIO_FAST);
+ scu_pinmux(SCU_XCVR_B2, SCU_GPIO_FAST);
+ scu_pinmux(SCU_XCVR_B3, SCU_GPIO_FAST);
+ scu_pinmux(SCU_XCVR_B4, SCU_GPIO_FAST);
+ scu_pinmux(SCU_XCVR_B5, SCU_GPIO_FAST);
+ scu_pinmux(SCU_XCVR_B6, SCU_GPIO_FAST);
+ scu_pinmux(SCU_XCVR_B7, SCU_GPIO_FAST);
+#endif
+ scu_pinmux(SCU_XCVR_ENABLE, SCU_GPIO_FAST);
+ scu_pinmux(SCU_XCVR_RXENABLE, SCU_GPIO_FAST);
+ scu_pinmux(SCU_XCVR_TXENABLE, SCU_GPIO_FAST);
+
+ /* Set GPIO pins as outputs. */
+ GPIO2_DIR |= (PIN_XCVR_ENABLE | PIN_XCVR_RXENABLE | PIN_XCVR_TXENABLE);
+#ifdef JELLYBEAN
+ GPIO_DIR(PORT_XCVR_RXHP) |= PIN_XCVR_RXHP;
+ GPIO_DIR(PORT_XCVR_B) |=
+ PIN_XCVR_B1
+ | PIN_XCVR_B2
+ | PIN_XCVR_B3
+ | PIN_XCVR_B4
+ | PIN_XCVR_B5
+ | PIN_XCVR_B6
+ | PIN_XCVR_B7
+ ;
+#endif
+
+ max2837_mode_shutdown();
+#ifdef JELLYBEAN
+ gpio_set(PORT_XCVR_RXHP, PIN_XCVR_RXHP);
+ gpio_set(PORT_XCVR_B,
+ PIN_XCVR_B1
+ | PIN_XCVR_B2
+ | PIN_XCVR_B3
+ | PIN_XCVR_B4
+ | PIN_XCVR_B5
+ | PIN_XCVR_B6
+ | PIN_XCVR_B7
+ );
+#endif
+#endif
+}
+
+void max2837_mode_shutdown(void) {
+ /* All circuit blocks are powered down, except the 4-wire serial bus
+ * and its internal programmable registers.
+ */
+ gpio_clear(PORT_XCVR_ENABLE,
+ (PIN_XCVR_ENABLE | PIN_XCVR_RXENABLE | PIN_XCVR_TXENABLE));
+}
+
+void max2837_mode_standby(void) {
+ /* Used to enable the frequency synthesizer block while the rest of the
+ * device is powered down. In this mode, PLL, VCO, and LO generator
+ * are on, so that Tx or Rx modes can be quickly enabled from this mode.
+ * These and other blocks can be selectively enabled in this mode.
+ */
+ gpio_clear(PORT_XCVR_ENABLE, (PIN_XCVR_RXENABLE | PIN_XCVR_TXENABLE));
+ gpio_set(PORT_XCVR_ENABLE, PIN_XCVR_ENABLE);
+}
+
+void max2837_mode_tx(void) {
+ /* All Tx circuit blocks are powered on. The external PA is powered on
+ * after a programmable delay using the on-chip PA bias DAC. The slow-
+ * charging Rx circuits are in a precharged “idle-off” state for fast
+ * Tx-to-Rx turnaround time.
+ */
+ gpio_clear(PORT_XCVR_ENABLE, PIN_XCVR_RXENABLE);
+ gpio_set(PORT_XCVR_ENABLE,
+ (PIN_XCVR_ENABLE | PIN_XCVR_TXENABLE));
+}
+
+void max2837_mode_rx(void) {
+ /* All Rx circuit blocks are powered on and active. Antenna signal is
+ * applied; RF is downconverted, filtered, and buffered at Rx BB I and Q
+ * outputs. The slow- charging Tx circuits are in a precharged “idle-off”
+ * state for fast Rx-to-Tx turnaround time.
+ */
+ gpio_clear(PORT_XCVR_ENABLE, PIN_XCVR_TXENABLE);
+ gpio_set(PORT_XCVR_ENABLE,
+ (PIN_XCVR_ENABLE | PIN_XCVR_RXENABLE));
+}
+
+max2837_mode_t max2837_mode(void) {
+ if( gpio_get(PORT_XCVR_ENABLE, PIN_XCVR_ENABLE) ) {
+ if( gpio_get(PORT_XCVR_ENABLE, PIN_XCVR_TXENABLE) ) {
+ return MAX2837_MODE_TX;
+ } else if( gpio_get(PORT_XCVR_ENABLE, PIN_XCVR_RXENABLE) ) {
+ return MAX2837_MODE_RX;
+ } else {
+ return MAX2837_MODE_STANDBY;
+ }
+ } else {
+ return MAX2837_MODE_SHUTDOWN;
+ }
+}
+
+/* SPI register read. */
+uint16_t max2837_spi_read(uint8_t r) {
+ gpio_clear(PORT_XCVR_CS, PIN_XCVR_CS);
+ const uint16_t value = ssp_transfer(SSP1_NUM, (uint16_t)((1 << 15) | (r << 10)));
+ gpio_set(PORT_XCVR_CS, PIN_XCVR_CS);
+ return value & 0x3ff;
+}
+
+/* SPI register write */
+void max2837_spi_write(uint8_t r, uint16_t v) {
+
+#ifdef BUS_PIRATE
+ LOG("{0x%02x 0x%02x]\n", 0x00 | ((uint16_t)r<<2) | ((v>>8) & 0x3),
+ v & 0xff);
+#elif DEBUG
+ LOG("0x%03x -> reg%d\n", v, r);
+#else
+ gpio_clear(PORT_XCVR_CS, PIN_XCVR_CS);
+ ssp_transfer(SSP1_NUM, (uint16_t)((r << 10) | (v & 0x3ff)));
+ gpio_set(PORT_XCVR_CS, PIN_XCVR_CS);
+#endif
+}
--- /dev/null
+++ b/firmware/common/max2837_drv.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2012 Will Code? (TODO: Proper attribution)
+ * Copyright 2014 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 __MAX2837_DRV_H
+#define __MAX2837_DRV_H
+
+#include <stdint.h>
+
+typedef enum {
+ MAX2837_MODE_SHUTDOWN,
+ MAX2837_MODE_STANDBY,
+ MAX2837_MODE_TX,
+ MAX2837_MODE_RX
+} max2837_mode_t;
+
+void max2837_pin_config(void);
+void max2837_mode_shutdown(void);
+void max2837_mode_standby(void);
+void max2837_mode_tx(void);
+void max2837_mode_rx(void);
+max2837_mode_t max2837_mode(void);
+
+uint16_t max2837_spi_read(uint8_t r);
+void max2837_spi_write(uint8_t r, uint16_t v);
+
+#endif // __MAX2837_DRV_H
--- a/firmware/hackrf-common.cmake
+++ b/firmware/hackrf-common.cmake
@@ -136,6 +136,7 @@
${PATH_HACKRF_FIRMWARE_COMMON}/si5351c.c
${PATH_HACKRF_FIRMWARE_COMMON}/si5351c_drv.c
${PATH_HACKRF_FIRMWARE_COMMON}/max2837.c
+ ${PATH_HACKRF_FIRMWARE_COMMON}/max2837_drv.c
${PATH_HACKRF_FIRMWARE_COMMON}/max5864.c
${PATH_HACKRF_FIRMWARE_COMMON}/rffc5071.c
m0_bin.s
|