flashc.h 36 KB

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