示例#1
0
文件: flash.c 项目: falkorichter/ioio
DWORD FlashReadDWORD(DWORD address) {
  DWORD_VAL a = { address };
  DWORD_VAL res;
  TBLPAG = a.word.HW;
  res.word.HW = __builtin_tblrdh(a.word.LW);
  res.word.LW = __builtin_tblrdl(a.word.LW);
  return res.Val;
}
示例#2
0
文件: MPFS.c 项目: ftapparo/Arduino
/*********************************************************************
 * Function:        static DWORD ReadProgramMemory(DWORD address)
 *
 * PreCondition:    None
 *
 * Input:           Program memory address to read from.  Should be 
 *					an even number.
 *
 * Output:          Program word at the specified address.  For the 
 *					PIC24, dsPIC, etc. which have a 24 bit program 
 *					word size, the upper byte is 0x00.
 *
 * Side Effects:    None
 *
 * Overview:        Modifies and restores TBLPAG.  Make sure that if 
 *					using interrupts and the PSV feature of the CPU 
 *					in an ISR that the TBLPAG register is preloaded 
 *					with the correct value (rather than assuming 
 *					TBLPAG is always pointing to the .const section.
 *
 * Note:            None
 ********************************************************************/
static DWORD ReadProgramMemory(DWORD address) 
{  
	DWORD dwResult;
	WORD wTBLPAGSave;

	wTBLPAGSave = TBLPAG;
	TBLPAG = ((WORD*)&address)[1];
	((WORD*)&dwResult)[1] = __builtin_tblrdh((WORD)address);
	((WORD*)&dwResult)[0] = __builtin_tblrdl((WORD)address);
	TBLPAG = wTBLPAGSave;

	return dwResult;
}
示例#3
0
/********************************************************************
* Function: 	ValidAppPresent()
********************************************************************/
BOOL ValidAppPresent(void)
{
   volatile DWORD AppPtr;

   TBLPAG = 0x00;

   AppPtr = ((DWORD)__builtin_tblrdh(0) << 16);
   AppPtr = AppPtr | ((DWORD)__builtin_tblrdl(0));

   if(AppPtr == 0xFFFFFF)
      return FALSE;
   else
      return TRUE;
}
DWORD ReadProgramMemory(DWORD address) 
{  
      DWORD_VAL dwvResult;
    WORD wTBLPAGSave;
 
      wTBLPAGSave = TBLPAG;
    TBLPAG = ((DWORD_VAL*)&address)->w[1];

    dwvResult.w[1] = __builtin_tblrdh((WORD)address);
    dwvResult.w[0] = __builtin_tblrdl((WORD)address);
    TBLPAG = wTBLPAGSave;
 
      return dwvResult.Val;
}
示例#5
0
u32 flashRead1Instruction ( u32 * wordAddress )
{
    DWORD_VAL value;
    u32 temp = *wordAddress;
    u32 offset = temp & FLASH_TABLE_PAGE_SIZE_MASK; /* offset into table page */
    TBLPAG = temp >> FLASH_TABLE_PAGE_SIZE_SHIFT; /* select table page */

    /* a pic 24 word is 16-bits, we write 3-Bytes + phantom = 2 16-bit words */
    *wordAddress += 2;

    value.word.LW = __builtin_tblrdl( offset );
    value.word.HW = __builtin_tblrdh( offset );

    return value.Val;
}
示例#6
0
文件: main.c 项目: Gekkio/m-stack
		offset += 2;
	}

	asm("DISI #5");
	__builtin_write_NVM();

	while (NVMCONbits.WR == 1)
		;
}

/* Read an instruction from flash. word_addr is the word address, not
 * the byte address. */
static void read_flash(uint32_t word_addr, uint16_t *low, uint16_t *high)
{
	TBLPAG = word_addr >> 16 & 0xff;
	*high = __builtin_tblrdh(word_addr & 0xffff);
	*low  = __builtin_tblrdl(word_addr & 0xffff);
}

/* Read data starting at prog_addr into the global prog_buf. prog_addr
 * and len are in words, not bytes. */
static void read_prog_data(uint32_t prog_addr, uint32_t len/*words*/)
{
	int i;
	for (i = 0; i < len; i += 2) {
		read_flash(prog_addr + i,
		           &prog_buf[i]   /*low*/,
		           &prog_buf[i+1] /*high*/);
	}
}