flashc.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
  2. /*This file is prepared for Doxygen automatic documentation generation.*/
  3. /*! \file *********************************************************************
  4. *
  5. * \brief FLASHC driver for AVR32 UC3.
  6. *
  7. * AVR32 Flash Controller driver module.
  8. *
  9. * - Compiler: IAR EWAVR32 and GNU GCC for AVR32
  10. * - Supported devices: All AVR32 devices with a FLASHC module can be used.
  11. * - AppNote:
  12. *
  13. * \author Atmel Corporation: http://www.atmel.com \n
  14. * Support and FAQ: http://support.atmel.no/
  15. *
  16. ******************************************************************************/
  17. /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
  18. *
  19. * Redistribution and use in source and binary forms, with or without
  20. * modification, are permitted provided that the following conditions are met:
  21. *
  22. * 1. Redistributions of source code must retain the above copyright notice, this
  23. * list of conditions and the following disclaimer.
  24. *
  25. * 2. Redistributions in binary form must reproduce the above copyright notice,
  26. * this list of conditions and the following disclaimer in the documentation
  27. * and/or other materials provided with the distribution.
  28. *
  29. * 3. The name of Atmel may not be used to endorse or promote products derived
  30. * from this software without specific prior written permission.
  31. *
  32. * 4. This software may only be redistributed and used in connection with an Atmel
  33. * AVR product.
  34. *
  35. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  37. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  38. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  39. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  40. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  41. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  42. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  45. *
  46. */
  47. #ifndef _FLASHC_H_
  48. #define _FLASHC_H_
  49. #include <avr32/io.h>
  50. #include <stddef.h>
  51. #include "compiler.h"
  52. //! Number of flash regions defined by the FLASHC.
  53. #define AVR32_FLASHC_REGIONS (AVR32_FLASHC_FLASH_SIZE /\
  54. (AVR32_FLASHC_PAGES_PR_REGION * AVR32_FLASHC_PAGE_SIZE))
  55. /*! \name Flash Properties
  56. */
  57. //! @{
  58. /*! \brief Gets the size of the whole flash array.
  59. *
  60. * \return The size of the whole flash array in bytes.
  61. */
  62. extern unsigned int flashc_get_flash_size(void);
  63. /*! \brief Gets the total number of pages in the flash array.
  64. *
  65. * \return The total number of pages in the flash array.
  66. */
  67. extern unsigned int flashc_get_page_count(void);
  68. /*! \brief Gets the number of pages in each flash region.
  69. *
  70. * \return The number of pages in each flash region.
  71. */
  72. extern unsigned int flashc_get_page_count_per_region(void);
  73. /*! \brief Gets the region number of a page.
  74. *
  75. * \param page_number The page number:
  76. * \arg \c 0 to <tt>(flashc_get_page_count() - 1)</tt>: a page number within
  77. * the flash array;
  78. * \arg <tt>< 0</tt>: the current page number.
  79. *
  80. * \return The region number of the specified page.
  81. */
  82. extern unsigned int flashc_get_page_region(int page_number);
  83. /*! \brief Gets the number of the first page of a region.
  84. *
  85. * \param region The region number: \c 0 to <tt>(AVR32_FLASHC_REGIONS - 1)</tt>.
  86. *
  87. * \return The number of the first page of the specified region.
  88. */
  89. extern unsigned int flashc_get_region_first_page_number(unsigned int region);
  90. //! @}
  91. /*! \name FLASHC Control
  92. */
  93. //! @{
  94. /*! \brief Gets the number of wait states of flash read accesses.
  95. *
  96. * \return The number of wait states of flash read accesses.
  97. */
  98. extern unsigned int flashc_get_wait_state(void);
  99. /*! \brief Sets the number of wait states of flash read accesses.
  100. *
  101. * \param wait_state The number of wait states of flash read accesses: \c 0 to
  102. * \c 1.
  103. */
  104. extern void flashc_set_wait_state(unsigned int wait_state);
  105. /*! \brief Tells whether the Flash Ready interrupt is enabled.
  106. *
  107. * \return Whether the Flash Ready interrupt is enabled.
  108. */
  109. extern Bool flashc_is_ready_int_enabled(void);
  110. /*! \brief Enables or disables the Flash Ready interrupt.
  111. *
  112. * \param enable Whether to enable the Flash Ready interrupt: \c TRUE or
  113. * \c FALSE.
  114. */
  115. extern void flashc_enable_ready_int(Bool enable);
  116. /*! \brief Tells whether the Lock Error interrupt is enabled.
  117. *
  118. * \return Whether the Lock Error interrupt is enabled.
  119. */
  120. extern Bool flashc_is_lock_error_int_enabled(void);
  121. /*! \brief Enables or disables the Lock Error interrupt.
  122. *
  123. * \param enable Whether to enable the Lock Error interrupt: \c TRUE or
  124. * \c FALSE.
  125. */
  126. extern void flashc_enable_lock_error_int(Bool enable);
  127. /*! \brief Tells whether the Programming Error interrupt is enabled.
  128. *
  129. * \return Whether the Programming Error interrupt is enabled.
  130. */
  131. extern Bool flashc_is_prog_error_int_enabled(void);
  132. /*! \brief Enables or disables the Programming Error interrupt.
  133. *
  134. * \param enable Whether to enable the Programming Error interrupt: \c TRUE or
  135. * \c FALSE.
  136. */
  137. extern void flashc_enable_prog_error_int(Bool enable);
  138. //! @}
  139. /*! \name FLASHC Status
  140. */
  141. //! @{
  142. /*! \brief Tells whether the FLASHC is ready to run a new command.
  143. *
  144. * \return Whether the FLASHC is ready to run a new command.
  145. */
  146. extern Bool flashc_is_ready(void);
  147. /*! \brief Waits actively until the FLASHC is ready to run a new command.
  148. *
  149. * This is the default function assigned to \ref flashc_wait_until_ready.
  150. */
  151. extern void flashc_default_wait_until_ready(void);
  152. //! Pointer to the function used by the driver when it needs to wait until the
  153. //! FLASHC is ready to run a new command.
  154. //! The default function is \ref flashc_default_wait_until_ready.
  155. //! The user may change this pointer to use another implementation.
  156. extern void (*volatile flashc_wait_until_ready)(void);
  157. /*! \brief Tells whether a Lock Error has occurred during the last function
  158. * called that issued one or more FLASHC commands.
  159. *
  160. * \return Whether a Lock Error has occurred during the last function called
  161. * that issued one or more FLASHC commands.
  162. */
  163. extern Bool flashc_is_lock_error(void);
  164. /*! \brief Tells whether a Programming Error has occurred during the last
  165. * function called that issued one or more FLASHC commands.
  166. *
  167. * \return Whether a Programming Error has occurred during the last function
  168. * called that issued one or more FLASHC commands.
  169. */
  170. extern Bool flashc_is_programming_error(void);
  171. //! @}
  172. /*! \name FLASHC Command Control
  173. */
  174. //! @{
  175. /*! \brief Gets the last issued FLASHC command.
  176. *
  177. * \return The last issued FLASHC command.
  178. */
  179. extern unsigned int flashc_get_command(void);
  180. /*! \brief Gets the current FLASHC page number.
  181. *
  182. * \return The current FLASHC page number.
  183. */
  184. extern unsigned int flashc_get_page_number(void);
  185. /*! \brief Issues a FLASHC command.
  186. *
  187. * \param command The command: \c AVR32_FLASHC_FCMD_CMD_x.
  188. * \param page_number The page number to apply the command to:
  189. * \arg \c 0 to <tt>(flashc_get_page_count() - 1)</tt>: a page number within
  190. * the flash array;
  191. * \arg <tt>< 0</tt>: use this to apply the command to the current page number
  192. * or if the command does not apply to any page number;
  193. * \arg this argument may have other meanings according to the command. See
  194. * the FLASHC chapter of the MCU datasheet.
  195. *
  196. * \warning A Lock Error is issued if the command violates the protection
  197. * mechanism.
  198. *
  199. * \warning A Programming Error is issued if the command is invalid.
  200. *
  201. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  202. * \ref flashc_is_programming_error is updated.
  203. */
  204. extern void flashc_issue_command(unsigned int command, int page_number);
  205. //! @}
  206. /*! \name FLASHC Global Commands
  207. */
  208. //! @{
  209. /*! \brief Issues a No Operation command to the FLASHC.
  210. *
  211. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  212. * \ref flashc_is_programming_error is updated.
  213. */
  214. extern void flashc_no_operation(void);
  215. /*! \brief Issues an Erase All command to the FLASHC.
  216. *
  217. * This command erases all bits in the flash array, the general-purpose fuse
  218. * bits and the Security bit. The User page is not erased.
  219. *
  220. * This command also ensures that all volatile memories, such as register file
  221. * and RAMs, are erased before the Security bit is erased, i.e. deactivated.
  222. *
  223. * \warning A Lock Error is issued if at least one region is locked or the
  224. * bootloader protection is active.
  225. *
  226. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  227. * \ref flashc_is_programming_error is updated.
  228. *
  229. * \note An erase operation can only set bits.
  230. */
  231. extern void flashc_erase_all(void);
  232. //! @}
  233. /*! \name FLASHC Protection Mechanisms
  234. */
  235. //! @{
  236. /*! \brief Tells whether the Security bit is active.
  237. *
  238. * \return Whether the Security bit is active.
  239. */
  240. extern Bool flashc_is_security_bit_active(void);
  241. /*! \brief Activates the Security bit.
  242. *
  243. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  244. * \ref flashc_is_programming_error is updated.
  245. */
  246. extern void flashc_activate_security_bit(void);
  247. /*! \brief Gets the bootloader protected size.
  248. *
  249. * \return The bootloader protected size in bytes.
  250. */
  251. extern unsigned int flashc_get_bootloader_protected_size(void);
  252. /*! \brief Sets the bootloader protected size.
  253. *
  254. * \param bootprot_size The wanted bootloader protected size in bytes. If this
  255. * size is not supported, the actual size will be the
  256. * nearest greater available size or the maximal possible
  257. * size if the requested size is too large.
  258. *
  259. * \return The actual bootloader protected size in bytes.
  260. *
  261. * \warning A Lock Error is issued if the Security bit is active.
  262. *
  263. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  264. * \ref flashc_is_programming_error is updated.
  265. */
  266. extern unsigned int flashc_set_bootloader_protected_size(unsigned int bootprot_size);
  267. /*! \brief Tells whether external privileged fetch is locked.
  268. *
  269. * \return Whether external privileged fetch is locked.
  270. */
  271. extern Bool flashc_is_external_privileged_fetch_locked(void);
  272. /*! \brief Locks or unlocks external privileged fetch.
  273. *
  274. * \param lock Whether to lock external privileged fetch: \c TRUE or \c FALSE.
  275. *
  276. * \warning A Lock Error is issued if the Security bit is active.
  277. *
  278. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  279. * \ref flashc_is_programming_error is updated.
  280. */
  281. extern void flashc_lock_external_privileged_fetch(Bool lock);
  282. /*! \brief Tells whether the region of a page is locked.
  283. *
  284. * \param page_number The page number:
  285. * \arg \c 0 to <tt>(flashc_get_page_count() - 1)</tt>: a page number within
  286. * the flash array;
  287. * \arg <tt>< 0</tt>: the current page number.
  288. *
  289. * \return Whether the region of the specified page is locked.
  290. */
  291. extern Bool flashc_is_page_region_locked(int page_number);
  292. /*! \brief Tells whether a region is locked.
  293. *
  294. * \param region The region number: \c 0 to <tt>(AVR32_FLASHC_REGIONS - 1)</tt>.
  295. *
  296. * \return Whether the specified region is locked.
  297. */
  298. extern Bool flashc_is_region_locked(unsigned int region);
  299. /*! \brief Locks or unlocks the region of a page.
  300. *
  301. * \param page_number The page number:
  302. * \arg \c 0 to <tt>(flashc_get_page_count() - 1)</tt>: a page number within
  303. * the flash array;
  304. * \arg <tt>< 0</tt>: the current page number.
  305. * \param lock Whether to lock the region of the specified page: \c TRUE or
  306. * \c FALSE.
  307. *
  308. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  309. * \ref flashc_is_programming_error is updated.
  310. */
  311. extern void flashc_lock_page_region(int page_number, Bool lock);
  312. /*! \brief Locks or unlocks a region.
  313. *
  314. * \param region The region number: \c 0 to <tt>(AVR32_FLASHC_REGIONS - 1)</tt>.
  315. * \param lock Whether to lock the specified region: \c TRUE or \c FALSE.
  316. *
  317. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  318. * \ref flashc_is_programming_error is updated.
  319. */
  320. extern void flashc_lock_region(unsigned int region, Bool lock);
  321. /*! \brief Locks or unlocks all regions.
  322. *
  323. * \param lock Whether to lock the regions: \c TRUE or \c FALSE.
  324. *
  325. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  326. * \ref flashc_is_programming_error is updated.
  327. */
  328. extern void flashc_lock_all_regions(Bool lock);
  329. //! @}
  330. /*! \name Access to General-Purpose Fuses
  331. */
  332. //! @{
  333. /*! \brief Reads a general-purpose fuse bit.
  334. *
  335. * \param gp_fuse_bit The general-purpose fuse bit: \c 0 to \c 63.
  336. *
  337. * \return The value of the specified general-purpose fuse bit.
  338. *
  339. * \note The actual number of general-purpose fuse bits implemented by hardware
  340. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  341. * fixed at 1 by hardware.
  342. */
  343. extern Bool flashc_read_gp_fuse_bit(unsigned int gp_fuse_bit);
  344. /*! \brief Reads a general-purpose fuse bit-field.
  345. *
  346. * \param pos The bit-position of the general-purpose fuse bit-field: \c 0 to
  347. * \c 63.
  348. * \param width The bit-width of the general-purpose fuse bit-field: \c 0 to
  349. * \c 64.
  350. *
  351. * \return The value of the specified general-purpose fuse bit-field.
  352. *
  353. * \note The actual number of general-purpose fuse bits implemented by hardware
  354. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  355. * fixed at 1 by hardware.
  356. */
  357. extern U64 flashc_read_gp_fuse_bitfield(unsigned int pos, unsigned int width);
  358. /*! \brief Reads a general-purpose fuse byte.
  359. *
  360. * \param gp_fuse_byte The general-purpose fuse byte: \c 0 to \c 7.
  361. *
  362. * \return The value of the specified general-purpose fuse byte.
  363. *
  364. * \note The actual number of general-purpose fuse bits implemented by hardware
  365. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  366. * fixed at 1 by hardware.
  367. */
  368. extern U8 flashc_read_gp_fuse_byte(unsigned int gp_fuse_byte);
  369. /*! \brief Reads all general-purpose fuses.
  370. *
  371. * \return The value of all general-purpose fuses as a word.
  372. *
  373. * \note The actual number of general-purpose fuse bits implemented by hardware
  374. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  375. * fixed at 1 by hardware.
  376. */
  377. extern U64 flashc_read_all_gp_fuses(void);
  378. /*! \brief Erases a general-purpose fuse bit.
  379. *
  380. * \param gp_fuse_bit The general-purpose fuse bit: \c 0 to \c 63.
  381. * \param check Whether to check erase: \c TRUE or \c FALSE.
  382. *
  383. * \return Whether the erase succeeded or always \c TRUE if erase check was not
  384. * requested.
  385. *
  386. * \warning A Lock Error is issued if the Security bit is active and the command
  387. * is applied to BOOTPROT or EPFL fuses.
  388. *
  389. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  390. * \ref flashc_is_programming_error is updated.
  391. *
  392. * \note An erase operation can only set bits.
  393. *
  394. * \note The actual number of general-purpose fuse bits implemented by hardware
  395. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  396. * fixed at 1 by hardware.
  397. */
  398. extern Bool flashc_erase_gp_fuse_bit(unsigned int gp_fuse_bit, Bool check);
  399. /*! \brief Erases a general-purpose fuse bit-field.
  400. *
  401. * \param pos The bit-position of the general-purpose fuse bit-field: \c 0 to
  402. * \c 63.
  403. * \param width The bit-width of the general-purpose fuse bit-field: \c 0 to
  404. * \c 64.
  405. * \param check Whether to check erase: \c TRUE or \c FALSE.
  406. *
  407. * \return Whether the erase succeeded or always \c TRUE if erase check was not
  408. * requested.
  409. *
  410. * \warning A Lock Error is issued if the Security bit is active and the command
  411. * is applied to BOOTPROT or EPFL fuses.
  412. *
  413. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  414. * \ref flashc_is_programming_error is updated.
  415. *
  416. * \note An erase operation can only set bits.
  417. *
  418. * \note The actual number of general-purpose fuse bits implemented by hardware
  419. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  420. * fixed at 1 by hardware.
  421. */
  422. extern Bool flashc_erase_gp_fuse_bitfield(unsigned int pos, unsigned int width, Bool check);
  423. /*! \brief Erases a general-purpose fuse byte.
  424. *
  425. * \param gp_fuse_byte The general-purpose fuse byte: \c 0 to \c 7.
  426. * \param check Whether to check erase: \c TRUE or \c FALSE.
  427. *
  428. * \return Whether the erase succeeded or always \c TRUE if erase check was not
  429. * requested.
  430. *
  431. * \warning A Lock Error is issued if the Security bit is active.
  432. *
  433. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  434. * \ref flashc_is_programming_error is updated.
  435. *
  436. * \note An erase operation can only set bits.
  437. *
  438. * \note The actual number of general-purpose fuse bits implemented by hardware
  439. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  440. * fixed at 1 by hardware.
  441. */
  442. extern Bool flashc_erase_gp_fuse_byte(unsigned int gp_fuse_byte, Bool check);
  443. /*! \brief Erases all general-purpose fuses.
  444. *
  445. * \param check Whether to check erase: \c TRUE or \c FALSE.
  446. *
  447. * \return Whether the erase succeeded or always \c TRUE if erase check was not
  448. * requested.
  449. *
  450. * \warning A Lock Error is issued if the Security bit is active.
  451. *
  452. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  453. * \ref flashc_is_programming_error is updated.
  454. *
  455. * \note An erase operation can only set bits.
  456. *
  457. * \note The actual number of general-purpose fuse bits implemented by hardware
  458. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  459. * fixed at 1 by hardware.
  460. */
  461. extern Bool flashc_erase_all_gp_fuses(Bool check);
  462. /*! \brief Writes a general-purpose fuse bit.
  463. *
  464. * \param gp_fuse_bit The general-purpose fuse bit: \c 0 to \c 63.
  465. * \param value The value of the specified general-purpose fuse bit.
  466. *
  467. * \warning A Lock Error is issued if the Security bit is active and the command
  468. * is applied to BOOTPROT or EPFL fuses.
  469. *
  470. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  471. * \ref flashc_is_programming_error is updated.
  472. *
  473. * \note A write operation can only clear bits.
  474. *
  475. * \note The actual number of general-purpose fuse bits implemented by hardware
  476. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  477. * fixed at 1 by hardware.
  478. */
  479. extern void flashc_write_gp_fuse_bit(unsigned int gp_fuse_bit, Bool value);
  480. /*! \brief Writes a general-purpose fuse bit-field.
  481. *
  482. * \param pos The bit-position of the general-purpose fuse bit-field: \c 0 to
  483. * \c 63.
  484. * \param width The bit-width of the general-purpose fuse bit-field: \c 0 to
  485. * \c 64.
  486. * \param value The value of the specified general-purpose fuse bit-field.
  487. *
  488. * \warning A Lock Error is issued if the Security bit is active and the command
  489. * is applied to BOOTPROT or EPFL fuses.
  490. *
  491. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  492. * \ref flashc_is_programming_error is updated.
  493. *
  494. * \note A write operation can only clear bits.
  495. *
  496. * \note The actual number of general-purpose fuse bits implemented by hardware
  497. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  498. * fixed at 1 by hardware.
  499. */
  500. extern void flashc_write_gp_fuse_bitfield(unsigned int pos, unsigned int width, U64 value);
  501. /*! \brief Writes a general-purpose fuse byte.
  502. *
  503. * \param gp_fuse_byte The general-purpose fuse byte: \c 0 to \c 7.
  504. * \param value The value of the specified general-purpose fuse byte.
  505. *
  506. * \warning A Lock Error is issued if the Security bit is active.
  507. *
  508. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  509. * \ref flashc_is_programming_error is updated.
  510. *
  511. * \note A write operation can only clear bits.
  512. *
  513. * \note The actual number of general-purpose fuse bits implemented by hardware
  514. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  515. * fixed at 1 by hardware.
  516. */
  517. extern void flashc_write_gp_fuse_byte(unsigned int gp_fuse_byte, U8 value);
  518. /*! \brief Writes all general-purpose fuses.
  519. *
  520. * \param value The value of all general-purpose fuses as a word.
  521. *
  522. * \warning A Lock Error is issued if the Security bit is active.
  523. *
  524. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  525. * \ref flashc_is_programming_error is updated.
  526. *
  527. * \note A write operation can only clear bits.
  528. *
  529. * \note The actual number of general-purpose fuse bits implemented by hardware
  530. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  531. * fixed at 1 by hardware.
  532. */
  533. extern void flashc_write_all_gp_fuses(U64 value);
  534. /*! \brief Sets a general-purpose fuse bit with the appropriate erase and write
  535. * operations.
  536. *
  537. * \param gp_fuse_bit The general-purpose fuse bit: \c 0 to \c 63.
  538. * \param value The value of the specified general-purpose fuse bit.
  539. *
  540. * \warning A Lock Error is issued if the Security bit is active and the command
  541. * is applied to BOOTPROT or EPFL fuses.
  542. *
  543. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  544. * \ref flashc_is_programming_error is updated.
  545. *
  546. * \note The actual number of general-purpose fuse bits implemented by hardware
  547. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  548. * fixed at 1 by hardware.
  549. */
  550. extern void flashc_set_gp_fuse_bit(unsigned int gp_fuse_bit, Bool value);
  551. /*! \brief Sets a general-purpose fuse bit-field with the appropriate erase and
  552. * write operations.
  553. *
  554. * \param pos The bit-position of the general-purpose fuse bit-field: \c 0 to
  555. * \c 63.
  556. * \param width The bit-width of the general-purpose fuse bit-field: \c 0 to
  557. * \c 64.
  558. * \param value The value of the specified general-purpose fuse bit-field.
  559. *
  560. * \warning A Lock Error is issued if the Security bit is active and the command
  561. * is applied to BOOTPROT or EPFL fuses.
  562. *
  563. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  564. * \ref flashc_is_programming_error is updated.
  565. *
  566. * \note The actual number of general-purpose fuse bits implemented by hardware
  567. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  568. * fixed at 1 by hardware.
  569. */
  570. extern void flashc_set_gp_fuse_bitfield(unsigned int pos, unsigned int width, U64 value);
  571. /*! \brief Sets a general-purpose fuse byte with the appropriate erase and write
  572. * operations.
  573. *
  574. * \param gp_fuse_byte The general-purpose fuse byte: \c 0 to \c 7.
  575. * \param value The value of the specified general-purpose fuse byte.
  576. *
  577. * \warning A Lock Error is issued if the Security bit is active.
  578. *
  579. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  580. * \ref flashc_is_programming_error is updated.
  581. *
  582. * \note The actual number of general-purpose fuse bits implemented by hardware
  583. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  584. * fixed at 1 by hardware.
  585. */
  586. extern void flashc_set_gp_fuse_byte(unsigned int gp_fuse_byte, U8 value);
  587. /*! \brief Sets all general-purpose fuses with the appropriate erase and write
  588. * operations.
  589. *
  590. * \param value The value of all general-purpose fuses as a word.
  591. *
  592. * \warning A Lock Error is issued if the Security bit is active.
  593. *
  594. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  595. * \ref flashc_is_programming_error is updated.
  596. *
  597. * \note The actual number of general-purpose fuse bits implemented by hardware
  598. * is given by \c AVR32_FLASHC_GPF_NUM. The other bits among the 64 are
  599. * fixed at 1 by hardware.
  600. */
  601. extern void flashc_set_all_gp_fuses(U64 value);
  602. //! @}
  603. /*! \name Access to Flash Pages
  604. */
  605. //! @{
  606. /*! \brief Clears the page buffer.
  607. *
  608. * This command resets all bits in the page buffer to one. Write accesses to the
  609. * page buffer can only change page buffer bits from one to zero.
  610. *
  611. * \warning The page buffer is not automatically reset after a page write.
  612. *
  613. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  614. * \ref flashc_is_programming_error is updated.
  615. */
  616. extern void flashc_clear_page_buffer(void);
  617. /*! \brief Tells whether the page to which the last Quick Page Read or Quick
  618. * Page Read User Page command was applied was erased.
  619. *
  620. * \return Whether the page to which the last Quick Page Read or Quick Page Read
  621. * User Page command was applied was erased.
  622. */
  623. extern Bool flashc_is_page_erased(void);
  624. /*! \brief Applies the Quick Page Read command to a page.
  625. *
  626. * \param page_number The page number:
  627. * \arg \c 0 to <tt>(flashc_get_page_count() - 1)</tt>: a page number within
  628. * the flash array;
  629. * \arg <tt>< 0</tt>: the current page number.
  630. *
  631. * \return Whether the specified page is erased.
  632. *
  633. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  634. * \ref flashc_is_programming_error is updated.
  635. */
  636. extern Bool flashc_quick_page_read(int page_number);
  637. /*! \brief Erases a page.
  638. *
  639. * \param page_number The page number:
  640. * \arg \c 0 to <tt>(flashc_get_page_count() - 1)</tt>: a page number within
  641. * the flash array;
  642. * \arg <tt>< 0</tt>: the current page number.
  643. * \param check Whether to check erase: \c TRUE or \c FALSE.
  644. *
  645. * \return Whether the erase succeeded or always \c TRUE if erase check was not
  646. * requested.
  647. *
  648. * \warning A Lock Error is issued if the command is applied to a page belonging
  649. * to a locked region or to the bootloader protected area.
  650. *
  651. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  652. * \ref flashc_is_programming_error is updated.
  653. *
  654. * \note An erase operation can only set bits.
  655. */
  656. extern Bool flashc_erase_page(int page_number, Bool check);
  657. /*! \brief Erases all pages within the flash array.
  658. *
  659. * \param check Whether to check erase: \c TRUE or \c FALSE.
  660. *
  661. * \return Whether the erase succeeded or always \c TRUE if erase check was not
  662. * requested.
  663. *
  664. * \warning A Lock Error is issued if at least one region is locked or the
  665. * bootloader protection is active.
  666. *
  667. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  668. * \ref flashc_is_programming_error is updated.
  669. *
  670. * \note An erase operation can only set bits.
  671. */
  672. extern Bool flashc_erase_all_pages(Bool check);
  673. /*! \brief Writes a page from the page buffer.
  674. *
  675. * \param page_number The page number:
  676. * \arg \c 0 to <tt>(flashc_get_page_count() - 1)</tt>: a page number within
  677. * the flash array;
  678. * \arg <tt>< 0</tt>: the current page number.
  679. *
  680. * \warning A Lock Error is issued if the command is applied to a page belonging
  681. * to a locked region or to the bootloader protected area.
  682. *
  683. * \warning The page buffer is not automatically reset after a page write.
  684. *
  685. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  686. * \ref flashc_is_programming_error is updated.
  687. *
  688. * \note A write operation can only clear bits.
  689. */
  690. extern void flashc_write_page(int page_number);
  691. /*! \brief Issues a Quick Page Read User Page command to the FLASHC.
  692. *
  693. * \return Whether the User page is erased.
  694. *
  695. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  696. * \ref flashc_is_programming_error is updated.
  697. */
  698. extern Bool flashc_quick_user_page_read(void);
  699. /*! \brief Erases the User page.
  700. *
  701. * \param check Whether to check erase: \c TRUE or \c FALSE.
  702. *
  703. * \return Whether the erase succeeded or always \c TRUE if erase check was not
  704. * requested.
  705. *
  706. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  707. * \ref flashc_is_programming_error is updated.
  708. *
  709. * \note An erase operation can only set bits.
  710. */
  711. extern Bool flashc_erase_user_page(Bool check);
  712. /*! \brief Writes the User page from the page buffer.
  713. *
  714. * \warning The page buffer is not automatically reset after a page write.
  715. *
  716. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  717. * \ref flashc_is_programming_error is updated.
  718. *
  719. * \note A write operation can only clear bits.
  720. */
  721. extern void flashc_write_user_page(void);
  722. /*! \brief Copies \a nbytes bytes to the flash destination pointed to by \a dst
  723. * from the repeated \a src source byte.
  724. *
  725. * The destination areas that are not within the flash array or the User page
  726. * are ignored.
  727. *
  728. * All pointer and size alignments are supported.
  729. *
  730. * \param dst Pointer to flash destination.
  731. * \param src Source byte.
  732. * \param nbytes Number of bytes to set.
  733. * \param erase Whether to erase before writing: \c TRUE or \c FALSE.
  734. *
  735. * \return The value of \a dst.
  736. *
  737. * \warning This function may be called with \a erase set to \c FALSE only if
  738. * the destination consists only of erased words, i.e. this function
  739. * can not be used to write only one bit of a previously written word.
  740. * E.g., if \c 0x00000001 then \c 0xFFFFFFFE are written to a word, the
  741. * resulting value in flash may be different from \c 0x00000000.
  742. *
  743. * \warning A Lock Error is issued if the command is applied to pages belonging
  744. * to a locked region or to the bootloader protected area.
  745. *
  746. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  747. * \ref flashc_is_programming_error is updated.
  748. */
  749. extern volatile void *flashc_memset8(volatile void *dst, U8 src, size_t nbytes, Bool erase);
  750. /*! \brief Copies \a nbytes bytes to the flash destination pointed to by \a dst
  751. * from the repeated \a src big-endian source half-word.
  752. *
  753. * The destination areas that are not within the flash array or the User page
  754. * are ignored.
  755. *
  756. * All pointer and size alignments are supported.
  757. *
  758. * \param dst Pointer to flash destination.
  759. * \param src Source half-word.
  760. * \param nbytes Number of bytes to set.
  761. * \param erase Whether to erase before writing: \c TRUE or \c FALSE.
  762. *
  763. * \return The value of \a dst.
  764. *
  765. * \warning This function may be called with \a erase set to \c FALSE only if
  766. * the destination consists only of erased words, i.e. this function
  767. * can not be used to write only one bit of a previously written word.
  768. * E.g., if \c 0x00000001 then \c 0xFFFFFFFE are written to a word, the
  769. * resulting value in flash may be different from \c 0x00000000.
  770. *
  771. * \warning A Lock Error is issued if the command is applied to pages belonging
  772. * to a locked region or to the bootloader protected area.
  773. *
  774. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  775. * \ref flashc_is_programming_error is updated.
  776. */
  777. extern volatile void *flashc_memset16(volatile void *dst, U16 src, size_t nbytes, Bool erase);
  778. /*! \brief Copies \a nbytes bytes to the flash destination pointed to by \a dst
  779. * from the repeated \a src big-endian source word.
  780. *
  781. * The destination areas that are not within the flash array or the User page
  782. * are ignored.
  783. *
  784. * All pointer and size alignments are supported.
  785. *
  786. * \param dst Pointer to flash destination.
  787. * \param src Source word.
  788. * \param nbytes Number of bytes to set.
  789. * \param erase Whether to erase before writing: \c TRUE or \c FALSE.
  790. *
  791. * \return The value of \a dst.
  792. *
  793. * \warning This function may be called with \a erase set to \c FALSE only if
  794. * the destination consists only of erased words, i.e. this function
  795. * can not be used to write only one bit of a previously written word.
  796. * E.g., if \c 0x00000001 then \c 0xFFFFFFFE are written to a word, the
  797. * resulting value in flash may be different from \c 0x00000000.
  798. *
  799. * \warning A Lock Error is issued if the command is applied to pages belonging
  800. * to a locked region or to the bootloader protected area.
  801. *
  802. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  803. * \ref flashc_is_programming_error is updated.
  804. */
  805. extern volatile void *flashc_memset32(volatile void *dst, U32 src, size_t nbytes, Bool erase);
  806. /*! \brief Copies \a nbytes bytes to the flash destination pointed to by \a dst
  807. * from the repeated \a src big-endian source double-word.
  808. *
  809. * The destination areas that are not within the flash array or the User page
  810. * are ignored.
  811. *
  812. * All pointer and size alignments are supported.
  813. *
  814. * \param dst Pointer to flash destination.
  815. * \param src Source double-word.
  816. * \param nbytes Number of bytes to set.
  817. * \param erase Whether to erase before writing: \c TRUE or \c FALSE.
  818. *
  819. * \return The value of \a dst.
  820. *
  821. * \warning This function may be called with \a erase set to \c FALSE only if
  822. * the destination consists only of erased words, i.e. this function
  823. * can not be used to write only one bit of a previously written word.
  824. * E.g., if \c 0x00000001 then \c 0xFFFFFFFE are written to a word, the
  825. * resulting value in flash may be different from \c 0x00000000.
  826. *
  827. * \warning A Lock Error is issued if the command is applied to pages belonging
  828. * to a locked region or to the bootloader protected area.
  829. *
  830. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  831. * \ref flashc_is_programming_error is updated.
  832. */
  833. extern volatile void *flashc_memset64(volatile void *dst, U64 src, size_t nbytes, Bool erase);
  834. /*! \brief Copies \a nbytes bytes to the flash destination pointed to by \a dst
  835. * from the repeated \a src big-endian source pattern.
  836. *
  837. * The destination areas that are not within the flash array or the User page
  838. * are ignored.
  839. *
  840. * All pointer and size alignments are supported.
  841. *
  842. * \param dst Pointer to flash destination.
  843. * \param src Source double-word.
  844. * \param src_width \a src width in bits: 8, 16, 32 or 64.
  845. * \param nbytes Number of bytes to set.
  846. * \param erase Whether to erase before writing: \c TRUE or \c FALSE.
  847. *
  848. * \return The value of \a dst.
  849. *
  850. * \warning This function may be called with \a erase set to \c FALSE only if
  851. * the destination consists only of erased words, i.e. this function
  852. * can not be used to write only one bit of a previously written word.
  853. * E.g., if \c 0x00000001 then \c 0xFFFFFFFE are written to a word, the
  854. * resulting value in flash may be different from \c 0x00000000.
  855. *
  856. * \warning A Lock Error is issued if the command is applied to pages belonging
  857. * to a locked region or to the bootloader protected area.
  858. *
  859. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  860. * \ref flashc_is_programming_error is updated.
  861. */
  862. #define flashc_memset(dst, src, src_width, nbytes, erase) \
  863. TPASTE2(flashc_memset, src_width)((dst), (src), (nbytes), (erase))
  864. /*! \brief Copies \a nbytes bytes to the flash destination pointed to by \a dst
  865. * from the source pointed to by \a src.
  866. *
  867. * The destination areas that are not within the flash array or the User page
  868. * are ignored.
  869. *
  870. * All pointer and size alignments are supported.
  871. *
  872. * \param dst Pointer to flash destination.
  873. * \param src Pointer to source data.
  874. * \param nbytes Number of bytes to copy.
  875. * \param erase Whether to erase before writing: \c TRUE or \c FALSE.
  876. *
  877. * \return The value of \a dst.
  878. *
  879. * \warning If copying takes place between areas that overlap, the behavior is
  880. * undefined.
  881. *
  882. * \warning This function may be called with \a erase set to \c FALSE only if
  883. * the destination consists only of erased words, i.e. this function
  884. * can not be used to write only one bit of a previously written word.
  885. * E.g., if \c 0x00000001 then \c 0xFFFFFFFE are written to a word, the
  886. * resulting value in flash may be different from \c 0x00000000.
  887. *
  888. * \warning A Lock Error is issued if the command is applied to pages belonging
  889. * to a locked region or to the bootloader protected area.
  890. *
  891. * \note The FLASHC error status returned by \ref flashc_is_lock_error and
  892. * \ref flashc_is_programming_error is updated.
  893. */
  894. extern volatile void *flashc_memcpy(volatile void *dst, const void *src, size_t nbytes, Bool erase);
  895. #if UC3C
  896. /*! \brief Depednding to the CPU frequency, set the wait states of flash read
  897. * accesses and enable or disable the High speed read mode.
  898. *
  899. * \param cpu_f_hz The CPU frequency
  900. */
  901. void flashc_set_flash_waitstate_and_readmode(unsigned long cpu_f_hz);
  902. #endif // UC3C device-specific implementation
  903. //! @}
  904. #endif // _FLASHC_H_