📄 patchi2c.c
字号:
/*
* File: patchi2c.c
* Target device: Any MPC8xx processor with a CPM-driven I2C
* Description: Simple I2C driver using patch to relocate I2C parameters.
* This driver uses the RAM microcode patch which relocates
* the I2C and SPI parameters to locations other than their
* default. This code does the following:
*
* 1. Loads and enables the microcode.
*
* 2. Sets up the I2C in master mode to transmit a message
* to itself (i.e. loopback). It performs an I2C write
* transmission to its own station address. [Note that
* loopback operation is not possible for I2C reads.]
*
* 3. Enters an infinite loop after sending the message.
*
* NOTES <<<IMPORTANT: PLEASE READ>>>:
* 1) A pullup resistor is required on the I2C data and clock lines
* (PB27 and PB26 of the MPC860)
* 2) DISABLE Data Cache for pages containing Rx/Tx buffers.
*
*
* 7/18/97 sgj Initial version.
* 10/14/97 sgj Fixed bug -- initialize RSTATE and TSTATE params
* 05/05/00 bgo Fixed bug -- removed Init RX & TX CPCR commands.
* These are not supported with patch. Cleaned up
* comments. Added UcodeCopy function.
* 14.May.02 pbb Changed example code to actual 850 code.
*
*/
#include <string.h>
#include "mpc860.h"
#include "patchi2c.h"
/* Internal Routines */
void startup(void);
void UcodeInit();
void UcodeCopy(unsigned long immr);
void RLI2CInit();
void I2CStart();
void Main(void);
/* Set of I2C Receive Buffers and Transmit Buffer */
LB rtxbuf[NUM_RXBDS+1];
void Main()
{
int breakonme = 0;
UcodeInit(); /* Initialize Microcode */
RLI2CInit(); /* Initialize I2C (using relocated parameters) */
I2CStart(); /* Start I2C in loopback */
breakonme++; /* This is just a convenient place to break using */
/* a source-level debugger. No significance. */
while(1); /* Loop forever. */
}
/**************************************************************
*
* Function Name: UcodeInit
* Description: Microcode Initialization Routine
* Copies microcode patch to the first 512 bytes
* and a 256 byte extension of DPRAM. Sets the
* Trap register values and enables DPRAM microcode
* to execute.
* Input Parameters: none
* Return Values: none
*
*************************************************************/
void UcodeInit()
{
EPPC *immr = (EPPC *) (GetIMMR() & 0xffff0000); /* Get IMMR value. */
immr->cp_rccr = 0; /* Disable microcode program area */
UcodeCopy((unsigned long) immr); /* Copy microcode patch to DPRAM. */
/* Activate the microcode per the instructions in the microcode manual*/
/* NOTE: We're only relocating the I2C parameters (not SPI). */
immr->cp_rctr3 = 0x802e; /* Write Trap register 3 value. */
immr->cp_rctr4 = 0x802c; /* Write Trap register 4 value. */
immr->cp_rccr = 1; /* Enable DPRAM microcode to execute from */
/* the first 512 bytes and a 256 byte */
/* extension of DPRAM. */
} /* end UcodeInit() */
/**************************************************************
*
* Function Name: UcodeInit
* Description: Copies microcode patch to the first 512 bytes
* and a 256 byte extension of DPRAM.
* Input Parameters: Internal Memory Map Register value.
* Return Values: none
*
* NOTE: This function implements version 1.1 of the 860
* I2C/SPI relocation microcode patch. See the pdf file
* included in the zip file for patch revision history.
*
*************************************************************/
void UcodeCopy(unsigned long immr)
{
*((unsigned long *)(immr + 0x2000)) = 0x7fffefd9;
*((unsigned long *)(immr + 0x2004)) = 0x3ffd0000;
*((unsigned long *)(immr + 0x2008)) = 0x7ffb49f7;
*((unsigned long *)(immr + 0x200c)) = 0x7ff90000;
*((unsigned long *)(immr + 0x2010)) = 0x5fefadf7;
*((unsigned long *)(immr + 0x2014)) = 0x5f88adf7;
*((unsigned long *)(immr + 0x2018)) = 0x5fefaff7;
*((unsigned long *)(immr + 0x201c)) = 0x5f88aff7;
*((unsigned long *)(immr + 0x2020)) = 0x3a9cfbc8;
*((unsigned long *)(immr + 0x2024)) = 0x77cae1bb;
*((unsigned long *)(immr + 0x2028)) = 0xf4de7fad;
*((unsigned long *)(immr + 0x202c)) = 0xabae9330;
*((unsigned long *)(immr + 0x2030)) = 0x4e08fdcf;
*((unsigned long *)(immr + 0x2034)) = 0x6e0faff8;
*((unsigned long *)(immr + 0x2038)) = 0x7ccf76cf;
*((unsigned long *)(immr + 0x203c)) = 0xfdaff9cf;
*((unsigned long *)(immr + 0x2040)) = 0xabf88dc8;
*((unsigned long *)(immr + 0x2044)) = 0xab5879f7;
*((unsigned long *)(immr + 0x2048)) = 0xb0926a27;
*((unsigned long *)(immr + 0x204c)) = 0xdfd079f7;
*((unsigned long *)(immr + 0x2050)) = 0xb090e6bb;
*((unsigned long *)(immr + 0x2054)) = 0xe5bbe74f;
*((unsigned long *)(immr + 0x2058)) = 0xaa616f0f;
*((unsigned long *)(immr + 0x205c)) = 0x6ffb76ce;
*((unsigned long *)(immr + 0x2060)) = 0xee0cf9cf;
*((unsigned long *)(immr + 0x2064)) = 0x2bfbefef;
*((unsigned long *)(immr + 0x2068)) = 0xcfeef9cf;
*((unsigned long *)(immr + 0x206c)) = 0x76cead23;
*((unsigned long *)(immr + 0x2070)) = 0x90b3df99;
*((unsigned long *)(immr + 0x2074)) = 0x7fddd0c1;
*((unsigned long *)(immr + 0x2078)) = 0x4bf847fd;
*((unsigned long *)(immr + 0x207c)) = 0x7ccf76ce;
*((unsigned long *)(immr + 0x2080)) = 0xcfef77ca;
*((unsigned long *)(immr + 0x2084)) = 0x7eaf7fad;
*((unsigned long *)(immr + 0x2088)) = 0x7dfdf0b7;
*((unsigned long *)(immr + 0x208c)) = 0xef7a7fca;
*((unsigned long *)(immr + 0x2090)) = 0x77cafbc8;
*((unsigned long *)(immr + 0x2094)) = 0x6079e722;
*((unsigned long *)(immr + 0x2098)) = 0xfbc85fff;
*((unsigned long *)(immr + 0x209c)) = 0xdfff5fb3;
*((unsigned long *)(immr + 0x20a0)) = 0xfffbfbc8;
*((unsigned long *)(immr + 0x20a4)) = 0xf3c894a5;
*((unsigned long *)(immr + 0x20a8)) = 0xe7c9edf9;
*((unsigned long *)(immr + 0x20ac)) = 0x7f9a7fad;
*((unsigned long *)(immr + 0x20b0)) = 0x5f36afe8;
*((unsigned long *)(immr + 0x20b4)) = 0x5f5bffdf;
*((unsigned long *)(immr + 0x20b8)) = 0xdf95cb9e;
*((unsigned long *)(immr + 0x20bc)) = 0xaf7d5fc3;
*((unsigned long *)(immr + 0x20c0)) = 0xafed8c1b;
*((unsigned long *)(immr + 0x20c4)) = 0x5fc3afdd;
*((unsigned long *)(immr + 0x20c8)) = 0x5fc5df99;
*((unsigned long *)(immr + 0x20cc)) = 0x7efdb0b3;
*((unsigned long *)(immr + 0x20d0)) = 0x5fb3fffe;
*((unsigned long *)(immr + 0x20d4)) = 0xabae5fb3;
*((unsigned long *)(immr + 0x20d8)) = 0xfffe5fd0;
*((unsigned long *)(immr + 0x20dc)) = 0x600be6bb;
*((unsigned long *)(immr + 0x20e0)) = 0x600b5fd0;
*((unsigned long *)(immr + 0x20e4)) = 0xdfc827fb;
*((unsigned long *)(immr + 0x20e8)) = 0xefdf5fca;
*((unsigned long *)(immr + 0x20ec)) = 0xcfde3a9c;
*((unsigned long *)(immr + 0x20f0)) = 0xe7c9edf9;
*((unsigned long *)(immr + 0x20f4)) = 0xf3c87f9e;
*((unsigned long *)(immr + 0x20f8)) = 0x54ca7fed;
*((unsigned long *)(immr + 0x20fc)) = 0x2d3a3637;
*((unsigned long *)(immr + 0x2100)) = 0x756f7e9a;
*((unsigned long *)(immr + 0x2104)) = 0xf1ce37ef;
*((unsigned long *)(immr + 0x2108)) = 0x2e677fee;
*((unsigned long *)(immr + 0x210c)) = 0x10ebadf8;
*((unsigned long *)(immr + 0x2110)) = 0xefdecfea;
*((unsigned long *)(immr + 0x2114)) = 0xe52f7d9f;
*((unsigned long *)(immr + 0x2118)) = 0xe12bf1ce;
*((unsigned long *)(immr + 0x211c)) = 0x5f647e9a;
*((unsigned long *)(immr + 0x2120)) = 0x4df8cfea;
*((unsigned long *)(immr + 0x2124)) = 0x5f717d9b;
*((unsigned long *)(immr + 0x2128)) = 0xefeecfea;
*((unsigned long *)(immr + 0x212c)) = 0x5f73e522;
*((unsigned long *)(immr + 0x2130)) = 0xefde5f73;
*((unsigned long *)(immr + 0x2134)) = 0xcfda0b61;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -