Changeset 620:ac139e476a85
- Timestamp:
- 06/22/08 20:36:43 (7 months ago)
- Author:
- Maxime Petazzoni <maxime.petazzoni@…>
- Branch:
- default
- Message:
-
Refactor some EFC code
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r616
|
r620
|
|
| 25 | 25 | } |
| 26 | 26 | |
| 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) { |
| | 27 | static bool nx__efc_do_write(U32 page) { |
| 31 | 28 | U32 ret; |
| 32 | | U8 i; |
| 33 | 29 | |
| 34 | 30 | 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 | | } |
| 45 | 31 | |
| 46 | 32 | /* Trigger the flash write command. */ |
| … |
… |
|
| 59 | 45 | |
| 60 | 46 | return TRUE; |
| | 47 | } |
| | 48 | |
| | 49 | static 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 | */ |
| | 56 | bool 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); |
| 61 | 71 | } |
| 62 | 72 | |
| … |
… |
|
| 78 | 88 | |
| 79 | 89 | bool 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); |
| 82 | 104 | } |
| 83 | 105 | |