| 1 |
608 |
jeremybenn |
/* ----------------------------------------------------------------------------
|
| 2 |
|
|
* ATMEL Microcontroller Software Support
|
| 3 |
|
|
* ----------------------------------------------------------------------------
|
| 4 |
|
|
* Copyright (c) 2008, Atmel Corporation
|
| 5 |
|
|
*
|
| 6 |
|
|
* All rights reserved.
|
| 7 |
|
|
*
|
| 8 |
|
|
* Redistribution and use in source and binary forms, with or without
|
| 9 |
|
|
* modification, are permitted provided that the following conditions are met:
|
| 10 |
|
|
*
|
| 11 |
|
|
* - Redistributions of source code must retain the above copyright notice,
|
| 12 |
|
|
* this list of conditions and the disclaimer below.
|
| 13 |
|
|
*
|
| 14 |
|
|
* Atmel's name may not be used to endorse or promote products derived from
|
| 15 |
|
|
* this software without specific prior written permission.
|
| 16 |
|
|
*
|
| 17 |
|
|
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
| 18 |
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
| 19 |
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
| 20 |
|
|
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 21 |
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 22 |
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
| 23 |
|
|
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 24 |
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 25 |
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
| 26 |
|
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 27 |
|
|
* ----------------------------------------------------------------------------
|
| 28 |
|
|
*/
|
| 29 |
|
|
|
| 30 |
|
|
#ifndef EFC_H
|
| 31 |
|
|
#define EFC_H
|
| 32 |
|
|
|
| 33 |
|
|
//------------------------------------------------------------------------------
|
| 34 |
|
|
// Headers
|
| 35 |
|
|
//------------------------------------------------------------------------------
|
| 36 |
|
|
|
| 37 |
|
|
#include <board.h>
|
| 38 |
|
|
|
| 39 |
|
|
#ifdef BOARD_FLASH_EFC
|
| 40 |
|
|
|
| 41 |
|
|
//------------------------------------------------------------------------------
|
| 42 |
|
|
// Constants
|
| 43 |
|
|
//------------------------------------------------------------------------------
|
| 44 |
|
|
|
| 45 |
|
|
/// Number of GPNVMs available on each chip.
|
| 46 |
|
|
#if defined(at91sam7s16) || defined(at91sam7s161) || defined(at91sam7s32) \
|
| 47 |
|
|
|| defined(at91sam7s321) || defined(at91sam7s64) || defined(at91sam7s128) \
|
| 48 |
|
|
|| defined(at91sam7s256) || defined(at91sam7s512)
|
| 49 |
|
|
|
| 50 |
|
|
#define EFC_NUM_GPNVMS 2
|
| 51 |
|
|
|
| 52 |
|
|
#elif defined(at91sam7se32) || defined(at91sam7se256) || defined(at91sam7se512) \
|
| 53 |
|
|
|| defined(at91sam7x128) || defined(at91sam7x256) || defined(at91sam7x512) \
|
| 54 |
|
|
|| defined(at91sam7xc128) || defined(at91sam7xc256) || defined(at91sam7xc512) \
|
| 55 |
|
|
|
| 56 |
|
|
#define EFC_NUM_GPNVMS 3
|
| 57 |
|
|
|
| 58 |
|
|
#elif defined(at91sam7a3)
|
| 59 |
|
|
|
| 60 |
|
|
#define EFC_NUM_GPNVMS 0
|
| 61 |
|
|
#endif
|
| 62 |
|
|
|
| 63 |
|
|
// Missing FRDY bit for SAM7A3
|
| 64 |
|
|
#if defined(at91sam7a3)
|
| 65 |
|
|
#define AT91C_MC_FRDY (AT91C_MC_EOP | AT91C_MC_EOL)
|
| 66 |
|
|
#endif
|
| 67 |
|
|
|
| 68 |
|
|
// No security bit on SAM7A3
|
| 69 |
|
|
#if defined(at91sam7a3)
|
| 70 |
|
|
#define EFC_NO_SECURITY_BIT
|
| 71 |
|
|
#endif
|
| 72 |
|
|
|
| 73 |
|
|
//------------------------------------------------------------------------------
|
| 74 |
|
|
// Types
|
| 75 |
|
|
//------------------------------------------------------------------------------
|
| 76 |
|
|
|
| 77 |
|
|
// For chips which do not define AT91S_EFC
|
| 78 |
|
|
#if !defined(AT91C_BASE_EFC) && !defined(AT91C_BASE_EFC0)
|
| 79 |
|
|
typedef struct _AT91S_EFC {
|
| 80 |
|
|
|
| 81 |
|
|
AT91_REG EFC_FMR;
|
| 82 |
|
|
AT91_REG EFC_FCR;
|
| 83 |
|
|
AT91_REG EFC_FSR;
|
| 84 |
|
|
|
| 85 |
|
|
} AT91S_EFC, *AT91PS_EFC;
|
| 86 |
|
|
#define AT91C_BASE_EFC (AT91_CAST(AT91PS_EFC) 0xFFFFFF60)
|
| 87 |
|
|
#endif
|
| 88 |
|
|
|
| 89 |
|
|
//------------------------------------------------------------------------------
|
| 90 |
|
|
// Functions
|
| 91 |
|
|
//------------------------------------------------------------------------------
|
| 92 |
|
|
|
| 93 |
|
|
extern void EFC_SetMasterClock(unsigned int mck);
|
| 94 |
|
|
|
| 95 |
|
|
extern void EFC_EnableIt(AT91S_EFC *pEfc, unsigned int sources);
|
| 96 |
|
|
|
| 97 |
|
|
extern void EFC_DisableIt(AT91S_EFC *pEfc, unsigned int sources);
|
| 98 |
|
|
|
| 99 |
|
|
extern void EFC_SetEraseBeforeProgramming(AT91S_EFC *pEfc, unsigned char enable);
|
| 100 |
|
|
|
| 101 |
|
|
extern void EFC_TranslateAddress(
|
| 102 |
|
|
unsigned int address,
|
| 103 |
|
|
AT91S_EFC **ppEfc,
|
| 104 |
|
|
unsigned short *pPage,
|
| 105 |
|
|
unsigned short *pOffset);
|
| 106 |
|
|
|
| 107 |
|
|
extern void EFC_ComputeAddress(
|
| 108 |
|
|
AT91S_EFC *pEfc,
|
| 109 |
|
|
unsigned short page,
|
| 110 |
|
|
unsigned short offset,
|
| 111 |
|
|
unsigned int *pAddress);
|
| 112 |
|
|
|
| 113 |
|
|
extern void EFC_StartCommand(
|
| 114 |
|
|
AT91S_EFC *pEfc,
|
| 115 |
|
|
unsigned char command,
|
| 116 |
|
|
unsigned short argument);
|
| 117 |
|
|
|
| 118 |
|
|
extern unsigned char EFC_PerformCommand(
|
| 119 |
|
|
AT91S_EFC *pEfc,
|
| 120 |
|
|
unsigned char command,
|
| 121 |
|
|
unsigned short argument);
|
| 122 |
|
|
|
| 123 |
|
|
extern unsigned int EFC_GetStatus(AT91S_EFC *pEfc);
|
| 124 |
|
|
|
| 125 |
|
|
#endif //#ifdef BOARD_FLASH_EFC
|
| 126 |
|
|
#endif //#ifndef EFC_H
|
| 127 |
|
|
|