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

📄 mmc.lst

📁 硬盘、u盘、mmc、cd-rom mp3播放器源码
💻 LST
📖 第 1 页 / 共 4 页
字号:
 297   4              return (MMC_END);
 298   4            }
 299   3          }
 300   2        }
 301   1      }
 302          
C51 COMPILER V6.20c  MMC                                                                   07/10/2002 15:17:49 PAGE 6   

 303          
 304          /*F**************************************************************************
 305          * NAME: mmc_update_acq
 306          *----------------------------------------------------------------------------
 307          * PARAMS:   
 308          *
 309          * return:
 310          *   MMC_OK:     state result OK
 311          *   MMC_ERROR:  state result KO
 312          *   MMC_END:    end of new card acquisition
 313          *----------------------------------------------------------------------------
 314          * PURPOSE: 
 315          *   New card acquisition
 316          *----------------------------------------------------------------------------
 317          * EXAMPLE:
 318          *----------------------------------------------------------------------------
 319          * NOTE:
 320          *   - This function must be called 5 or 6 times for completion
 321          *     depending on busy card
 322          *   - Each call must be delayed enough to leave time for command
 323          *     transmission and response reception
 324          *   - It does not take care of the DSR
 325          *
 326          *   STATES: MMC_STACK_OP_COND   send operating condition
 327          *           MMC_STACK_CID       check busy and send CID or op cond again
 328          *           MMC_STACK_SRA       check CID response and set relative address
 329          *           MMC_STACK_CSD       send CSD request
 330          *           MMC_STACK_END       check CSD reception
 331          *----------------------------------------------------------------------------
 332          * REQUIREMENTS:
 333          *****************************************************************************/
 334          Byte mmc_update_acq (void)
 335          {
 336   1      Uint32  response;
 337   1      
 338   1        switch (mmc_state)
 339   1        {
 340   2          case MMC_STACK_OP_COND:
 341   2          {
 342   3            mmc_send_cmd(MMC_SEND_OP_COND, MMC_OCR_INIT, MMC_RESP_R3);
 343   3            mmc_state = MMC_STACK_CID;
 344   3            return (MMC_OK);
 345   3          }
 346   2      
 347   2          case MMC_STACK_CID:
 348   2          {
 349   3            if (mmc_check_response() == MMC_ERR_RESP)
 350   3            {
 351   4              mmc_send_scmd(MMC_ALL_SEND_CID, MMC_RESP_R2);
 352   4              mmc_state = MMC_STACK_SRA;          /* card already in stack ? */
 353   4            }
 354   3            else
 355   3            {
 356   4              response = mmc_read_response();
 357   4              if ((((Byte*)&response)[0] & MMC_BUSY_OCR) != MMC_BUSY_OCR)
 358   4              {   /* at least one card is busy */
 359   5                mmc_send_cmd(MMC_SEND_OP_COND, MMC_OCR_INIT, MMC_RESP_R3);
 360   5              }
 361   4              else
 362   4              {
 363   5                mmc_send_scmd(MMC_ALL_SEND_CID, MMC_RESP_R2);
 364   5                mmc_state = MMC_STACK_SRA;
C51 COMPILER V6.20c  MMC                                                                   07/10/2002 15:17:49 PAGE 7   

 365   5              }
 366   4            }
 367   3            return (MMC_OK);
 368   3          }
 369   2      
 370   2          case MMC_STACK_SRA:
 371   2          {
 372   3            if (mmc_check_response() == MMC_ERR_RESP)
 373   3            {
 374   4              mmc_state = MMC_FUNCT_START;
 375   4              return (MMC_ERROR);                 /* no response: no new card */
 376   4            }
 377   3            else
 378   3            {
 379   4              mmc_send_cmd(MMC_SET_RELATIVE_ADDRESS, MMC_RCA_2, MMC_RESP_R1);
 380   4              mmc_state = MMC_STACK_CSD;
 381   4              return (MMC_OK);
 382   4            }
 383   3          }
 384   2      
 385   2          case MMC_STACK_CSD:
 386   2          {
 387   3            if (mmc_check_response() == MMC_ERR_RESP)
 388   3            {
 389   4              mmc_state = MMC_FUNCT_START;
 390   4              return (MMC_ERROR);                 /* no response */
 391   4            }
 392   3            else
 393   3            {
 394   4              mmc_send_cmd(MMC_SEND_CSD, MMC_RCA_2, MMC_RESP_R2);
 395   4              mmc_state = MMC_STACK_END;
 396   4              return (MMC_OK);
 397   4            }
 398   3          }
 399   2      
 400   2          case MMC_STACK_END:
 401   2          {
 402   3            if (mmc_check_response() == MMC_ERR_RESP)
 403   3            {
 404   4              mmc_state = MMC_FUNCT_START;
 405   4              return (MMC_ERROR);                 /* no response */
 406   4            }
 407   3            else
 408   3            {
 409   4              Mmc_set_clock(MMC_CLK_TRANS);       /* set MMC clock to max */
 410   4              mmc_state = MMC_FUNCT_START;
 411   4              return (MMC_END);
 412   4            }
 413   3          }
 414   2        }
 415   1      }
 416          
 417          
 418          /*F**************************************************************************
 419          * NAME: mmc_setup_card
 420          *----------------------------------------------------------------------------
 421          * PARAMS:
 422          *   card_id: 0:  RCA 1
 423          *            1:  RCA 2
 424          *
 425          * return:
 426          *   MMC_OK:     state result OK
C51 COMPILER V6.20c  MMC                                                                   07/10/2002 15:17:49 PAGE 8   

 427          *   MMC_ERROR:  state result KO
 428          *   MMC_END:    end of setup execution
 429          *----------------------------------------------------------------------------
 430          * PURPOSE: 
 431          *   Select the corresponding card
 432          *----------------------------------------------------------------------------
 433          * EXAMPLE:
 434          *----------------------------------------------------------------------------
 435          * NOTE:
 436          *   - This function must be called at least 2 times for completion
 437          *   - Each call must be delayed enough to leave time for command
 438          *     transmission and response reception
 439          *   - Contrary to what is written in MMC spec, the request CSD can
 440          *     not be done in transfer state
 441          *
 442          *   STATES: MMC_SETUP_SELECT   select card
 443          *           MMC_SETUP_STATUS   check status
 444          *----------------------------------------------------------------------------
 445          * REQUIREMENTS:
 446          *****************************************************************************/
 447          Byte mmc_setup_card (bit card_id)
 448          {
 449   1        switch (mmc_state)
 450   1        {
 451   2          case MMC_SETUP_SELECT:
 452   2          {
 453   3            if (card_id == MMC_CARD1)
 454   3            {
 455   4              mmc_send_cmd(MMC_SELECT_CARD, MMC_RCA_1, MMC_RESP_R1);
 456   4            }
 457   3            else
 458   3            {
 459   4              mmc_send_cmd(MMC_SELECT_CARD, MMC_RCA_2, MMC_RESP_R1);
 460   4            }
 461   3            mmc_state = MMC_SETUP_STATUS;
 462   3            return (MMC_OK);
 463   3          }
 464   2      
 465   2          case MMC_SETUP_STATUS:
 466   2          {
 467   3            if (mmc_check_response() == MMC_ERR_RESP)
 468   3            {
 469   4              mmc_state = MMC_FUNCT_START;
 470   4              return (MMC_ERROR);                 /* response error */
 471   4            }
 472   3            else
 473   3            {
 474   4              if (Mmc_card_busy())
 475   4              {
 476   5                mmc_state = MMC_FUNCT_START;
 477   5                return (MMC_ERROR);               /* bus busy */
 478   5              }
 479   4              if ((mmc_read_response() & MMC_STBY_STATE_MSK) != MMC_STBY_STATE)
 480   4              {
 481   5                mmc_state = MMC_FUNCT_START;
 482   5                return (MMC_ERROR);               /* bad status */
 483   5              }
 484   4              else
 485   4              {
 486   5                mmc_state = MMC_FUNCT_START;
 487   5                return (MMC_END);
 488   5              }
C51 COMPILER V6.20c  MMC                                                                   07/10/2002 15:17:49 PAGE 9   

 489   4            }
 490   3          }
 491   2        }
 492   1      }
 493          
 494          
 495          /*F**************************************************************************
 496          * NAME: mmc_check_stack
 497          *----------------------------------------------------------------------------
 498          * PARAMS:
 499          *
 500          * return:
 501          *   OK: card present
 502          *   KO: card not present
 503          *----------------------------------------------------------------------------
 504          * PURPOSE: 
 505          *   Return a status on card presence or not
 506          *----------------------------------------------------------------------------
 507          * EXAMPLE:
 508          *----------------------------------------------------------------------------
 509          * NOTE:
 510          *----------------------------------------------------------------------------
 511          * REQUIREMENTS:
 512          *****************************************************************************/
 513          bit mmc_check_stack (void)
 514          {
 515   1      Byte t;
 516   1      
 517   1        Mmc_enable();
 518   1        mmc_send_cmd(MMC_SEND_OP_COND, MMC_OCR_INIT, MMC_RESP_R3);
 519   1      
 520   1        t = MMC_RESPONSE_TIME;
 521   1        while (mmc_check_response() == MMC_ERR_RESP)
 522   1        {
 523   2          if (t == MMC_TIME_OUT)
 524   2          {
 525   3            Mmc_disable();
 526   3            return KO;
 527   3          }
 528   2          t--;
 529   2        }
 530   1        return OK;
 531   1      }
 532          
 533          
 534          /*F**************************************************************************
 535          * NAME: mmc_check_presence
 536          *----------------------------------------------------------------------------
 537          * PARAMS:
 538          *   card_id: 0:  RCA 1
 539          *            1:  RCA 2
 540          *
 541          * return:
 542          *   OK: addressed card present
 543          *   KO: addressed card not present
 544          *----------------------------------------------------------------------------
 545          * PURPOSE: 
 546          *   Return a status on card presence or not
 547          *----------------------------------------------------------------------------
 548          * EXAMPLE:
 549          *----------------------------------------------------------------------------
 550          * NOTE:
C51 COMPILER V6.20c  MMC                                                                   07/10/2002 15:17:49 PAGE 10  

 551          *----------------------------------------------------------------------------
 552          * REQUIREMENTS:
 553          *****************************************************************************/
 554          bit mmc_check_presence (bit card_id)
 555          {
 556   1      Byte t;
 557   1      
 558   1        if (mmc_mem_busy)
 559   1        {
 560   2          mmc_mem_busy = FALSE;
 561   2          while (Mmc_card_busy());                /* wait end of programming */
 562   2        }
 563   1        if (card_id == MMC_CARD1)
 564   1        {
 565   2          mmc_send_cmd(MMC_SEND_STATUS, MMC_RCA_1, MMC_RESP_R1);
 566   2        }
 567   1        else
 568   1        {
 569   2          mmc_send_cmd(MMC_SEND_STATUS, MMC_RCA_2, MMC_RESP_R1);
 570   2        }
 571   1      
 572   1        t = MMC_RESPONSE_TIME;
 573   1        while (mmc_check_response() == MMC_ERR_RESP)
 574   1        {
 575   2          if (t == MMC_TIME_OUT)
 576   2          {
 577   3            return KO;
 578   3          }
 579   2          t--;
 580   2        }
 581   1        return OK;
 582   1      }
 583          
 584          
 585          /*F**************************************************************************
 586          * NAME: mmc_read_open
 587          *----------------------------------------------------------------------------
 588          * PARAMS:
 589          *   pos: address of the logic sector to read (size 512 bytes)
 590          *   global: gl_ptr_mem
 591          *
 592          * return:
 593          *   open status:  OK: open done
 594          *                 KO: open not done
 595          *----------------------------------------------------------------------------
 596          * PURPOSE: 
 597          *   Open memory card in read mode (read block)
 598          *----------------------------------------------------------------------------
 599          * EXAMPLE:
 600          *----------------------------------------------------------------------------

⌨️ 快捷键说明

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