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
|
From b8421cc14fd73809571ff9940fecb80e5bf54d55 Mon Sep 17 00:00:00 2001
From: Jared Boone <jboone@earfeast.com>
Date: Sun, 9 Nov 2014 22:10:27 -0800
Subject: [PATCH 26/68] SSP1: Merge MAX2837 and MAX5864 SPI code to use single
SPI interface.
Conflicts:
firmware/common/hackrf_core.c
firmware/common/hackrf_core.h
---
firmware/common/hackrf_core.c | 55 ++++++++++++++++++++--------
firmware/common/hackrf_core.h | 6 +++
firmware/common/max2837.c | 2 +-
firmware/common/max2837_spi.c | 79 ----------------------------------------
firmware/common/max2837_spi.h | 34 -----------------
firmware/common/max2837_target.c | 10 +++++
firmware/common/max2837_target.h | 4 ++
firmware/common/max5864.c | 6 ++-
firmware/common/max5864_spi.c | 78 ---------------------------------------
firmware/common/max5864_spi.h | 33 -----------------
firmware/common/max5864_target.c | 10 +++++
firmware/common/max5864_target.h | 3 ++
firmware/common/rffc5071.c | 2 +-
firmware/common/rffc5071_spi.c | 3 +-
firmware/common/rffc5071_spi.h | 2 +-
firmware/common/spi.c | 4 +-
firmware/common/spi.h | 5 ++-
firmware/common/spi_ssp1.c | 79 ++++++++++++++++++++++++++++++++++++++++
firmware/common/spi_ssp1.h | 44 ++++++++++++++++++++++
firmware/common/w25q80bv.c | 3 +-
firmware/common/w25q80bv_spi.c | 3 +-
firmware/common/w25q80bv_spi.h | 2 +-
firmware/hackrf-common.cmake | 3 +-
23 files changed, 216 insertions(+), 254 deletions(-)
delete mode 100644 firmware/common/max2837_spi.c
delete mode 100644 firmware/common/max2837_spi.h
delete mode 100644 firmware/common/max5864_spi.c
delete mode 100644 firmware/common/max5864_spi.h
create mode 100644 firmware/common/spi_ssp1.c
create mode 100644 firmware/common/spi_ssp1.h
--- a/firmware/common/hackrf_core.c
+++ b/firmware/common/hackrf_core.c
@@ -23,11 +23,10 @@
#include "hackrf_core.h"
#include "si5351c.h"
+#include "spi_ssp1.h"
#include "max2837.h"
-#include "max2837_spi.h"
#include "max2837_target.h"
#include "max5864.h"
-#include "max5864_spi.h"
#include "max5864_target.h"
#include "rffc5071.h"
#include "rffc5071_spi.h"
@@ -45,27 +44,53 @@
.i2c_address = 0x60,
};
-spi_t max2837_spi = {
- .init = max2837_spi_init,
- .transfer = max2837_spi_transfer,
- .transfer_gather = max2837_spi_transfer_gather,
+const ssp1_config_t ssp1_config_max2837 = {
+ /* FIXME speed up once everything is working reliably */
+ /*
+ // Freq About 0.0498MHz / 49.8KHz => Freq = PCLK / (CPSDVSR * [SCR+1]) with PCLK=PLL1=204MHz
+ const uint8_t serial_clock_rate = 32;
+ const uint8_t clock_prescale_rate = 128;
+ */
+ // Freq About 4.857MHz => Freq = PCLK / (CPSDVSR * [SCR+1]) with PCLK=PLL1=204MHz
+ .data_bits = SSP_DATA_16BITS,
+ .serial_clock_rate = 21,
+ .clock_prescale_rate = 2,
+ .select = max2837_target_spi_select,
+ .unselect = max2837_target_spi_unselect,
};
-max2837_driver_t max2837 = {
- .spi = &max2837_spi,
+const ssp1_config_t ssp1_config_max5864 = {
+ /* FIXME speed up once everything is working reliably */
+ /*
+ // Freq About 0.0498MHz / 49.8KHz => Freq = PCLK / (CPSDVSR * [SCR+1]) with PCLK=PLL1=204MHz
+ const uint8_t serial_clock_rate = 32;
+ const uint8_t clock_prescale_rate = 128;
+ */
+ // Freq About 4.857MHz => Freq = PCLK / (CPSDVSR * [SCR+1]) with PCLK=PLL1=204MHz
+ .data_bits = SSP_DATA_8BITS,
+ .serial_clock_rate = 21,
+ .clock_prescale_rate = 2,
+ .select = max5864_target_spi_select,
+ .unselect = max5864_target_spi_unselect,
+};
+
+spi_t spi_ssp1 = {
+ .config = &ssp1_config_max2837,
+ .init = spi_ssp1_init,
+ .transfer = spi_ssp1_transfer,
+ .transfer_gather = spi_ssp1_transfer_gather,
};
-spi_t max5864_spi = {
- .init = max5864_spi_init,
- .transfer = max5864_spi_transfer,
- .transfer_gather = max5864_spi_transfer_gather,
+max2837_driver_t max2837 = {
+ .spi = &spi_ssp1,
};
max5864_driver_t max5864 = {
- .spi = &max5864_spi,
+ .spi = &spi_ssp1,
};
spi_t rffc5071_spi = {
+ .config = NULL,
.init = rffc5071_spi_init,
.transfer = rffc5071_spi_transfer,
.transfer_gather = rffc5071_spi_transfer_gather,
@@ -546,12 +571,12 @@
void ssp1_set_mode_max2837(void)
{
- spi_init(max2837.spi);
+ spi_init(max2837.spi, &ssp1_config_max2837);
}
void ssp1_set_mode_max5864(void)
{
- spi_init(max5864.spi);
+ spi_init(max5864.spi, &ssp1_config_max5864);
}
void pin_setup(void) {
--- a/firmware/common/hackrf_core.h
+++ b/firmware/common/hackrf_core.h
@@ -34,6 +34,8 @@
#include "si5351c_drv.h"
+#include "spi_ssp1.h"
+
#include "max2837.h"
#include "max5864.h"
#include "rffc5071.h"
@@ -357,6 +359,10 @@
} transceiver_mode_t;
void delay(uint32_t duration);
+
+extern const ssp1_config_t ssp1_config_max2837;
+extern const ssp1_config_t ssp1_config_max5864;
+
extern max2837_driver_t max2837;
extern rffc5071_driver_t rffc5072;
--- a/firmware/common/max2837.c
+++ b/firmware/common/max2837.c
@@ -79,7 +79,7 @@
/* Set up all registers according to defaults specified in docs. */
static void max2837_init(max2837_driver_t* const drv)
{
- spi_init(drv->spi);
+ spi_init(drv->spi, &ssp1_config_max2837);
max2837_mode_shutdown(drv);
max2837_target_init(drv);
--- a/firmware/common/max2837_spi.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2012 Will Code? (TODO: Proper attribution)
- * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
- *
- * 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_spi.h"
-
-#include <libopencm3/lpc43xx/gpio.h>
-#include <libopencm3/lpc43xx/scu.h>
-#include <libopencm3/lpc43xx/ssp.h>
-
-#include "hackrf_core.h"
-
-void max2837_spi_init(spi_t* const spi) {
- (void)spi;
-
- /* FIXME speed up once everything is working reliably */
- /*
- // Freq About 0.0498MHz / 49.8KHz => Freq = PCLK / (CPSDVSR * [SCR+1]) with PCLK=PLL1=204MHz
- const uint8_t serial_clock_rate = 32;
- const uint8_t clock_prescale_rate = 128;
- */
- // Freq About 4.857MHz => Freq = PCLK / (CPSDVSR * [SCR+1]) with PCLK=PLL1=204MHz
- const uint8_t serial_clock_rate = 21;
- const uint8_t clock_prescale_rate = 2;
-
- ssp_init(SSP1_NUM,
- SSP_DATA_16BITS,
- SSP_FRAME_SPI,
- SSP_CPOL_0_CPHA_0,
- serial_clock_rate,
- clock_prescale_rate,
- SSP_MODE_NORMAL,
- SSP_MASTER,
- SSP_SLAVE_OUT_ENABLE);
-
- /* Configure SSP1 Peripheral (to be moved later in SSP driver) */
- scu_pinmux(SCU_SSP1_MISO, (SCU_SSP_IO | SCU_CONF_FUNCTION5));
- scu_pinmux(SCU_SSP1_MOSI, (SCU_SSP_IO | SCU_CONF_FUNCTION5));
- scu_pinmux(SCU_SSP1_SCK, (SCU_SSP_IO | SCU_CONF_FUNCTION1));
-}
-
-void max2837_spi_transfer_gather(spi_t* const spi, const spi_transfer_t* const transfers, const size_t count) {
- (void)spi;
-
- gpio_clear(PORT_XCVR_CS, PIN_XCVR_CS);
- for(size_t i=0; i<count; i++) {
- const size_t data_count = transfers[i].count;
- uint16_t* const data = transfers[i].data;
- for(size_t j=0; j<data_count; j++) {
- data[j] = ssp_transfer(SSP1_NUM, data[j]);
- }
- }
- gpio_set(PORT_XCVR_CS, PIN_XCVR_CS);
-}
-
-void max2837_spi_transfer(spi_t* const spi, void* const data, const size_t count) {
- const spi_transfer_t transfers[] = {
- { data, count },
- };
- max2837_spi_transfer_gather(spi, transfers, 1);
-}
--- a/firmware/common/max2837_spi.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2012 Will Code? (TODO: Proper attribution)
- * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
- *
- * 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_SPI_H__
-#define __MAX2837_SPI_H__
-
-#include "stddef.h"
-
-#include "spi.h"
-
-void max2837_spi_init(spi_t* const spi);
-void max2837_spi_transfer(spi_t* const spi, void* const data, const size_t count);
-void max2837_spi_transfer_gather(spi_t* const spi, const spi_transfer_t* const transfers, const size_t count);
-
-#endif/*__MAX2837_SPI_H__*/
--- a/firmware/common/max2837_target.c
+++ b/firmware/common/max2837_target.c
@@ -77,6 +77,16 @@
#endif
}
+void max2837_target_spi_select(spi_t* const spi) {
+ (void)spi;
+ gpio_clear(PORT_XCVR_CS, PIN_XCVR_CS);
+}
+
+void max2837_target_spi_unselect(spi_t* const spi) {
+ (void)spi;
+ gpio_set(PORT_XCVR_CS, PIN_XCVR_CS);
+}
+
void max2837_mode_shutdown(max2837_driver_t* const drv) {
(void)drv;
/* All circuit blocks are powered down, except the 4-wire serial bus
--- a/firmware/common/max2837_target.h
+++ b/firmware/common/max2837_target.h
@@ -24,8 +24,12 @@
#define __MAX2837_TARGET_H
#include "max2837.h"
+#include "spi.h"
void max2837_target_init(max2837_driver_t* const drv);
+void max2837_target_spi_select(spi_t* const spi);
+void max2837_target_spi_unselect(spi_t* const spi);
+
void max2837_mode_shutdown(max2837_driver_t* const drv);
void max2837_mode_standby(max2837_driver_t* const drv);
void max2837_mode_tx(max2837_driver_t* const drv);
--- a/firmware/common/max5864.c
+++ b/firmware/common/max5864.c
@@ -24,12 +24,14 @@
#include "max5864.h"
#include "max5864_target.h"
+#include "hackrf_core.h"
+
static void max5864_write(max5864_driver_t* const drv, uint8_t value) {
spi_transfer(drv->spi, &value, 1);
}
-void max5864_init(max5864_driver_t* const drv) {
- spi_init(drv->spi);
+static void max5864_init(max5864_driver_t* const drv) {
+ spi_init(drv->spi, &ssp1_config_max5864);
max5864_target_init(drv);
}
--- a/firmware/common/max5864_spi.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
- *
- * 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 "max5864_spi.h"
-
-#include <libopencm3/lpc43xx/gpio.h>
-#include <libopencm3/lpc43xx/scu.h>
-#include <libopencm3/lpc43xx/ssp.h>
-
-#include "hackrf_core.h"
-
-void max5864_spi_init(spi_t* const spi) {
- (void)spi;
-
- /* FIXME speed up once everything is working reliably */
- /*
- // Freq About 0.0498MHz / 49.8KHz => Freq = PCLK / (CPSDVSR * [SCR+1]) with PCLK=PLL1=204MHz
- const uint8_t serial_clock_rate = 32;
- const uint8_t clock_prescale_rate = 128;
- */
- // Freq About 4.857MHz => Freq = PCLK / (CPSDVSR * [SCR+1]) with PCLK=PLL1=204MHz
- const uint8_t serial_clock_rate = 21;
- const uint8_t clock_prescale_rate = 2;
-
- ssp_init(SSP1_NUM,
- SSP_DATA_8BITS,
- SSP_FRAME_SPI,
- SSP_CPOL_0_CPHA_0,
- serial_clock_rate,
- clock_prescale_rate,
- SSP_MODE_NORMAL,
- SSP_MASTER,
- SSP_SLAVE_OUT_ENABLE);
-
- /* Configure SSP1 Peripheral (to be moved later in SSP driver) */
- scu_pinmux(SCU_SSP1_MISO, (SCU_SSP_IO | SCU_CONF_FUNCTION5));
- scu_pinmux(SCU_SSP1_MOSI, (SCU_SSP_IO | SCU_CONF_FUNCTION5));
- scu_pinmux(SCU_SSP1_SCK, (SCU_SSP_IO | SCU_CONF_FUNCTION1));
-}
-
-void max5864_spi_transfer_gather(spi_t* const spi, const spi_transfer_t* const transfers, const size_t count) {
- (void)spi;
-
- gpio_clear(PORT_AD_CS, PIN_AD_CS);
- for(size_t i=0; i<count; i++) {
- const size_t data_count = transfers[i].count;
- uint8_t* const data = transfers[i].data;
- for(size_t j=0; j<data_count; j++) {
- data[j] = ssp_transfer(SSP1_NUM, data[j]);
- }
- }
- gpio_set(PORT_AD_CS, PIN_AD_CS);
-}
-
-void max5864_spi_transfer(spi_t* const spi, void* const data, const size_t count) {
- const spi_transfer_t transfers[] = {
- { data, count },
- };
- max5864_spi_transfer_gather(spi, transfers, 1);
-}
--- a/firmware/common/max5864_spi.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
- *
- * 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 __MAX5864_SPI_H__
-#define __MAX5864_SPI_H__
-
-#include <stddef.h>
-
-#include "spi.h"
-
-void max5864_spi_init(spi_t* const spi);
-void max5864_spi_transfer(spi_t* const spi, void* const value, const size_t count);
-void max5864_spi_transfer_gather(spi_t* const spi, const spi_transfer_t* const transfers, const size_t count);
-
-#endif/*__MAX5864_SPI_H__*/
--- a/firmware/common/max5864_target.c
+++ b/firmware/common/max5864_target.c
@@ -36,3 +36,13 @@
GPIO_SET(PORT_AD_CS) = PIN_AD_CS;
GPIO_DIR(PORT_AD_CS) |= PIN_AD_CS;
}
+
+void max5864_target_spi_select(spi_t* const spi) {
+ (void)spi;
+ gpio_clear(PORT_AD_CS, PIN_AD_CS);
+}
+
+void max5864_target_spi_unselect(spi_t* const spi) {
+ (void)spi;
+ gpio_set(PORT_AD_CS, PIN_AD_CS);
+}
--- a/firmware/common/max5864_target.h
+++ b/firmware/common/max5864_target.h
@@ -23,7 +23,10 @@
#define __MAX5864_TARGET_H__
#include "max5864.h"
+#include "spi.h"
void max5864_target_init(max5864_driver_t* const drv);
+void max5864_target_spi_select(spi_t* const spi);
+void max5864_target_spi_unselect(spi_t* const spi);
#endif/*__MAX5864_TARGET_H__*/
--- a/firmware/common/rffc5071.c
+++ b/firmware/common/rffc5071.c
@@ -90,7 +90,7 @@
{
rffc5071_init(drv);
- spi_init(drv->spi);
+ spi_init(drv->spi, NULL);
/* initial setup */
/* put zeros in freq contol registers */
--- a/firmware/common/rffc5071_spi.c
+++ b/firmware/common/rffc5071_spi.c
@@ -83,7 +83,8 @@
gpio_set(PORT_MIXER_RESETX, PIN_MIXER_RESETX); /* active low */
}
-void rffc5071_spi_init(spi_t* const spi) {
+void rffc5071_spi_init(spi_t* const spi, const void* const config) {
+ (void)config;
rffc5071_spi_bus_init(spi);
rffc5071_spi_target_init(spi);
}
--- a/firmware/common/rffc5071_spi.h
+++ b/firmware/common/rffc5071_spi.h
@@ -25,7 +25,7 @@
#include "spi.h"
-void rffc5071_spi_init(spi_t* const spi);
+void rffc5071_spi_init(spi_t* const spi, const void* const config);
void rffc5071_spi_transfer(spi_t* const spi, void* const data, const size_t count);
void rffc5071_spi_transfer_gather(spi_t* const spi, const spi_transfer_t* const transfer, const size_t count);
--- a/firmware/common/spi.c
+++ b/firmware/common/spi.c
@@ -21,8 +21,8 @@
#include "spi.h"
-void spi_init(spi_t* const spi) {
- spi->init(spi);
+void spi_init(spi_t* const spi, const void* const config) {
+ spi->init(spi, config);
}
void spi_transfer(spi_t* const spi, void* const data, const size_t count) {
--- a/firmware/common/spi.h
+++ b/firmware/common/spi.h
@@ -33,12 +33,13 @@
typedef struct spi_t spi_t;
struct spi_t {
- void (*init)(spi_t* const spi);
+ const void* config;
+ void (*init)(spi_t* const spi, const void* const config);
void (*transfer)(spi_t* const spi, void* const data, const size_t count);
void (*transfer_gather)(spi_t* const spi, const spi_transfer_t* const transfers, const size_t count);
};
-void spi_init(spi_t* const spi);
+void spi_init(spi_t* const spi, const void* const config);
void spi_transfer(spi_t* const spi, void* const data, const size_t count);
void spi_transfer_gather(spi_t* const spi, const spi_transfer_t* const transfers, const size_t count);
--- /dev/null
+++ b/firmware/common/spi_ssp1.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
+ *
+ * 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 "spi_ssp1.h"
+
+#include <libopencm3/lpc43xx/scu.h>
+#include <libopencm3/lpc43xx/ssp.h>
+
+#include "hackrf_core.h"
+
+void spi_ssp1_init(spi_t* const spi, const void* const _config) {
+ const ssp1_config_t* const config = _config;
+
+ ssp_init(SSP1_NUM,
+ config->data_bits,
+ SSP_FRAME_SPI,
+ SSP_CPOL_0_CPHA_0,
+ config->serial_clock_rate,
+ config->clock_prescale_rate,
+ SSP_MODE_NORMAL,
+ SSP_MASTER,
+ SSP_SLAVE_OUT_ENABLE);
+
+ spi->config = config;
+
+ /* Configure SSP1 Peripheral (to be moved later in SSP driver) */
+ scu_pinmux(SCU_SSP1_MISO, (SCU_SSP_IO | SCU_CONF_FUNCTION5));
+ scu_pinmux(SCU_SSP1_MOSI, (SCU_SSP_IO | SCU_CONF_FUNCTION5));
+ scu_pinmux(SCU_SSP1_SCK, (SCU_SSP_IO | SCU_CONF_FUNCTION1));
+}
+
+void spi_ssp1_transfer_gather(spi_t* const spi, const spi_transfer_t* const transfers, const size_t count) {
+ const ssp1_config_t* const config = spi->config;
+
+ const size_t word_size = (SSP1_CR0 & 0xf) + 1;
+
+ config->select(spi);
+ for(size_t i=0; i<count; i++) {
+ const size_t data_count = transfers[i].count;
+
+ if( word_size > 8 ) {
+ uint16_t* const data = transfers[i].data;
+ for(size_t j=0; j<data_count; j++) {
+ data[j] = ssp_transfer(SSP1_NUM, data[j]);
+ }
+ } else {
+ uint8_t* const data = transfers[i].data;
+ for(size_t j=0; j<data_count; j++) {
+ data[j] = ssp_transfer(SSP1_NUM, data[j]);
+ }
+ }
+ }
+ config->unselect(spi);
+}
+
+void spi_ssp1_transfer(spi_t* const spi, void* const data, const size_t count) {
+ const spi_transfer_t transfers[] = {
+ { data, count },
+ };
+ spi_ssp1_transfer_gather(spi, transfers, 1);
+}
--- /dev/null
+++ b/firmware/common/spi_ssp1.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
+ *
+ * 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 __SPI_SSP1_H__
+#define __SPI_SSP1_H__
+
+#include <stdint.h>
+#include <stddef.h>
+
+#include "spi.h"
+
+#include <libopencm3/lpc43xx/ssp.h>
+
+typedef struct ssp1_config_t {
+ ssp_datasize_t data_bits;
+ uint8_t serial_clock_rate;
+ uint8_t clock_prescale_rate;
+ void (*select)(spi_t* const spi);
+ void (*unselect)(spi_t* const spi);
+} ssp1_config_t;
+
+void spi_ssp1_init(spi_t* const spi, const void* const config);
+void spi_ssp1_transfer(spi_t* const spi, void* const value, const size_t count);
+void spi_ssp1_transfer_gather(spi_t* const spi, const spi_transfer_t* const transfers, const size_t count);
+
+#endif/*__SPI_SSP1_H__*/
--- a/firmware/common/w25q80bv.c
+++ b/firmware/common/w25q80bv.c
@@ -58,7 +58,7 @@
drv->num_pages = 4096U;
drv->num_bytes = 1048576U;
- spi_init(drv->spi);
+ spi_init(drv->spi, NULL);
device_id = 0;
while(device_id != W25Q80BV_DEVICE_ID_RES)
@@ -201,6 +201,7 @@
}
spi_t w25q80bv_spi = {
+ .config = NULL,
.init = w25q80bv_spi_init,
.transfer = w25q80bv_spi_transfer,
.transfer_gather = w25q80bv_spi_transfer_gather,
--- a/firmware/common/w25q80bv_spi.c
+++ b/firmware/common/w25q80bv_spi.c
@@ -30,8 +30,9 @@
#include "hackrf_core.h"
-void w25q80bv_spi_init(spi_t* const spi) {
+void w25q80bv_spi_init(spi_t* const spi, const void* const config) {
(void)spi;
+ (void)config;
const uint8_t serial_clock_rate = 2;
const uint8_t clock_prescale_rate = 2;
--- a/firmware/common/w25q80bv_spi.h
+++ b/firmware/common/w25q80bv_spi.h
@@ -28,7 +28,7 @@
#include "spi.h"
-void w25q80bv_spi_init(spi_t* const spi);
+void w25q80bv_spi_init(spi_t* const spi, const void* const config);
void w25q80bv_spi_transfer_gather(spi_t* const spi, const spi_transfer_t* const transfers, const size_t transfer_count);
void w25q80bv_spi_transfer(spi_t* const spi, void* const data, const size_t count);
--- a/firmware/hackrf-common.cmake
+++ b/firmware/hackrf-common.cmake
@@ -136,14 +136,13 @@
${PATH_HACKRF_FIRMWARE_COMMON}/si5351c.c
${PATH_HACKRF_FIRMWARE_COMMON}/si5351c_drv.c
${PATH_HACKRF_FIRMWARE_COMMON}/max2837.c
- ${PATH_HACKRF_FIRMWARE_COMMON}/max2837_spi.c
${PATH_HACKRF_FIRMWARE_COMMON}/max2837_target.c
${PATH_HACKRF_FIRMWARE_COMMON}/max5864.c
- ${PATH_HACKRF_FIRMWARE_COMMON}/max5864_spi.c
${PATH_HACKRF_FIRMWARE_COMMON}/max5864_target.c
${PATH_HACKRF_FIRMWARE_COMMON}/rffc5071.c
${PATH_HACKRF_FIRMWARE_COMMON}/rffc5071_spi.c
${PATH_HACKRF_FIRMWARE_COMMON}/spi.c
+ ${PATH_HACKRF_FIRMWARE_COMMON}/spi_ssp1.c
m0_bin.s
)
|