AVR32 Flash Controller driver module.
Definition in file flashc.c.
#include <avr32/io.h>
#include <stddef.h>
#include "compiler.h"
#include "flashc.h"
Go to the source code of this file.
Data Structures | |
union | u_avr32_flashc_fcmd_t |
union | u_avr32_flashc_fcr_t |
FLASHC Status | |
static unsigned int | flashc_error_status = 0 |
Sticky error status of the FLASHC. | |
void(*volatile | flashc_wait_until_ready )(void) = flashc_default_wait_until_ready |
Pointer to the function used by the driver when it needs to wait until the FLASHC is ready to run a new command. | |
void | flashc_default_wait_until_ready (void) |
Waits actively until the FLASHC is ready to run a new command. | |
static unsigned int | flashc_get_error_status (void) |
Gets the error status of the FLASHC. | |
Bool | flashc_is_lock_error (void) |
Tells whether a Lock Error has occurred during the last function called that issued one or more FLASHC commands. | |
Bool | flashc_is_programming_error (void) |
Tells whether a Programming Error has occurred during the last function called that issued one or more FLASHC commands. | |
Bool | flashc_is_ready (void) |
Tells whether the FLASHC is ready to run a new command. | |
Functions | |
FLASHC Protection Mechanisms | |
void | flashc_activate_security_bit (void) |
Activates the Security bit. | |
unsigned int | flashc_get_bootloader_protected_size (void) |
Gets the bootloader protected size. | |
Bool | flashc_is_external_privileged_fetch_locked (void) |
Tells whether external privileged fetch is locked. | |
Bool | flashc_is_page_region_locked (int page_number) |
Tells whether the region of a page is locked. | |
Bool | flashc_is_region_locked (unsigned int region) |
Tells whether a region is locked. | |
Bool | flashc_is_security_bit_active (void) |
Tells whether the Security bit is active. | |
void | flashc_lock_all_regions (Bool lock) |
Locks or unlocks all regions. | |
void | flashc_lock_external_privileged_fetch (Bool lock) |
Locks or unlocks external privileged fetch. | |
void | flashc_lock_page_region (int page_number, Bool lock) |
Locks or unlocks the region of a page. | |
void | flashc_lock_region (unsigned int region, Bool lock) |
Locks or unlocks a region. | |
unsigned int | flashc_set_bootloader_protected_size (unsigned int bootprot_size) |
Sets the bootloader protected size. | |
Access to Flash Pages | |
void | flashc_clear_page_buffer (void) |
Clears the page buffer. | |
Bool | flashc_erase_all_pages (Bool check) |
Erases all pages within the flash array. | |
Bool | flashc_erase_page (int page_number, Bool check) |
Erases a page. | |
Bool | flashc_erase_user_page (Bool check) |
Erases the User page. | |
Bool | flashc_is_page_erased (void) |
Tells whether the page to which the last Quick Page Read or Quick Page Read User Page command was applied was erased. | |
volatile void * | flashc_memcpy (volatile void *dst, const void *src, size_t nbytes, Bool erase) |
Copies nbytes bytes to the flash destination pointed to by dst from the source pointed to by src. | |
volatile void * | flashc_memset16 (volatile void *dst, U16 src, size_t nbytes, Bool erase) |
Copies nbytes bytes to the flash destination pointed to by dst from the repeated src big-endian source half-word. | |
volatile void * | flashc_memset32 (volatile void *dst, U32 src, size_t nbytes, Bool erase) |
Copies nbytes bytes to the flash destination pointed to by dst from the repeated src big-endian source word. | |
volatile void * | flashc_memset64 (volatile void *dst, U64 src, size_t nbytes, Bool erase) |
Copies nbytes bytes to the flash destination pointed to by dst from the repeated src big-endian source double-word. | |
volatile void * | flashc_memset8 (volatile void *dst, U8 src, size_t nbytes, Bool erase) |
Copies nbytes bytes to the flash destination pointed to by dst from the repeated src source byte. | |
Bool | flashc_quick_page_read (int page_number) |
Applies the Quick Page Read command to a page. | |
Bool | flashc_quick_user_page_read (void) |
Issues a Quick Page Read User Page command to the FLASHC. | |
void | flashc_write_page (int page_number) |
Writes a page from the page buffer. | |
void | flashc_write_user_page (void) |
Writes the User page from the page buffer. | |
FLASHC Control | |
void | flashc_enable_lock_error_int (Bool enable) |
Enables or disables the Lock Error interrupt. | |
void | flashc_enable_prog_error_int (Bool enable) |
Enables or disables the Programming Error interrupt. | |
void | flashc_enable_ready_int (Bool enable) |
Enables or disables the Flash Ready interrupt. | |
unsigned int | flashc_get_wait_state (void) |
Gets the number of wait states of flash read accesses. | |
Bool | flashc_is_lock_error_int_enabled (void) |
Tells whether the Lock Error interrupt is enabled. | |
Bool | flashc_is_prog_error_int_enabled (void) |
Tells whether the Programming Error interrupt is enabled. | |
Bool | flashc_is_ready_int_enabled (void) |
Tells whether the Flash Ready interrupt is enabled. | |
void | flashc_set_wait_state (unsigned int wait_state) |
Sets the number of wait states of flash read accesses. | |
FLASHC Global Commands | |
void | flashc_erase_all (void) |
Issues an Erase All command to the FLASHC. | |
void | flashc_no_operation (void) |
Issues a No Operation command to the FLASHC. | |
Access to General-Purpose Fuses | |
Bool | flashc_erase_all_gp_fuses (Bool check) |
Erases all general-purpose fuses. | |
Bool | flashc_erase_gp_fuse_bit (unsigned int gp_fuse_bit, Bool check) |
Erases a general-purpose fuse bit. | |
Bool | flashc_erase_gp_fuse_bitfield (unsigned int pos, unsigned int width, Bool check) |
Erases a general-purpose fuse bit-field. | |
Bool | flashc_erase_gp_fuse_byte (unsigned int gp_fuse_byte, Bool check) |
Erases a general-purpose fuse byte. | |
U64 | flashc_read_all_gp_fuses (void) |
Reads all general-purpose fuses. | |
Bool | flashc_read_gp_fuse_bit (unsigned int gp_fuse_bit) |
Reads a general-purpose fuse bit. | |
U64 | flashc_read_gp_fuse_bitfield (unsigned int pos, unsigned int width) |
Reads a general-purpose fuse bit-field. | |
U8 | flashc_read_gp_fuse_byte (unsigned int gp_fuse_byte) |
Reads a general-purpose fuse byte. | |
void | flashc_set_all_gp_fuses (U64 value) |
Sets all general-purpose fuses with the appropriate erase and write operations. | |
void | flashc_set_gp_fuse_bit (unsigned int gp_fuse_bit, Bool value) |
Sets a general-purpose fuse bit with the appropriate erase and write operations. | |
void | flashc_set_gp_fuse_bitfield (unsigned int pos, unsigned int width, U64 value) |
Sets a general-purpose fuse bit-field with the appropriate erase and write operations. | |
void | flashc_set_gp_fuse_byte (unsigned int gp_fuse_byte, U8 value) |
Sets a general-purpose fuse byte with the appropriate erase and write operations. | |
void | flashc_write_all_gp_fuses (U64 value) |
Writes all general-purpose fuses. | |
void | flashc_write_gp_fuse_bit (unsigned int gp_fuse_bit, Bool value) |
Writes a general-purpose fuse bit. | |
void | flashc_write_gp_fuse_bitfield (unsigned int pos, unsigned int width, U64 value) |
Writes a general-purpose fuse bit-field. | |
void | flashc_write_gp_fuse_byte (unsigned int gp_fuse_byte, U8 value) |
Writes a general-purpose fuse byte. | |
FLASHC Command Control | |
unsigned int | flashc_get_command (void) |
Gets the last issued FLASHC command. | |
unsigned int | flashc_get_page_number (void) |
Gets the current FLASHC page number. | |
void | flashc_issue_command (unsigned int command, int page_number) |
Issues a FLASHC command. | |
Flash Properties | |
unsigned int | flashc_get_flash_size (void) |
Gets the size of the whole flash array. | |
unsigned int | flashc_get_page_count (void) |
Gets the total number of pages in the flash array. | |
unsigned int | flashc_get_page_count_per_region (void) |
Gets the number of pages in each flash region. | |
unsigned int | flashc_get_page_region (int page_number) |
Gets the region number of a page. | |
unsigned int | flashc_get_region_first_page_number (unsigned int region) |
Gets the number of the first page of a region. |
void flashc_activate_security_bit | ( | void | ) |
Activates the Security bit.
Definition at line 325 of file flashc.c.
References flashc_issue_command().
00326 { 00327 flashc_issue_command(AVR32_FLASHC_FCMD_CMD_SSB, -1); 00328 }
void flashc_clear_page_buffer | ( | void | ) |
Clears the page buffer.
This command resets all bits in the page buffer to one. Write accesses to the page buffer can only change page buffer bits from one to zero.
Definition at line 600 of file flashc.c.
References flashc_issue_command().
Referenced by flashc_memcpy(), and flashc_memset64().
00601 { 00602 flashc_issue_command(AVR32_FLASHC_FCMD_CMD_CPB, -1); 00603 }
void flashc_default_wait_until_ready | ( | void | ) |
Waits actively until the FLASHC is ready to run a new command.
This is the default function assigned to flashc_wait_until_ready.
Definition at line 212 of file flashc.c.
References flashc_is_ready().
00213 { 00214 while (!flashc_is_ready()); 00215 }
void flashc_enable_lock_error_int | ( | Bool | enable | ) |
Enables or disables the Lock Error interrupt.
enable | Whether to enable the Lock Error interrupt: TRUE or FALSE . |
Definition at line 176 of file flashc.c.
References u_avr32_flashc_fcr_t::fcr, and u_avr32_flashc_fcr_t::FCR.
00177 { 00178 u_avr32_flashc_fcr_t u_avr32_flashc_fcr = {AVR32_FLASHC.fcr}; 00179 u_avr32_flashc_fcr.FCR.locke = (enable != FALSE); 00180 AVR32_FLASHC.fcr = u_avr32_flashc_fcr.fcr; 00181 }
void flashc_enable_prog_error_int | ( | Bool | enable | ) |
Enables or disables the Programming Error interrupt.
enable | Whether to enable the Programming Error interrupt: TRUE or FALSE . |
Definition at line 190 of file flashc.c.
References u_avr32_flashc_fcr_t::fcr, and u_avr32_flashc_fcr_t::FCR.
00191 { 00192 u_avr32_flashc_fcr_t u_avr32_flashc_fcr = {AVR32_FLASHC.fcr}; 00193 u_avr32_flashc_fcr.FCR.proge = (enable != FALSE); 00194 AVR32_FLASHC.fcr = u_avr32_flashc_fcr.fcr; 00195 }
void flashc_enable_ready_int | ( | Bool | enable | ) |
Enables or disables the Flash Ready interrupt.
enable | Whether to enable the Flash Ready interrupt: TRUE or FALSE . |
Definition at line 162 of file flashc.c.
References u_avr32_flashc_fcr_t::fcr, and u_avr32_flashc_fcr_t::FCR.
00163 { 00164 u_avr32_flashc_fcr_t u_avr32_flashc_fcr = {AVR32_FLASHC.fcr}; 00165 u_avr32_flashc_fcr.FCR.frdy = (enable != FALSE); 00166 AVR32_FLASHC.fcr = u_avr32_flashc_fcr.fcr; 00167 }
void flashc_erase_all | ( | void | ) |
Issues an Erase All command to the FLASHC.
This command erases all bits in the flash array, the general-purpose fuse bits and the Security bit. The User page is not erased.
This command also ensures that all volatile memories, such as register file and RAMs, are erased before the Security bit is erased, i.e. deactivated.
An erase operation can only set bits.
Definition at line 305 of file flashc.c.
References flashc_issue_command().
00306 { 00307 flashc_issue_command(AVR32_FLASHC_FCMD_CMD_EA, -1); 00308 }
Bool flashc_erase_all_gp_fuses | ( | Bool | check | ) |
Erases all general-purpose fuses.
check | Whether to check erase: TRUE or FALSE . |
TRUE
if erase check was not requested.An erase operation can only set bits.
The actual number of general-purpose fuse bits implemented by hardware is given by AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 480 of file flashc.c.
References flashc_issue_command(), and flashc_read_all_gp_fuses().
Referenced by flashc_erase_gp_fuse_byte(), and flashc_set_all_gp_fuses().
00481 { 00482 flashc_issue_command(AVR32_FLASHC_FCMD_CMD_EAGPF, -1); 00483 return (check) ? (flashc_read_all_gp_fuses() == 0xFFFFFFFFFFFFFFFFULL) : TRUE; 00484 }
Bool flashc_erase_all_pages | ( | Bool | check | ) |
Erases all pages within the flash array.
check | Whether to check erase: TRUE or FALSE . |
TRUE
if erase check was not requested.An erase operation can only set bits.
Definition at line 633 of file flashc.c.
References flashc_erase_page(), flashc_error_status, and flashc_get_page_count().
00634 { 00635 Bool all_pages_erased = TRUE; 00636 unsigned int error_status = 0; 00637 unsigned int page_number = flashc_get_page_count(); 00638 while (page_number) 00639 { 00640 all_pages_erased &= flashc_erase_page(--page_number, check); 00641 error_status |= flashc_error_status; 00642 } 00643 flashc_error_status = error_status; 00644 return all_pages_erased; 00645 }
Bool flashc_erase_gp_fuse_bit | ( | unsigned int | gp_fuse_bit, | |
Bool | check | |||
) |
Erases a general-purpose fuse bit.
gp_fuse_bit | The general-purpose fuse bit: 0 to 63 . | |
check | Whether to check erase: TRUE or FALSE . |
TRUE
if erase check was not requested.An erase operation can only set bits.
The actual number of general-purpose fuse bits implemented by hardware is given by AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 437 of file flashc.c.
References flashc_issue_command(), and flashc_read_gp_fuse_bit().
Referenced by flashc_erase_gp_fuse_bitfield(), and flashc_set_gp_fuse_bit().
00438 { 00439 flashc_issue_command(AVR32_FLASHC_FCMD_CMD_EGPB, gp_fuse_bit & 0x3F); 00440 return (check) ? flashc_read_gp_fuse_bit(gp_fuse_bit) : TRUE; 00441 }
Bool flashc_erase_gp_fuse_bitfield | ( | unsigned int | pos, | |
unsigned int | width, | |||
Bool | check | |||
) |
Erases a general-purpose fuse bit-field.
pos | The bit-position of the general-purpose fuse bit-field: 0 to 63 . | |
width | The bit-width of the general-purpose fuse bit-field: 0 to 64 . | |
check | Whether to check erase: TRUE or FALSE . |
TRUE
if erase check was not requested.An erase operation can only set bits.
The actual number of general-purpose fuse bits implemented by hardware is given by AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 444 of file flashc.c.
References flashc_erase_gp_fuse_bit(), flashc_error_status, and flashc_read_gp_fuse_bitfield().
00445 { 00446 unsigned int error_status = 0; 00447 unsigned int gp_fuse_bit; 00448 pos &= 0x3F; 00449 width = min(width, 64); 00450 for (gp_fuse_bit = pos; gp_fuse_bit < pos + width; gp_fuse_bit++) 00451 { 00452 flashc_erase_gp_fuse_bit(gp_fuse_bit, FALSE); 00453 error_status |= flashc_error_status; 00454 } 00455 flashc_error_status = error_status; 00456 return (check) ? (flashc_read_gp_fuse_bitfield(pos, width) == (1ULL << width) - 1) : TRUE; 00457 }
Bool flashc_erase_gp_fuse_byte | ( | unsigned int | gp_fuse_byte, | |
Bool | check | |||
) |
Erases a general-purpose fuse byte.
gp_fuse_byte | The general-purpose fuse byte: 0 to 7 . | |
check | Whether to check erase: TRUE or FALSE . |
TRUE
if erase check was not requested.An erase operation can only set bits.
The actual number of general-purpose fuse bits implemented by hardware is given by AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 460 of file flashc.c.
References flashc_erase_all_gp_fuses(), flashc_error_status, flashc_read_all_gp_fuses(), flashc_read_gp_fuse_byte(), and flashc_write_gp_fuse_byte().
Referenced by flashc_set_gp_fuse_byte().
00461 { 00462 unsigned int error_status; 00463 unsigned int current_gp_fuse_byte; 00464 U64 value = flashc_read_all_gp_fuses(); 00465 flashc_erase_all_gp_fuses(FALSE); 00466 error_status = flashc_error_status; 00467 for (current_gp_fuse_byte = 0; current_gp_fuse_byte < 8; current_gp_fuse_byte++, value >>= 8) 00468 { 00469 if (current_gp_fuse_byte != gp_fuse_byte) 00470 { 00471 flashc_write_gp_fuse_byte(current_gp_fuse_byte, value); 00472 error_status |= flashc_error_status; 00473 } 00474 } 00475 flashc_error_status = error_status; 00476 return (check) ? (flashc_read_gp_fuse_byte(gp_fuse_byte) == 0xFF) : TRUE; 00477 }
Bool flashc_erase_page | ( | int | page_number, | |
Bool | check | |||
) |
Erases a page.
page_number | The page number:
| |
check | Whether to check erase: TRUE or FALSE . |
TRUE
if erase check was not requested.An erase operation can only set bits.
Definition at line 619 of file flashc.c.
References flashc_error_status, flashc_issue_command(), and flashc_quick_page_read().
Referenced by flashc_erase_all_pages(), flashc_memcpy(), and flashc_memset64().
00620 { 00621 Bool page_erased = TRUE; 00622 flashc_issue_command(AVR32_FLASHC_FCMD_CMD_EP, page_number); 00623 if (check) 00624 { 00625 unsigned int error_status = flashc_error_status; 00626 page_erased = flashc_quick_page_read(-1); 00627 flashc_error_status |= error_status; 00628 } 00629 return page_erased; 00630 }
Bool flashc_erase_user_page | ( | Bool | check | ) |
Erases the User page.
check | Whether to check erase: TRUE or FALSE . |
TRUE
if erase check was not requested.An erase operation can only set bits.
Definition at line 661 of file flashc.c.
References flashc_issue_command(), and flashc_quick_user_page_read().
Referenced by flashc_memcpy(), and flashc_memset64().
00662 { 00663 flashc_issue_command(AVR32_FLASHC_FCMD_CMD_EUP, -1); 00664 return (check) ? flashc_quick_user_page_read() : TRUE; 00665 }
unsigned int flashc_get_bootloader_protected_size | ( | void | ) |
Gets the bootloader protected size.
Definition at line 331 of file flashc.c.
References flashc_read_gp_fuse_bitfield().
Referenced by flashc_set_bootloader_protected_size().
00332 { 00333 unsigned int bootprot = (1 << AVR32_FLASHC_FGPFRLO_BOOTPROT_SIZE) - 1 - 00334 flashc_read_gp_fuse_bitfield(AVR32_FLASHC_FGPFRLO_BOOTPROT_OFFSET, 00335 AVR32_FLASHC_FGPFRLO_BOOTPROT_SIZE); 00336 return (bootprot) ? AVR32_FLASHC_PAGE_SIZE << bootprot : 0; 00337 }
unsigned int flashc_get_command | ( | void | ) |
static unsigned int flashc_get_error_status | ( | void | ) | [static] |
Gets the error status of the FLASHC.
AVR32_FLASHC_FSR_LOCKE_MASK
and AVR32_FLASHC_FSR_PROGE_MASK
.Definition at line 231 of file flashc.c.
Referenced by flashc_issue_command().
00232 { 00233 return AVR32_FLASHC.fsr & (AVR32_FLASHC_FSR_LOCKE_MASK | 00234 AVR32_FLASHC_FSR_PROGE_MASK); 00235 }
unsigned int flashc_get_flash_size | ( | void | ) |
Gets the size of the whole flash array.
Definition at line 78 of file flashc.c.
Referenced by flashc_get_page_count(), flashc_memcpy(), and flashc_memset64().
00079 { 00080 #if (defined AVR32_FLASHC_300_H_INCLUDED) 00081 static const unsigned int FLASH_SIZE[1 << AVR32_FLASHC_PR_FSZ_SIZE] = 00082 { 00083 32 << 10, 00084 64 << 10, 00085 128 << 10, 00086 256 << 10, 00087 384 << 10, 00088 512 << 10, 00089 768 << 10, 00090 1024 << 10 00091 }; 00092 return FLASH_SIZE[(AVR32_FLASHC.pr & AVR32_FLASHC_PR_FSZ_MASK) >> AVR32_FLASHC_PR_FSZ_OFFSET]; 00093 #else 00094 static const unsigned int FLASH_SIZE[1 << AVR32_FLASHC_FSR_FSZ_SIZE] = 00095 { 00096 32 << 10, 00097 64 << 10, 00098 128 << 10, 00099 256 << 10, 00100 384 << 10, 00101 512 << 10, 00102 768 << 10, 00103 1024 << 10 00104 }; 00105 return FLASH_SIZE[(AVR32_FLASHC.fsr & AVR32_FLASHC_FSR_FSZ_MASK) >> AVR32_FLASHC_FSR_FSZ_OFFSET]; 00106 #endif 00107 }
unsigned int flashc_get_page_count | ( | void | ) |
Gets the total number of pages in the flash array.
Definition at line 110 of file flashc.c.
References flashc_get_flash_size().
Referenced by flashc_erase_all_pages(), and flashc_get_page_count_per_region().
00111 { 00112 return flashc_get_flash_size() / AVR32_FLASHC_PAGE_SIZE; 00113 }
unsigned int flashc_get_page_count_per_region | ( | void | ) |
Gets the number of pages in each flash region.
Definition at line 116 of file flashc.c.
References AVR32_FLASHC_REGIONS, and flashc_get_page_count().
Referenced by flashc_get_page_region(), and flashc_get_region_first_page_number().
00117 { 00118 return flashc_get_page_count() / AVR32_FLASHC_REGIONS; 00119 }
unsigned int flashc_get_page_number | ( | void | ) |
Gets the current FLASHC page number.
Definition at line 271 of file flashc.c.
Referenced by flashc_get_page_region().
00272 { 00273 return (AVR32_FLASHC.fcmd & AVR32_FLASHC_FCMD_PAGEN_MASK) >> AVR32_FLASHC_FCMD_PAGEN_OFFSET; 00274 }
unsigned int flashc_get_page_region | ( | int | page_number | ) |
Gets the region number of a page.
page_number | The page number:
|
Definition at line 122 of file flashc.c.
References flashc_get_page_count_per_region(), and flashc_get_page_number().
Referenced by flashc_is_page_region_locked().
00123 { 00124 return ((page_number >= 0) ? page_number : flashc_get_page_number()) / flashc_get_page_count_per_region(); 00125 }
unsigned int flashc_get_region_first_page_number | ( | unsigned int | region | ) |
Gets the number of the first page of a region.
region | The region number: 0 to (AVR32_FLASHC_REGIONS - 1) . |
Definition at line 128 of file flashc.c.
References flashc_get_page_count_per_region().
Referenced by flashc_lock_region().
00129 { 00130 return region * flashc_get_page_count_per_region(); 00131 }
unsigned int flashc_get_wait_state | ( | void | ) |
Bool flashc_is_external_privileged_fetch_locked | ( | void | ) |
Tells whether external privileged fetch is locked.
Definition at line 356 of file flashc.c.
References flashc_read_gp_fuse_bit().
00357 { 00358 return (!flashc_read_gp_fuse_bit(AVR32_FLASHC_FGPFRLO_EPFL_OFFSET)); 00359 }
Bool flashc_is_lock_error | ( | void | ) |
Tells whether a Lock Error has occurred during the last function called that issued one or more FLASHC commands.
Definition at line 245 of file flashc.c.
References flashc_error_status.
00246 { 00247 return ((flashc_error_status & AVR32_FLASHC_FSR_LOCKE_MASK) != 0); 00248 }
Bool flashc_is_lock_error_int_enabled | ( | void | ) |
Bool flashc_is_page_erased | ( | void | ) |
Tells whether the page to which the last Quick Page Read or Quick Page Read User Page command was applied was erased.
Definition at line 606 of file flashc.c.
Referenced by flashc_quick_page_read(), and flashc_quick_user_page_read().
Bool flashc_is_page_region_locked | ( | int | page_number | ) |
Tells whether the region of a page is locked.
page_number | The page number:
|
Definition at line 368 of file flashc.c.
References flashc_get_page_region(), and flashc_is_region_locked().
00369 { 00370 return flashc_is_region_locked(flashc_get_page_region(page_number)); 00371 }
Bool flashc_is_prog_error_int_enabled | ( | void | ) |
Bool flashc_is_programming_error | ( | void | ) |
Tells whether a Programming Error has occurred during the last function called that issued one or more FLASHC commands.
Definition at line 251 of file flashc.c.
References flashc_error_status.
00252 { 00253 return ((flashc_error_status & AVR32_FLASHC_FSR_PROGE_MASK) != 0); 00254 }
Bool flashc_is_ready | ( | void | ) |
Tells whether the FLASHC is ready to run a new command.
Definition at line 206 of file flashc.c.
Referenced by flashc_default_wait_until_ready().
Bool flashc_is_ready_int_enabled | ( | void | ) |
Bool flashc_is_region_locked | ( | unsigned int | region | ) |
Tells whether a region is locked.
region | The region number: 0 to (AVR32_FLASHC_REGIONS - 1) . |
Definition at line 374 of file flashc.c.
References AVR32_FLASHC_REGIONS.
Referenced by flashc_is_page_region_locked().
00375 { 00376 return ((AVR32_FLASHC.fsr & AVR32_FLASHC_FSR_LOCK0_MASK << (region & (AVR32_FLASHC_REGIONS - 1))) != 0); 00377 }
Bool flashc_is_security_bit_active | ( | void | ) |
void flashc_issue_command | ( | unsigned int | command, | |
int | page_number | |||
) |
Issues a FLASHC command.
command | The command: AVR32_FLASHC_FCMD_CMD_x . | |
page_number | The page number to apply the command to:
|
A Programming Error is issued if the command is invalid.
Definition at line 277 of file flashc.c.
References u_avr32_flashc_fcmd_t::FCMD, u_avr32_flashc_fcmd_t::fcmd, flashc_error_status, flashc_get_error_status(), and flashc_wait_until_ready.
Referenced by flashc_activate_security_bit(), flashc_clear_page_buffer(), flashc_erase_all(), flashc_erase_all_gp_fuses(), flashc_erase_gp_fuse_bit(), flashc_erase_page(), flashc_erase_user_page(), flashc_lock_page_region(), flashc_no_operation(), flashc_quick_page_read(), flashc_quick_user_page_read(), flashc_write_gp_fuse_bit(), flashc_write_gp_fuse_byte(), flashc_write_page(), and flashc_write_user_page().
00278 { 00279 u_avr32_flashc_fcmd_t u_avr32_flashc_fcmd; 00280 flashc_wait_until_ready(); 00281 u_avr32_flashc_fcmd.fcmd = AVR32_FLASHC.fcmd; 00282 u_avr32_flashc_fcmd.FCMD.cmd = command; 00283 if (page_number >= 0) u_avr32_flashc_fcmd.FCMD.pagen = page_number; 00284 u_avr32_flashc_fcmd.FCMD.key = AVR32_FLASHC_FCMD_KEY_KEY; 00285 AVR32_FLASHC.fcmd = u_avr32_flashc_fcmd.fcmd; 00286 flashc_error_status = flashc_get_error_status(); 00287 flashc_wait_until_ready(); 00288 }
void flashc_lock_all_regions | ( | Bool | lock | ) |
Locks or unlocks all regions.
lock | Whether to lock the regions: TRUE or FALSE . |
Definition at line 392 of file flashc.c.
References AVR32_FLASHC_REGIONS, flashc_error_status, and flashc_lock_region().
00393 { 00394 unsigned int error_status = 0; 00395 unsigned int region = AVR32_FLASHC_REGIONS; 00396 while (region) 00397 { 00398 flashc_lock_region(--region, lock); 00399 error_status |= flashc_error_status; 00400 } 00401 flashc_error_status = error_status; 00402 }
void flashc_lock_external_privileged_fetch | ( | Bool | lock | ) |
Locks or unlocks external privileged fetch.
lock | Whether to lock external privileged fetch: TRUE or FALSE . |
Definition at line 362 of file flashc.c.
References flashc_set_gp_fuse_bit().
00363 { 00364 flashc_set_gp_fuse_bit(AVR32_FLASHC_FGPFRLO_EPFL_OFFSET, !lock); 00365 }
void flashc_lock_page_region | ( | int | page_number, | |
Bool | lock | |||
) |
Locks or unlocks the region of a page.
page_number | The page number:
| |
lock | Whether to lock the region of the specified page: TRUE or FALSE . |
Definition at line 380 of file flashc.c.
References flashc_issue_command().
Referenced by flashc_lock_region().
00381 { 00382 flashc_issue_command((lock) ? AVR32_FLASHC_FCMD_CMD_LP : AVR32_FLASHC_FCMD_CMD_UP, page_number); 00383 }
void flashc_lock_region | ( | unsigned int | region, | |
Bool | lock | |||
) |
Locks or unlocks a region.
region | The region number: 0 to (AVR32_FLASHC_REGIONS - 1) . | |
lock | Whether to lock the specified region: TRUE or FALSE . |
Definition at line 386 of file flashc.c.
References flashc_get_region_first_page_number(), and flashc_lock_page_region().
Referenced by flashc_lock_all_regions().
00387 { 00388 flashc_lock_page_region(flashc_get_region_first_page_number(region), lock); 00389 }
volatile void* flashc_memcpy | ( | volatile void * | dst, | |
const void * | src, | |||
size_t | nbytes, | |||
Bool | erase | |||
) |
Copies nbytes bytes to the flash destination pointed to by dst from the source pointed to by src.
The destination areas that are not within the flash array or the User page are ignored.
All pointer and size alignments are supported.
dst | Pointer to flash destination. | |
src | Pointer to source data. | |
nbytes | Number of bytes to copy. | |
erase | Whether to erase before writing: TRUE or FALSE . |
This function may be called with erase set to FALSE
only if the destination consists only of erased words, i.e. this function can not be used to write only one bit of a previously written word. E.g., if 0x00000001
then 0xFFFFFFFE
are written to a word, the resulting value in flash may be different from 0x00000000
.
A Lock Error is issued if the command is applied to pages belonging to a locked region or to the bootloader protected area.
Definition at line 865 of file flashc.c.
References flashc_clear_page_buffer(), flashc_erase_page(), flashc_erase_user_page(), flashc_error_status, flashc_get_flash_size(), flashc_write_page(), and flashc_write_user_page().
Referenced by flash_rw_example().
00866 { 00867 // Use aggregated pointers to have several alignments available for a same address. 00868 UnionCVPtr flash_array_end; 00869 UnionVPtr dest; 00870 UnionCPtr source; 00871 StructCVPtr dest_end; 00872 UnionCVPtr flash_page_source_end; 00873 Bool incomplete_flash_page_end; 00874 Union64 flash_dword; 00875 Bool flash_dword_pending = FALSE; 00876 UnionVPtr tmp; 00877 unsigned int error_status = 0; 00878 unsigned int i, j; 00879 00880 // Reformat arguments. 00881 flash_array_end.u8ptr = AVR32_FLASH + flashc_get_flash_size(); 00882 dest.u8ptr = dst; 00883 source.u8ptr = src; 00884 dest_end.u8ptr = dest.u8ptr + nbytes; 00885 00886 // If destination is outside flash, go to next flash page if any. 00887 if (dest.u8ptr < AVR32_FLASH) 00888 { 00889 source.u8ptr += AVR32_FLASH - dest.u8ptr; 00890 dest.u8ptr = AVR32_FLASH; 00891 } 00892 else if (flash_array_end.u8ptr <= dest.u8ptr && dest.u8ptr < AVR32_FLASHC_USER_PAGE) 00893 { 00894 source.u8ptr += AVR32_FLASHC_USER_PAGE - dest.u8ptr; 00895 dest.u8ptr = AVR32_FLASHC_USER_PAGE; 00896 } 00897 00898 // If end of destination is outside flash, move it to the end of the previous flash page if any. 00899 if (dest_end.u8ptr > AVR32_FLASHC_USER_PAGE + AVR32_FLASHC_USER_PAGE_SIZE) 00900 { 00901 dest_end.u8ptr = AVR32_FLASHC_USER_PAGE + AVR32_FLASHC_USER_PAGE_SIZE; 00902 } 00903 else if (AVR32_FLASHC_USER_PAGE >= dest_end.u8ptr && dest_end.u8ptr > flash_array_end.u8ptr) 00904 { 00905 dest_end.u8ptr = flash_array_end.u8ptr; 00906 } 00907 00908 // Align each end of destination pointer with its natural boundary. 00909 dest_end.u16ptr = (U16 *)Align_down((U32)dest_end.u8ptr, sizeof(U16)); 00910 dest_end.u32ptr = (U32 *)Align_down((U32)dest_end.u16ptr, sizeof(U32)); 00911 dest_end.u64ptr = (U64 *)Align_down((U32)dest_end.u32ptr, sizeof(U64)); 00912 00913 // While end of destination is not reached... 00914 while (dest.u8ptr < dest_end.u8ptr) 00915 { 00916 // Clear the page buffer in order to prepare data for a flash page write. 00917 flashc_clear_page_buffer(); 00918 error_status |= flashc_error_status; 00919 00920 // Determine where the source data will end in the current flash page. 00921 flash_page_source_end.u64ptr = 00922 (U64 *)min((U32)dest_end.u64ptr, 00923 Align_down((U32)dest.u8ptr, AVR32_FLASHC_PAGE_SIZE) + AVR32_FLASHC_PAGE_SIZE); 00924 00925 // Determine if the current destination page has an incomplete end. 00926 incomplete_flash_page_end = (Align_down((U32)dest.u8ptr, AVR32_FLASHC_PAGE_SIZE) >= 00927 Align_down((U32)dest_end.u8ptr, AVR32_FLASHC_PAGE_SIZE)); 00928 00929 // If destination does not point to the beginning of the current flash page... 00930 if (!Test_align((U32)dest.u8ptr, AVR32_FLASHC_PAGE_SIZE)) 00931 { 00932 // Fill the beginning of the page buffer with the current flash page data. 00933 // This is required by the hardware, even if page erase is not requested, 00934 // in order to be able to write successfully to erased parts of flash 00935 // pages that have already been written to. 00936 for (tmp.u8ptr = (U8 *)Align_down((U32)dest.u8ptr, AVR32_FLASHC_PAGE_SIZE); 00937 tmp.u64ptr < (U64 *)Align_down((U32)dest.u8ptr, sizeof(U64)); 00938 tmp.u64ptr++) 00939 *tmp.u64ptr = *tmp.u64ptr; 00940 00941 // If destination is not 64-bit aligned... 00942 if (!Test_align((U32)dest.u8ptr, sizeof(U64))) 00943 { 00944 // Fill the beginning of the flash double-word buffer with the current 00945 // flash page data. 00946 // This is required by the hardware, even if page erase is not 00947 // requested, in order to be able to write successfully to erased parts 00948 // of flash pages that have already been written to. 00949 for (i = 0; i < Get_align((U32)dest.u8ptr, sizeof(U64)); i++) 00950 flash_dword.u8[i] = *tmp.u8ptr++; 00951 00952 // Fill the end of the flash double-word buffer with the source data. 00953 for (; i < sizeof(U64); i++) 00954 flash_dword.u8[i] = *source.u8ptr++; 00955 00956 // Align the destination pointer with its 64-bit boundary. 00957 dest.u64ptr = (U64 *)Align_down((U32)dest.u8ptr, sizeof(U64)); 00958 00959 // If the current destination double-word is not the last one... 00960 if (dest.u64ptr < dest_end.u64ptr) 00961 { 00962 // Write the flash double-word buffer to the page buffer. 00963 *dest.u64ptr++ = flash_dword.u64; 00964 } 00965 // If the current destination double-word is the last one, the flash 00966 // double-word buffer must be kept for later. 00967 else flash_dword_pending = TRUE; 00968 } 00969 } 00970 00971 // Read the source data with the maximal possible alignment and write it to 00972 // the page buffer with 64-bit alignment. 00973 switch (Get_align((U32)source.u8ptr, sizeof(U32))) 00974 { 00975 case 0: 00976 for (i = flash_page_source_end.u64ptr - dest.u64ptr; i; i--) 00977 *dest.u64ptr++ = *source.u64ptr++; 00978 break; 00979 00980 case sizeof(U16): 00981 for (i = flash_page_source_end.u64ptr - dest.u64ptr; i; i--) 00982 { 00983 for (j = 0; j < sizeof(U64) / sizeof(U16); j++) flash_dword.u16[j] = *source.u16ptr++; 00984 *dest.u64ptr++ = flash_dword.u64; 00985 } 00986 break; 00987 00988 default: 00989 for (i = flash_page_source_end.u64ptr - dest.u64ptr; i; i--) 00990 { 00991 for (j = 0; j < sizeof(U64); j++) flash_dword.u8[j] = *source.u8ptr++; 00992 *dest.u64ptr++ = flash_dword.u64; 00993 } 00994 } 00995 00996 // If the current destination page has an incomplete end... 00997 if (incomplete_flash_page_end) 00998 { 00999 // If the flash double-word buffer is in use, do not initialize it. 01000 if (flash_dword_pending) i = Get_align((U32)dest_end.u8ptr, sizeof(U64)); 01001 // If the flash double-word buffer is free... 01002 else 01003 { 01004 // Fill the beginning of the flash double-word buffer with the source data. 01005 for (i = 0; i < Get_align((U32)dest_end.u8ptr, sizeof(U64)); i++) 01006 flash_dword.u8[i] = *source.u8ptr++; 01007 } 01008 01009 // This is required by the hardware, even if page erase is not requested, 01010 // in order to be able to write successfully to erased parts of flash 01011 // pages that have already been written to. 01012 { 01013 tmp.u8ptr = (volatile U8 *)dest_end.u8ptr; 01014 01015 // If end of destination is not 64-bit aligned... 01016 if (!Test_align((U32)dest_end.u8ptr, sizeof(U64))) 01017 { 01018 // Fill the end of the flash double-word buffer with the current flash page data. 01019 for (; i < sizeof(U64); i++) 01020 flash_dword.u8[i] = *tmp.u8ptr++; 01021 01022 // Write the flash double-word buffer to the page buffer. 01023 *dest.u64ptr++ = flash_dword.u64; 01024 } 01025 01026 // Fill the end of the page buffer with the current flash page data. 01027 for (; !Test_align((U32)tmp.u64ptr, AVR32_FLASHC_PAGE_SIZE); tmp.u64ptr++) 01028 *tmp.u64ptr = *tmp.u64ptr; 01029 } 01030 } 01031 01032 // If the current flash page is in the flash array... 01033 if (dest.u8ptr <= AVR32_FLASHC_USER_PAGE) 01034 { 01035 // Erase the current page if requested and write it from the page buffer. 01036 if (erase) 01037 { 01038 flashc_erase_page(-1, FALSE); 01039 error_status |= flashc_error_status; 01040 } 01041 flashc_write_page(-1); 01042 error_status |= flashc_error_status; 01043 01044 // If the end of the flash array is reached, go to the User page. 01045 if (dest.u8ptr >= flash_array_end.u8ptr) 01046 { 01047 source.u8ptr += AVR32_FLASHC_USER_PAGE - dest.u8ptr; 01048 dest.u8ptr = AVR32_FLASHC_USER_PAGE; 01049 } 01050 } 01051 // If the current flash page is the User page... 01052 else 01053 { 01054 // Erase the User page if requested and write it from the page buffer. 01055 if (erase) 01056 { 01057 flashc_erase_user_page(FALSE); 01058 error_status |= flashc_error_status; 01059 } 01060 flashc_write_user_page(); 01061 error_status |= flashc_error_status; 01062 } 01063 } 01064 01065 // Update the FLASHC error status. 01066 flashc_error_status = error_status; 01067 01068 // Return the initial destination pointer as the standard memcpy function does. 01069 return dst; 01070 }
volatile void* flashc_memset16 | ( | volatile void * | dst, | |
U16 | src, | |||
size_t | nbytes, | |||
Bool | erase | |||
) |
Copies nbytes bytes to the flash destination pointed to by dst from the repeated src big-endian source half-word.
The destination areas that are not within the flash array or the User page are ignored.
All pointer and size alignments are supported.
dst | Pointer to flash destination. | |
src | Source half-word. | |
nbytes | Number of bytes to set. | |
erase | Whether to erase before writing: TRUE or FALSE . |
FALSE
only if the destination consists only of erased words, i.e. this function can not be used to write only one bit of a previously written word. E.g., if 0x00000001
then 0xFFFFFFFE
are written to a word, the resulting value in flash may be different from 0x00000000
.A Lock Error is issued if the command is applied to pages belonging to a locked region or to the bootloader protected area.
Definition at line 680 of file flashc.c.
References flashc_memset32().
Referenced by flashc_memset8().
00681 { 00682 return flashc_memset32(dst, src | (U32)src << 16, nbytes, erase); 00683 }
volatile void* flashc_memset32 | ( | volatile void * | dst, | |
U32 | src, | |||
size_t | nbytes, | |||
Bool | erase | |||
) |
Copies nbytes bytes to the flash destination pointed to by dst from the repeated src big-endian source word.
The destination areas that are not within the flash array or the User page are ignored.
All pointer and size alignments are supported.
dst | Pointer to flash destination. | |
src | Source word. | |
nbytes | Number of bytes to set. | |
erase | Whether to erase before writing: TRUE or FALSE . |
FALSE
only if the destination consists only of erased words, i.e. this function can not be used to write only one bit of a previously written word. E.g., if 0x00000001
then 0xFFFFFFFE
are written to a word, the resulting value in flash may be different from 0x00000000
.A Lock Error is issued if the command is applied to pages belonging to a locked region or to the bootloader protected area.
Definition at line 686 of file flashc.c.
References flashc_memset64().
Referenced by flashc_memset16().
00687 { 00688 return flashc_memset64(dst, src | (U64)src << 32, nbytes, erase); 00689 }
volatile void* flashc_memset64 | ( | volatile void * | dst, | |
U64 | src, | |||
size_t | nbytes, | |||
Bool | erase | |||
) |
Copies nbytes bytes to the flash destination pointed to by dst from the repeated src big-endian source double-word.
The destination areas that are not within the flash array or the User page are ignored.
All pointer and size alignments are supported.
dst | Pointer to flash destination. | |
src | Source double-word. | |
nbytes | Number of bytes to set. | |
erase | Whether to erase before writing: TRUE or FALSE . |
FALSE
only if the destination consists only of erased words, i.e. this function can not be used to write only one bit of a previously written word. E.g., if 0x00000001
then 0xFFFFFFFE
are written to a word, the resulting value in flash may be different from 0x00000000
.A Lock Error is issued if the command is applied to pages belonging to a locked region or to the bootloader protected area.
Definition at line 692 of file flashc.c.
References flashc_clear_page_buffer(), flashc_erase_page(), flashc_erase_user_page(), flashc_error_status, flashc_get_flash_size(), flashc_write_page(), and flashc_write_user_page().
Referenced by flashc_memset32().
00693 { 00694 // Use aggregated pointers to have several alignments available for a same address. 00695 UnionCVPtr flash_array_end; 00696 UnionVPtr dest; 00697 Union64 source = {0}; 00698 StructCVPtr dest_end; 00699 UnionCVPtr flash_page_source_end; 00700 Bool incomplete_flash_page_end; 00701 Union64 flash_dword; 00702 UnionVPtr tmp; 00703 unsigned int error_status = 0; 00704 unsigned int i; 00705 00706 // Reformat arguments. 00707 flash_array_end.u8ptr = AVR32_FLASH + flashc_get_flash_size(); 00708 dest.u8ptr = dst; 00709 for (i = (Get_align((U32)dest.u8ptr, sizeof(U64)) - 1) & (sizeof(U64) - 1); 00710 src; i = (i - 1) & (sizeof(U64) - 1)) 00711 { 00712 source.u8[i] = src; 00713 src >>= 8; 00714 } 00715 dest_end.u8ptr = dest.u8ptr + nbytes; 00716 00717 // If destination is outside flash, go to next flash page if any. 00718 if (dest.u8ptr < AVR32_FLASH) 00719 { 00720 dest.u8ptr = AVR32_FLASH; 00721 } 00722 else if (flash_array_end.u8ptr <= dest.u8ptr && dest.u8ptr < AVR32_FLASHC_USER_PAGE) 00723 { 00724 dest.u8ptr = AVR32_FLASHC_USER_PAGE; 00725 } 00726 00727 // If end of destination is outside flash, move it to the end of the previous flash page if any. 00728 if (dest_end.u8ptr > AVR32_FLASHC_USER_PAGE + AVR32_FLASHC_USER_PAGE_SIZE) 00729 { 00730 dest_end.u8ptr = AVR32_FLASHC_USER_PAGE + AVR32_FLASHC_USER_PAGE_SIZE; 00731 } 00732 else if (AVR32_FLASHC_USER_PAGE >= dest_end.u8ptr && dest_end.u8ptr > flash_array_end.u8ptr) 00733 { 00734 dest_end.u8ptr = flash_array_end.u8ptr; 00735 } 00736 00737 // Align each end of destination pointer with its natural boundary. 00738 dest_end.u16ptr = (U16 *)Align_down((U32)dest_end.u8ptr, sizeof(U16)); 00739 dest_end.u32ptr = (U32 *)Align_down((U32)dest_end.u16ptr, sizeof(U32)); 00740 dest_end.u64ptr = (U64 *)Align_down((U32)dest_end.u32ptr, sizeof(U64)); 00741 00742 // While end of destination is not reached... 00743 while (dest.u8ptr < dest_end.u8ptr) 00744 { 00745 // Clear the page buffer in order to prepare data for a flash page write. 00746 flashc_clear_page_buffer(); 00747 error_status |= flashc_error_status; 00748 00749 // Determine where the source data will end in the current flash page. 00750 flash_page_source_end.u64ptr = 00751 (U64 *)min((U32)dest_end.u64ptr, 00752 Align_down((U32)dest.u8ptr, AVR32_FLASHC_PAGE_SIZE) + AVR32_FLASHC_PAGE_SIZE); 00753 00754 // Determine if the current destination page has an incomplete end. 00755 incomplete_flash_page_end = (Align_down((U32)dest.u8ptr, AVR32_FLASHC_PAGE_SIZE) >= 00756 Align_down((U32)dest_end.u8ptr, AVR32_FLASHC_PAGE_SIZE)); 00757 00758 // Use a flash double-word buffer to manage unaligned accesses. 00759 flash_dword.u64 = source.u64; 00760 00761 // If destination does not point to the beginning of the current flash page... 00762 if (!Test_align((U32)dest.u8ptr, AVR32_FLASHC_PAGE_SIZE)) 00763 { 00764 // Fill the beginning of the page buffer with the current flash page data. 00765 // This is required by the hardware, even if page erase is not requested, 00766 // in order to be able to write successfully to erased parts of flash 00767 // pages that have already been written to. 00768 for (tmp.u8ptr = (U8 *)Align_down((U32)dest.u8ptr, AVR32_FLASHC_PAGE_SIZE); 00769 tmp.u64ptr < (U64 *)Align_down((U32)dest.u8ptr, sizeof(U64)); 00770 tmp.u64ptr++) 00771 *tmp.u64ptr = *tmp.u64ptr; 00772 00773 // If destination is not 64-bit aligned... 00774 if (!Test_align((U32)dest.u8ptr, sizeof(U64))) 00775 { 00776 // Fill the beginning of the flash double-word buffer with the current 00777 // flash page data. 00778 // This is required by the hardware, even if page erase is not 00779 // requested, in order to be able to write successfully to erased parts 00780 // of flash pages that have already been written to. 00781 for (i = 0; i < Get_align((U32)dest.u8ptr, sizeof(U64)); i++) 00782 flash_dword.u8[i] = *tmp.u8ptr++; 00783 00784 // Align the destination pointer with its 64-bit boundary. 00785 dest.u64ptr = (U64 *)Align_down((U32)dest.u8ptr, sizeof(U64)); 00786 00787 // If the current destination double-word is not the last one... 00788 if (dest.u64ptr < dest_end.u64ptr) 00789 { 00790 // Write the flash double-word buffer to the page buffer and reinitialize it. 00791 *dest.u64ptr++ = flash_dword.u64; 00792 flash_dword.u64 = source.u64; 00793 } 00794 } 00795 } 00796 00797 // Write the source data to the page buffer with 64-bit alignment. 00798 for (i = flash_page_source_end.u64ptr - dest.u64ptr; i; i--) 00799 *dest.u64ptr++ = source.u64; 00800 00801 // If the current destination page has an incomplete end... 00802 if (incomplete_flash_page_end) 00803 { 00804 // This is required by the hardware, even if page erase is not requested, 00805 // in order to be able to write successfully to erased parts of flash 00806 // pages that have already been written to. 00807 { 00808 tmp.u8ptr = (volatile U8 *)dest_end.u8ptr; 00809 00810 // If end of destination is not 64-bit aligned... 00811 if (!Test_align((U32)dest_end.u8ptr, sizeof(U64))) 00812 { 00813 // Fill the end of the flash double-word buffer with the current flash page data. 00814 for (i = Get_align((U32)dest_end.u8ptr, sizeof(U64)); i < sizeof(U64); i++) 00815 flash_dword.u8[i] = *tmp.u8ptr++; 00816 00817 // Write the flash double-word buffer to the page buffer. 00818 *dest.u64ptr++ = flash_dword.u64; 00819 } 00820 00821 // Fill the end of the page buffer with the current flash page data. 00822 for (; !Test_align((U32)tmp.u64ptr, AVR32_FLASHC_PAGE_SIZE); tmp.u64ptr++) 00823 *tmp.u64ptr = *tmp.u64ptr; 00824 } 00825 } 00826 00827 // If the current flash page is in the flash array... 00828 if (dest.u8ptr <= AVR32_FLASHC_USER_PAGE) 00829 { 00830 // Erase the current page if requested and write it from the page buffer. 00831 if (erase) 00832 { 00833 flashc_erase_page(-1, FALSE); 00834 error_status |= flashc_error_status; 00835 } 00836 flashc_write_page(-1); 00837 error_status |= flashc_error_status; 00838 00839 // If the end of the flash array is reached, go to the User page. 00840 if (dest.u8ptr >= flash_array_end.u8ptr) 00841 dest.u8ptr = AVR32_FLASHC_USER_PAGE; 00842 } 00843 // If the current flash page is the User page... 00844 else 00845 { 00846 // Erase the User page if requested and write it from the page buffer. 00847 if (erase) 00848 { 00849 flashc_erase_user_page(FALSE); 00850 error_status |= flashc_error_status; 00851 } 00852 flashc_write_user_page(); 00853 error_status |= flashc_error_status; 00854 } 00855 } 00856 00857 // Update the FLASHC error status. 00858 flashc_error_status = error_status; 00859 00860 // Return the initial destination pointer as the standard memset function does. 00861 return dst; 00862 }
volatile void* flashc_memset8 | ( | volatile void * | dst, | |
U8 | src, | |||
size_t | nbytes, | |||
Bool | erase | |||
) |
Copies nbytes bytes to the flash destination pointed to by dst from the repeated src source byte.
The destination areas that are not within the flash array or the User page are ignored.
All pointer and size alignments are supported.
dst | Pointer to flash destination. | |
src | Source byte. | |
nbytes | Number of bytes to set. | |
erase | Whether to erase before writing: TRUE or FALSE . |
FALSE
only if the destination consists only of erased words, i.e. this function can not be used to write only one bit of a previously written word. E.g., if 0x00000001
then 0xFFFFFFFE
are written to a word, the resulting value in flash may be different from 0x00000000
.A Lock Error is issued if the command is applied to pages belonging to a locked region or to the bootloader protected area.
Definition at line 674 of file flashc.c.
References flashc_memset16().
00675 { 00676 return flashc_memset16(dst, src | (U16)src << 8, nbytes, erase); 00677 }
void flashc_no_operation | ( | void | ) |
Issues a No Operation command to the FLASHC.
Definition at line 299 of file flashc.c.
References flashc_issue_command().
00300 { 00301 flashc_issue_command(AVR32_FLASHC_FCMD_CMD_NOP, -1); 00302 }
Bool flashc_quick_page_read | ( | int | page_number | ) |
Applies the Quick Page Read command to a page.
page_number | The page number:
|
Definition at line 612 of file flashc.c.
References flashc_is_page_erased(), and flashc_issue_command().
Referenced by flashc_erase_page().
00613 { 00614 flashc_issue_command(AVR32_FLASHC_FCMD_CMD_QPR, page_number); 00615 return flashc_is_page_erased(); 00616 }
Bool flashc_quick_user_page_read | ( | void | ) |
Issues a Quick Page Read User Page command to the FLASHC.
Definition at line 654 of file flashc.c.
References flashc_is_page_erased(), and flashc_issue_command().
Referenced by flashc_erase_user_page().
00655 { 00656 flashc_issue_command(AVR32_FLASHC_FCMD_CMD_QPRUP, -1); 00657 return flashc_is_page_erased(); 00658 }
U64 flashc_read_all_gp_fuses | ( | void | ) |
Reads all general-purpose fuses.
AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware. Definition at line 431 of file flashc.c.
Referenced by flashc_erase_all_gp_fuses(), flashc_erase_gp_fuse_byte(), flashc_read_gp_fuse_bit(), flashc_read_gp_fuse_bitfield(), and flashc_read_gp_fuse_byte().
Bool flashc_read_gp_fuse_bit | ( | unsigned int | gp_fuse_bit | ) |
Reads a general-purpose fuse bit.
gp_fuse_bit | The general-purpose fuse bit: 0 to 63 . |
AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware. Definition at line 413 of file flashc.c.
References flashc_read_all_gp_fuses().
Referenced by flashc_erase_gp_fuse_bit(), and flashc_is_external_privileged_fetch_locked().
00414 { 00415 return ((flashc_read_all_gp_fuses() & 1ULL << (gp_fuse_bit & 0x3F)) != 0); 00416 }
U64 flashc_read_gp_fuse_bitfield | ( | unsigned int | pos, | |
unsigned int | width | |||
) |
Reads a general-purpose fuse bit-field.
pos | The bit-position of the general-purpose fuse bit-field: 0 to 63 . | |
width | The bit-width of the general-purpose fuse bit-field: 0 to 64 . |
AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware. Definition at line 419 of file flashc.c.
References flashc_read_all_gp_fuses().
Referenced by flashc_erase_gp_fuse_bitfield(), and flashc_get_bootloader_protected_size().
00420 { 00421 return flashc_read_all_gp_fuses() >> (pos & 0x3F) & ((1ULL << min(width, 64)) - 1); 00422 }
U8 flashc_read_gp_fuse_byte | ( | unsigned int | gp_fuse_byte | ) |
Reads a general-purpose fuse byte.
gp_fuse_byte | The general-purpose fuse byte: 0 to 7 . |
AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware. Definition at line 425 of file flashc.c.
References flashc_read_all_gp_fuses().
Referenced by flashc_erase_gp_fuse_byte().
00426 { 00427 return flashc_read_all_gp_fuses() >> ((gp_fuse_byte & 0x07) << 3); 00428 }
void flashc_set_all_gp_fuses | ( | U64 | value | ) |
Sets all general-purpose fuses with the appropriate erase and write operations.
value | The value of all general-purpose fuses as a word. |
The actual number of general-purpose fuse bits implemented by hardware is given by AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 572 of file flashc.c.
References flashc_erase_all_gp_fuses(), flashc_error_status, and flashc_write_all_gp_fuses().
00573 { 00574 unsigned int error_status; 00575 switch (value) 00576 { 00577 case 0xFFFFFFFFFFFFFFFFULL: 00578 flashc_erase_all_gp_fuses(FALSE); 00579 break; 00580 case 0x0000000000000000ULL: 00581 flashc_write_all_gp_fuses(0x0000000000000000ULL); 00582 break; 00583 default: 00584 flashc_erase_all_gp_fuses(FALSE); 00585 error_status = flashc_error_status; 00586 flashc_write_all_gp_fuses(value); 00587 flashc_error_status |= error_status; 00588 } 00589 }
unsigned int flashc_set_bootloader_protected_size | ( | unsigned int | bootprot_size | ) |
Sets the bootloader protected size.
bootprot_size | The wanted bootloader protected size in bytes. If this size is not supported, the actual size will be the nearest greater available size or the maximal possible size if the requested size is too large. |
Definition at line 340 of file flashc.c.
References flashc_get_bootloader_protected_size(), and flashc_set_gp_fuse_bitfield().
00341 { 00342 flashc_set_gp_fuse_bitfield(AVR32_FLASHC_FGPFRLO_BOOTPROT_OFFSET, 00343 AVR32_FLASHC_FGPFRLO_BOOTPROT_SIZE, 00344 (1 << AVR32_FLASHC_FGPFRLO_BOOTPROT_SIZE) - 1 - 00345 ((bootprot_size) ? 00346 32 - clz((((min(max(bootprot_size, AVR32_FLASHC_PAGE_SIZE << 1), 00347 AVR32_FLASHC_PAGE_SIZE << 00348 ((1 << AVR32_FLASHC_FGPFRLO_BOOTPROT_SIZE) - 1)) + 00349 AVR32_FLASHC_PAGE_SIZE - 1) / 00350 AVR32_FLASHC_PAGE_SIZE) << 1) - 1) - 1 : 00351 0)); 00352 return flashc_get_bootloader_protected_size(); 00353 }
void flashc_set_gp_fuse_bit | ( | unsigned int | gp_fuse_bit, | |
Bool | value | |||
) |
Sets a general-purpose fuse bit with the appropriate erase and write operations.
gp_fuse_bit | The general-purpose fuse bit: 0 to 63 . | |
value | The value of the specified general-purpose fuse bit. |
The actual number of general-purpose fuse bits implemented by hardware is given by AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 528 of file flashc.c.
References flashc_erase_gp_fuse_bit(), and flashc_write_gp_fuse_bit().
Referenced by flashc_lock_external_privileged_fetch(), and flashc_set_gp_fuse_bitfield().
00529 { 00530 if (value) 00531 flashc_erase_gp_fuse_bit(gp_fuse_bit, FALSE); 00532 else 00533 flashc_write_gp_fuse_bit(gp_fuse_bit, FALSE); 00534 }
void flashc_set_gp_fuse_bitfield | ( | unsigned int | pos, | |
unsigned int | width, | |||
U64 | value | |||
) |
Sets a general-purpose fuse bit-field with the appropriate erase and write operations.
pos | The bit-position of the general-purpose fuse bit-field: 0 to 63 . | |
width | The bit-width of the general-purpose fuse bit-field: 0 to 64 . | |
value | The value of the specified general-purpose fuse bit-field. |
The actual number of general-purpose fuse bits implemented by hardware is given by AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 537 of file flashc.c.
References flashc_error_status, and flashc_set_gp_fuse_bit().
Referenced by flashc_set_bootloader_protected_size().
00538 { 00539 unsigned int error_status = 0; 00540 unsigned int gp_fuse_bit; 00541 pos &= 0x3F; 00542 width = min(width, 64); 00543 for (gp_fuse_bit = pos; gp_fuse_bit < pos + width; gp_fuse_bit++, value >>= 1) 00544 { 00545 flashc_set_gp_fuse_bit(gp_fuse_bit, value & 0x01); 00546 error_status |= flashc_error_status; 00547 } 00548 flashc_error_status = error_status; 00549 }
void flashc_set_gp_fuse_byte | ( | unsigned int | gp_fuse_byte, | |
U8 | value | |||
) |
Sets a general-purpose fuse byte with the appropriate erase and write operations.
gp_fuse_byte | The general-purpose fuse byte: 0 to 7 . | |
value | The value of the specified general-purpose fuse byte. |
The actual number of general-purpose fuse bits implemented by hardware is given by AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 552 of file flashc.c.
References flashc_erase_gp_fuse_byte(), flashc_error_status, and flashc_write_gp_fuse_byte().
00553 { 00554 unsigned int error_status; 00555 switch (value) 00556 { 00557 case 0xFF: 00558 flashc_erase_gp_fuse_byte(gp_fuse_byte, FALSE); 00559 break; 00560 case 0x00: 00561 flashc_write_gp_fuse_byte(gp_fuse_byte, 0x00); 00562 break; 00563 default: 00564 flashc_erase_gp_fuse_byte(gp_fuse_byte, FALSE); 00565 error_status = flashc_error_status; 00566 flashc_write_gp_fuse_byte(gp_fuse_byte, value); 00567 flashc_error_status |= error_status; 00568 } 00569 }
void flashc_set_wait_state | ( | unsigned int | wait_state | ) |
Sets the number of wait states of flash read accesses.
wait_state | The number of wait states of flash read accesses: 0 to 1 . |
Definition at line 148 of file flashc.c.
References u_avr32_flashc_fcr_t::fcr, and u_avr32_flashc_fcr_t::FCR.
00149 { 00150 u_avr32_flashc_fcr_t u_avr32_flashc_fcr = {AVR32_FLASHC.fcr}; 00151 u_avr32_flashc_fcr.FCR.fws = wait_state; 00152 AVR32_FLASHC.fcr = u_avr32_flashc_fcr.fcr; 00153 }
void flashc_write_all_gp_fuses | ( | U64 | value | ) |
Writes all general-purpose fuses.
value | The value of all general-purpose fuses as a word. |
A write operation can only clear bits.
The actual number of general-purpose fuse bits implemented by hardware is given by AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 515 of file flashc.c.
References flashc_error_status, and flashc_write_gp_fuse_byte().
Referenced by flashc_set_all_gp_fuses().
00516 { 00517 unsigned int error_status = 0; 00518 unsigned int gp_fuse_byte; 00519 for (gp_fuse_byte = 0; gp_fuse_byte < 8; gp_fuse_byte++, value >>= 8) 00520 { 00521 flashc_write_gp_fuse_byte(gp_fuse_byte, value); 00522 error_status |= flashc_error_status; 00523 } 00524 flashc_error_status = error_status; 00525 }
void flashc_write_gp_fuse_bit | ( | unsigned int | gp_fuse_bit, | |
Bool | value | |||
) |
Writes a general-purpose fuse bit.
gp_fuse_bit | The general-purpose fuse bit: 0 to 63 . | |
value | The value of the specified general-purpose fuse bit. |
A write operation can only clear bits.
The actual number of general-purpose fuse bits implemented by hardware is given by AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 487 of file flashc.c.
References flashc_issue_command().
Referenced by flashc_set_gp_fuse_bit(), and flashc_write_gp_fuse_bitfield().
00488 { 00489 if (!value) 00490 flashc_issue_command(AVR32_FLASHC_FCMD_CMD_WGPB, gp_fuse_bit & 0x3F); 00491 }
void flashc_write_gp_fuse_bitfield | ( | unsigned int | pos, | |
unsigned int | width, | |||
U64 | value | |||
) |
Writes a general-purpose fuse bit-field.
pos | The bit-position of the general-purpose fuse bit-field: 0 to 63 . | |
width | The bit-width of the general-purpose fuse bit-field: 0 to 64 . | |
value | The value of the specified general-purpose fuse bit-field. |
A write operation can only clear bits.
The actual number of general-purpose fuse bits implemented by hardware is given by AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 494 of file flashc.c.
References flashc_error_status, and flashc_write_gp_fuse_bit().
00495 { 00496 unsigned int error_status = 0; 00497 unsigned int gp_fuse_bit; 00498 pos &= 0x3F; 00499 width = min(width, 64); 00500 for (gp_fuse_bit = pos; gp_fuse_bit < pos + width; gp_fuse_bit++, value >>= 1) 00501 { 00502 flashc_write_gp_fuse_bit(gp_fuse_bit, value & 0x01); 00503 error_status |= flashc_error_status; 00504 } 00505 flashc_error_status = error_status; 00506 }
void flashc_write_gp_fuse_byte | ( | unsigned int | gp_fuse_byte, | |
U8 | value | |||
) |
Writes a general-purpose fuse byte.
gp_fuse_byte | The general-purpose fuse byte: 0 to 7 . | |
value | The value of the specified general-purpose fuse byte. |
A write operation can only clear bits.
The actual number of general-purpose fuse bits implemented by hardware is given by AVR32_FLASHC_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 509 of file flashc.c.
References flashc_issue_command().
Referenced by flashc_erase_gp_fuse_byte(), flashc_set_gp_fuse_byte(), and flashc_write_all_gp_fuses().
00510 { 00511 flashc_issue_command(AVR32_FLASHC_FCMD_CMD_PGPFB, (gp_fuse_byte & 0x07) | value << 3); 00512 }
void flashc_write_page | ( | int | page_number | ) |
Writes a page from the page buffer.
page_number | The page number:
|
The page buffer is not automatically reset after a page write.
A write operation can only clear bits.
Definition at line 648 of file flashc.c.
References flashc_issue_command().
Referenced by flashc_memcpy(), and flashc_memset64().
00649 { 00650 flashc_issue_command(AVR32_FLASHC_FCMD_CMD_WP, page_number); 00651 }
void flashc_write_user_page | ( | void | ) |
Writes the User page from the page buffer.
A write operation can only clear bits.
Definition at line 668 of file flashc.c.
References flashc_issue_command().
Referenced by flashc_memcpy(), and flashc_memset64().
00669 { 00670 flashc_issue_command(AVR32_FLASHC_FCMD_CMD_WUP, -1); 00671 }
unsigned int flashc_error_status = 0 [static] |
Sticky error status of the FLASHC.
This variable is updated by functions that issue FLASHC commands. It contains the cumulated FLASHC error status of all the FLASHC commands issued by a function.
Definition at line 242 of file flashc.c.
Referenced by flashc_erase_all_pages(), flashc_erase_gp_fuse_bitfield(), flashc_erase_gp_fuse_byte(), flashc_erase_page(), flashc_is_lock_error(), flashc_is_programming_error(), flashc_issue_command(), flashc_lock_all_regions(), flashc_memcpy(), flashc_memset64(), flashc_set_all_gp_fuses(), flashc_set_gp_fuse_bitfield(), flashc_set_gp_fuse_byte(), flashc_write_all_gp_fuses(), and flashc_write_gp_fuse_bitfield().
void(*volatile flashc_wait_until_ready)(void) = flashc_default_wait_until_ready |
Pointer to the function used by the driver when it needs to wait until the FLASHC is ready to run a new command.
The default function is flashc_default_wait_until_ready. The user may change this pointer to use another implementation.
Referenced by flashc_issue_command().