⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmc.lst

📁 at91sam7x256 FREERTOS sd卡的读写程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
##############################################################################
#                                                                            #
# IAR ARM ANSI C/C++ Compiler V4.31A/W32 EVALUATION    15/Dec/2007  16:23:58 #
# Copyright 1999-2005 IAR Systems. All rights reserved.                      #
#                                                                            #
#    Cpu mode        =  interwork                                            #
#    Endian          =  little                                               #
#    Stack alignment =  4                                                    #
#    Source file     =  G:\AT91_ENERGY\ATMEL_ARM\mmssys\mmc_sd\mmc.c         #
#    Command line    =  G:\AT91_ENERGY\ATMEL_ARM\mmssys\mmc_sd\mmc.c -D      #
#                       AT91SAM7X256 -D PULL_UP_USB -D USE_LED -lC           #
#                       "G:\AT91_ENERGY\ATMEL_ARM\mmssys\AT91SAM7X-Mass      #
#                       Storage\compil\RAM_Debug\List\" --remarks -o         #
#                       "G:\AT91_ENERGY\ATMEL_ARM\mmssys\AT91SAM7X-Mass      #
#                       Storage\compil\RAM_Debug\Obj\" -z9 --debug           #
#                       --cpu_mode thumb --endian little --cpu ARM7TDMI      #
#                       --stack_align 4 --interwork -e --fpu None            #
#                       --dlib_config "C:\Program Files\IAR                  #
#                       Systems\Embedded Workbench 4.0                       #
#                       Evaluation\ARM\LIB\dl4tptinl8f.h" -I                 #
#                       "G:\AT91_ENERGY\ATMEL_ARM\mmssys\AT91SAM7X-Mass      #
#                       Storage\compil\srcIAR\" -I                           #
#                       "G:\AT91_ENERGY\ATMEL_ARM\mmssys\AT91SAM7X-Mass      #
#                       Storage\compil\..\src\" -I                           #
#                       "G:\AT91_ENERGY\ATMEL_ARM\mmssys\AT91SAM7X-Mass      #
#                       Storage\compil\..\..\" -I                            #
#                       "G:\AT91_ENERGY\ATMEL_ARM\mmssys\AT91SAM7X-Mass      #
#                       Storage\compil\..\..\FILESYSTEM\inc\" -I             #
#                       "G:\AT91_ENERGY\ATMEL_ARM\mmssys\AT91SAM7X-Mass      #
#                       Storage\compil\..\..\MASSSTORAGE\inc\" -I            #
#                       "G:\AT91_ENERGY\ATMEL_ARM\mmssys\AT91SAM7X-Mass      #
#                       Storage\compil\..\..\AT91SAM7X256\" -I               #
#                       "G:\AT91_ENERGY\ATMEL_ARM\mmssys\AT91SAM7X-Mass      #
#                       Storage\compil\..\inc\" -I                           #
#                       "G:\AT91_ENERGY\ATMEL_ARM\mmssys\AT91SAM7X-Mass      #
#                       Storage\compil\..\..\mmc_sd\" -I                     #
#                       "G:\AT91_ENERGY\ATMEL_ARM\mmssys\AT91SAM7X-Mass      #
#                       Storage\compil\..\..\COMMON_FS_MS\" -I "C:\Program   #
#                       Files\IAR Systems\Embedded Workbench 4.0             #
#                       Evaluation\ARM\INC\"                                 #
#    List file       =  G:\AT91_ENERGY\ATMEL_ARM\mmssys\AT91SAM7X-Mass       #
#                       Storage\compil\RAM_Debug\List\mmc.lst                #
#    Object file     =  G:\AT91_ENERGY\ATMEL_ARM\mmssys\AT91SAM7X-Mass       #
#                       Storage\compil\RAM_Debug\Obj\mmc.r79                 #
#                                                                            #
#                                                                            #
##############################################################################

G:\AT91_ENERGY\ATMEL_ARM\mmssys\mmc_sd\mmc.c
      1          /*-----------------------------------------------------------------------*/
      2          /* MMC/SDC (in SPI mode) control module  2006                   */
      3          /*-----------------------------------------------------------------------*/
      4          
      5          #include <stdio.h>
      6          #include "mmc.h"
      7          #include "string.h"
      8          #include "project.h" 
      9          #define CARD_WP_PIN      AT91C_PIO_PA16
     10          #define CARD_INS_PIN     AT91C_PIO_PA15
     11          static AT91PS_PIO  pPIOA = AT91C_BASE_PIOA;
     12          static AT91PS_SPI  pSPI  = AT91C_BASE_SPI0;
     13          #define CARD_SELECT_PIN  AT91C_PA13_SPI0_NPCS1
     14          #define SPI_CSR_NUM      0
     15          #define SPI_SCBR_MIN     2
     16          

   \                                 In segment DATA_Z, align 4, align-sorted
     17          unsigned char  GetBuff[512] ;
   \                     GetBuff:
   \   00000000                      DS8 512
     18          
     19          /* MMC/SD command (in SPI) */
     20          #define CMD0	(0x40+0)	/* GO_IDLE_STATE */
     21          #define CMD1	(0x40+1)	/* SEND_OP_COND */
     22          #define CMD9	(0x40+9)	/* SEND_CSD */
     23          #define CMD10	(0x40+10)	/* SEND_CID */
     24          #define CMD12	(0x40+12)	/* STOP_TRANSMISSION */
     25          #define CMD17	(0x40+17)	/* READ_SINGLE_BLOCK */
     26          #define CMD18	(0x40+18)	/* READ_MULTIPLE_BLOCK */
     27          #define CMD24	(0x40+24)	/* WRITE_BLOCK */
     28          #define CMD25	(0x40+25)	/* WRITE_MULTIPLE_BLOCK */
     29          #define CMD58	(0x40+58)	/* READ_OCR */
     30          
     31          
     32          /* Control signals (Platform dependent) */
     33          #define SELECT()	(pPIOA->PIO_CODR = CARD_SELECT_PIN) /* MMC CS = L */
     34          #define	DESELECT()	(pPIOA->PIO_SODR = CARD_SELECT_PIN) /* MMC CS = H */
     35          
     36          #define SOCKWP		CARD_WP_PIN			/* Write protect switch (PB5) */
     37          #define SOCKINS		CARD_INS_PIN		/* Card detect switch (PB4) */
     38          
     39          #define POWER_ON()
     40          #define POWER_OFF()
     41          
     42          static volatile

   \                                 In segment DATA_I, align 1, align-sorted
     43          DSTATUS Stat = STA_NOINIT;	/* Disk status */
   \                     Stat:
   \   00000000                      DS8 1
   \   00000001                      REQUIRE `?<Initializer for Stat>`
   \   00000001                      DS8 1
   \   00000002                      REQUIRE `?<Initializer for Timer>`
     44          
     45          // AT91: thru systime
     46          static volatile
     47          BYTE Timer;			/* 100Hz decrement timer */
     48          
     49          
     50          
     51          /*-----------------------------------------------------------------------*/
     52          /* Module Private Functions                                              */
     53          
     54          
     55          #if 0
     56          /*--------------------------------*/
     57          /* Transmit a byte to MMC via SPI */
     58          /* (Platform dependent)           */
     59          
     60          #define xmit_spi(dat) 	SPDR=(dat); loop_until_bit_is_set(SPSR,SPIF)
     61          
     62          /*---------------------------------*/
     63          /* Receive a byte from MMC via SPI */
     64          /* (Platform dependent)            */
     65          
     66          static
     67          BYTE rcvr_spi()
     68          {
     69          	SPDR = 0xFF;
     70          	loop_until_bit_is_set(SPSR, SPIF);
     71          	return SPDR;
     72          }
     73          
     74          /* Alternative macro to receive data fast */
     75          #define rcvr_spi_m(dst)	SPDR=0xFF; loop_until_bit_is_set(SPSR,SPIF); *(dst)=SPDR
     76          
     77          #endif
     78          
     79          extern void AT91F_DBGU_Printk(	char *buffer)   ;
     80          extern void AT91F_DBGU_Init(void);
     81          
     82          //*****************************************************
     83          

   \                                 In segment CODE, align 4, keep-with-next
     84          static void AT91_spiSetSpeed(BYTE speed)
     85          {
     86          	DWORD reg;
     87          
     88          	if ( speed < SPI_SCBR_MIN ) speed = SPI_SCBR_MIN;
   \                     AT91_spiSetSpeed:
   \   00000000   0228               CMP         R0,#+2
   \   00000002   00D2               BCS         ??AT91_spiSetSpeed_0
   \   00000004   0220               MOV         R0,#+2
     89          	if ( speed > 1 ) speed &= 0xFE;
     90          
     91          	reg = pSPI->SPI_CSR[SPI_CSR_NUM];
   \                     ??AT91_spiSetSpeed_0:
   \   00000006   ....               LDR         R1,??DataTable4    ;; 0xfffe0030
   \   00000008   0A68               LDR         R2,[R1, #+0]
     92          	reg = ( reg & ~(AT91C_SPI_SCBR) ) | ( (DWORD)speed << 8 );
     93          	pSPI->SPI_CSR[SPI_CSR_NUM] = reg;
   \   0000000A   044B               LDR         R3,??AT91_spiSetSpeed_1  ;; 0xffff00ff
   \   0000000C   1340               AND         R3,R2
   \   0000000E   FE22               MOV         R2,#+254
   \   00000010   0240               AND         R2,R0
   \   00000012   1002               LSL         R0,R2,#+8
   \   00000014   1843               ORR         R0,R3
   \   00000016   0860               STR         R0,[R1, #+0]
     94          }
   \   00000018   00B0               ADD         SP,#+0
   \   0000001A   7047               BX          LR                 ;; return
   \                     ??AT91_spiSetSpeed_1:
   \   0000001C   FF00FFFF           DC32        0xffff00ff
     95          

   \                                 In segment CODE, align 4, keep-with-next
     96          static BYTE AT91_spi(BYTE outgoing)
     97          {
   \                     AT91_spi:
   \   00000000   0649               LDR         R1,??AT91_spi_0    ;; 0xfffe0010
     98          	BYTE incoming;
     99          
    100          	while( !( pSPI->SPI_SR & AT91C_SPI_TDRE ) ); // transfer compl. wait
   \                     ??AT91_spi_1:
   \   00000002   0A68               LDR         R2,[R1, #+0]
   \   00000004   9207               LSL         R2,R2,#+30
   \   00000006   FCD5               BPL         ??AT91_spi_1
    101          	pSPI->SPI_TDR = (WORD)( outgoing );
   \   00000008   054A               LDR         R2,??AT91_spi_0+0x4  ;; 0xfffe000c
   \   0000000A   1060               STR         R0,[R2, #+0]
    102          	while( !( pSPI->SPI_SR & AT91C_SPI_RDRF ) ); // wait for char
   \                     ??AT91_spi_2:
   \   0000000C   0868               LDR         R0,[R1, #+0]
   \   0000000E   C007               LSL         R0,R0,#+31
   \   00000010   FCD5               BPL         ??AT91_spi_2
    103          	incoming = (BYTE)( pSPI->SPI_RDR );
   \   00000012   0448               LDR         R0,??AT91_spi_0+0x8  ;; 0xfffe0008
   \   00000014   0068               LDR         R0,[R0, #+0]
   \   00000016   0006               LSL         R0,R0,#+24
   \   00000018   000E               LSR         R0,R0,#+24
    104          
    105          	return incoming;
   \   0000001A   7047               BX          LR                 ;; return
   \                     ??AT91_spi_0:
   \   0000001C   1000FEFF           DC32        0xfffe0010
   \   00000020   0C00FEFF           DC32        0xfffe000c
   \   00000024   0800FEFF           DC32        0xfffe0008
    106          }
    107          
    108          /*--------------------------------*/
    109          /* Transmit a byte to MMC via SPI */
    110          /* (Platform dependent)           */
    111          
    112          static
    113          void xmit_spi(BYTE dat)
    114          {
    115          	AT91_spi(dat);
    116          }
    117          
    118          /*---------------------------------*/
    119          /* Receive a byte from MMC via SPI */
    120          /* (Platform dependent)            */
    121          
    122          static
    123          BYTE rcvr_spi(void)
    124          {
    125          	return AT91_spi(0xff);
    126          }
    127          
    128          /* Alternative "macro" (not at AT91 so far) to receive data fast */
    129          static
    130          void rcvr_spi_m(BYTE *dst)
    131          {
    132          	*dst = rcvr_spi();
    133          }
    134          
    135          
    136          /*---------------------*/
    137          /* Wait for card ready */
    138          

   \                                 In segment CODE, align 4, keep-with-next
    139          static
    140          BYTE wait_ready ()
    141          {
   \                     wait_ready:
   \   00000000   10B5               PUSH        {R4,LR}
    142          	BYTE res;
    143          	
    144          	Timer = 50;			/* Wait for ready in timeout of 500ms */
   \   00000002   ....               LDR         R4,??DataTable8    ;; Stat
   \   00000004   3220               MOV         R0,#+50

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -