summaryrefslogtreecommitdiff
path: root/openpicc
diff options
context:
space:
mode:
Diffstat (limited to 'openpicc')
-rw-r--r--openpicc/Makefile1
-rw-r--r--openpicc/application/da.c72
-rw-r--r--openpicc/application/da.h7
-rw-r--r--openpicc/application/main.c4
-rw-r--r--openpicc/application/openpicc.h1
-rw-r--r--openpicc/config/board.h8
6 files changed, 90 insertions, 3 deletions
diff --git a/openpicc/Makefile b/openpicc/Makefile
index 76804a7..50d07e4 100644
--- a/openpicc/Makefile
+++ b/openpicc/Makefile
@@ -74,6 +74,7 @@ ARM_SRC= \
application/led.c \
application/cmd.c \
application/env.c \
+ application/da.c \
os/boot/Cstartup_SAM7.c \
os/core/list.c \
os/core/queue.c \
diff --git a/openpicc/application/da.c b/openpicc/application/da.c
new file mode 100644
index 0000000..64cee5b
--- /dev/null
+++ b/openpicc/application/da.c
@@ -0,0 +1,72 @@
+/* SPI DAC AD5300 Driver for OpenPICC
+ * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
+ * All bugs added by Henryk Plötz <henryk@ploetzli.ch> (c) 2006-2007
+ *
+ * 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 of the License, 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; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+
+#include "openpicc.h"
+#include "board.h"
+
+#include <sys/types.h>
+#include <lib_AT91SAM7.h>
+
+static const AT91PS_SPI spi = AT91C_BASE_SPI;
+
+void da_comp_carr(u_int8_t position)
+{
+ volatile int i;
+
+ while (!(spi->SPI_SR & AT91C_SPI_TDRE)) { }
+ AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
+ /* shift four left, since it is an eight-bit value written as 16 bit xfer
+ bits 15 and 14 are don't care
+ bits 13 and 12 are mode (0 is normal operation)
+ bits 11 thru 4 are data
+ bits 3 thru 0 are don't care
+ */
+ spi->SPI_TDR = position << 4;
+ while (!(spi->SPI_SR & AT91C_SPI_TDRE)) { }
+ for (i = 0; i < 0xff; i++) { }
+ AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
+}
+
+void da_init(void)
+{
+ AT91F_SPI_CfgPMC();
+ AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA,
+ AT91C_PA13_MOSI | AT91C_PA14_SPCK, 0);
+
+ AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
+ AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
+
+#if 0
+ AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, AT91C_ID_SPI,
+ OPENPCD_IRQ_PRIO_SPI,
+ AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, &spi_irq);
+ AT91G_AIC_EnableIt(AT9C_BASE_AIC, AT91C_ID_SPI);
+#endif
+ AT91F_SPI_CfgMode(spi, AT91C_SPI_MSTR |
+ AT91C_SPI_PS_FIXED | AT91C_SPI_MODFDIS);
+ /* CPOL = 1, NCPHA = 1, CSAAT = 0, BITS = 1000, SCBR = 13 (3.69MHz),
+ * DLYBS = 6 (125nS), DLYBCT = 0 */
+ AT91F_SPI_CfgCs(spi, 0, AT91C_SPI_CPOL | AT91C_SPI_BITS_16 |
+ AT91C_SPI_NCPHA | (13 << 8) | (6 << 16));
+ AT91F_SPI_Enable(spi);
+
+ da_comp_carr(DA_BASELINE);
+}
diff --git a/openpicc/application/da.h b/openpicc/application/da.h
new file mode 100644
index 0000000..e264e2b
--- /dev/null
+++ b/openpicc/application/da.h
@@ -0,0 +1,7 @@
+#ifndef _DA_H
+#define _DA_H
+
+extern void da_comp_carr(u_int8_t position);
+extern void da_init(void);
+
+#endif
diff --git a/openpicc/application/main.c b/openpicc/application/main.c
index 6dc9637..d69fc1e 100644
--- a/openpicc/application/main.c
+++ b/openpicc/application/main.c
@@ -38,6 +38,8 @@
#include "led.h"
#include "env.h"
#include "cmd.h"
+#include "da.h"
+#include "pll.h"
/**********************************************************************/
static inline void prvSetupHardware (void)
@@ -80,6 +82,8 @@ int main (void)
vLedInit();
+ da_init();
+
xTaskCreate (vUSBCDCTask, (signed portCHAR *) "USB", TASK_USB_STACK,
NULL, TASK_USB_PRIORITY, NULL);
diff --git a/openpicc/application/openpicc.h b/openpicc/application/openpicc.h
index d3575a6..1ed4273 100644
--- a/openpicc/application/openpicc.h
+++ b/openpicc/application/openpicc.h
@@ -32,5 +32,6 @@ typedef signed char s_int8_t;
typedef signed short s_int16_t;
typedef int s_int32_t;
+#define DA_BASELINE 200
#endif/*__OPENPICC_H__*/
diff --git a/openpicc/config/board.h b/openpicc/config/board.h
index 5a56155..065c26d 100644
--- a/openpicc/config/board.h
+++ b/openpicc/config/board.h
@@ -50,15 +50,17 @@
#define MCKKHz (MCK/1000) //
/*-----------------*/
-/* LED declaration */
+/* Pins */
/*-----------------*/
-//#define LED_GREEN (1L<<23)
#define LED_GREEN AT91C_PIO_PA25
-//#define LED_RED (1L<<20)
#define LED_RED AT91C_PIO_PA12
#define LED_MASK (LED_GREEN|LED_RED)
+#define OPENPICC_PIO_SS2_DT_THRESH AT91C_PIO_PA8
+#define OPENPICC_PIO_PLL_INHIBIT AT91C_PIO_PA24
+#define OPENPICC_PIO_PLL_LOCK AT91C_PIO_PA4
+
/*-----------------*/
/* task priorities */
/*-----------------*/
personal git repositories of Harald Welte. Your mileage may vary