PIC24 Support Libraries
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pic24_flash.h
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
3  * All rights reserved.
4  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
5  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
6  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation for any purpose, without fee, and without written agreement is
10  * hereby granted, provided that the above copyright notice, the following
11  * two paragraphs and the authors appear in all copies of this software.
12  *
13  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
15  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
16  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17  *
18  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
23  *
24  * Please maintain this header in its entirety when copying/modifying
25  * these files.
26  *
27  *
28  */
29 
30 // Documentation for this file. If the \file tag isn't present,
31 // this file won't be documented.
32 /** \file
33  * FLASH memory read/write support functions
34  */
35 
36 #ifndef _PIC24_FLASH_H_
37 #define _PIC24_FLASH_H_
38 
39 #include <stdint.h>
40 
41 #if (defined(__dsPIC33E__) || defined(__PIC24E__))
42 //this family will use double word programming.
43 //assume a page size of 1024 instructions as this is true for most of these family members
44 #define FLASH_ROWSIZE 2 //in number of instructions
45 #define FLASH_ROWS_PER_PAGE (1024/FLASH_ROWSIZE)
46 #else
47 #define FLASH_ROWSIZE 64 //in number of instructions
48 #define FLASH_ROWS_PER_PAGE 8
49 #endif
50 #define FLASH_PAGEINSTR (FLASH_ROWSIZE * FLASH_ROWS_PER_PAGE) //8 rows of 64 instructions
51 #define FLASH_PAGESIZE (FLASH_PAGEINSTR*2) //each instruction appears to occupy 2 program memory addresses
52 #define FLASH_PAGEBYTES (FLASH_PAGEINSTR*3) //total bytes is FLASH_PAGEINSTR *3 = 1536
53 #define FLASH_ROWBYTES (FLASH_ROWSIZE*3) //bytes in one row
54 
55 void doWriteLatchFlash(uint16_t u16_addrhi, uint16_t u16_addrlo, uint16_t u16_wordhi, uint16_t u16_wordlo);
56 uint32_t doReadLatchFlash(uint16_t u16_addrhi, uint16_t u16_addrlo);
57 void doEraseFlash (uint16_t u16_addrhi, uint16_t u16_addrlo);
58 void doWriteFlash();
59 void doWritePageFlash(union32 u32_pmemAddress, uint8_t* pu8_data, uint16_t u16_len);
60 void doReadPageFlash(union32 u32_pmemAddress, uint8_t* pu8_data, uint16_t u16_len);
61 
62 
63 #endif