AVR32 Flash Controller driver module.
Definition in file flashcdw.h.
#include <avr32/io.h>
#include <stddef.h>
#include "compiler.h"
Go to the source code of this file.
Access to Flash Pages | |
#define | flashcdw_memset(dst, src, src_width, nbytes, erase) TPASTE2(flashcdw_memset, src_width)((dst), (src), (nbytes), (erase)) |
Copies nbytes bytes to the flash destination pointed to by dst from the repeated src big-endian source pattern. | |
void | flashcdw_clear_page_buffer (void) |
Clears the page buffer. | |
Bool | flashcdw_erase_all_pages (Bool check) |
Erases all pages within the flash array. | |
Bool | flashcdw_erase_page (int page_number, Bool check) |
Erases a page. | |
Bool | flashcdw_erase_user_page (Bool check) |
Erases the User page. | |
Bool | flashcdw_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 * | flashcdw_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 * | flashcdw_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 * | flashcdw_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 * | flashcdw_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 * | flashcdw_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 | flashcdw_quick_page_read (int page_number) |
Applies the Quick Page Read command to a page. | |
Bool | flashcdw_quick_user_page_read (void) |
Issues a Quick Page Read User Page command to the FLASHCDW. | |
void | flashcdw_write_page (int page_number) |
Writes a page from the page buffer. | |
void | flashcdw_write_user_page (void) |
Writes the User page from the page buffer. | |
FLASHCDW Status | |
void(*volatile | flashcdw_wait_until_ready )(void) |
Pointer to the function used by the driver when it needs to wait until the FLASHCDW is ready to run a new command. | |
void | flashcdw_default_wait_until_ready (void) |
Waits actively until the FLASHCDW is ready to run a new command. | |
Bool | flashcdw_is_high_speed_enabled (void) |
Tells whether the High-speed read mode is enabled. | |
Bool | flashcdw_is_lock_error (void) |
Tells whether a Lock Error has occurred during the last function called that issued one or more FLASHCDW commands. | |
Bool | flashcdw_is_programming_error (void) |
Tells whether a Programming Error has occurred during the last function called that issued one or more FLASHCDW commands. | |
Bool | flashcdw_is_ready (void) |
Tells whether the FLASHCDW is ready to run a new command. | |
Defines | |
#define | AVR32_FLASHCDW_REGIONS |
Number of flash regions defined by the FLASHCDW. | |
Functions | |
FLASHCDW Protection Mechanisms | |
void | flashcdw_activate_security_bit (void) |
Activates the Security bit. | |
void | flashcdw_disable_jtag_user_protection (void) |
Disable the jtag user protection feature (i.e. erase (set to "1") the UPROT bit). | |
void | flashcdw_enable_jtag_user_protection (void) |
Enable the jtag user protection feature (i.e. program (set to "0") the UPROT bit). | |
void | flashcdw_enable_secure_state_no_debug (void) |
Enable the Secure State with the Secure State debug disabled. | |
void | flashcdw_enable_secure_state_with_debug (void) |
Enable the Secure State with the Secure State debug enabled. | |
unsigned int | flashcdw_get_bootloader_protected_size (void) |
Gets the bootloader protected size. | |
Bool | flashcdw_is_external_privileged_fetch_locked (void) |
Tells whether external privileged fetch is locked. | |
Bool | flashcdw_is_jtag_user_protection_enabled (void) |
Tells whether the jtag user protection is enabled. | |
Bool | flashcdw_is_page_region_locked (int page_number) |
Tells whether the region of a page is locked. | |
Bool | flashcdw_is_region_locked (unsigned int region) |
Tells whether a region is locked. | |
Bool | flashcdw_is_secure_state_debug_enabled (void) |
Tells whether the Secure State debug is enabled. | |
Bool | flashcdw_is_secure_state_enabled (void) |
Tells whether the Secure State is enabled. | |
Bool | flashcdw_is_security_bit_active (void) |
Tells whether the Security bit is active. | |
void | flashcdw_lock_all_regions (Bool lock) |
Locks or unlocks all regions. | |
void | flashcdw_lock_external_privileged_fetch (Bool lock) |
Locks or unlocks external privileged fetch. | |
void | flashcdw_lock_page_region (int page_number, Bool lock) |
Locks or unlocks the region of a page. | |
void | flashcdw_lock_region (unsigned int region, Bool lock) |
Locks or unlocks a region. | |
unsigned int | flashcdw_set_bootloader_protected_size (unsigned int bootprot_size) |
Sets the bootloader protected size. | |
FLASHCDW Control | |
void | flashcdw_enable_lock_error_int (Bool enable) |
Enables or disables the Lock Error interrupt. | |
void | flashcdw_enable_prog_error_int (Bool enable) |
Enables or disables the Programming Error interrupt. | |
void | flashcdw_enable_ready_int (Bool enable) |
Enables or disables the Flash Ready interrupt. | |
unsigned int | flashcdw_get_wait_state (void) |
Gets the number of wait states of flash read accesses. | |
Bool | flashcdw_is_lock_error_int_enabled (void) |
Tells whether the Lock Error interrupt is enabled. | |
Bool | flashcdw_is_prog_error_int_enabled (void) |
Tells whether the Programming Error interrupt is enabled. | |
Bool | flashcdw_is_ready_int_enabled (void) |
Tells whether the Flash Ready interrupt is enabled. | |
void | flashcdw_set_flash_waitstate_and_readmode (unsigned long cpu_f_hz) |
Depednding to the CPU frequency, set the wait states of flash read accesses and enable or disable the High speed read mode. | |
void | flashcdw_set_wait_state (unsigned int wait_state) |
Sets the number of wait states of flash read accesses. | |
FLASHCDW Global Commands | |
void | flashcdw_erase_all (void) |
Issues an Erase All command to the FLASHCDW. | |
void | flashcdw_no_operation (void) |
Issues a No Operation command to the FLASHCDW. | |
Access to General-Purpose Fuses | |
Bool | flashcdw_erase_all_gp_fuses (Bool check) |
Erases all general-purpose fuses. | |
Bool | flashcdw_erase_gp_fuse_bit (unsigned int gp_fuse_bit, Bool check) |
Erases a general-purpose fuse bit. | |
Bool | flashcdw_erase_gp_fuse_bitfield (unsigned int pos, unsigned int width, Bool check) |
Erases a general-purpose fuse bit-field. | |
Bool | flashcdw_erase_gp_fuse_byte (unsigned int gp_fuse_byte, Bool check) |
Erases a general-purpose fuse byte. | |
U64 | flashcdw_read_all_gp_fuses (void) |
Reads all general-purpose fuses. | |
Bool | flashcdw_read_gp_fuse_bit (unsigned int gp_fuse_bit) |
Reads a general-purpose fuse bit. | |
U64 | flashcdw_read_gp_fuse_bitfield (unsigned int pos, unsigned int width) |
Reads a general-purpose fuse bit-field. | |
U8 | flashcdw_read_gp_fuse_byte (unsigned int gp_fuse_byte) |
Reads a general-purpose fuse byte. | |
void | flashcdw_set_all_gp_fuses (U64 value) |
Sets all general-purpose fuses with the appropriate erase and write operations. | |
void | flashcdw_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 | flashcdw_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 | flashcdw_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 | flashcdw_write_all_gp_fuses (U64 value) |
Writes all general-purpose fuses. | |
void | flashcdw_write_gp_fuse_bit (unsigned int gp_fuse_bit, Bool value) |
Writes a general-purpose fuse bit. | |
void | flashcdw_write_gp_fuse_bitfield (unsigned int pos, unsigned int width, U64 value) |
Writes a general-purpose fuse bit-field. | |
void | flashcdw_write_gp_fuse_byte (unsigned int gp_fuse_byte, U8 value) |
Writes a general-purpose fuse byte. | |
FLASHCDW Command Control | |
unsigned int | flashcdw_get_command (void) |
Gets the last issued FLASHCDW command. | |
unsigned int | flashcdw_get_page_number (void) |
Gets the current FLASHCDW page number. | |
void | flashcdw_issue_command (unsigned int command, int page_number) |
Issues a FLASHCDW command. | |
Flash Properties | |
unsigned int | flashcdw_get_flash_size (void) |
Gets the size of the whole flash array. | |
unsigned int | flashcdw_get_page_count (void) |
Gets the total number of pages in the flash array. | |
unsigned int | flashcdw_get_page_count_per_region (void) |
Gets the number of pages in each flash region. | |
unsigned int | flashcdw_get_page_region (int page_number) |
Gets the region number of a page. | |
unsigned int | flashcdw_get_region_first_page_number (unsigned int region) |
Gets the number of the first page of a region. |
#define AVR32_FLASHCDW_REGIONS |
Value:
(AVR32_FLASHCDW_FLASH_SIZE /\ (AVR32_FLASHCDW_PAGES_PR_REGION * AVR32_FLASHCDW_PAGE_SIZE))
Definition at line 80 of file flashcdw.h.
Referenced by flashcdw_get_page_count_per_region(), flashcdw_is_region_locked(), and flashcdw_lock_all_regions().
#define flashcdw_memset | ( | dst, | |||
src, | |||||
src_width, | |||||
nbytes, | |||||
erase | ) | TPASTE2(flashcdw_memset, src_width)((dst), (src), (nbytes), (erase)) |
Copies nbytes bytes to the flash destination pointed to by dst from the repeated src big-endian source pattern.
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. | |
src_width | src width in bits: 8, 16, 32 or 64. | |
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 or to a secure area requiring secure privileges.
Definition at line 1062 of file flashcdw.h.
Referenced by flash_rw_example().
void flashcdw_activate_security_bit | ( | void | ) |
Activates the Security bit.
Definition at line 349 of file flashcdw.c.
References flashcdw_issue_command().
00350 { 00351 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_SSB, -1); 00352 }
void flashcdw_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 669 of file flashcdw.c.
References flashcdw_issue_command().
Referenced by flashcdw_memcpy(), and flashcdw_memset64().
00670 { 00671 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_CPB, -1); 00672 }
void flashcdw_default_wait_until_ready | ( | void | ) |
Waits actively until the FLASHCDW is ready to run a new command.
This is the default function assigned to flashcdw_wait_until_ready.
Definition at line 230 of file flashcdw.c.
References flashcdw_is_ready().
00231 { 00232 while (!flashcdw_is_ready()); 00233 }
void flashcdw_disable_jtag_user_protection | ( | void | ) |
Disable the jtag user protection feature (i.e. erase (set to "1") the UPROT bit).
Definition at line 401 of file flashcdw.c.
References flashcdw_set_gp_fuse_bit().
00402 { 00403 flashcdw_set_gp_fuse_bit(AVR32_FLASHCDW_FGPFRLO_UPROT_OFFSET, TRUE); 00404 }
void flashcdw_enable_jtag_user_protection | ( | void | ) |
Enable the jtag user protection feature (i.e. program (set to "0") the UPROT bit).
Definition at line 396 of file flashcdw.c.
References flashcdw_set_gp_fuse_bit().
00397 { 00398 flashcdw_set_gp_fuse_bit(AVR32_FLASHCDW_FGPFRLO_UPROT_OFFSET, FALSE); 00399 }
void flashcdw_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 194 of file flashcdw.c.
References u_avr32_flashcdw_fcr_t::fcr, and u_avr32_flashcdw_fcr_t::FCR.
00195 { 00196 u_avr32_flashcdw_fcr_t u_avr32_flashcdw_fcr = {AVR32_FLASHCDW.fcr}; 00197 u_avr32_flashcdw_fcr.FCR.locke = (enable != FALSE); 00198 AVR32_FLASHCDW.fcr = u_avr32_flashcdw_fcr.fcr; 00199 }
void flashcdw_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 208 of file flashcdw.c.
References u_avr32_flashcdw_fcr_t::fcr, and u_avr32_flashcdw_fcr_t::FCR.
00209 { 00210 u_avr32_flashcdw_fcr_t u_avr32_flashcdw_fcr = {AVR32_FLASHCDW.fcr}; 00211 u_avr32_flashcdw_fcr.FCR.proge = (enable != FALSE); 00212 AVR32_FLASHCDW.fcr = u_avr32_flashcdw_fcr.fcr; 00213 }
void flashcdw_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 180 of file flashcdw.c.
References u_avr32_flashcdw_fcr_t::fcr, and u_avr32_flashcdw_fcr_t::FCR.
00181 { 00182 u_avr32_flashcdw_fcr_t u_avr32_flashcdw_fcr = {AVR32_FLASHCDW.fcr}; 00183 u_avr32_flashcdw_fcr.FCR.frdy = (enable != FALSE); 00184 AVR32_FLASHCDW.fcr = u_avr32_flashcdw_fcr.fcr; 00185 }
void flashcdw_enable_secure_state_no_debug | ( | void | ) |
Enable the Secure State with the Secure State debug disabled.
Definition at line 423 of file flashcdw.c.
References flashcdw_write_gp_fuse_bitfield().
00424 { 00425 flashcdw_write_gp_fuse_bitfield(AVR32_FLASHCDW_FGPFRLO_SECURE_OFFSET, 00426 AVR32_FLASHCDW_FGPFRLO_SECURE_SIZE, 00427 AVR32_FLASHCDW_FGPFRLO_SECURE_SSEN_SSDDIS); 00428 }
void flashcdw_enable_secure_state_with_debug | ( | void | ) |
Enable the Secure State with the Secure State debug enabled.
Definition at line 430 of file flashcdw.c.
References flashcdw_write_gp_fuse_bitfield().
00431 { 00432 flashcdw_write_gp_fuse_bitfield(AVR32_FLASHCDW_FGPFRLO_SECURE_OFFSET, 00433 AVR32_FLASHCDW_FGPFRLO_SECURE_SIZE, 00434 AVR32_FLASHCDW_FGPFRLO_SECURE_SSEN_SSDEN); 00435 }
void flashcdw_erase_all | ( | void | ) |
Issues an Erase All command to the FLASHCDW.
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 329 of file flashcdw.c.
References flashcdw_issue_command().
00330 { 00331 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_EA, -1); 00332 }
Bool flashcdw_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_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 549 of file flashcdw.c.
References flashcdw_issue_command(), and flashcdw_read_all_gp_fuses().
Referenced by flashcdw_erase_gp_fuse_byte(), and flashcdw_set_all_gp_fuses().
00550 { 00551 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_EAGPF, -1); 00552 return (check) ? (flashcdw_read_all_gp_fuses() == 0xFFFFFFFFFFFFFFFFULL) : TRUE; 00553 }
Bool flashcdw_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 702 of file flashcdw.c.
References flashcdw_erase_page(), flashcdw_error_status, and flashcdw_get_page_count().
00703 { 00704 Bool all_pages_erased = TRUE; 00705 unsigned int error_status = 0; 00706 unsigned int page_number = flashcdw_get_page_count(); 00707 while (page_number) 00708 { 00709 all_pages_erased &= flashcdw_erase_page(--page_number, check); 00710 error_status |= flashcdw_error_status; 00711 } 00712 flashcdw_error_status = error_status; 00713 return all_pages_erased; 00714 }
Bool flashcdw_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_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 506 of file flashcdw.c.
References flashcdw_issue_command(), and flashcdw_read_gp_fuse_bit().
Referenced by flashcdw_erase_gp_fuse_bitfield(), and flashcdw_set_gp_fuse_bit().
00507 { 00508 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_EGPB, gp_fuse_bit & 0x3F); 00509 return (check) ? flashcdw_read_gp_fuse_bit(gp_fuse_bit) : TRUE; 00510 }
Bool flashcdw_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_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 513 of file flashcdw.c.
References flashcdw_erase_gp_fuse_bit(), flashcdw_error_status, and flashcdw_read_gp_fuse_bitfield().
00514 { 00515 unsigned int error_status = 0; 00516 unsigned int gp_fuse_bit; 00517 pos &= 0x3F; 00518 width = min(width, 64); 00519 for (gp_fuse_bit = pos; gp_fuse_bit < pos + width; gp_fuse_bit++) 00520 { 00521 flashcdw_erase_gp_fuse_bit(gp_fuse_bit, FALSE); 00522 error_status |= flashcdw_error_status; 00523 } 00524 flashcdw_error_status = error_status; 00525 return (check) ? (flashcdw_read_gp_fuse_bitfield(pos, width) == (1ULL << width) - 1) : TRUE; 00526 }
Bool flashcdw_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_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 529 of file flashcdw.c.
References flashcdw_erase_all_gp_fuses(), flashcdw_error_status, flashcdw_read_all_gp_fuses(), flashcdw_read_gp_fuse_byte(), and flashcdw_write_gp_fuse_byte().
Referenced by flashcdw_set_gp_fuse_byte().
00530 { 00531 unsigned int error_status; 00532 unsigned int current_gp_fuse_byte; 00533 U64 value = flashcdw_read_all_gp_fuses(); 00534 flashcdw_erase_all_gp_fuses(FALSE); 00535 error_status = flashcdw_error_status; 00536 for (current_gp_fuse_byte = 0; current_gp_fuse_byte < 8; current_gp_fuse_byte++, value >>= 8) 00537 { 00538 if (current_gp_fuse_byte != gp_fuse_byte) 00539 { 00540 flashcdw_write_gp_fuse_byte(current_gp_fuse_byte, value); 00541 error_status |= flashcdw_error_status; 00542 } 00543 } 00544 flashcdw_error_status = error_status; 00545 return (check) ? (flashcdw_read_gp_fuse_byte(gp_fuse_byte) == 0xFF) : TRUE; 00546 }
Bool flashcdw_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 688 of file flashcdw.c.
References flashcdw_error_status, flashcdw_issue_command(), and flashcdw_quick_page_read().
Referenced by flashcdw_erase_all_pages(), flashcdw_memcpy(), and flashcdw_memset64().
00689 { 00690 Bool page_erased = TRUE; 00691 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_EP, page_number); 00692 if (check) 00693 { 00694 unsigned int error_status = flashcdw_error_status; 00695 page_erased = flashcdw_quick_page_read(-1); 00696 flashcdw_error_status |= error_status; 00697 } 00698 return page_erased; 00699 }
Bool flashcdw_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 730 of file flashcdw.c.
References flashcdw_issue_command(), and flashcdw_quick_user_page_read().
Referenced by flashcdw_memcpy(), and flashcdw_memset64().
00731 { 00732 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_EUP, -1); 00733 return (check) ? flashcdw_quick_user_page_read() : TRUE; 00734 }
unsigned int flashcdw_get_bootloader_protected_size | ( | void | ) |
Gets the bootloader protected size.
Definition at line 355 of file flashcdw.c.
References flashcdw_read_gp_fuse_bitfield().
Referenced by flashcdw_set_bootloader_protected_size().
00356 { 00357 unsigned int bootprot = (1 << AVR32_FLASHCDW_FGPFRLO_BOOTPROT_SIZE) - 1 - 00358 flashcdw_read_gp_fuse_bitfield(AVR32_FLASHCDW_FGPFRLO_BOOTPROT_OFFSET, 00359 AVR32_FLASHCDW_FGPFRLO_BOOTPROT_SIZE); 00360 return (bootprot) ? AVR32_FLASHCDW_PAGE_SIZE << bootprot : 0; 00361 }
unsigned int flashcdw_get_command | ( | void | ) |
Gets the last issued FLASHCDW command.
Definition at line 289 of file flashcdw.c.
00290 { 00291 return (AVR32_FLASHCDW.fcmd & AVR32_FLASHCDW_FCMD_CMD_MASK) >> AVR32_FLASHCDW_FCMD_CMD_OFFSET; 00292 }
unsigned int flashcdw_get_flash_size | ( | void | ) |
Gets the size of the whole flash array.
Definition at line 78 of file flashcdw.c.
Referenced by flashcdw_get_page_count(), flashcdw_memcpy(), and flashcdw_memset64().
00079 { 00080 static const unsigned int FLASH_SIZE[1 << AVR32_FLASHCDW_FPR_FSZ_SIZE] = 00081 { 00082 4 << 10, 00083 8 << 10, 00084 16 << 10, 00085 32 << 10, 00086 48 << 10, 00087 64 << 10, 00088 96 << 10, 00089 128 << 10, 00090 192 << 10, 00091 256 << 10, 00092 384 << 10, 00093 512 << 10, 00094 768 << 10, 00095 1024 << 10, 00096 2048 << 10 00097 }; 00098 return FLASH_SIZE[(AVR32_FLASHCDW.fpr & AVR32_FLASHCDW_FPR_FSZ_MASK) >> AVR32_FLASHCDW_FPR_FSZ_OFFSET]; 00099 }
unsigned int flashcdw_get_page_count | ( | void | ) |
Gets the total number of pages in the flash array.
Definition at line 102 of file flashcdw.c.
References flashcdw_get_flash_size().
Referenced by flashcdw_erase_all_pages(), and flashcdw_get_page_count_per_region().
00103 { 00104 return flashcdw_get_flash_size() / AVR32_FLASHCDW_PAGE_SIZE; 00105 }
unsigned int flashcdw_get_page_count_per_region | ( | void | ) |
Gets the number of pages in each flash region.
Definition at line 108 of file flashcdw.c.
References AVR32_FLASHCDW_REGIONS, and flashcdw_get_page_count().
Referenced by flashcdw_get_page_region(), and flashcdw_get_region_first_page_number().
00109 { 00110 return flashcdw_get_page_count() / AVR32_FLASHCDW_REGIONS; 00111 }
unsigned int flashcdw_get_page_number | ( | void | ) |
Gets the current FLASHCDW page number.
Definition at line 295 of file flashcdw.c.
Referenced by flashcdw_get_page_region().
00296 { 00297 return (AVR32_FLASHCDW.fcmd & AVR32_FLASHCDW_FCMD_PAGEN_MASK) >> AVR32_FLASHCDW_FCMD_PAGEN_OFFSET; 00298 }
unsigned int flashcdw_get_page_region | ( | int | page_number | ) |
Gets the region number of a page.
page_number | The page number:
|
Definition at line 114 of file flashcdw.c.
References flashcdw_get_page_count_per_region(), and flashcdw_get_page_number().
Referenced by flashcdw_is_page_region_locked().
00115 { 00116 return ((page_number >= 0) ? page_number : flashcdw_get_page_number()) / flashcdw_get_page_count_per_region(); 00117 }
unsigned int flashcdw_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_FLASHCDW_REGIONS - 1) . |
Definition at line 120 of file flashcdw.c.
References flashcdw_get_page_count_per_region().
Referenced by flashcdw_lock_region().
00121 { 00122 return region * flashcdw_get_page_count_per_region(); 00123 }
unsigned int flashcdw_get_wait_state | ( | void | ) |
Gets the number of wait states of flash read accesses.
Definition at line 134 of file flashcdw.c.
00135 { 00136 return (AVR32_FLASHCDW.fcr & AVR32_FLASHCDW_FCR_FWS_MASK) >> AVR32_FLASHCDW_FCR_FWS_OFFSET; 00137 }
Bool flashcdw_is_external_privileged_fetch_locked | ( | void | ) |
Tells whether external privileged fetch is locked.
Definition at line 380 of file flashcdw.c.
References flashcdw_read_gp_fuse_bit().
00381 { 00382 return (!flashcdw_read_gp_fuse_bit(AVR32_FLASHCDW_FGPFRLO_EPFL_OFFSET)); 00383 }
Bool flashcdw_is_high_speed_enabled | ( | void | ) |
Tells whether the High-speed read mode is enabled.
Definition at line 275 of file flashcdw.c.
Bool flashcdw_is_jtag_user_protection_enabled | ( | void | ) |
Tells whether the jtag user protection is enabled.
Definition at line 391 of file flashcdw.c.
References flashcdw_read_gp_fuse_bit().
00392 { 00393 return (!flashcdw_read_gp_fuse_bit(AVR32_FLASHCDW_FGPFRLO_UPROT_OFFSET)); 00394 }
Bool flashcdw_is_lock_error | ( | void | ) |
Tells whether a Lock Error has occurred during the last function called that issued one or more FLASHCDW commands.
Definition at line 263 of file flashcdw.c.
References flashcdw_error_status.
00264 { 00265 return ((flashcdw_error_status & AVR32_FLASHCDW_FSR_LOCKE_MASK) != 0); 00266 }
Bool flashcdw_is_lock_error_int_enabled | ( | void | ) |
Tells whether the Lock Error interrupt is enabled.
Definition at line 188 of file flashcdw.c.
Bool flashcdw_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 675 of file flashcdw.c.
Referenced by flashcdw_quick_page_read(), and flashcdw_quick_user_page_read().
Bool flashcdw_is_page_region_locked | ( | int | page_number | ) |
Tells whether the region of a page is locked.
page_number | The page number:
|
Definition at line 437 of file flashcdw.c.
References flashcdw_get_page_region(), and flashcdw_is_region_locked().
00438 { 00439 return flashcdw_is_region_locked(flashcdw_get_page_region(page_number)); 00440 }
Bool flashcdw_is_prog_error_int_enabled | ( | void | ) |
Tells whether the Programming Error interrupt is enabled.
Definition at line 202 of file flashcdw.c.
Bool flashcdw_is_programming_error | ( | void | ) |
Tells whether a Programming Error has occurred during the last function called that issued one or more FLASHCDW commands.
Definition at line 269 of file flashcdw.c.
References flashcdw_error_status.
00270 { 00271 return ((flashcdw_error_status & AVR32_FLASHCDW_FSR_PROGE_MASK) != 0); 00272 }
Bool flashcdw_is_ready | ( | void | ) |
Tells whether the FLASHCDW is ready to run a new command.
Definition at line 224 of file flashcdw.c.
Referenced by flashcdw_default_wait_until_ready().
Bool flashcdw_is_ready_int_enabled | ( | void | ) |
Tells whether the Flash Ready interrupt is enabled.
Definition at line 174 of file flashcdw.c.
Bool flashcdw_is_region_locked | ( | unsigned int | region | ) |
Tells whether a region is locked.
region | The region number: 0 to (AVR32_FLASHCDW_REGIONS - 1) . |
Definition at line 443 of file flashcdw.c.
References AVR32_FLASHCDW_REGIONS.
Referenced by flashcdw_is_page_region_locked().
00444 { 00445 return ((AVR32_FLASHCDW.fsr & AVR32_FLASHCDW_FSR_LOCK0_MASK << (region & (AVR32_FLASHCDW_REGIONS - 1))) != 0); 00446 }
Bool flashcdw_is_secure_state_debug_enabled | ( | void | ) |
Tells whether the Secure State debug is enabled.
Definition at line 416 of file flashcdw.c.
References flashcdw_read_gp_fuse_bitfield().
00417 { 00418 return( AVR32_FLASHCDW_FGPFRLO_SECURE_SSEN_SSDEN 00419 == flashcdw_read_gp_fuse_bitfield(AVR32_FLASHCDW_FGPFRLO_SECURE_OFFSET, 00420 AVR32_FLASHCDW_FGPFRLO_SECURE_SIZE) ); 00421 }
Bool flashcdw_is_secure_state_enabled | ( | void | ) |
Tells whether the Secure State is enabled.
Definition at line 406 of file flashcdw.c.
References flashcdw_read_gp_fuse_bitfield().
00407 { 00408 U64 temp = flashcdw_read_gp_fuse_bitfield(AVR32_FLASHCDW_FGPFRLO_SECURE_OFFSET, 00409 AVR32_FLASHCDW_FGPFRLO_SECURE_SIZE); 00410 if((AVR32_FLASHCDW_FGPFRLO_SECURE_SSEN_SSDDIS == temp) || (AVR32_FLASHCDW_FGPFRLO_SECURE_SSEN_SSDEN == temp)) 00411 return TRUE; 00412 else 00413 return FALSE; 00414 }
Bool flashcdw_is_security_bit_active | ( | void | ) |
Tells whether the Security bit is active.
Definition at line 343 of file flashcdw.c.
void flashcdw_issue_command | ( | unsigned int | command, | |
int | page_number | |||
) |
Issues a FLASHCDW command.
command | The command: AVR32_FLASHCDW_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 301 of file flashcdw.c.
References u_avr32_flashcdw_fcmd_t::FCMD, u_avr32_flashcdw_fcmd_t::fcmd, flashcdw_error_status, flashcdw_get_error_status(), and flashcdw_wait_until_ready.
Referenced by flashcdw_activate_security_bit(), flashcdw_clear_page_buffer(), flashcdw_erase_all(), flashcdw_erase_all_gp_fuses(), flashcdw_erase_gp_fuse_bit(), flashcdw_erase_page(), flashcdw_erase_user_page(), flashcdw_lock_page_region(), flashcdw_no_operation(), flashcdw_quick_page_read(), flashcdw_quick_user_page_read(), flashcdw_set_flash_waitstate_and_readmode(), flashcdw_write_gp_fuse_bit(), flashcdw_write_gp_fuse_byte(), flashcdw_write_page(), and flashcdw_write_user_page().
00302 { 00303 u_avr32_flashcdw_fcmd_t u_avr32_flashcdw_fcmd; 00304 flashcdw_wait_until_ready(); 00305 u_avr32_flashcdw_fcmd.fcmd = AVR32_FLASHCDW.fcmd; 00306 u_avr32_flashcdw_fcmd.FCMD.cmd = command; 00307 if (page_number >= 0) u_avr32_flashcdw_fcmd.FCMD.pagen = page_number; 00308 u_avr32_flashcdw_fcmd.FCMD.key = AVR32_FLASHCDW_FCMD_KEY_KEY; 00309 AVR32_FLASHCDW.fcmd = u_avr32_flashcdw_fcmd.fcmd; 00310 flashcdw_error_status = flashcdw_get_error_status(); 00311 flashcdw_wait_until_ready(); 00312 }
void flashcdw_lock_all_regions | ( | Bool | lock | ) |
Locks or unlocks all regions.
lock | Whether to lock the regions: TRUE or FALSE . |
Definition at line 461 of file flashcdw.c.
References AVR32_FLASHCDW_REGIONS, flashcdw_error_status, and flashcdw_lock_region().
00462 { 00463 unsigned int error_status = 0; 00464 unsigned int region = AVR32_FLASHCDW_REGIONS; 00465 while (region) 00466 { 00467 flashcdw_lock_region(--region, lock); 00468 error_status |= flashcdw_error_status; 00469 } 00470 flashcdw_error_status = error_status; 00471 }
void flashcdw_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 386 of file flashcdw.c.
References flashcdw_set_gp_fuse_bit().
00387 { 00388 flashcdw_set_gp_fuse_bit(AVR32_FLASHCDW_FGPFRLO_EPFL_OFFSET, !lock); 00389 }
void flashcdw_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 449 of file flashcdw.c.
References flashcdw_issue_command().
Referenced by flashcdw_lock_region().
00450 { 00451 flashcdw_issue_command((lock) ? AVR32_FLASHCDW_FCMD_CMD_LP : AVR32_FLASHCDW_FCMD_CMD_UP, page_number); 00452 }
void flashcdw_lock_region | ( | unsigned int | region, | |
Bool | lock | |||
) |
Locks or unlocks a region.
region | The region number: 0 to (AVR32_FLASHCDW_REGIONS - 1) . | |
lock | Whether to lock the specified region: TRUE or FALSE . |
Definition at line 455 of file flashcdw.c.
References flashcdw_get_region_first_page_number(), and flashcdw_lock_page_region().
Referenced by flashcdw_lock_all_regions().
00456 { 00457 flashcdw_lock_page_region(flashcdw_get_region_first_page_number(region), lock); 00458 }
volatile void* flashcdw_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 or to a secure area requiring secure privileges.
Definition at line 945 of file flashcdw.c.
References flashcdw_clear_page_buffer(), flashcdw_erase_page(), flashcdw_erase_user_page(), flashcdw_error_status, flashcdw_get_flash_size(), flashcdw_write_page(), and flashcdw_write_user_page().
Referenced by flash_rw_example().
00946 { 00947 // Use aggregated pointers to have several alignments available for a same address. 00948 UnionCVPtr flash_array_end; 00949 UnionVPtr dest; 00950 UnionCPtr source; 00951 StructCVPtr dest_end; 00952 UnionCVPtr flash_page_source_end; 00953 Bool incomplete_flash_page_end; 00954 Union64 flash_dword; 00955 Bool flash_dword_pending = FALSE; 00956 UnionVPtr tmp; 00957 unsigned int error_status = 0; 00958 unsigned int i, j; 00959 00960 // Reformat arguments. 00961 flash_array_end.u8ptr = AVR32_FLASH + flashcdw_get_flash_size(); 00962 dest.u8ptr = dst; 00963 source.u8ptr = src; 00964 dest_end.u8ptr = dest.u8ptr + nbytes; 00965 00966 // If destination is outside flash, go to next flash page if any. 00967 if (dest.u8ptr < AVR32_FLASH) 00968 { 00969 source.u8ptr += AVR32_FLASH - dest.u8ptr; 00970 dest.u8ptr = AVR32_FLASH; 00971 } 00972 else if (flash_array_end.u8ptr <= dest.u8ptr && dest.u8ptr < AVR32_FLASHCDW_USER_PAGE) 00973 { 00974 source.u8ptr += AVR32_FLASHCDW_USER_PAGE - dest.u8ptr; 00975 dest.u8ptr = AVR32_FLASHCDW_USER_PAGE; 00976 } 00977 00978 // If end of destination is outside flash, move it to the end of the previous flash page if any. 00979 if (dest_end.u8ptr > AVR32_FLASHCDW_USER_PAGE + AVR32_FLASHCDW_USER_PAGE_SIZE) 00980 { 00981 dest_end.u8ptr = AVR32_FLASHCDW_USER_PAGE + AVR32_FLASHCDW_USER_PAGE_SIZE; 00982 } 00983 else if (AVR32_FLASHCDW_USER_PAGE >= dest_end.u8ptr && dest_end.u8ptr > flash_array_end.u8ptr) 00984 { 00985 dest_end.u8ptr = flash_array_end.u8ptr; 00986 } 00987 00988 // Align each end of destination pointer with its natural boundary. 00989 dest_end.u16ptr = (U16 *)Align_down((U32)dest_end.u8ptr, sizeof(U16)); 00990 dest_end.u32ptr = (U32 *)Align_down((U32)dest_end.u16ptr, sizeof(U32)); 00991 dest_end.u64ptr = (U64 *)Align_down((U32)dest_end.u32ptr, sizeof(U64)); 00992 00993 // While end of destination is not reached... 00994 while (dest.u8ptr < dest_end.u8ptr) 00995 { 00996 // Clear the page buffer in order to prepare data for a flash page write. 00997 flashcdw_clear_page_buffer(); 00998 error_status |= flashcdw_error_status; 00999 01000 // Determine where the source data will end in the current flash page. 01001 flash_page_source_end.u64ptr = 01002 (U64 *)min((U32)dest_end.u64ptr, 01003 Align_down((U32)dest.u8ptr, AVR32_FLASHCDW_PAGE_SIZE) + AVR32_FLASHCDW_PAGE_SIZE); 01004 01005 // Determine if the current destination page has an incomplete end. 01006 incomplete_flash_page_end = (Align_down((U32)dest.u8ptr, AVR32_FLASHCDW_PAGE_SIZE) >= 01007 Align_down((U32)dest_end.u8ptr, AVR32_FLASHCDW_PAGE_SIZE)); 01008 01009 // If destination does not point to the beginning of the current flash page... 01010 if (!Test_align((U32)dest.u8ptr, AVR32_FLASHCDW_PAGE_SIZE)) 01011 { 01012 // Fill the beginning of the page buffer with the current flash page data. 01013 // This is required by the hardware, even if page erase is not requested, 01014 // in order to be able to write successfully to erased parts of flash 01015 // pages that have already been written to. 01016 for (tmp.u8ptr = (U8 *)Align_down((U32)dest.u8ptr, AVR32_FLASHCDW_PAGE_SIZE); 01017 tmp.u64ptr < (U64 *)Align_down((U32)dest.u8ptr, sizeof(U64)); 01018 tmp.u64ptr++) 01019 { 01020 *tmp.u32ptr = *tmp.u32ptr; 01021 *(tmp.u32ptr+1) = *(tmp.u32ptr+1); 01022 } 01023 01024 // If destination is not 64-bit aligned... 01025 if (!Test_align((U32)dest.u8ptr, sizeof(U64))) 01026 { 01027 // Fill the beginning of the flash double-word buffer with the current 01028 // flash page data. 01029 // This is required by the hardware, even if page erase is not 01030 // requested, in order to be able to write successfully to erased parts 01031 // of flash pages that have already been written to. 01032 for (i = 0; i < Get_align((U32)dest.u8ptr, sizeof(U64)); i++) 01033 flash_dword.u8[i] = *tmp.u8ptr++; 01034 01035 // Fill the end of the flash double-word buffer with the source data. 01036 for (; i < sizeof(U64); i++) 01037 flash_dword.u8[i] = *source.u8ptr++; 01038 01039 // Align the destination pointer with its 64-bit boundary. 01040 dest.u64ptr = (U64 *)Align_down((U32)dest.u8ptr, sizeof(U64)); 01041 01042 // If the current destination double-word is not the last one... 01043 if (dest.u64ptr < dest_end.u64ptr) 01044 { 01045 // Write the flash double-word buffer to the page buffer. 01046 *dest.u32ptr++ = flash_dword.u32[0]; 01047 *dest.u32ptr++ = flash_dword.u32[1]; 01048 } 01049 // If the current destination double-word is the last one, the flash 01050 // double-word buffer must be kept for later. 01051 else flash_dword_pending = TRUE; 01052 } 01053 } 01054 01055 // Read the source data with the maximal possible alignment and write it to 01056 // the page buffer with 64-bit alignment. 01057 switch (Get_align((U32)source.u8ptr, sizeof(U32))) 01058 { 01059 case 0: 01060 for (i = flash_page_source_end.u64ptr - dest.u64ptr; i; i--) 01061 { 01062 *dest.u32ptr++ = *source.u32ptr++; 01063 *dest.u32ptr++ = *source.u32ptr++; 01064 } 01065 break; 01066 01067 case sizeof(U16): 01068 for (i = flash_page_source_end.u64ptr - dest.u64ptr; i; i--) 01069 { 01070 for (j = 0; j < sizeof(U64) / sizeof(U16); j++) flash_dword.u16[j] = *source.u16ptr++; 01071 *dest.u32ptr++ = flash_dword.u32[0]; 01072 *dest.u32ptr++ = flash_dword.u32[1]; 01073 } 01074 break; 01075 01076 default: 01077 for (i = flash_page_source_end.u64ptr - dest.u64ptr; i; i--) 01078 { 01079 for (j = 0; j < sizeof(U64); j++) flash_dword.u8[j] = *source.u8ptr++; 01080 *dest.u32ptr++ = flash_dword.u32[0]; 01081 *dest.u32ptr++ = flash_dword.u32[1]; 01082 } 01083 } 01084 01085 // If the current destination page has an incomplete end... 01086 if (incomplete_flash_page_end) 01087 { 01088 // If the flash double-word buffer is in use, do not initialize it. 01089 if (flash_dword_pending) i = Get_align((U32)dest_end.u8ptr, sizeof(U64)); 01090 // If the flash double-word buffer is free... 01091 else 01092 { 01093 // Fill the beginning of the flash double-word buffer with the source data. 01094 for (i = 0; i < Get_align((U32)dest_end.u8ptr, sizeof(U64)); i++) 01095 flash_dword.u8[i] = *source.u8ptr++; 01096 } 01097 01098 // This is required by the hardware, even if page erase is not requested, 01099 // in order to be able to write successfully to erased parts of flash 01100 // pages that have already been written to. 01101 { 01102 tmp.u8ptr = (volatile U8 *)dest_end.u8ptr; 01103 01104 // If end of destination is not 64-bit aligned... 01105 if (!Test_align((U32)dest_end.u8ptr, sizeof(U64))) 01106 { 01107 // Fill the end of the flash double-word buffer with the current flash page data. 01108 for (; i < sizeof(U64); i++) 01109 flash_dword.u8[i] = *tmp.u8ptr++; 01110 01111 // Write the flash double-word buffer to the page buffer. 01112 *dest.u32ptr++ = flash_dword.u32[0]; 01113 *dest.u32ptr++ = flash_dword.u32[1]; 01114 } 01115 01116 // Fill the end of the page buffer with the current flash page data. 01117 for (; !Test_align((U32)tmp.u64ptr, AVR32_FLASHCDW_PAGE_SIZE); tmp.u64ptr++) 01118 { 01119 *tmp.u32ptr = *tmp.u32ptr; 01120 *(tmp.u32ptr+1) = *(tmp.u32ptr+1); 01121 } 01122 } 01123 } 01124 01125 // If the current flash page is in the flash array... 01126 if (dest.u8ptr <= AVR32_FLASHCDW_USER_PAGE) 01127 { 01128 // Erase the current page if requested and write it from the page buffer. 01129 if (erase) 01130 { 01131 flashcdw_erase_page(-1, FALSE); 01132 error_status |= flashcdw_error_status; 01133 } 01134 flashcdw_write_page(-1); 01135 error_status |= flashcdw_error_status; 01136 01137 // If the end of the flash array is reached, go to the User page. 01138 if (dest.u8ptr >= flash_array_end.u8ptr) 01139 { 01140 source.u8ptr += AVR32_FLASHCDW_USER_PAGE - dest.u8ptr; 01141 dest.u8ptr = AVR32_FLASHCDW_USER_PAGE; 01142 } 01143 } 01144 // If the current flash page is the User page... 01145 else 01146 { 01147 // Erase the User page if requested and write it from the page buffer. 01148 if (erase) 01149 { 01150 flashcdw_erase_user_page(FALSE); 01151 error_status |= flashcdw_error_status; 01152 } 01153 flashcdw_write_user_page(); 01154 error_status |= flashcdw_error_status; 01155 } 01156 } 01157 01158 // Update the FLASHC error status. 01159 flashcdw_error_status = error_status; 01160 01161 // Return the initial destination pointer as the standard memcpy function does. 01162 return dst; 01163 }
volatile void* flashcdw_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 or to a secure area requiring secure privileges.
Definition at line 749 of file flashcdw.c.
References flashcdw_memset32().
Referenced by flashcdw_memset8().
00750 { 00751 return flashcdw_memset32(dst, src | (U32)src << 16, nbytes, erase); 00752 }
volatile void* flashcdw_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 or to a secure area requiring secure privileges.
Definition at line 755 of file flashcdw.c.
References flashcdw_memset64().
Referenced by flashcdw_memset16().
00756 { 00757 return flashcdw_memset64(dst, src | (U64)src << 32, nbytes, erase); 00758 }
volatile void* flashcdw_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 or to a secure area requiring secure privileges.
Definition at line 761 of file flashcdw.c.
References flashcdw_clear_page_buffer(), flashcdw_erase_page(), flashcdw_erase_user_page(), flashcdw_error_status, flashcdw_get_flash_size(), flashcdw_write_page(), and flashcdw_write_user_page().
Referenced by flashcdw_memset32().
00762 { 00763 // Use aggregated pointers to have several alignments available for a same address. 00764 UnionCVPtr flash_array_end; 00765 UnionVPtr dest; 00766 Union64 source = {0}; 00767 StructCVPtr dest_end; 00768 UnionCVPtr flash_page_source_end; 00769 Bool incomplete_flash_page_end; 00770 Union64 flash_dword; 00771 UnionVPtr tmp; 00772 unsigned int error_status = 0; 00773 unsigned int i; 00774 00775 // Reformat arguments. 00776 flash_array_end.u8ptr = AVR32_FLASH + flashcdw_get_flash_size(); 00777 dest.u8ptr = dst; 00778 for (i = (Get_align((U32)dest.u8ptr, sizeof(U64)) - 1) & (sizeof(U64) - 1); 00779 src; i = (i - 1) & (sizeof(U64) - 1)) 00780 { 00781 source.u8[i] = src; 00782 src >>= 8; 00783 } 00784 dest_end.u8ptr = dest.u8ptr + nbytes; 00785 00786 // If destination is outside flash, go to next flash page if any. 00787 if (dest.u8ptr < AVR32_FLASH) 00788 { 00789 dest.u8ptr = AVR32_FLASH; 00790 } 00791 else if (flash_array_end.u8ptr <= dest.u8ptr && dest.u8ptr < AVR32_FLASHCDW_USER_PAGE) 00792 { 00793 dest.u8ptr = AVR32_FLASHCDW_USER_PAGE; 00794 } 00795 00796 // If end of destination is outside flash, move it to the end of the previous flash page if any. 00797 if (dest_end.u8ptr > AVR32_FLASHCDW_USER_PAGE + AVR32_FLASHCDW_USER_PAGE_SIZE) 00798 { 00799 dest_end.u8ptr = AVR32_FLASHCDW_USER_PAGE + AVR32_FLASHCDW_USER_PAGE_SIZE; 00800 } 00801 else if (AVR32_FLASHCDW_USER_PAGE >= dest_end.u8ptr && dest_end.u8ptr > flash_array_end.u8ptr) 00802 { 00803 dest_end.u8ptr = flash_array_end.u8ptr; 00804 } 00805 00806 // Align each end of destination pointer with its natural boundary. 00807 dest_end.u16ptr = (U16 *)Align_down((U32)dest_end.u8ptr, sizeof(U16)); 00808 dest_end.u32ptr = (U32 *)Align_down((U32)dest_end.u16ptr, sizeof(U32)); 00809 dest_end.u64ptr = (U64 *)Align_down((U32)dest_end.u32ptr, sizeof(U64)); 00810 00811 // While end of destination is not reached... 00812 while (dest.u8ptr < dest_end.u8ptr) 00813 { 00814 // Clear the page buffer in order to prepare data for a flash page write. 00815 flashcdw_clear_page_buffer(); 00816 error_status |= flashcdw_error_status; 00817 00818 // Determine where the source data will end in the current flash page. 00819 flash_page_source_end.u64ptr = 00820 (U64 *)min((U32)dest_end.u64ptr, 00821 Align_down((U32)dest.u8ptr, AVR32_FLASHCDW_PAGE_SIZE) + AVR32_FLASHCDW_PAGE_SIZE); 00822 00823 // Determine if the current destination page has an incomplete end. 00824 incomplete_flash_page_end = (Align_down((U32)dest.u8ptr, AVR32_FLASHCDW_PAGE_SIZE) >= 00825 Align_down((U32)dest_end.u8ptr, AVR32_FLASHCDW_PAGE_SIZE)); 00826 00827 // Use a flash double-word buffer to manage unaligned accesses. 00828 flash_dword.u64 = source.u64; 00829 00830 // If destination does not point to the beginning of the current flash page... 00831 if (!Test_align((U32)dest.u8ptr, AVR32_FLASHCDW_PAGE_SIZE)) 00832 { 00833 // Fill the beginning of the page buffer with the current flash page data. 00834 // This is required by the hardware, even if page erase is not requested, 00835 // in order to be able to write successfully to erased parts of flash 00836 // pages that have already been written to. 00837 for (tmp.u8ptr = (U8 *)Align_down((U32)dest.u8ptr, AVR32_FLASHCDW_PAGE_SIZE); 00838 tmp.u64ptr < (U64 *)Align_down((U32)dest.u8ptr, sizeof(U64)); 00839 tmp.u64ptr++) 00840 { 00841 *tmp.u32ptr = *tmp.u32ptr; 00842 *(tmp.u32ptr+1) = *(tmp.u32ptr+1); 00843 } 00844 00845 // If destination is not 64-bit aligned... 00846 if (!Test_align((U32)dest.u8ptr, sizeof(U64))) 00847 { 00848 // Fill the beginning of the flash double-word buffer with the current 00849 // flash page data. 00850 // This is required by the hardware, even if page erase is not 00851 // requested, in order to be able to write successfully to erased parts 00852 // of flash pages that have already been written to. 00853 for (i = 0; i < Get_align((U32)dest.u8ptr, sizeof(U64)); i++) 00854 flash_dword.u8[i] = *tmp.u8ptr++; 00855 00856 // Align the destination pointer with its 64-bit boundary. 00857 dest.u64ptr = (U64 *)Align_down((U32)dest.u8ptr, sizeof(U64)); 00858 00859 // If the current destination double-word is not the last one... 00860 if (dest.u64ptr < dest_end.u64ptr) 00861 { 00862 // Write the flash double-word buffer to the page buffer and reinitialize it. 00863 *dest.u32ptr++ = flash_dword.u32[0]; 00864 *dest.u32ptr++ = flash_dword.u32[1]; 00865 flash_dword.u64 = source.u64; 00866 } 00867 } 00868 } 00869 00870 // Write the source data to the page buffer with 64-bit alignment. 00871 for (i = flash_page_source_end.u64ptr - dest.u64ptr; i; i--) 00872 { 00873 *dest.u32ptr++ = source.u32[0]; 00874 *dest.u32ptr++ = source.u32[1]; 00875 } 00876 00877 // If the current destination page has an incomplete end... 00878 if (incomplete_flash_page_end) 00879 { 00880 // This is required by the hardware, even if page erase is not requested, 00881 // in order to be able to write successfully to erased parts of flash 00882 // pages that have already been written to. 00883 { 00884 tmp.u8ptr = (volatile U8 *)dest_end.u8ptr; 00885 00886 // If end of destination is not 64-bit aligned... 00887 if (!Test_align((U32)dest_end.u8ptr, sizeof(U64))) 00888 { 00889 // Fill the end of the flash double-word buffer with the current flash page data. 00890 for (i = Get_align((U32)dest_end.u8ptr, sizeof(U64)); i < sizeof(U64); i++) 00891 flash_dword.u8[i] = *tmp.u8ptr++; 00892 00893 // Write the flash double-word buffer to the page buffer. 00894 *dest.u32ptr++ = flash_dword.u32[0]; 00895 *dest.u32ptr++ = flash_dword.u32[1]; 00896 } 00897 00898 // Fill the end of the page buffer with the current flash page data. 00899 for (; !Test_align((U32)tmp.u64ptr, AVR32_FLASHCDW_PAGE_SIZE); tmp.u64ptr++) 00900 { 00901 *tmp.u32ptr = *tmp.u32ptr; 00902 *(tmp.u32ptr+1) = *(tmp.u32ptr+1); 00903 } 00904 } 00905 } 00906 00907 // If the current flash page is in the flash array... 00908 if (dest.u8ptr <= AVR32_FLASHCDW_USER_PAGE) 00909 { 00910 // Erase the current page if requested and write it from the page buffer. 00911 if (erase) 00912 { 00913 flashcdw_erase_page(-1, FALSE); 00914 error_status |= flashcdw_error_status; 00915 } 00916 flashcdw_write_page(-1); 00917 error_status |= flashcdw_error_status; 00918 00919 // If the end of the flash array is reached, go to the User page. 00920 if (dest.u8ptr >= flash_array_end.u8ptr) 00921 dest.u8ptr = AVR32_FLASHCDW_USER_PAGE; 00922 } 00923 // If the current flash page is the User page... 00924 else 00925 { 00926 // Erase the User page if requested and write it from the page buffer. 00927 if (erase) 00928 { 00929 flashcdw_erase_user_page(FALSE); 00930 error_status |= flashcdw_error_status; 00931 } 00932 flashcdw_write_user_page(); 00933 error_status |= flashcdw_error_status; 00934 } 00935 } 00936 00937 // Update the FLASHC error status. 00938 flashcdw_error_status = error_status; 00939 00940 // Return the initial destination pointer as the standard memset function does. 00941 return dst; 00942 }
volatile void* flashcdw_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 cannot 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 or to a secure area requiring secure privileges.
Definition at line 743 of file flashcdw.c.
References flashcdw_memset16().
00744 { 00745 return flashcdw_memset16(dst, src | (U16)src << 8, nbytes, erase); 00746 }
void flashcdw_no_operation | ( | void | ) |
Issues a No Operation command to the FLASHCDW.
Definition at line 323 of file flashcdw.c.
References flashcdw_issue_command().
00324 { 00325 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_NOP, -1); 00326 }
Bool flashcdw_quick_page_read | ( | int | page_number | ) |
Applies the Quick Page Read command to a page.
page_number | The page number:
|
Definition at line 681 of file flashcdw.c.
References flashcdw_is_page_erased(), and flashcdw_issue_command().
Referenced by flashcdw_erase_page().
00682 { 00683 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_QPR, page_number); 00684 return flashcdw_is_page_erased(); 00685 }
Bool flashcdw_quick_user_page_read | ( | void | ) |
Issues a Quick Page Read User Page command to the FLASHCDW.
Definition at line 723 of file flashcdw.c.
References flashcdw_is_page_erased(), and flashcdw_issue_command().
Referenced by flashcdw_erase_user_page().
00724 { 00725 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_QPRUP, -1); 00726 return flashcdw_is_page_erased(); 00727 }
U64 flashcdw_read_all_gp_fuses | ( | void | ) |
Reads all general-purpose fuses.
AVR32_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware. Definition at line 500 of file flashcdw.c.
Referenced by flashcdw_erase_all_gp_fuses(), flashcdw_erase_gp_fuse_byte(), flashcdw_read_gp_fuse_bit(), flashcdw_read_gp_fuse_bitfield(), and flashcdw_read_gp_fuse_byte().
Bool flashcdw_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_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware. Definition at line 482 of file flashcdw.c.
References flashcdw_read_all_gp_fuses().
Referenced by flashcdw_erase_gp_fuse_bit(), flashcdw_is_external_privileged_fetch_locked(), and flashcdw_is_jtag_user_protection_enabled().
00483 { 00484 return ((flashcdw_read_all_gp_fuses() & 1ULL << (gp_fuse_bit & 0x3F)) != 0); 00485 }
U64 flashcdw_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_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware. Definition at line 488 of file flashcdw.c.
References flashcdw_read_all_gp_fuses().
Referenced by flashcdw_erase_gp_fuse_bitfield(), flashcdw_get_bootloader_protected_size(), flashcdw_is_secure_state_debug_enabled(), and flashcdw_is_secure_state_enabled().
00489 { 00490 return flashcdw_read_all_gp_fuses() >> (pos & 0x3F) & ((1ULL << min(width, 64)) - 1); 00491 }
U8 flashcdw_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_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware. Definition at line 494 of file flashcdw.c.
References flashcdw_read_all_gp_fuses().
Referenced by flashcdw_erase_gp_fuse_byte().
00495 { 00496 return flashcdw_read_all_gp_fuses() >> ((gp_fuse_byte & 0x07) << 3); 00497 }
void flashcdw_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_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 641 of file flashcdw.c.
References flashcdw_erase_all_gp_fuses(), flashcdw_error_status, and flashcdw_write_all_gp_fuses().
00642 { 00643 unsigned int error_status; 00644 switch (value) 00645 { 00646 case 0xFFFFFFFFFFFFFFFFULL: 00647 flashcdw_erase_all_gp_fuses(FALSE); 00648 break; 00649 case 0x0000000000000000ULL: 00650 flashcdw_write_all_gp_fuses(0x0000000000000000ULL); 00651 break; 00652 default: 00653 flashcdw_erase_all_gp_fuses(FALSE); 00654 error_status = flashcdw_error_status; 00655 flashcdw_write_all_gp_fuses(value); 00656 flashcdw_error_status |= error_status; 00657 } 00658 }
unsigned int flashcdw_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 364 of file flashcdw.c.
References flashcdw_get_bootloader_protected_size(), and flashcdw_set_gp_fuse_bitfield().
00365 { 00366 flashcdw_set_gp_fuse_bitfield(AVR32_FLASHCDW_FGPFRLO_BOOTPROT_OFFSET, 00367 AVR32_FLASHCDW_FGPFRLO_BOOTPROT_SIZE, 00368 (1 << AVR32_FLASHCDW_FGPFRLO_BOOTPROT_SIZE) - 1 - 00369 ((bootprot_size) ? 00370 32 - clz((((min(max(bootprot_size, AVR32_FLASHCDW_PAGE_SIZE << 1), 00371 AVR32_FLASHCDW_PAGE_SIZE << 00372 ((1 << AVR32_FLASHCDW_FGPFRLO_BOOTPROT_SIZE) - 1)) + 00373 AVR32_FLASHCDW_PAGE_SIZE - 1) / 00374 AVR32_FLASHCDW_PAGE_SIZE) << 1) - 1) - 1 : 00375 0)); 00376 return flashcdw_get_bootloader_protected_size(); 00377 }
void flashcdw_set_flash_waitstate_and_readmode | ( | unsigned long | cpu_f_hz | ) |
Depednding to the CPU frequency, set the wait states of flash read accesses and enable or disable the High speed read mode.
cpu_f_hz | The CPU frequency |
Definition at line 148 of file flashcdw.c.
References flashcdw_issue_command(), and flashcdw_set_wait_state().
00149 { 00150 if(cpu_f_hz > AVR32_FLASHCDW_FWS_0_MAX_FREQ) // > 15MHz 00151 { 00152 if(cpu_f_hz <= AVR32_FLASHCDW_FWS_1_MAX_FREQ) // <= 30MHz 00153 { 00154 // Set a wait-state, disable the high-speed read mode. 00155 flashcdw_set_wait_state(1); 00156 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_HSDIS, -1); 00157 } 00158 else 00159 { 00160 // Set a wait-state, enable the high-speed read mode. 00161 flashcdw_set_wait_state(1); 00162 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_HSEN, -1); 00163 } 00164 } 00165 else // <= 15MHz 00166 { 00167 // No wait-state, disable the high-speed read mode 00168 flashcdw_set_wait_state(0); 00169 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_HSDIS, -1); 00170 } 00171 }
void flashcdw_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_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 597 of file flashcdw.c.
References flashcdw_erase_gp_fuse_bit(), and flashcdw_write_gp_fuse_bit().
Referenced by flashcdw_disable_jtag_user_protection(), flashcdw_enable_jtag_user_protection(), flashcdw_lock_external_privileged_fetch(), and flashcdw_set_gp_fuse_bitfield().
00598 { 00599 if (value) 00600 flashcdw_erase_gp_fuse_bit(gp_fuse_bit, FALSE); 00601 else 00602 flashcdw_write_gp_fuse_bit(gp_fuse_bit, FALSE); 00603 }
void flashcdw_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_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 606 of file flashcdw.c.
References flashcdw_error_status, and flashcdw_set_gp_fuse_bit().
Referenced by flashcdw_set_bootloader_protected_size().
00607 { 00608 unsigned int error_status = 0; 00609 unsigned int gp_fuse_bit; 00610 pos &= 0x3F; 00611 width = min(width, 64); 00612 for (gp_fuse_bit = pos; gp_fuse_bit < pos + width; gp_fuse_bit++, value >>= 1) 00613 { 00614 flashcdw_set_gp_fuse_bit(gp_fuse_bit, value & 0x01); 00615 error_status |= flashcdw_error_status; 00616 } 00617 flashcdw_error_status = error_status; 00618 }
void flashcdw_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_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 621 of file flashcdw.c.
References flashcdw_erase_gp_fuse_byte(), flashcdw_error_status, and flashcdw_write_gp_fuse_byte().
00622 { 00623 unsigned int error_status; 00624 switch (value) 00625 { 00626 case 0xFF: 00627 flashcdw_erase_gp_fuse_byte(gp_fuse_byte, FALSE); 00628 break; 00629 case 0x00: 00630 flashcdw_write_gp_fuse_byte(gp_fuse_byte, 0x00); 00631 break; 00632 default: 00633 flashcdw_erase_gp_fuse_byte(gp_fuse_byte, FALSE); 00634 error_status = flashcdw_error_status; 00635 flashcdw_write_gp_fuse_byte(gp_fuse_byte, value); 00636 flashcdw_error_status |= error_status; 00637 } 00638 }
void flashcdw_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 140 of file flashcdw.c.
References u_avr32_flashcdw_fcr_t::fcr, and u_avr32_flashcdw_fcr_t::FCR.
Referenced by flashcdw_set_flash_waitstate_and_readmode().
00141 { 00142 u_avr32_flashcdw_fcr_t u_avr32_flashcdw_fcr = {AVR32_FLASHCDW.fcr}; 00143 u_avr32_flashcdw_fcr.FCR.fws = wait_state; 00144 AVR32_FLASHCDW.fcr = u_avr32_flashcdw_fcr.fcr; 00145 }
void flashcdw_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_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 584 of file flashcdw.c.
References flashcdw_error_status, and flashcdw_write_gp_fuse_byte().
Referenced by flashcdw_set_all_gp_fuses().
00585 { 00586 unsigned int error_status = 0; 00587 unsigned int gp_fuse_byte; 00588 for (gp_fuse_byte = 0; gp_fuse_byte < 8; gp_fuse_byte++, value >>= 8) 00589 { 00590 flashcdw_write_gp_fuse_byte(gp_fuse_byte, value); 00591 error_status |= flashcdw_error_status; 00592 } 00593 flashcdw_error_status = error_status; 00594 }
void flashcdw_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_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 556 of file flashcdw.c.
References flashcdw_issue_command().
Referenced by flashcdw_set_gp_fuse_bit(), and flashcdw_write_gp_fuse_bitfield().
00557 { 00558 if (!value) 00559 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_WGPB, gp_fuse_bit & 0x3F); 00560 }
void flashcdw_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_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 563 of file flashcdw.c.
References flashcdw_error_status, and flashcdw_write_gp_fuse_bit().
Referenced by flashcdw_enable_secure_state_no_debug(), and flashcdw_enable_secure_state_with_debug().
00564 { 00565 unsigned int error_status = 0; 00566 unsigned int gp_fuse_bit; 00567 pos &= 0x3F; 00568 width = min(width, 64); 00569 for (gp_fuse_bit = pos; gp_fuse_bit < pos + width; gp_fuse_bit++, value >>= 1) 00570 { 00571 flashcdw_write_gp_fuse_bit(gp_fuse_bit, value & 0x01); 00572 error_status |= flashcdw_error_status; 00573 } 00574 flashcdw_error_status = error_status; 00575 }
void flashcdw_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_FLASHCDW_GPF_NUM
. The other bits among the 64 are fixed at 1 by hardware.
Definition at line 578 of file flashcdw.c.
References flashcdw_issue_command().
Referenced by flashcdw_erase_gp_fuse_byte(), flashcdw_set_gp_fuse_byte(), and flashcdw_write_all_gp_fuses().
00579 { 00580 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_PGPFB, (gp_fuse_byte & 0x07) | value << 3); 00581 }
void flashcdw_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 717 of file flashcdw.c.
References flashcdw_issue_command().
Referenced by flashcdw_memcpy(), and flashcdw_memset64().
00718 { 00719 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_WP, page_number); 00720 }
void flashcdw_write_user_page | ( | void | ) |
Writes the User page from the page buffer.
A write operation can only clear bits.
Definition at line 737 of file flashcdw.c.
References flashcdw_issue_command().
Referenced by flashcdw_memcpy(), and flashcdw_memset64().
00738 { 00739 flashcdw_issue_command(AVR32_FLASHCDW_FCMD_CMD_WUP, -1); 00740 }
void(*volatile flashcdw_wait_until_ready)(void) |
Pointer to the function used by the driver when it needs to wait until the FLASHCDW is ready to run a new command.
The default function is flashcdw_default_wait_until_ready. The user may change this pointer to use another implementation.
Referenced by flashcdw_issue_command().