📄 spid.lst
字号:
###############################################################################
# #
# 24/Apr/2009 16:18:24 #
# IAR ARM ANSI C/C++ Compiler V5.11.0.20622/W32 EVALUATION #
# Copyright 1999-2007 IAR Systems. All rights reserved. #
# #
# Cpu mode = arm #
# Endian = little #
# Source file = D:\basic-dataflash-project-at91sam7se-ek\at91lib\memorie #
# s\spi-flash\spid.c #
# Command line = D:\basic-dataflash-project-at91sam7se-ek\at91lib\memorie #
# s\spi-flash\spid.c -D at91sam7se512 -D sram -D #
# TRACE_LEVEL=4 -lC D:\basic-dataflash-project-at91sam7se- #
# ek\at91sam7se-ek\basic-dataflash-project\ewp\at91sam7se5 #
# 12_sram\List\ --remarks --diag_suppress Pe826,Pe1375 -o #
# D:\basic-dataflash-project-at91sam7se-ek\at91sam7se-ek\b #
# asic-dataflash-project\ewp\at91sam7se512_sram\Obj\ #
# --no_cse --no_unroll --no_inline --no_code_motion #
# --no_tbaa --no_clustering --no_scheduling --debug #
# --endian little --cpu ARM7TDMI -e --fpu None #
# --dlib_config "D:\Program Files\arm\ARM\INC\DLib_Config_ #
# Full.h" -I D:\basic-dataflash-project-at91sam7se-ek\at91 #
# sam7se-ek\basic-dataflash-project\ewp\..\..\..\at91lib/p #
# eripherals\ -I D:\basic-dataflash-project-at91sam7se-ek\ #
# at91sam7se-ek\basic-dataflash-project\ewp\..\..\..\at91l #
# ib\ -I D:\basic-dataflash-project-at91sam7se-ek\at91sam7 #
# se-ek\basic-dataflash-project\ewp\..\..\..\at91lib/memor #
# ies\ -I D:\basic-dataflash-project-at91sam7se-ek\at91sam #
# 7se-ek\basic-dataflash-project\ewp\..\..\..\at91lib/boar #
# ds/at91sam7se-ek\ -I "D:\Program Files\arm\ARM\INC\" #
# --interwork --cpu_mode arm -Oh #
# List file = D:\basic-dataflash-project-at91sam7se-ek\at91sam7se-ek\b #
# asic-dataflash-project\ewp\at91sam7se512_sram\List\spid. #
# lst #
# Object file = D:\basic-dataflash-project-at91sam7se-ek\at91sam7se-ek\b #
# asic-dataflash-project\ewp\at91sam7se512_sram\Obj\spid.o #
# #
# #
###############################################################################
D:\basic-dataflash-project-at91sam7se-ek\at91lib\memories\spi-flash\spid.c
1 /* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2008, Atmel Corporation
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the disclaimer below.
13 *
14 * Atmel's name may not be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * ----------------------------------------------------------------------------
28 */
29
30 //------------------------------------------------------------------------------
31 // Headers
32 //------------------------------------------------------------------------------
33
34 #include "spid.h"
35 #include <board.h>
36
37 //------------------------------------------------------------------------------
38 // Macros
39 //------------------------------------------------------------------------------
40
41 /// Write PMC register
42 #define WRITE_PMC(pPmc, regName, value) pPmc->regName = (value)
43
44 /// Write SPI register
45 #define WRITE_SPI(pSpi, regName, value) pSpi->regName = (value)
46
47 /// Read SPI registers
48 #define READ_SPI(pSpi, regName) (pSpi->regName)
49
50 //------------------------------------------------------------------------------
51 // Exported functions
52 //------------------------------------------------------------------------------
53
54 //------------------------------------------------------------------------------
55 /// Initializes the Spid structure and the corresponding SPI hardware.
56 /// Always returns 0.
57 /// \param pSpid Pointer to a Spid instance.
58 /// \param pSpiHw Associated SPI peripheral.
59 /// \param spiId SPI peripheral identifier.
60 //------------------------------------------------------------------------------
\ In section .text, align 4, keep-with-next
61 unsigned char SPID_Configure(Spid *pSpid, AT91S_SPI *pSpiHw, unsigned char spiId)
62 {
63 // Initialize the SPI structure
64 pSpid->pSpiHw = pSpiHw;
\ SPID_Configure:
\ 00000000 001080E5 STR R1,[R0, #+0]
65 pSpid->spiId = spiId;
\ 00000004 0420C0E5 STRB R2,[R0, #+4]
66 pSpid->semaphore = 1;
\ 00000008 0120A0E3 MOV R2,#+1
\ 0000000C 0C20C0E5 STRB R2,[R0, #+12]
67 pSpid->pCurrentCommand = 0;
\ 00000010 0020A0E3 MOV R2,#+0
\ 00000014 082080E5 STR R2,[R0, #+8]
68
69 // Enable the SPI clock
70 WRITE_PMC(AT91C_BASE_PMC, PMC_PCER, (1 << pSpid->spiId));
\ 00000018 0120A0E3 MOV R2,#+1
\ 0000001C D430D0E1 LDRSB R3,[R0, #+4]
\ 00000020 1223A0E1 LSL R2,R2,R3
\ 00000024 EF30E0E3 MVN R3,#+239
\ 00000028 C03FC3E3 BIC R3,R3,#0x300
\ 0000002C 002083E5 STR R2,[R3, #+0]
71
72 // Execute a software reset of the SPI twice
73 WRITE_SPI(pSpiHw, SPI_CR, AT91C_SPI_SWRST);
\ 00000030 8020A0E3 MOV R2,#+128
\ 00000034 002081E5 STR R2,[R1, #+0]
74 WRITE_SPI(pSpiHw, SPI_CR, AT91C_SPI_SWRST);
\ 00000038 002081E5 STR R2,[R1, #+0]
75
76 // Configure SPI in Master Mode with No CS selected !!!
77 WRITE_SPI(pSpiHw, SPI_MR, AT91C_SPI_MSTR | AT91C_SPI_MODFDIS | AT91C_SPI_PCS);
\ 0000003C 1120A0E3 MOV R2,#+17
\ 00000040 F02A82E3 ORR R2,R2,#0xF0000
\ 00000044 042081E5 STR R2,[R1, #+4]
78
79 // Disable the PDC transfer
80 WRITE_SPI(pSpiHw, SPI_PTCR, AT91C_PDC_RXTDIS | AT91C_PDC_TXTDIS);
\ 00000048 0220A0E3 MOV R2,#+2
\ 0000004C 802F82E3 ORR R2,R2,#0x200
\ 00000050 202181E5 STR R2,[R1, #+288]
81
82 // Enable the SPI
83 WRITE_SPI(pSpiHw, SPI_CR, AT91C_SPI_SPIEN);
\ 00000054 0120A0E3 MOV R2,#+1
\ 00000058 002081E5 STR R2,[R1, #+0]
84
85 // Enable the SPI clock
86 WRITE_PMC(AT91C_BASE_PMC, PMC_PCDR, (1 << pSpid->spiId));
\ 0000005C D400D0E1 LDRSB R0,[R0, #+4]
\ 00000060 1200A0E1 LSL R0,R2,R0
\ 00000064 041083E3 ORR R1,R3,#0x4
\ 00000068 000081E5 STR R0,[R1, #+0]
87
88 return 0;
\ 0000006C 0000A0E3 MOV R0,#+0
\ 00000070 1EFF2FE1 BX LR ;; return
89 }
90
91 //------------------------------------------------------------------------------
92 /// Configures the parameters for the device corresponding to the cs.
93 /// \param pSpid Pointer to a Spid instance.
94 /// \param cs number corresponding to the SPI chip select.
95 /// \param csr SPI_CSR value to setup.
96 //------------------------------------------------------------------------------
\ In section .text, align 4, keep-with-next
97 void SPID_ConfigureCS(Spid *pSpid, unsigned char cs, unsigned int csr)
98 {
99 AT91S_SPI *pSpiHw = pSpid->pSpiHw;
100 WRITE_SPI(pSpiHw, SPI_CSR[cs], csr);
\ SPID_ConfigureCS:
\ 00000000 000090E5 LDR R0,[R0, #+0]
\ 00000004 010180E0 ADD R0,R0,R1, LSL #+2
\ 00000008 302080E5 STR R2,[R0, #+48]
101 }
\ 0000000C 1EFF2FE1 BX LR ;; return
102
103 //------------------------------------------------------------------------------
104 /// Starts a SPI master transfer. This is a non blocking function. It will
105 /// return as soon as the transfer is started.
106 /// Returns 0 if the transfer has been started successfully; otherwise returns
107 /// SPID_ERROR_LOCK is the driver is in use, or SPID_ERROR if the command is not
108 /// valid.
109 /// \param pSpid Pointer to a Spid instance.
110 /// \param pCommand Pointer to the SPI command to execute.
111 //------------------------------------------------------------------------------
\ In section .text, align 4, keep-with-next
112 unsigned char SPID_SendCommand(Spid *pSpid, SpidCmd *pCommand)
113 {
\ SPID_SendCommand:
\ 00000000 01402DE9 PUSH {R0,LR}
114 AT91S_SPI *pSpiHw = pSpid->pSpiHw;
\ 00000004 002090E5 LDR R2,[R0, #+0]
115 unsigned int spiMr;
116
117 // Try to get the dataflash semaphore
118 if (pSpid->semaphore == 0) {
\ 00000008 0C30D0E5 LDRB R3,[R0, #+12]
\ 0000000C 000053E3 CMP R3,#+0
119
120 return SPID_ERROR_LOCK;
\ 00000010 0200A003 MOVEQ R0,#+2
\ 00000014 2A00000A BEQ ??SPID_SendCommand_0
121 }
122 pSpid->semaphore--;
\ 00000018 0C30D0E5 LDRB R3,[R0, #+12]
\ 0000001C 013043E2 SUB R3,R3,#+1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -