Changeset 620:ac139e476a85

Show
Ignore:
Timestamp:
06/22/08 20:36:43 (7 months ago)
Author:
Maxime Petazzoni <maxime.petazzoni@…>
Branch:
default
Message:

Refactor some EFC code

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • nxos/base/drivers/_efc.c

    r616 r620  
    2525} 
    2626 
    27 /* Write one page at the given page number in the flash. 
    28  * Use interrupt-driven flash programming ? 
    29  */ 
    30 bool nx__efc_write_page(U32 *data, U32 page) { 
     27static bool nx__efc_do_write(U32 page) { 
    3128  U32 ret; 
    32   U8 i; 
    3329 
    3430  NX_ASSERT(page < EFC_PAGES); 
    35  
    36   /* Wait for the flash to be ready. */ 
    37   while (!(*AT91C_MC_FSR & AT91C_MC_FRDY)); 
    38  
    39   nx_systick_wait_ms(EFC_THROTTLE_TIMER); 
    40  
    41   /* Write the page data to the flash in-memory mapping. */ 
    42   for (i=0 ; i<EFC_PAGE_WORDS ; i++) { 
    43       FLASH_BASE_PTR[i+page*EFC_PAGE_WORDS] = data[i]; 
    44   } 
    4531 
    4632  /* Trigger the flash write command. */ 
     
    5945 
    6046  return TRUE; 
     47} 
     48 
     49static inline void nx__efc_wait_for_flash(void) { 
     50  while (!(*AT91C_MC_FSR & AT91C_MC_FRDY)); 
     51} 
     52 
     53/* Write one page at the given page number in the flash. 
     54 * Use interrupt-driven flash programming ? 
     55 */ 
     56bool nx__efc_write_page(U32 *data, U32 page) { 
     57  U8 i; 
     58 
     59  NX_ASSERT(page < EFC_PAGES); 
     60 
     61  /* Wait for the flash to be ready. */ 
     62  nx__efc_wait_for_flash(); 
     63  nx_systick_wait_ms(EFC_THROTTLE_TIMER); 
     64 
     65  /* Write the page data to the flash in-memory mapping. */ 
     66  for (i=0 ; i<EFC_PAGE_WORDS ; i++) { 
     67      FLASH_BASE_PTR[i+page*EFC_PAGE_WORDS] = data[i]; 
     68  } 
     69 
     70  return nx__efc_do_write(page); 
    6171} 
    6272 
     
    7888 
    7989bool nx__efc_erase_page(U32 page, U32 value) { 
    80   U32 data[EFC_PAGE_WORDS] = {value}; 
    81   return nx__efc_write_page(data, page); 
     90  U8 i; 
     91 
     92  NX_ASSERT(page < EFC_PAGES); 
     93 
     94  /* Wait for the flash to be ready. */ 
     95  nx__efc_wait_for_flash(); 
     96  nx_systick_wait_ms(EFC_THROTTLE_TIMER); 
     97 
     98  /* Write the page data to the flash in-memory mapping. */ 
     99  for (i=0 ; i<EFC_PAGE_WORDS ; i++) { 
     100      FLASH_BASE_PTR[i+page*EFC_PAGE_WORDS] = value; 
     101  } 
     102 
     103  return nx__efc_do_write(page); 
    82104} 
    83105