[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r7460 - usrp2/trunk/firmware/lib
From: |
eb |
Subject: |
[Commit-gnuradio] r7460 - usrp2/trunk/firmware/lib |
Date: |
Thu, 17 Jan 2008 16:20:12 -0700 (MST) |
Author: eb
Date: 2008-01-17 16:20:11 -0700 (Thu, 17 Jan 2008)
New Revision: 7460
Modified:
usrp2/trunk/firmware/lib/memory_map.h
usrp2/trunk/firmware/lib/spi.c
Log:
reworked spi.c to use pointer-to-struct style
Modified: usrp2/trunk/firmware/lib/memory_map.h
===================================================================
--- usrp2/trunk/firmware/lib/memory_map.h 2008-01-17 22:48:27 UTC (rev
7459)
+++ usrp2/trunk/firmware/lib/memory_map.h 2008-01-17 23:20:11 UTC (rev
7460)
@@ -1,6 +1,6 @@
/* -*- c -*- */
/*
- * Copyright 2007 Free Software Foundation, Inc.
+ * Copyright 2007,2008 Free Software Foundation, Inc.
*
* 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
@@ -60,15 +60,19 @@
// SPI Core, Slave 2. See core docs for more info
#define SPI_BASE 0x8000 // Base address (16-bit)
-// Register address offsets
-#define SPI_TXRX0 0x000
-#define SPI_TXRX1 0x004
-#define SPI_TXRX2 0x008
-#define SPI_TXRX3 0x00c
-#define SPI_CTRL 0x010
-#define SPI_DIV 0x014
-#define SPI_SS 0x018
+typedef struct {
+ volatile uint32_t txrx0;
+ volatile uint32_t txrx1;
+ volatile uint32_t txrx2;
+ volatile uint32_t txrx3;
+ volatile uint32_t ctrl;
+ volatile uint32_t div;
+ volatile uint32_t ss;
+} spi_regs_t;
+#define spi_regs ((spi_regs_t *) SPI_BASE)
+
+
// Masks for controlling different peripherals
#define SPI_SS_AD9510 1
#define SPI_SS_AD9777 2
Modified: usrp2/trunk/firmware/lib/spi.c
===================================================================
--- usrp2/trunk/firmware/lib/spi.c 2008-01-17 22:48:27 UTC (rev 7459)
+++ usrp2/trunk/firmware/lib/spi.c 2008-01-17 23:20:11 UTC (rev 7460)
@@ -1,5 +1,5 @@
/*
- * Copyright 2007 Free Software Foundation, Inc.
+ * Copyright 2007,2008 Free Software Foundation, Inc.
*
* 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
@@ -21,52 +21,44 @@
void
spi_init(void)
{
- volatile int *p;
-
- // Set divider
- p = (int *)(SPI_BASE+SPI_DIV);
- *p = 0; // 0 = Div by 2, 1 = Div-by-4
+ /*
+ * f_sclk = f_wb / ((div + 1) * 2)
+ */
+ spi_regs->div = 0; // 0 = Div by 2 (50 MHz); 1 = Div-by-4 (25 MHz)
}
void
spi_wait(void)
{
- volatile int *p;
- p = (int *)(SPI_BASE+SPI_CTRL);
- while(*p & SPI_CTRL_GO_BSY)
- {}
+ while (spi_regs->ctrl & SPI_CTRL_GO_BSY)
+ ;
}
int
spi_transact(int readback, int slave, int data, int length, int inv_tx)
{
- volatile int *p;
int flags;
if(inv_tx)
flags = SPI_CTRL_ASS | (SPI_CTRL_CHAR_LEN & length);
else
- flags = SPI_CTRL_ASS | SPI_CTRL_TXNEG | (SPI_CTRL_CHAR_LEN & length);
+ flags = SPI_CTRL_ASS | (SPI_CTRL_CHAR_LEN & length) | SPI_CTRL_TXNEG;
spi_wait();
// Tell it which SPI device to access
- p = (int *)(SPI_BASE+SPI_SS);
- *p = slave & 0xFF;
+ spi_regs->ss = slave & 0xff;
// Data we will send
- p = (int *)(SPI_BASE+SPI_TXRX0);
- *p = data;
+ spi_regs->txrx0 = data;
// Run it -- write once and rewrite with GO set
- p = (int *)(SPI_BASE+SPI_CTRL);
- *p = flags;
- *p = flags | SPI_CTRL_GO_BSY;
+ spi_regs->ctrl = flags;
+ spi_regs->ctrl = flags | SPI_CTRL_GO_BSY;
if(readback) {
spi_wait();
- p = (int *)(SPI_BASE+SPI_TXRX0);
- return *p;
+ return spi_regs->txrx0;
}
else
return 0;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r7460 - usrp2/trunk/firmware/lib,
eb <=