1 /*This file is prepared for Doxygen automatic documentation generation.*/
\r
2 /*! \file *********************************************************************
\r
4 * \brief FLASHC driver for AVR32 UC3.
\r
6 * AVR32 Flash Controller driver module.
\r
8 * - Compiler: IAR EWAVR32 and GNU GCC for AVR32
\r
9 * - Supported devices: All AVR32 devices with a FLASHC module can be used.
\r
12 * \author Atmel Corporation: http://www.atmel.com \n
\r
13 * Support and FAQ: http://support.atmel.no/
\r
15 ******************************************************************************/
\r
17 /* Copyright (c) 2007, Atmel Corporation All rights reserved.
\r
19 * Redistribution and use in source and binary forms, with or without
\r
20 * modification, are permitted provided that the following conditions are met:
\r
22 * 1. Redistributions of source code must retain the above copyright notice,
\r
23 * this list of conditions and the following disclaimer.
\r
25 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
26 * this list of conditions and the following disclaimer in the documentation
\r
27 * and/or other materials provided with the distribution.
\r
29 * 3. The name of ATMEL may not be used to endorse or promote products derived
\r
30 * from this software without specific prior written permission.
\r
32 * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
\r
33 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
34 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
\r
35 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
\r
36 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
\r
37 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
\r
38 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
\r
39 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
\r
41 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
48 #include <avr32/io.h>
\r
50 #include "compiler.h"
\r
53 //! Number of flash regions defined by the FLASHC.
\r
54 #define AVR32_FLASHC_REGIONS (AVR32_FLASHC_FLASH_SIZE /\
\r
55 (AVR32_FLASHC_PAGES_PR_REGION * AVR32_FLASHC_PAGE_SIZE))
\r
58 /*! \name Flash Properties
\r
62 /*! \brief Gets the size of the whole flash array.
\r
64 * \return The size of the whole flash array in bytes.
\r
66 extern unsigned int flashc_get_flash_size(void);
\r
68 /*! \brief Gets the total number of pages in the flash array.
\r
70 * \return The total number of pages in the flash array.
\r
72 extern unsigned int flashc_get_page_count(void);
\r
74 /*! \brief Gets the number of pages in each flash region.
\r
76 * \return The number of pages in each flash region.
\r
78 extern unsigned int flashc_get_page_count_per_region(void);
\r
80 /*! \brief Gets the region number of a page.
\r
82 * \param page_number The page number:
\r
83 * \arg \c 0 to <tt>(flashc_get_page_count() - 1)</tt>: a page number within
\r
85 * \arg <tt>< 0</tt>: the current page number.
\r
87 * \return The region number of the specified page.
\r
89 extern unsigned int flashc_get_page_region(int page_number);
\r
91 /*! \brief Gets the number of the first page of a region.
\r
93 * \param region The region number: \c 0 to <tt>(AVR32_FLASHC_REGIONS - 1)</tt>.
\r
95 * \return The number of the first page of the specified region.
\r
97 extern unsigned int flashc_get_region_first_page_number(unsigned int region);
\r
102 /*! \name FLASHC Control
\r
106 /*! \brief Gets the number of wait states of flash read accesses.
\r
108 * \return The number of wait states of flash read accesses.
\r
110 extern unsigned int flashc_get_wait_state(void);
\r
112 /*! \brief Sets the number of wait states of flash read accesses.
\r
114 * \param wait_state The number of wait states of flash read accesses: \c 0 to
\r
117 extern void flashc_set_wait_state(unsigned int wait_state);
\r
119 /*! \brief Tells whether the Flash Ready interrupt is enabled.
\r
121 * \return Whether the Flash Ready interrupt is enabled.
\r
123 extern Bool flashc_is_ready_int_enabled(void);
\r
125 /*! \brief Enables or disables the Flash Ready interrupt.
\r
127 * \param enable Whether to enable the Flash Ready interrupt: \c TRUE or
\r
130 extern void flashc_enable_ready_int(Bool enable);
\r
132 /*! \brief Tells whether the Lock Error interrupt is enabled.
\r
134 * \return Whether the Lock Error interrupt is enabled.
\r
136 extern Bool flashc_is_lock_error_int_enabled(void);
\r
138 /*! \brief Enables or disables the Lock Error interrupt.
\r
140 * \param enable Whether to enable the Lock Error interrupt: \c TRUE or
\r
143 extern void flashc_enable_lock_error_int(Bool enable);
\r
145 /*! \brief Tells whether the Programming Error interrupt is enabled.
\r
147 * \return Whether the Programming Error interrupt is enabled.
\r
149 extern Bool flashc_is_prog_error_int_enabled(void);
\r
151 /*! \brief Enables or disables the Programming Error interrupt.
\r
153 * \param enable Whether to enable the Programming Error interrupt: \c TRUE or
\r
156 extern void flashc_enable_prog_error_int(Bool enable);
\r
161 /*! \name FLASHC Status
\r
165 /*! \brief Tells whether the FLASHC is ready to run a new command.
\r
167 * \return Whether the FLASHC is ready to run a new command.
\r
169 extern Bool flashc_is_ready(void);
\r
171 /*! \brief Waits actively until the FLASHC is ready to run a new command.
\r
173 * This is the default function assigned to \ref flashc_wait_until_ready.
\r
175 extern void flashc_default_wait_until_ready(void);
\r
177 //! Pointer to the function used by the driver when it needs to wait until the
\r
178 //! FLASHC is ready to run a new command.
\r
179 //! The default function is \ref flashc_default_wait_until_ready.
\r
180 //! The user may change this pointer to use another implementation.
\r
181 extern void (*volatile flashc_wait_until_ready)(void);
\r
183 /*! \brief Tells whether a Lock Error has occurred during the last function
\r
184 * called that issued one or more FLASHC commands.
\r
186 * \return Whether a Lock Error has occurred during the last function called
\r
187 * that issued one or more FLASHC commands.
\r
189 extern Bool flashc_is_lock_error(void);
\r
191 /*! \brief Tells whether a Programming Error has occurred during the last
\r
192 * function called that issued one or more FLASHC commands.
\r
194 * \return Whether a Programming Error has occurred during the last function
\r
195 * called that issued one or more FLASHC commands.
\r
197 extern Bool flashc_is_programming_error(void);
\r
202 /*! \name FLASHC Command Control
\r
206 /*! \brief Gets the last issued FLASHC command.
\r
208 * \return The last issued FLASHC command.
\r
210 extern unsigned int flashc_get_command(void);
\r
212 /*! \brief Gets the current FLASHC page number.
\r
214 * \return The current FLASHC page number.
\r
216 extern unsigned int flashc_get_page_number(void);
\r
218 /*! \brief Issues a FLASHC command.
\r
220 * \param command The command: \c AVR32_FLASHC_FCMD_CMD_x.
\r
221 * \param page_number The page number to apply the command to:
\r
222 * \arg \c 0 to <tt>(flashc_get_page_count() - 1)</tt>: a page number within
\r
224 * \arg <tt>< 0</tt>: use this to apply the command to the current page number
\r
225 * or if the command does not apply to any page number;
\r
226 * \arg this argument may have other meanings according to the command. See
\r
227 * the FLASHC chapter of the MCU datasheet.
\r
229 * \warning A Lock Error is issued if the command violates the protection
\r
232 * \warning A Programming Error is issued if the command is invalid.
\r
234 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
235 * \ref flashc_is_programming_error is updated.
\r
237 extern void flashc_issue_command(unsigned int command, int page_number);
\r
242 /*! \name FLASHC Global Commands
\r
246 /*! \brief Issues a No Operation command to the FLASHC.
\r
248 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
249 * \ref flashc_is_programming_error is updated.
\r
251 extern void flashc_no_operation(void);
\r
253 /*! \brief Issues an Erase All command to the FLASHC.
\r
255 * This command erases all bits in the flash array, the general-purpose fuse
\r
256 * bits and the Security bit. The User page is not erased.
\r
258 * This command also ensures that all volatile memories, such as register file
\r
259 * and RAMs, are erased before the Security bit is erased, i.e. deactivated.
\r
261 * \warning A Lock Error is issued if at least one region is locked or the
\r
262 * bootloader protection is active.
\r
264 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
265 * \ref flashc_is_programming_error is updated.
\r
267 * \note An erase operation can only set bits.
\r
269 extern void flashc_erase_all(void);
\r
274 /*! \name FLASHC Protection Mechanisms
\r
278 /*! \brief Tells whether the Security bit is active.
\r
280 * \return Whether the Security bit is active.
\r
282 extern Bool flashc_is_security_bit_active(void);
\r
284 /*! \brief Activates the Security bit.
\r
286 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
287 * \ref flashc_is_programming_error is updated.
\r
289 extern void flashc_activate_security_bit(void);
\r
291 /*! \brief Gets the bootloader protected size.
\r
293 * \return The bootloader protected size in bytes.
\r
295 extern unsigned int flashc_get_bootloader_protected_size(void);
\r
297 /*! \brief Sets the bootloader protected size.
\r
299 * \param bootprot_size The wanted bootloader protected size in bytes. If this
\r
300 * size is not supported, the actual size will be the
\r
301 * nearest greater available size or the maximal possible
\r
302 * size if the requested size is too large.
\r
304 * \return The actual bootloader protected size in bytes.
\r
306 * \warning A Lock Error is issued if the Security bit is active.
\r
308 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
309 * \ref flashc_is_programming_error is updated.
\r
311 extern unsigned int flashc_set_bootloader_protected_size(unsigned int bootprot_size);
\r
313 /*! \brief Tells whether external privileged fetch is locked.
\r
315 * \return Whether external privileged fetch is locked.
\r
317 extern Bool flashc_is_external_privileged_fetch_locked(void);
\r
319 /*! \brief Locks or unlocks external privileged fetch.
\r
321 * \param lock Whether to lock external privileged fetch: \c TRUE or \c FALSE.
\r
323 * \warning A Lock Error is issued if the Security bit is active.
\r
325 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
326 * \ref flashc_is_programming_error is updated.
\r
328 extern void flashc_lock_external_privileged_fetch(Bool lock);
\r
330 /*! \brief Tells whether the region of a page is locked.
\r
332 * \param page_number The page number:
\r
333 * \arg \c 0 to <tt>(flashc_get_page_count() - 1)</tt>: a page number within
\r
335 * \arg <tt>< 0</tt>: the current page number.
\r
337 * \return Whether the region of the specified page is locked.
\r
339 extern Bool flashc_is_page_region_locked(int page_number);
\r
341 /*! \brief Tells whether a region is locked.
\r
343 * \param region The region number: \c 0 to <tt>(AVR32_FLASHC_REGIONS - 1)</tt>.
\r
345 * \return Whether the specified region is locked.
\r
347 extern Bool flashc_is_region_locked(unsigned int region);
\r
349 /*! \brief Locks or unlocks the region of a page.
\r
351 * \param page_number The page number:
\r
352 * \arg \c 0 to <tt>(flashc_get_page_count() - 1)</tt>: a page number within
\r
354 * \arg <tt>< 0</tt>: the current page number.
\r
355 * \param lock Whether to lock the region of the specified page: \c TRUE or
\r
358 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
359 * \ref flashc_is_programming_error is updated.
\r
361 extern void flashc_lock_page_region(int page_number, Bool lock);
\r
363 /*! \brief Locks or unlocks a region.
\r
365 * \param region The region number: \c 0 to <tt>(AVR32_FLASHC_REGIONS - 1)</tt>.
\r
366 * \param lock Whether to lock the specified region: \c TRUE or \c FALSE.
\r
368 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
369 * \ref flashc_is_programming_error is updated.
\r
371 extern void flashc_lock_region(unsigned int region, Bool lock);
\r
373 /*! \brief Locks or unlocks all regions.
\r
375 * \param lock Whether to lock the regions: \c TRUE or \c FALSE.
\r
377 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
378 * \ref flashc_is_programming_error is updated.
\r
380 extern void flashc_lock_all_regions(Bool lock);
\r
385 /*! \name Access to General-Purpose Fuses
\r
389 /*! \brief Reads a general-purpose fuse bit.
\r
391 * \param gp_fuse_bit The general-purpose fuse bit: \c 0 to \c 31.
\r
393 * \return The value of the specified general-purpose fuse bit.
\r
395 extern Bool flashc_read_gp_fuse_bit(unsigned int gp_fuse_bit);
\r
397 /*! \brief Reads a general-purpose fuse bit-field.
\r
399 * \param pos The bit-position of the general-purpose fuse bit-field: \c 0 to
\r
401 * \param width The bit-width of the general-purpose fuse bit-field: \c 0 to
\r
404 * \return The value of the specified general-purpose fuse bit-field.
\r
406 extern U32 flashc_read_gp_fuse_bitfield(unsigned int pos, unsigned int width);
\r
408 /*! \brief Reads a general-purpose fuse byte.
\r
410 * \param gp_fuse_byte The general-purpose fuse byte: \c 0 to \c 3.
\r
412 * \return The value of the specified general-purpose fuse byte.
\r
414 extern U8 flashc_read_gp_fuse_byte(unsigned int gp_fuse_byte);
\r
416 /*! \brief Reads all general-purpose fuses.
\r
418 * \return The value of all general-purpose fuses as a word.
\r
420 extern U32 flashc_read_all_gp_fuses(void);
\r
422 /*! \brief Erases a general-purpose fuse bit.
\r
424 * \param gp_fuse_bit The general-purpose fuse bit: \c 0 to \c 31.
\r
425 * \param check Whether to check erase: \c TRUE or \c FALSE.
\r
427 * \return Whether the erase succeeded or always \c TRUE if erase check was not
\r
430 * \warning A Lock Error is issued if the Security bit is active and the command
\r
431 * is applied to BOOTPROT or EPFL fuses.
\r
433 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
434 * \ref flashc_is_programming_error is updated.
\r
436 * \note An erase operation can only set bits.
\r
438 extern Bool flashc_erase_gp_fuse_bit(unsigned int gp_fuse_bit, Bool check);
\r
440 /*! \brief Erases a general-purpose fuse bit-field.
\r
442 * \param pos The bit-position of the general-purpose fuse bit-field: \c 0 to
\r
444 * \param width The bit-width of the general-purpose fuse bit-field: \c 0 to
\r
446 * \param check Whether to check erase: \c TRUE or \c FALSE.
\r
448 * \return Whether the erase succeeded or always \c TRUE if erase check was not
\r
451 * \warning A Lock Error is issued if the Security bit is active and the command
\r
452 * is applied to BOOTPROT or EPFL fuses.
\r
454 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
455 * \ref flashc_is_programming_error is updated.
\r
457 * \note An erase operation can only set bits.
\r
459 extern Bool flashc_erase_gp_fuse_bitfield(unsigned int pos, unsigned int width, Bool check);
\r
461 /*! \brief Erases a general-purpose fuse byte.
\r
463 * \param gp_fuse_byte The general-purpose fuse byte: \c 0 to \c 3.
\r
464 * \param check Whether to check erase: \c TRUE or \c FALSE.
\r
466 * \return Whether the erase succeeded or always \c TRUE if erase check was not
\r
469 * \warning A Lock Error is issued if the Security bit is active.
\r
471 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
472 * \ref flashc_is_programming_error is updated.
\r
474 * \note An erase operation can only set bits.
\r
476 extern Bool flashc_erase_gp_fuse_byte(unsigned int gp_fuse_byte, Bool check);
\r
478 /*! \brief Erases all general-purpose fuses.
\r
480 * \param check Whether to check erase: \c TRUE or \c FALSE.
\r
482 * \return Whether the erase succeeded or always \c TRUE if erase check was not
\r
485 * \warning A Lock Error is issued if the Security bit is active.
\r
487 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
488 * \ref flashc_is_programming_error is updated.
\r
490 * \note An erase operation can only set bits.
\r
492 extern Bool flashc_erase_all_gp_fuses(Bool check);
\r
494 /*! \brief Writes a general-purpose fuse bit.
\r
496 * \param gp_fuse_bit The general-purpose fuse bit: \c 0 to \c 31.
\r
497 * \param value The value of the specified general-purpose fuse bit.
\r
499 * \warning A Lock Error is issued if the Security bit is active and the command
\r
500 * is applied to BOOTPROT or EPFL fuses.
\r
502 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
503 * \ref flashc_is_programming_error is updated.
\r
505 * \note A write operation can only clear bits.
\r
507 extern void flashc_write_gp_fuse_bit(unsigned int gp_fuse_bit, Bool value);
\r
509 /*! \brief Writes a general-purpose fuse bit-field.
\r
511 * \param pos The bit-position of the general-purpose fuse bit-field: \c 0 to
\r
513 * \param width The bit-width of the general-purpose fuse bit-field: \c 0 to
\r
515 * \param value The value of the specified general-purpose fuse bit-field.
\r
517 * \warning A Lock Error is issued if the Security bit is active and the command
\r
518 * is applied to BOOTPROT or EPFL fuses.
\r
520 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
521 * \ref flashc_is_programming_error is updated.
\r
523 * \note A write operation can only clear bits.
\r
525 extern void flashc_write_gp_fuse_bitfield(unsigned int pos, unsigned int width, U32 value);
\r
527 /*! \brief Writes a general-purpose fuse byte.
\r
529 * \param gp_fuse_byte The general-purpose fuse byte: \c 0 to \c 3.
\r
530 * \param value The value of the specified general-purpose fuse byte.
\r
532 * \warning A Lock Error is issued if the Security bit is active.
\r
534 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
535 * \ref flashc_is_programming_error is updated.
\r
537 * \note A write operation can only clear bits.
\r
539 extern void flashc_write_gp_fuse_byte(unsigned int gp_fuse_byte, U8 value);
\r
541 /*! \brief Writes all general-purpose fuses.
\r
543 * \param value The value of all general-purpose fuses as a word.
\r
545 * \warning A Lock Error is issued if the Security bit is active.
\r
547 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
548 * \ref flashc_is_programming_error is updated.
\r
550 * \note A write operation can only clear bits.
\r
552 extern void flashc_write_all_gp_fuses(U32 value);
\r
554 /*! \brief Sets a general-purpose fuse bit with the appropriate erase and write
\r
557 * \param gp_fuse_bit The general-purpose fuse bit: \c 0 to \c 31.
\r
558 * \param value The value of the specified general-purpose fuse bit.
\r
560 * \warning A Lock Error is issued if the Security bit is active and the command
\r
561 * is applied to BOOTPROT or EPFL fuses.
\r
563 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
564 * \ref flashc_is_programming_error is updated.
\r
566 extern void flashc_set_gp_fuse_bit(unsigned int gp_fuse_bit, Bool value);
\r
568 /*! \brief Sets a general-purpose fuse bit-field with the appropriate erase and
\r
569 * write operations.
\r
571 * \param pos The bit-position of the general-purpose fuse bit-field: \c 0 to
\r
573 * \param width The bit-width of the general-purpose fuse bit-field: \c 0 to
\r
575 * \param value The value of the specified general-purpose fuse bit-field.
\r
577 * \warning A Lock Error is issued if the Security bit is active and the command
\r
578 * is applied to BOOTPROT or EPFL fuses.
\r
580 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
581 * \ref flashc_is_programming_error is updated.
\r
583 extern void flashc_set_gp_fuse_bitfield(unsigned int pos, unsigned int width, U32 value);
\r
585 /*! \brief Sets a general-purpose fuse byte with the appropriate erase and write
\r
588 * \param gp_fuse_byte The general-purpose fuse byte: \c 0 to \c 3.
\r
589 * \param value The value of the specified general-purpose fuse byte.
\r
591 * \warning A Lock Error is issued if the Security bit is active.
\r
593 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
594 * \ref flashc_is_programming_error is updated.
\r
596 extern void flashc_set_gp_fuse_byte(unsigned int gp_fuse_byte, U8 value);
\r
598 /*! \brief Sets all general-purpose fuses with the appropriate erase and write
\r
601 * \param value The value of all general-purpose fuses as a word.
\r
603 * \warning A Lock Error is issued if the Security bit is active.
\r
605 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
606 * \ref flashc_is_programming_error is updated.
\r
608 extern void flashc_set_all_gp_fuses(U32 value);
\r
613 /*! \name Access to Flash Pages
\r
617 /*! \brief Clears the page buffer.
\r
619 * This command resets all bits in the page buffer to one. Write accesses to the
\r
620 * page buffer can only change page buffer bits from one to zero.
\r
622 * \warning The page buffer is not automatically reset after a page write.
\r
624 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
625 * \ref flashc_is_programming_error is updated.
\r
627 extern void flashc_clear_page_buffer(void);
\r
629 /*! \brief Tells whether the page to which the last Quick Page Read command was
\r
630 * applied was erased.
\r
632 * \return Whether the page to which the last Quick Page Read command was
\r
633 * applied was erased.
\r
635 extern Bool flashc_is_page_erased(void);
\r
637 /*! \brief Applies the Quick Page Read command to a page.
\r
639 * \param page_number The page number:
\r
640 * \arg \c 0 to <tt>(flashc_get_page_count() - 1)</tt>: a page number within
\r
642 * \arg <tt>< 0</tt>: the current page number.
\r
644 * \return Whether the specified page is erased.
\r
646 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
647 * \ref flashc_is_programming_error is updated.
\r
649 extern Bool flashc_quick_page_read(int page_number);
\r
651 /*! \brief Erases a page.
\r
653 * \param page_number The page number:
\r
654 * \arg \c 0 to <tt>(flashc_get_page_count() - 1)</tt>: a page number within
\r
656 * \arg <tt>< 0</tt>: the current page number.
\r
657 * \param check Whether to check erase: \c TRUE or \c FALSE.
\r
659 * \return Whether the erase succeeded or always \c TRUE if erase check was not
\r
662 * \warning A Lock Error is issued if the command is applied to a page belonging
\r
663 * to a locked region or to the bootloader protected area.
\r
665 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
666 * \ref flashc_is_programming_error is updated.
\r
668 * \note An erase operation can only set bits.
\r
670 extern Bool flashc_erase_page(int page_number, Bool check);
\r
672 /*! \brief Erases all pages within the flash array.
\r
674 * \param check Whether to check erase: \c TRUE or \c FALSE.
\r
676 * \return Whether the erase succeeded or always \c TRUE if erase check was not
\r
679 * \warning A Lock Error is issued if at least one region is locked or the
\r
680 * bootloader protection is active.
\r
682 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
683 * \ref flashc_is_programming_error is updated.
\r
685 * \note An erase operation can only set bits.
\r
687 extern Bool flashc_erase_all_pages(Bool check);
\r
689 /*! \brief Writes a page from the page buffer.
\r
691 * \param page_number The page number:
\r
692 * \arg \c 0 to <tt>(flashc_get_page_count() - 1)</tt>: a page number within
\r
694 * \arg <tt>< 0</tt>: the current page number.
\r
696 * \warning A Lock Error is issued if the command is applied to a page belonging
\r
697 * to a locked region or to the bootloader protected area.
\r
699 * \warning The page buffer is not automatically reset after a page write.
\r
701 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
702 * \ref flashc_is_programming_error is updated.
\r
704 * \note A write operation can only clear bits.
\r
706 extern void flashc_write_page(int page_number);
\r
708 /*! \brief Checks whether the User page is erased.
\r
710 * \return Whether the User page is erased.
\r
712 extern Bool flashc_check_user_page_erase(void);
\r
714 /*! \brief Erases the User page.
\r
716 * \param check Whether to check erase: \c TRUE or \c FALSE.
\r
718 * \return Whether the erase succeeded or always \c TRUE if erase check was not
\r
721 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
722 * \ref flashc_is_programming_error is updated.
\r
724 * \note An erase operation can only set bits.
\r
726 extern Bool flashc_erase_user_page(Bool check);
\r
728 /*! \brief Writes the User page from the page buffer.
\r
730 * \warning The page buffer is not automatically reset after a page write.
\r
732 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
733 * \ref flashc_is_programming_error is updated.
\r
735 * \note A write operation can only clear bits.
\r
737 extern void flashc_write_user_page(void);
\r
739 /*! \brief Copies \a nbytes bytes to the flash destination pointed to by \a dst
\r
740 * from the repeated \a src source byte.
\r
742 * The destination areas that are not within the flash array or the User page
\r
745 * All pointer and size alignments are supported.
\r
747 * \param dst Pointer to flash destination.
\r
748 * \param src Source byte.
\r
749 * \param nbytes Number of bytes to set.
\r
750 * \param erase Whether to erase before writing: \c TRUE or \c FALSE.
\r
752 * \return The value of \a dst.
\r
754 * \warning A Lock Error is issued if the command is applied to pages belonging
\r
755 * to a locked region or to the bootloader protected area.
\r
757 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
758 * \ref flashc_is_programming_error is updated.
\r
760 extern volatile void *flashc_memset8(volatile void *dst, U8 src, size_t nbytes, Bool erase);
\r
762 /*! \brief Copies \a nbytes bytes to the flash destination pointed to by \a dst
\r
763 * from the repeated \a src big-endian source half-word.
\r
765 * The destination areas that are not within the flash array or the User page
\r
768 * All pointer and size alignments are supported.
\r
770 * \param dst Pointer to flash destination.
\r
771 * \param src Source half-word.
\r
772 * \param nbytes Number of bytes to set.
\r
773 * \param erase Whether to erase before writing: \c TRUE or \c FALSE.
\r
775 * \return The value of \a dst.
\r
777 * \warning A Lock Error is issued if the command is applied to pages belonging
\r
778 * to a locked region or to the bootloader protected area.
\r
780 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
781 * \ref flashc_is_programming_error is updated.
\r
783 extern volatile void *flashc_memset16(volatile void *dst, U16 src, size_t nbytes, Bool erase);
\r
785 /*! \brief Copies \a nbytes bytes to the flash destination pointed to by \a dst
\r
786 * from the repeated \a src big-endian source word.
\r
788 * The destination areas that are not within the flash array or the User page
\r
791 * All pointer and size alignments are supported.
\r
793 * \param dst Pointer to flash destination.
\r
794 * \param src Source word.
\r
795 * \param nbytes Number of bytes to set.
\r
796 * \param erase Whether to erase before writing: \c TRUE or \c FALSE.
\r
798 * \return The value of \a dst.
\r
800 * \warning A Lock Error is issued if the command is applied to pages belonging
\r
801 * to a locked region or to the bootloader protected area.
\r
803 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
804 * \ref flashc_is_programming_error is updated.
\r
806 extern volatile void *flashc_memset32(volatile void *dst, U32 src, size_t nbytes, Bool erase);
\r
808 /*! \brief Copies \a nbytes bytes to the flash destination pointed to by \a dst
\r
809 * from the repeated \a src big-endian source double-word.
\r
811 * The destination areas that are not within the flash array or the User page
\r
814 * All pointer and size alignments are supported.
\r
816 * \param dst Pointer to flash destination.
\r
817 * \param src Source double-word.
\r
818 * \param nbytes Number of bytes to set.
\r
819 * \param erase Whether to erase before writing: \c TRUE or \c FALSE.
\r
821 * \return The value of \a dst.
\r
823 * \warning A Lock Error is issued if the command is applied to pages belonging
\r
824 * to a locked region or to the bootloader protected area.
\r
826 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
827 * \ref flashc_is_programming_error is updated.
\r
829 extern volatile void *flashc_memset64(volatile void *dst, U64 src, size_t nbytes, Bool erase);
\r
831 /*! \brief Copies \a nbytes bytes to the flash destination pointed to by \a dst
\r
832 * from the repeated \a src big-endian source pattern.
\r
834 * The destination areas that are not within the flash array or the User page
\r
837 * All pointer and size alignments are supported.
\r
839 * \param dst Pointer to flash destination.
\r
840 * \param src Source double-word.
\r
841 * \param src_width \a src width in bits: 8, 16, 32 or 64.
\r
842 * \param nbytes Number of bytes to set.
\r
843 * \param erase Whether to erase before writing: \c TRUE or \c FALSE.
\r
845 * \return The value of \a dst.
\r
847 * \warning A Lock Error is issued if the command is applied to pages belonging
\r
848 * to a locked region or to the bootloader protected area.
\r
850 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
851 * \ref flashc_is_programming_error is updated.
\r
853 #define flashc_memset(dst, src, src_width, nbytes, erase) \
\r
854 TPASTE2(flashc_memset, src_width)((dst), (src), (nbytes), (erase))
\r
856 /*! \brief Copies \a nbytes bytes to the flash destination pointed to by \a dst
\r
857 * from the source pointed to by \a src.
\r
859 * The destination areas that are not within the flash array or the User page
\r
862 * All pointer and size alignments are supported.
\r
864 * \param dst Pointer to flash destination.
\r
865 * \param src Pointer to source data.
\r
866 * \param nbytes Number of bytes to copy.
\r
867 * \param erase Whether to erase before writing: \c TRUE or \c FALSE.
\r
869 * \return The value of \a dst.
\r
871 * \warning If copying takes place between areas that overlap, the behavior is
\r
874 * \warning A Lock Error is issued if the command is applied to pages belonging
\r
875 * to a locked region or to the bootloader protected area.
\r
877 * \note The FLASHC error status returned by \ref flashc_is_lock_error and
\r
878 * \ref flashc_is_programming_error is updated.
\r
880 extern volatile void *flashc_memcpy(volatile void *dst, const void *src, size_t nbytes, Bool erase);
\r
885 #endif // _FLASHC_H_
\r