Project

General

Profile

Download (2.32 KB) Statistics
| Branch: | Tag: | Revision:
1
/* 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>
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

    
23
#include <sys/types.h>
24
#include <lib_AT91SAM7.h>
25
#include "../openpcd.h"
26

    
27
static const AT91PS_SPI spi = AT91C_BASE_SPI;
28

    
29
void da_comp_carr(u_int8_t position)
30
{
31
	volatile int i;
32

    
33
	while (!(spi->SPI_SR & AT91C_SPI_TDRE)) { }
34
	AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
35
	/* shift four left, since it is an eight-bit value written as 16 bit xfer 
36
	   bits 15 and 14 are don't care
37
	   bits 13 and 12 are mode (0 is normal operation)
38
	   bits 11 thru 4 are data
39
	   bits 3 thru 0 are don't care
40
	 */
41
	spi->SPI_TDR = position << 4;
42
	while (!(spi->SPI_SR & AT91C_SPI_TDRE)) { }
43
	for (i = 0; i < 0xff; i++) { }
44
	AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
45
}
46

    
47
void da_init(void)
48
{
49
	AT91F_SPI_CfgPMC();
50
	AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, 
51
			    AT91C_PA13_MOSI | AT91C_PA14_SPCK, 0);
52

    
53
	AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
54
	AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
55

    
56
#if 0
57
	AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, AT91C_ID_SPI,
58
			      OPENPCD_IRQ_PRIO_SPI,
59
			      AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, &spi_irq);
60
	AT91G_AIC_EnableIt(AT9C_BASE_AIC, AT91C_ID_SPI);
61
#endif
62
	AT91F_SPI_CfgMode(spi, AT91C_SPI_MSTR | 
63
			  AT91C_SPI_PS_FIXED | AT91C_SPI_MODFDIS);
64
	/* CPOL = 1, NCPHA = 1, CSAAT = 0, BITS = 1000, SCBR = 13 (3.69MHz),
65
	 * DLYBS = 6 (125nS), DLYBCT = 0 */
66
	AT91F_SPI_CfgCs(spi, 0, AT91C_SPI_CPOL | AT91C_SPI_BITS_16 | 
67
			AT91C_SPI_NCPHA | (13 << 8) | (6 << 16));
68
	AT91F_SPI_Enable(spi);
69
	
70
}
(2-2/26)
Add picture from clipboard (Maximum size: 48.8 MB)