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

📄 nf.lst

📁 一个可作为mp3播放器固件的代码集,包括解码,播放,控制,任务管理等.
💻 LST
📖 第 1 页 / 共 5 页
字号:
 758          *
 759          * return:
 760          *----------------------------------------------------------------------------
 761          * PURPOSE:
 762          *   Low level memory write update
 763          *----------------------------------------------------------------------------
 764          * EXAMPLE:
 765          *----------------------------------------------------------------------------
 766          * NOTE:
 767          *----------------------------------------------------------------------------
 768          * REQUIREMENTS:
 769          *****************************************************************************/
 770          bit nf_write_open (Uint32 pos)
 771          {
 772   1      Byte i;
 773   1      Byte j;
 774   1      bit change_zone = FALSE;
 775   1      
 776   1        gl_ptr_mem = pos;
 777   1        gl_cpt_page = 0;
 778   1      
 779   1        /* Determine the logical block value */
 780   1        nf_logical_block = (gl_ptr_mem >> 5);
 781   1        nf_zone = 0;
 782   1      
 783   1        while (nf_logical_block > 999)
 784   1        {
 785   2          nf_logical_block -= 1000;
 786   2          nf_zone++;
 787   2        }
 788   1        Nf_CS_ON();
 789   1      
 790   1        if (nf_zone != nf_old_zone)
 791   1        {
 792   2          change_zone = TRUE;
 793   2          if (nf_lut_modified)
 794   2          { /* save old lut */
 795   3            i = nf_old_zone;
 796   3            nf_old_zone = nf_zone;
 797   3            nf_zone = i;
C51 COMPILER V7.50   NF                                                                    09/20/2005 21:47:45 PAGE 14  

 798   3            nf_reassign_block();
 799   3            nf_lut_modified = FALSE;
 800   3            nf_zone = nf_old_zone;
 801   3          }
 802   2          else
 803   2          { /* update old zone value */
 804   3            nf_old_zone = nf_zone;
 805   3          }
 806   2          nf_block_min = 0xFFFF;
 807   2          gl_buf_free_idx = 0;
 808   2        }
 809   1      
 810   1        if ((nf_logical_block >= nf_block_min) && (nf_logical_block < (nf_block_min + NF_BUFFER_SIZE - 5)))
 811   1        { /* we don't have to update the buffer */
 812   2          nf_calc_logical_block();
 813   2          nf_gl_buf_idx = nf_logical_block - nf_block_min;
 814   2        }
 815   1        else 
 816   1        { /* we have to update the buffer */
 817   2          /* Store the look up table block address */
 818   2          nf_look_up_table_block =  nf_lut_block[nf_zone];
 819   2          /* If LUT have been modified */
 820   2          if (nf_lut_modified)           
 821   2          {
 822   3            nf_reassign_block();                  /* update the LUT */
 823   3          }
 824   2          /* Calculate the address for LUT access */
 825   2          gl_address = ((Uint32)(nf_look_up_table_block)<<5) + ((Uint32)(nf_logical_block) >> 8);
 826   2          gl_address += (Uint32)(nf_lut_index[nf_zone])<<2;
 827   2          /* Calculate the redundant block address value */
 828   2          nf_calc_logical_block();
 829   2          i = nf_logical_block;
 830   2          /* For the current zone, initialize the number of spare block */
 831   2          nf_spare_block = nf_spare_block_number[nf_zone];
 832   2          /* Calculate the low and the high block stored in the buffer */
 833   2          nf_block_min = nf_logical_block;
 834   2          nf_block_max = ((nf_logical_block + NF_BUFFER_SIZE) > 999) ? (1000 - nf_logical_block) : NF_BUFFER_SIZ
             -E;
 835   2      
 836   2          /* Open the look-up table */
 837   2          Nf_wait_busy();     
 838   2          if (((Byte*)&nf_logical_block)[1] & 0x80)
 839   2          {
 840   3            Nf_send_command(NF_READ_B_AREA_CMD);  /* 2nd half page */
 841   3            Nf_send_address((nf_logical_block << 1) - 256);
 842   3          }
 843   2          else
 844   2          {
 845   3            Nf_send_command(NF_READ_A_AREA_CMD);  /* first half page */
 846   3            Nf_send_address(nf_logical_block << 1);
 847   3          }
 848   2      
 849   2          Nf_send_address (((Byte*)&gl_address)[3]);     /* 2nd address cycle         */
 850   2          Nf_send_address (((Byte*)&gl_address)[2]);     /* 3rd address cycle         */
 851   2          if (NF_4_CYCLE_ADDRESS_BIT)                    /* Size of card >= 64Mbytes ?*/
 852   2            Nf_send_address ( ((Byte*)&gl_address)[1] ); /* 4th address cycle         */
 853   2        
 854   2          Nf_wait_busy();
 855   2      
 856   2          for (j = 0; j < nf_block_max ; j++)
 857   2          {
 858   3            /* Read conversion table : 64 datas */
C51 COMPILER V7.50   NF                                                                    09/20/2005 21:47:45 PAGE 15  

 859   3            nf_buf[j].b[0] = Nf_rd_byte();
 860   3            nf_buf[j].b[1] = Nf_rd_byte();
 861   3            i++;
 862   3            if (i == 0)
 863   3            {
 864   4              gl_address++;
 865   4              Nf_read_open_A_area(gl_address, 0x00);
 866   4            }
 867   3          }
 868   2        
 869   2          if (change_zone)        /* If it is a new zone, then load the spare buffer */
 870   2          {
 871   3            /* Check for used block : first, read in the LUT the free physical block */
 872   3            gl_address = ((Uint32)(nf_look_up_table_block)<<5) + 3;
 873   3            gl_address += (Uint32)(nf_lut_index[nf_zone])<<2;
 874   3            Nf_read_open_B_area(gl_address, 208);
 875   3            for (i = 0; i <= (nf_spare_block); i++)
 876   3            {
 877   4              nf_buf_free[i] = (Uint16)(Nf_rd_byte()<<8);
 878   4              nf_buf_free[i] +=  Nf_rd_byte();
 879   4            }
 880   3          }
 881   2          nf_gl_buf_idx = 0;           /* initialize index for main buffer */
 882   2          nf_gl_buf_idx_max = 0;       /* initialize the max index for the buffer */
 883   2        }
 884   1        
 885   1        /* if block is already assigned, then invert with a spare block */
 886   1        nf_block_used = (!(nf_buf[nf_gl_buf_idx].w & 0x8000)) ? TRUE : FALSE;
 887   1        if (nf_block_used)
 888   1        {
 889   2          if ((nf_buf_free[gl_buf_free_idx] & 0x7FFF) == nf_look_up_table_block)
 890   2          {
 891   3            gl_buf_free_idx++;
 892   3            if (gl_buf_free_idx >= nf_spare_block)
 893   3            {
 894   4              gl_buf_free_idx = 0;
 895   4            }      
 896   3          }
 897   2          /* assign block to be deleted */
 898   2          nf_block_to_be_deleted = nf_buf[nf_gl_buf_idx].w;
 899   2          nf_buf[nf_gl_buf_idx].w = nf_buf_free[gl_buf_free_idx];
 900   2          nf_buf_free[gl_buf_free_idx++] = nf_block_to_be_deleted | 0x8000;
 901   2          /* increase the index for spare block buffer */
 902   2          if (gl_buf_free_idx >= nf_spare_block)
 903   2          {
 904   3            gl_buf_free_idx = 0;
 905   3          }
 906   2        }
 907   1      
 908   1        /* Mark block as assigned */
 909   1        nf_buf[nf_gl_buf_idx].w &= 0x7FFF;       
 910   1      
 911   1        if (nf_gl_buf_idx > nf_gl_buf_idx_max)
 912   1          nf_gl_buf_idx_max = nf_gl_buf_idx;
 913   1      
 914   1        /* Update the current physical sector address */
 915   1        nf_current_physical_sector_addr = ((Uint32)(nf_buf[nf_gl_buf_idx].w) << 5);
 916   1      
 917   1        if (nf_block_used)                        /* Fisrt block already used block ?  */
 918   1        { 
 919   2          nf_copy_block_head();                   /* Copy the first part of the block  */
 920   2        }
C51 COMPILER V7.50   NF                                                                    09/20/2005 21:47:45 PAGE 16  

 921   1        else                                 
 922   1        { 
 923   2          nf_init_spare();                        /* else init spare data for new logical block  */
 924   2        }
 925   1      
 926   1        nf_busy = FALSE;                          /* Clear flag busy */
 927   1        nf_lut_modified = TRUE;
 928   1        /* Set LUT as modified */
 929   1        gl_address = ((Uint32)(nf_look_up_table_block)<<5);
 930   1        gl_address += (Uint32)(nf_lut_index[nf_zone])<<2;
 931   1        Nf_wait_busy();
 932   1        Nf_write_open_C_area(gl_address, 0x00);
 933   1        Nf_wr_byte(0x00);                         /* Reset first byte */
 934   1        Nf_send_command(NF_PAGE_PROGRAM_CMD);     /* Send program command to the device */
 935   1        
 936   1        return OK; 
 937   1      }
 938          
 939          
 940          /*F**************************************************************************
 941          * NAME: nf_write_close
 942          *----------------------------------------------------------------------------
 943          * PARAMS:
 944          *
 945          * return:
 946          *----------------------------------------------------------------------------
 947          * PURPOSE:
 948          *   Low level memory write close: release NF 
 949          *----------------------------------------------------------------------------
 950          * EXAMPLE:
 951          *----------------------------------------------------------------------------
 952          * NOTE:
 953          *----------------------------------------------------------------------------
 954          * REQUIREMENTS:
 955          *****************************************************************************/
 956          bit nf_write_close (void)
 957          { 
 958   1        Nf_CS_ON();
 959   1        if (gl_cpt_page)
 960   1        {
 961   2          while (((Byte*)&gl_cpt_page)[0] != NF_DATA_SIZE_H)
 962   2          {
 963   3            gl_cpt_page++;
 964   3            Nf_wr_byte(0x00);
 965   3          }
 966   2          nf_update_spare_data();
 967   2          Nf_send_command(NF_PAGE_PROGRAM_CMD);
 968   2          ((Byte*)&gl_cpt_page)[0] = 0;
 969   2          gl_ptr_mem++;
 970   2          ((Byte*)&nf_current_physical_sector_addr)[3]++;
 971   2        }
 972   1      
 973   1        /* Copy last part of a block if the block was assigned */
 974   1        if (nf_block_used)
 975   1        {
 976   2          if (((Byte*)&gl_ptr_mem)[3] & NF_BLOCK_MASK) 
 977   2            nf_copy_block_tail();
 978   2          nf_block_erase((Uint32)(nf_block_to_be_deleted) << 5);    /* Erase old block */
 979   2        }
 980   1        Nf_CS_OFF();
 981   1        return OK;
 982   1      }
C51 COMPILER V7.50   NF                                                                    09/20/2005 21:47:45 PAGE 17  

 983          
 984          
 985          /*F**************************************************************************
 986          * NAME: nf_write_byte
 987          *----------------------------------------------------------------------------
 988          * PARAMS:
 989          *   b: data to write
 990          *
 991          * RETURN:
 992          *   write status: OK: write done
 993          *                 KO: write not done
 994          *
 995          *----------------------------------------------------------------------------
 996          * PURPOSE:
 997          *   Low level memory write function
 998          *----------------------------------------------------------------------------
 999          * EXAMPLE:
1000          *----------------------------------------------------------------------------
1001          * NOTE:
1002          *----------------------------------------------------------------------------
1003          * REQUIREMENTS:
1004          *****************************************************************************/
1005          bit nf_write_byte (Byte b)
1006          {
1007   1        if (nf_busy)
1008   1        {
1009   2          nf_busy = FALSE;
1010   2          /* If previous block have to de deleted */
1011   2          if (nf_block_used)       
1012   2          {

⌨️ 快捷键说明

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