PIC24 Support Libraries
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 #pragma once
37 
38 #include <stdint.h>
39 #include "pic24_unions.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 
51 #define FLASH_PAGEINSTR (FLASH_ROWSIZE * FLASH_ROWS_PER_PAGE) //8 rows of 64 instructions
52 #define FLASH_PAGESIZE (FLASH_PAGEINSTR*2) //each instruction appears to occupy 2 program memory addresses
53 #define FLASH_PAGEBYTES (FLASH_PAGEINSTR*3) //total bytes is FLASH_PAGEINSTR *3 = 1536
54 #define FLASH_ROWBYTES (FLASH_ROWSIZE*3) //bytes in one row
55 
56 void doWriteLatchFlash(uint16_t u16_addrhi, uint16_t u16_addrlo, uint16_t u16_wordhi, uint16_t u16_wordlo);
57 uint32_t doReadLatchFlash(uint16_t u16_addrhi, uint16_t u16_addrlo);
58 void doEraseFlash (uint16_t u16_addrhi, uint16_t u16_addrlo);
59 void doWriteFlash();
60 void doWritePageFlash(union32 u32_pmemAddress, uint8_t* pu8_data, uint16_t u16_len);
61 void doReadPageFlash(union32 u32_pmemAddress, uint8_t* pu8_data, uint16_t u16_len);
uint32_t doReadLatchFlash(uint16_t u16_addrhi, uint16_t u16_addrlo)
Definition: pic24_flash.c:102
A union type for byte, word, or dword access for 32 bit values.
Definition: pic24_unions.h:49
void doWriteLatchFlash(uint16_t u16_addrhi, uint16_t u16_addrlo, uint16_t u16_wordhi, uint16_t u16_wordlo)
Definition: pic24_flash.c:49
void doWritePageFlash(union32 u32_pmemAddress, uint8_t *pu8_data, uint16_t u16_len)
Definition: pic24_flash.c:194
void doReadPageFlash(union32 u32_pmemAddress, uint8_t *pu8_data, uint16_t u16_len)
Definition: pic24_flash.c:247
unsigned char uint8_t
An abbreviation for an 8-bit unsigned integer.
Definition: dataXferImpl.h:194