📄 lpc2000_spi.lst
字号:
ARM COMPILER V2.42, lpc2000_spi 27/03/06 10:45:51 PAGE 1
ARM COMPILER V2.42, COMPILATION OF MODULE lpc2000_spi
OBJECT MODULE PLACED IN .\obj\lpc2000_spi.obj
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe src\lpc2000_spi.c THUMB DEBUG PRINT(.\LST\LPC2000_SPI.LST) TABS(4) OBJECT(.\
-obj\lpc2000_spi.obj)
stmt level source
1 /*****************************************************************************\
2 * efs - General purpose Embedded Filesystem library *
3 * --------------------- ----------------------------------- *
4 * *
5 * Filename : lpc2000_spi.c *
6 * Description : This file contains the functions needed to use efs for *
7 * accessing files on an SD-card connected to an LPC2xxx. *
8 * *
9 * This library is free software; you can redistribute it and/or *
10 * modify it under the terms of the GNU Lesser General Public *
11 * License as published by the Free Software Foundation; either *
12 * version 2.1 of the License, or (at your option) any later version. *
13 * *
14 * This library is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
17 * Lesser General Public License for more details. *
18 * *
19 * (c)2005 Martin Thomas *
20 * *
21 \*****************************************************************************/
22
23 /*****************************************************************************/
24 #include "LPC2000_regs.h"
25 #include "lpc2000_spi.h"
26 #include "sd.h"
27 #include "config.h"
28 /*****************************************************************************/
29
30 #ifndef HW_ENDPOINT_LPC2000_SPINUM
#error "HW_ENDPOINT_LPC2000_SPINUM has to be defined in config.h"
#endif
33
34 #if ( HW_ENDPOINT_LPC2000_SPINUM == 0 )
35 // LPC213x ### SPI0 ###
36
37 // SP0SPCR Bit-Definitions
38 #define CPHA 3
39 #define CPOL 4
40 #define MSTR 5
41 // SP0SPSR Bit-Definitions
42 #define SPIF 7
43
44 #define SPI_IODIR IODIR0
45 #define SPI_SCK_PIN 4 /* Clock P0.4 out */
46 #define SPI_MISO_PIN 5 /* from Card P0.5 in */
47 #define SPI_MOSI_PIN 6 /* to Card P0.6 out */
48 #define SPI_SS_PIN 7 /* Card-Select P0.7 - GPIO out */
49
50 #define SPI_PINSEL PINSEL0
51 #define SPI_SCK_FUNCBIT 8
52 #define SPI_MISO_FUNCBIT 10
53 #define SPI_MOSI_FUNCBIT 12
54 #define SPI_SS_FUNCBIT 14
55
56 #define SPI_PRESCALE_REG S0SPCCR
57 #define SPI_PRESCALE_MIN 8
58
ARM COMPILER V2.42, lpc2000_spi 27/03/06 10:45:51 PAGE 2
59 #define SELECT_CARD() IOCLR0 = (1<<SPI_SS_PIN)
60 #define UNSELECT_CARD() IOSET0 = (1<<SPI_SS_PIN)
61
62 #elif ( HW_ENDPOINT_LPC2000_SPINUM == 1 )
// LPC213x ### SSP ### ("SPI1")
// SSPCR0 Bit-Definitions
#define CPOL 6
#define CPHA 7
// SSPCR1 Bit-Defintions
#define SSE 1
#define MS 2
#define SCR 8
// SSPSR Bit-Definitions
#define TNF 1
#define RNE 2
#define BSY 4
#define SPI_IODIR IODIR0
#define SPI_SCK_PIN 17 /* Clock P0.17 out */
#define SPI_MISO_PIN 18 /* from Card P0.18 in */
#define SPI_MOSI_PIN 19 /* to Card P0.19 out */
/* Card-Select P0.20 - GPIO out during startup
Function 03 during normal operation */
#define SPI_SS_PIN 20
#define SPI_PINSEL PINSEL1
#define SPI_SCK_FUNCBIT 2
#define SPI_MISO_FUNCBIT 4
#define SPI_MOSI_FUNCBIT 6
#define SPI_SS_FUNCBIT 8
#define SPI_PRESCALE_REG SSPCPSR
/// TODO: too fast on prototyp wires #define SPI_PRESCALE_MIN 2
#define SPI_PRESCALE_MIN 4
/* only needed during init: */
#define SELECT_CARD() IOCLR0 = (1<<SPI_SS_PIN)
#define UNSELECT_CARD() IOSET0 = (1<<SPI_SS_PIN)
#else
#error "Invalid Interface-Number"
#endif
103
104
105
106
107 esint8 if_initInterface(hwInterface* file, eint8* opts)
108 {
109 1 euint32 sc;
110 1
111 1 if_spiInit(file); /* init at low speed */
112 1
113 1 if(sd_Init(file)<0) {
114 2 DBG((TXT("Card failed to init, breaking up...\n")));
115 2 return(-1);
116 2 }
117 1 if(sd_State(file)<0){
118 2 DBG((TXT("Card didn't return the ready state, breaking up...\n")));
119 2 return(-2);
120 2 }
121 1
122 1 // file->sectorCount=4; /* FIXME ASAP!! */
123 1
124 1 sd_getDriveSize(file, &sc);
ARM COMPILER V2.42, lpc2000_spi 27/03/06 10:45:51 PAGE 3
125 1 file->sectorCount = sc/512;
126 1 if( (sc%512) != 0) {
127 2 file->sectorCount--;
128 2 }
129 1 DBG((TXT("Drive Size is %lu Bytes (%lu Sectors)\n"), sc, file->sectorCount));
130 1
131 1 /* increase speed after init */
132 1 #if ( HW_ENDPOINT_LPC2000_SPINUM == 1 )
SSPCR0 = ((8-1)<<0) | (0<<CPOL);
#endif
135 1 if_spiSetSpeed(SPI_PRESCALE_MIN);
136 1 // if_spiSetSpeed(100); /* debug - slower */
137 1
138 1 DBG((TXT("Init done...\n")));
139 1 return(0);
140 1 }
*** WARNING C47 IN LINE 107 OF SRC\LPC2000_SPI.C: 'opts': unreferenced parameter
141 /*****************************************************************************/
142
143 esint8 if_readBuf(hwInterface* file,euint32 address,euint8* buf)
144 {
145 1 return(sd_readSector(file,address,buf,512));
146 1 }
147 /*****************************************************************************/
148
149 esint8 if_writeBuf(hwInterface* file,euint32 address,euint8* buf)
150 {
151 1 return(sd_writeSector(file,address, buf));
152 1 }
153 /*****************************************************************************/
154
155 esint8 if_setPos(hwInterface* file,euint32 address)
156 {
157 1 return(0);
158 1 }
*** WARNING C47 IN LINE 155 OF SRC\LPC2000_SPI.C: 'file': unreferenced parameter
*** WARNING C47 IN LINE 155 OF SRC\LPC2000_SPI.C: 'address': unreferenced parameter
159 /*****************************************************************************/
160
161 // Utility-functions which does not toogle CS.
162 // Only needed during card-init. During init
163 // the automatic chip-select is disabled for SSP
164
165 static euint8 my_if_spiSend(hwInterface *iface, euint8 outgoing)
166 {
167 1 euint8 incoming;
168 1
169 1 // SELECT_CARD(); // not here!
170 1
171 1 #if ( HW_ENDPOINT_LPC2000_SPINUM == 0 )
172 1 S0SPDR = outgoing;
173 1 while( !(S0SPSR & (1<<SPIF)) ) ;
174 1 incoming = S0SPDR;
175 1 #endif
176 1 #if ( HW_ENDPOINT_LPC2000_SPINUM == 1 )
while( !(SSPSR & (1<<TNF)) ) ;
SSPDR = outgoing;
while( !(SSPSR & (1<<RNE)) ) ;
incoming = SSPDR;
#endif
182 1
183 1 // UNSELECT_CARD(); // not here!
184 1
185 1 return(incoming);
186 1 }
*** WARNING C47 IN LINE 165 OF SRC\LPC2000_SPI.C: 'iface': unreferenced parameter
ARM COMPILER V2.42, lpc2000_spi 27/03/06 10:45:51 PAGE 4
187 /*****************************************************************************/
188
189 void if_spiInit(hwInterface *iface)
190 {
191 1 euint8 i;
192 1
193 1 // setup GPIO
194 1 SPI_IODIR |= (1<<SPI_SCK_PIN)|(1<<SPI_MOSI_PIN)|(1<<SPI_SS_PIN);
195 1 SPI_IODIR &= ~(1<<SPI_MISO_PIN);
196 1
197 1 // set Chip-Select high - unselect card
198 1 UNSELECT_CARD();
199 1
200 1 // reset Pin-Functions
201 1 SPI_PINSEL &= ~( (3<<SPI_SCK_FUNCBIT) | (3<<SPI_MISO_FUNCBIT) |
202 1 (3<<SPI_MOSI_FUNCBIT) | (3<<SPI_SS_FUNCBIT) );
203 1
204 1 #if ( HW_ENDPOINT_LPC2000_SPINUM == 0 )
205 1 DBG((TXT("spiInit for SPI(0)\n")));
206 1 SPI_PINSEL |= ( (1<<SPI_SCK_FUNCBIT) | (1<<SPI_MISO_FUNCBIT) |
207 1 (1<<SPI_MOSI_FUNCBIT) );
208 1 // enable SPI-Master
209 1 S0SPCR = (1<<MSTR)|(0<<CPOL); // TODO: check CPOL
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -