Project

General

Profile

Download (2.48 KB) Statistics
| Branch: | Tag: | Revision:
1 ee25d9a0 henryk
/* SPI DAC AD5300 Driver for OpenPICC
2
 * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
3
 * All bugs added by Henryk Plötz <henryk@ploetzli.ch> (c) 2006-2007
4
 *
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by 
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 *
19
 */
20
21
22
#include "openpicc.h"
23
#include "board.h"
24
25
#include <sys/types.h>
26
#include <lib_AT91SAM7.h>
27
28
static const AT91PS_SPI spi = AT91C_BASE_SPI;
29 948f16ee henryk
static u_int8_t last_value;
30 ee25d9a0 henryk
31
void da_comp_carr(u_int8_t position)
32
{
33
	volatile int i;
34
35
	while (!(spi->SPI_SR & AT91C_SPI_TDRE)) { }
36
	AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
37
	/* shift four left, since it is an eight-bit value written as 16 bit xfer 
38
	   bits 15 and 14 are don't care
39
	   bits 13 and 12 are mode (0 is normal operation)
40
	   bits 11 thru 4 are data
41
	   bits 3 thru 0 are don't care
42
	 */
43
	spi->SPI_TDR = position << 4;
44
	while (!(spi->SPI_SR & AT91C_SPI_TDRE)) { }
45
	for (i = 0; i < 0xff; i++) { }
46
	AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
47 948f16ee henryk
	last_value = position;
48
}
49
50
u_int8_t da_get_value(void)
51
{
52
	return last_value;
53 ee25d9a0 henryk
}
54
55
void da_init(void)
56
{
57
	AT91F_SPI_CfgPMC();
58
	AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, 
59
			    AT91C_PA13_MOSI | AT91C_PA14_SPCK, 0);
60
61
	AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
62
	AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
63
64
#if 0
65
	AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, AT91C_ID_SPI,
66
			      OPENPCD_IRQ_PRIO_SPI,
67
			      AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, &spi_irq);
68
	AT91G_AIC_EnableIt(AT9C_BASE_AIC, AT91C_ID_SPI);
69
#endif
70
	AT91F_SPI_CfgMode(spi, AT91C_SPI_MSTR | 
71
			  AT91C_SPI_PS_FIXED | AT91C_SPI_MODFDIS);
72
	/* CPOL = 1, NCPHA = 1, CSAAT = 0, BITS = 1000, SCBR = 13 (3.69MHz),
73
	 * DLYBS = 6 (125nS), DLYBCT = 0 */
74
	AT91F_SPI_CfgCs(spi, 0, AT91C_SPI_CPOL | AT91C_SPI_BITS_16 | 
75
			AT91C_SPI_NCPHA | (13 << 8) | (6 << 16));
76
	AT91F_SPI_Enable(spi);
77
	
78
	da_comp_carr(DA_BASELINE);
79
}
Add picture from clipboard (Maximum size: 48.8 MB)