📄 lpc2000_spi.lst
字号:
210 1 #endif
211 1
212 1 #if ( HW_ENDPOINT_LPC2000_SPINUM == 1 )
DBG((TXT("spiInit for SSP/SPI1\n")));
// setup Pin-Functions - keep automatic CS disabled during init
SPI_PINSEL |= ( (2<<SPI_SCK_FUNCBIT) | (2<<SPI_MISO_FUNCBIT) |
(2<<SPI_MOSI_FUNCBIT) | (0<<SPI_SS_FUNCBIT) );
// enable SPI-Master - slowest speed
SSPCR0 = ((8-1)<<0) | (0<<CPOL) | (0x20<<SCR); // (0xff<<SCR);
SSPCR1 = (1<<SSE);
#endif
221 1
222 1 // low speed during init
223 1 if_spiSetSpeed(254);
224 1
225 1 /* Send 20 spi commands with card not selected */
226 1 for(i=0;i<21;i++)
227 1 my_if_spiSend(iface,0xff);
228 1
229 1 #if ( HW_ENDPOINT_LPC2000_SPINUM == 0 )
230 1 // SPI0 does not offer automatic CS for slaves on LPC2138
231 1 // ( the SSEL-Pin is input-only )
232 1 // SELECT_CARD();
233 1 #endif
234 1
235 1 #if ( HW_ENDPOINT_LPC2000_SPINUM == 1 )
// enable automatic slave CS for SSP
SSPCR1 &= ~(1<<SSE); // disable interface
SPI_PINSEL |= ( (2<<SPI_SCK_FUNCBIT) | (2<<SPI_MISO_FUNCBIT) |
(2<<SPI_MOSI_FUNCBIT) | (2<<SPI_SS_FUNCBIT) );
SSPCR1 |= (1<<SSE); // enable interface
#endif
242 1
243 1 }
244 /*****************************************************************************/
245
246 void if_spiSetSpeed(euint8 speed)
247 {
248 1 speed &= 0xFE;
249 1 if ( speed < SPI_PRESCALE_MIN ) speed = SPI_PRESCALE_MIN ;
250 1 SPI_PRESCALE_REG = speed;
251 1 }
252
ARM COMPILER V2.42, lpc2000_spi 27/03/06 10:45:51 PAGE 5
253 /*****************************************************************************/
254
255 euint8 if_spiSend(hwInterface *iface, euint8 outgoing)
256 {
257 1 euint8 incoming;
258 1
259 1 #if ( HW_ENDPOINT_LPC2000_SPINUM == 0 )
260 1 SELECT_CARD();
261 1 S0SPDR = outgoing;
262 1 while( !(S0SPSR & (1<<SPIF)) ) ;
263 1 incoming = S0SPDR;
264 1 UNSELECT_CARD();
265 1 #endif
266 1
267 1 #if ( HW_ENDPOINT_LPC2000_SPINUM == 1 )
// SELECT_CARD(); // done by hardware
while( !(SSPSR & (1<<TNF)) ) ;
SSPDR = outgoing;
while( !(SSPSR & (1<<RNE)) ) ;
incoming = SSPDR;
// UNSELECT_CARD(); // done by hardware
#endif
275 1
276 1
277 1
278 1 return(incoming);
279 1 }
*** WARNING C47 IN LINE 255 OF SRC\LPC2000_SPI.C: 'iface': unreferenced parameter
280 /*****************************************************************************/
281
ARM COMPILER V2.42, lpc2000_spi 27/03/06 10:45:51 PAGE 6
ASSEMBLY LISTING OF GENERATED OBJECT CODE
*** EXTERNALS:
EXTERN CODE16 (lpc2000_debug_printf?T)
EXTERN CODE16 (sd_Init?T)
EXTERN CODE16 (sd_State?T)
EXTERN CODE16 (sd_readSector?T)
EXTERN CODE16 (sd_writeSector?T)
EXTERN CODE16 (sd_getDriveSize?T)
*** PUBLICS:
PUBLIC if_initInterface?T
PUBLIC if_readBuf?T
PUBLIC if_writeBuf?T
PUBLIC if_setPos?T
PUBLIC if_spiInit?T
PUBLIC if_spiSetSpeed?T
PUBLIC if_spiSend?T
*** DATA SEGMENT '?CON?lpc2000_spi':
00000000 ??S_5:
00000000 DB 'spiInit for SPI(0)',0x0A,0x00
00000014 ??S_4:
00000014 DB 'Init done...',0x0A,0x00
00000022 ??S_3:
00000022 DB 'Drive Size is %lu Bytes (%lu Sectors)',0x0A
00000048 DB 0x00
00000049 ??S_2:
00000049 DB 'Card didn't return the ready state, br'
0000006F DB 'eaking up...',0x0A,0x00
0000007D ??S_1:
0000007D DB 'Card failed to init, breaking up...',0x0A
000000A1 DB 0x00
*** CODE SEGMENT '?PR?if_initInterface?T?lpc2000_spi':
107: esint8 if_initInterface(hwInterface* file, eint8* opts)
00000000 B510 PUSH {R4,LR}
00000002 1C04 MOV R4,R0 ; file
00000004 ---- Variable 'file' assigned to Register 'R4' ----
00000004 B081 SUB R13,#0x4
108: {
00000006 ; SCOPE-START
111: if_spiInit(file); /* init at low speed */
00000006 1C20 MOV R0,R4 ; file
00000008 F7FF BL if_spiInit?T ; T=0x0001 (1)
0000000A FFFA BL if_spiInit?T ; T=0x0001 (2)
113: if(sd_Init(file)<0) {
0000000C 1C20 MOV R0,R4 ; file
0000000E F7FF BL sd_Init?T ; T=0x0001 (1)
00000010 FFF7 BL sd_Init?T ; T=0x0001 (2)
00000012 0600 LSL R0,R0,#0x18 ; sd_Init?T
00000014 1600 ASR R0,R0,#0x18
00000016 2800 CMP R0,#0x0
00000018 DA04 BGE L_1 ; T=0x00000024
114: DBG((TXT("Card failed to init, breaking up...\n")));
0000001A 4800 LDR R0,=??S_1 ; ??S_1
0000001C F7FF BL lpc2000_debug_printf?T ; T=0x0001 (1)
0000001E FFF0 BL lpc2000_debug_printf?T ; T=0x0001 (2)
115: return(-1);
00000020 4800 LDR R0,=0xFFFFFFFF
00000022 E028 B L_2 ; T=0x00000076
116: }
00000024 L_1:
117: if(sd_State(file)<0){
00000024 1C20 MOV R0,R4 ; file
00000026 F7FF BL sd_State?T ; T=0x0001 (1)
ARM COMPILER V2.42, lpc2000_spi 27/03/06 10:45:51 PAGE 7
00000028 FFEB BL sd_State?T ; T=0x0001 (2)
0000002A 0600 LSL R0,R0,#0x18 ; sd_State?T
0000002C 1600 ASR R0,R0,#0x18
0000002E 2800 CMP R0,#0x0
00000030 DA04 BGE L_3 ; T=0x0000003C
118: DBG((TXT("Card didn't return the ready state, breaking up...\n")));
00000032 4800 LDR R0,=??S_2 ; ??S_2
00000034 F7FF BL lpc2000_debug_printf?T ; T=0x0001 (1)
00000036 FFE4 BL lpc2000_debug_printf?T ; T=0x0001 (2)
119: return(-2);
00000038 4800 LDR R0,=0xFFFFFFFE
0000003A E01C B L_2 ; T=0x00000076
120: }
0000003C L_3:
124: sd_getDriveSize(file, &sc);
0000003C 1C20 MOV R0,R4 ; file
0000003E A900 ADD R1,R13,#0x0
00000040 F7FF BL sd_getDriveSize?T ; T=0x0001 (1)
00000042 FFDE BL sd_getDriveSize?T ; T=0x0001 (2)
125: file->sectorCount = sc/512;
00000044 9900 LDR R1,[R13,#0x0] ; sc
00000046 0A49 LSR R1,R1,#0x9
00000048 1C20 MOV R0,R4 ; file
0000004A 6001 STR R1,[R0,#0x0] ; file
126: if( (sc%512) != 0) {
0000004C 9800 LDR R0,[R13,#0x0] ; sc
0000004E 4800 LDR R1,=0x1FF
00000050 4208 TST R0,R1
00000052 D003 BEQ L_4 ; T=0x0000005C
127: file->sectorCount--;
00000054 1C20 MOV R0,R4 ; file
00000056 6801 LDR R1,[R0,#0x0] ; file
00000058 3901 SUB R1,#0x1
0000005A 6001 STR R1,[R0,#0x0] ; file
128: }
0000005C L_4:
129: DBG((TXT("Drive Size is %lu Bytes (%lu Sectors)\n"), sc, file->sectorCount));
0000005C 1C20 MOV R0,R4 ; file
0000005E 6802 LDR R2,[R0,#0x0] ; file
00000060 4800 LDR R0,=??S_3 ; ??S_3
00000062 9900 LDR R1,[R13,#0x0] ; sc
00000064 F7FF BL lpc2000_debug_printf?T ; T=0x0001 (1)
00000066 FFCC BL lpc2000_debug_printf?T ; T=0x0001 (2)
135: if_spiSetSpeed(SPI_PRESCALE_MIN);
00000068 2008 MOV R0,#0x8
0000006A F7FF BL if_spiSetSpeed?T ; T=0x0001 (1)
0000006C FFC9 BL if_spiSetSpeed?T ; T=0x0001 (2)
138: DBG((TXT("Init done...\n")));
0000006E 4800 LDR R0,=??S_4 ; ??S_4
00000070 F7FF BL lpc2000_debug_printf?T ; T=0x0001 (1)
00000072 FFC6 BL lpc2000_debug_printf?T ; T=0x0001 (2)
139: return(0);
00000074 2000 MOV R0,#0x0
00000076 ; SCOPE-END
140: }
00000076 L_2:
00000076 B001 ADD R13,#0x4
00000078 BC10 POP {R4}
0000007A BC08 POP {R3}
0000007C 4718 BX R3
0000007E ENDP ; 'if_initInterface?T'
*** CODE SEGMENT '?PR?if_readBuf?T?lpc2000_spi':
143: esint8 if_readBuf(hwInterface* file,euint32 address,euint8* buf)
00000000 B500 PUSH {LR}
00000002 1C13 MOV R3,R2 ; buf
00000004 ---- Variable 'buf' assigned to Register 'R3' ----
ARM COMPILER V2.42, lpc2000_spi 27/03/06 10:45:51 PAGE 8
00000004 1C0A MOV R2,R1 ; address
00000006 ---- Variable 'address' assigned to Register 'R2' ----
00000006 1C01 MOV R1,R0 ; file
00000008 ---- Variable 'file' assigned to Register 'R1' ----
145: return(sd_readSector(file,address,buf,512));
00000008 1C08 MOV R0,R1 ; file
0000000A 1C11 MOV R1,R2 ; address
0000000C 1C1A MOV R2,R3 ; buf
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -