1 | /* ---------------------------------------------------------------------------- */ |
---|
2 | /* Atmel Microcontroller Software Support */ |
---|
3 | /* SAM Software Package License */ |
---|
4 | /* ---------------------------------------------------------------------------- */ |
---|
5 | /* Copyright (c) 2015, Atmel Corporation */ |
---|
6 | /* */ |
---|
7 | /* All rights reserved. */ |
---|
8 | /* */ |
---|
9 | /* Redistribution and use in source and binary forms, with or without */ |
---|
10 | /* modification, are permitted provided that the following condition is met: */ |
---|
11 | /* */ |
---|
12 | /* - Redistributions of source code must retain the above copyright notice, */ |
---|
13 | /* this list of conditions and the disclaimer below. */ |
---|
14 | /* */ |
---|
15 | /* Atmel's name may not be used to endorse or promote products derived from */ |
---|
16 | /* this software without specific prior written permission. */ |
---|
17 | /* */ |
---|
18 | /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ |
---|
19 | /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ |
---|
20 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ |
---|
21 | /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ |
---|
22 | /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ |
---|
23 | /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ |
---|
24 | /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ |
---|
25 | /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ |
---|
26 | /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ |
---|
27 | /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ |
---|
28 | /* ---------------------------------------------------------------------------- */ |
---|
29 | |
---|
30 | /** |
---|
31 | * \file |
---|
32 | * |
---|
33 | * \section Purpose |
---|
34 | * |
---|
35 | * Interface for configuration the Enhanced Embedded Flash Controller (EEFC) |
---|
36 | * peripheral. |
---|
37 | * |
---|
38 | * \section Usage |
---|
39 | * |
---|
40 | * -# Enable/disable %flash ready interrupt sources using EFC_EnableFrdyIt() |
---|
41 | * and EFC_DisableFrdyIt(). |
---|
42 | * -# Translates the given address into which EEFC, page and offset values |
---|
43 | * for difference density %flash memory using EFC_TranslateAddress(). |
---|
44 | * -# Computes the address of a %flash access given the EFC, page and offset |
---|
45 | * for difference density %flash memory using EFC_ComputeAddress(). |
---|
46 | * -# Start the executing command with EFC_PerformCommand() |
---|
47 | * -# Retrieve the current status of the EFC using EFC_GetStatus(). |
---|
48 | * -# Retrieve the result of the last executed command with EFC_GetResult(). |
---|
49 | */ |
---|
50 | |
---|
51 | #ifndef _EEFC_ |
---|
52 | #define _EEFC_ |
---|
53 | |
---|
54 | /*---------------------------------------------------------------------------- |
---|
55 | * Headers |
---|
56 | *----------------------------------------------------------------------------*/ |
---|
57 | #include "chip.h" |
---|
58 | |
---|
59 | #include <stdint.h> |
---|
60 | |
---|
61 | /*---------------------------------------------------------------------------- |
---|
62 | * Definitions |
---|
63 | *----------------------------------------------------------------------------*/ |
---|
64 | /* TODO: Temporary definition for missing symbol in header file */ |
---|
65 | #define IFLASH_SECTOR_SIZE 65536u |
---|
66 | |
---|
67 | |
---|
68 | /* EFC command */ |
---|
69 | #define EFC_FCMD_GETD 0x00 /* Get Flash Descriptor */ |
---|
70 | #define EFC_FCMD_WP 0x01 /* Write page */ |
---|
71 | #define EFC_FCMD_WPL 0x02 /* Write page and lock */ |
---|
72 | #define EFC_FCMD_EWP 0x03 /* Erase page and write page */ |
---|
73 | #define EFC_FCMD_EWPL 0x04 /* Erase page and write page then lock */ |
---|
74 | #define EFC_FCMD_EA 0x05 /* Erase all */ |
---|
75 | #define EFC_FCMD_EPA 0x07 /* Erase pages */ |
---|
76 | #define EFC_FCMD_SLB 0x08 /* Set Lock Bit */ |
---|
77 | #define EFC_FCMD_CLB 0x09 /* Clear Lock Bit */ |
---|
78 | #define EFC_FCMD_GLB 0x0A /* Get Lock Bit */ |
---|
79 | #define EFC_FCMD_SFB 0x0B /* Set GPNVM Bit */ |
---|
80 | #define EFC_FCMD_CFB 0x0C /* Clear GPNVM Bit */ |
---|
81 | #define EFC_FCMD_GFB 0x0D /* Get GPNVM Bit */ |
---|
82 | #define EFC_FCMD_STUI 0x0E /* Start unique ID */ |
---|
83 | #define EFC_FCMD_SPUI 0x0F /* Stop unique ID */ |
---|
84 | #define EFC_FCMD_GCALB 0x10 /* Get CALIB Bit */ |
---|
85 | #define EFC_FCMD_ES 0x11 /* Erase Sector */ |
---|
86 | #define EFC_FCMD_WUS 0x12 /* Write User Signature */ |
---|
87 | #define EFC_FCMD_EUS 0x13 /* Erase User Signature */ |
---|
88 | #define EFC_FCMD_STUS 0x14 /* Start Read User Signature */ |
---|
89 | #define EFC_FCMD_SPUS 0x15 /* Stop Read User Signature */ |
---|
90 | |
---|
91 | /* The IAP function entry address */ |
---|
92 | #define CHIP_FLASH_IAP_ADDRESS (0x00800008) |
---|
93 | |
---|
94 | #ifdef __cplusplus |
---|
95 | extern "C" { |
---|
96 | #endif |
---|
97 | |
---|
98 | /*---------------------------------------------------------------------------- |
---|
99 | * Exported functions |
---|
100 | *----------------------------------------------------------------------------*/ |
---|
101 | |
---|
102 | extern void EFC_EnableFrdyIt(Efc *efc); |
---|
103 | |
---|
104 | extern void EFC_DisableFrdyIt(Efc *efc); |
---|
105 | |
---|
106 | extern void EFC_SetWaitState(Efc *efc, uint8_t cycles); |
---|
107 | |
---|
108 | extern void EFC_TranslateAddress(Efc **pEfc, uint32_t dwAddress, |
---|
109 | uint16_t *pwPage, uint16_t *pwOffset); |
---|
110 | |
---|
111 | extern void EFC_ComputeAddress(Efc *efc, uint16_t wPage, uint16_t wOffset, |
---|
112 | uint32_t *pdwAddress); |
---|
113 | |
---|
114 | extern uint32_t EFC_PerformCommand(Efc *efc, uint32_t dwCommand, |
---|
115 | uint32_t dwArgument, uint32_t dwUseIAP); |
---|
116 | |
---|
117 | extern uint32_t EFC_GetStatus(Efc *efc); |
---|
118 | |
---|
119 | extern uint32_t EFC_GetResult(Efc *efc); |
---|
120 | |
---|
121 | extern void EFC_SetFlashAccessMode(Efc *efc, uint32_t dwMode); |
---|
122 | |
---|
123 | #ifdef __cplusplus |
---|
124 | } |
---|
125 | #endif |
---|
126 | |
---|
127 | #endif /* #ifndef _EEFC_ */ |
---|
128 | |
---|