dsPIC33E/os_dsPIC33E_APIsB.c
// Read a page of data in program memory into RAM buffer using table read
// instruction.
// Author       : Fabian Kung
// Last Modified: 28 Nov 2018
// Argument     : unTablePage - Page number (for TBLPAG register) of the address
//                to the first word in program memory to read.
//                unTableOffset - Offset address to the first word in program
//                memory to read.
// Return       : None
// Example of usage:
// Assuming progData[] contains an array of integer data store in the program
// memory, we thus need to provide the page and offset address of the first
// element of progData[0] to this function.  To do this we use the built-in
// function that comes with the C-compiler.  We also assume the address of progData[0]
// is already aligned to the page boundary.  If this is not the case, the nearest
// address smaller than &progData[0] will be used.
//
// ProgMemReadPage(__builtin_tblpage(progData),__builtin_tbloffset(progData));
//

Read a page of data in program memory into RAM buffer using table read
instruction.
Author       : Fabian Kung
Last Modified: 28 Nov 2018
Argument     : unTablePage - Page number (for TBLPAG register) of the address
to the first word in program memory to read.
unTableOffset - Offset address to the first word in program
memory to read.
Return       : None
Example of usage:
Assuming progData[] contains an array of integer data store in the program
memory, we thus need to provide the page and offset address of the first
element of progData[0] to this function.  To do this we use the built-in
function that comes with the C-compiler.  We also assume the address of progData[0]
is already aligned to the page boundary.  If this is not the case, the nearest
address smaller than &progData[0] will be used.


Read a page of data in program memory into RAM buffer using table read instruction . Author : Fabian Kung Last Modified : 28 Nov 2018 Argument : unTablePage - Page number ( for TBLPAG register ) of the address to the first word in program memory to read . unTableOffset - Offset address to the first word in program memory to read . Return : None Example of usage : Assuming progData [] contains an array of integer data store in the program memory we thus need to provide the page and offset address of the first element of progData [ 0 ] to this function . To do this we use the built - in function that comes with the C - compiler . We also assume the address of progData [ 0 ] is already aligned to the page boundary . If this is not the case the nearest address smaller than &progData [ 0 ] will be used .
void ProgMemReadPage(unsigned int unTablePage, unsigned int unTableOffset)
{
    int i, nTblpag_bak;
    nTblpag_bak = TBLPAG;       
    TBLPAG = unTablePage;
    unTableOffset = unTableOffset & 0xF800;   
    for (i = 0; i<(DSPIC33E_PAGELENGTH*2); i++)
    {
        gnRamBuffer[i++] = __builtin_tblrdl(unTableOffset);
        gnRamBuffer[i] = __builtin_tblrdh (unTableOffset);
        unTableOffset += 2;
    }
    TBLPAG = nTblpag_bak;       
}
void ProgMemReadPage ( unsigned int unTablePage , unsigned int unTableOffset ) { int i , nTblpag_bak ; nTblpag_bak = TBLPAG ; TBLPAG = unTablePage ; unTableOffset = unTableOffset & 0xF800 ; for ( i = 0 ; i < ( DSPIC33E_PAGELENGTH * 2 ) ; i ++ ) { gnRamBuffer [ i ++ ] = __builtin_tblrdl ( unTableOffset ) ; gnRamBuffer [ i ] = __builtin_tblrdh ( unTableOffset ) ; unTableOffset += 2 ; } TBLPAG = nTblpag_bak ; }
Read a page of data in program memory into RAM buffer using table read
instruction.
Read a page of data in program memory into RAM buffer using table read instruction .
// The datasheet recommends backing up TBLPAG before 
 // modifying it.
 // Set to base of page.
 // For page size of 1024 24-bits words 
 // or 2x1024 16-bits words in the program memory.
 // 2x1024 - 1 = 2047 or 0x7FF.  The the lower
 // 11-bits of the address is always 0.  If the
 // lower 11-bits of offset is not 0, it means the
 // address of progData starts after the page
 // boundary, so we adjust it to start at the 
 // page boundary. 
 // Restore TBLPAG.
