示例#1
0
DMPAPI(bool) i2c_InitSW2(unsigned devs, int i2c0mode, unsigned long i2c0clkdelay, int i2c1mode, unsigned long i2c1clkdelay) {
    int  i;
    
    if (I2C_ioSection != -1)
	{
        err_print("I2C lib was already opened");
		return false;
	}
	if ((I2C_ioSection = io_Init()) == -1) return false;

    #ifdef ROBOIO
        switch (roboio_GetRBVer())
        {
            case RB_100b1:
            case RB_100b2:
            case RB_100b3:
            case RB_100:
            case RB_100RD:
            case RB_110:
            case RB_050:
                devs = devs & I2C_USEMODULE0;
                break;
            default:
                devs = 0;
                break;
        }
    #endif

    I2C_swMode[0] = i2c0mode; I2CSW_delay[0] = i2c0clkdelay;
    I2C_swMode[1] = i2c1mode; I2CSW_delay[1] = i2c1clkdelay;

    I2C_action[0] = I2C_action[1] = I2CACT_DISABLE;
    for (i=0; i<2; i++)
    {
        if ((i == 0) && ((devs & I2C_USEMODULE0) == 0)) continue;
        if ((i == 1) && ((devs & I2C_USEMODULE1) == 0)) continue;
        I2C_action[i] = I2CACT_IDLE;

        // switch GPIO/I2C pins into GPIO pins
        OLD_I2CGPIO3FLAG[i] = sb_Read(SB_IPFCTRL3_REG) & OLD_I2CGPIO3MASK[i];  // backup GPIO/I2C switch flag
        sb_Write(SB_IPFCTRL3_REG, sb_Read(SB_IPFCTRL3_REG) & (~OLD_I2CGPIO3MASK[i]));

        OLD_I2CGPIO3DIR[i] = io_inpb(GPIO3_DIR)  & (0x03 << (i*2+4));  // backup GPIO3 DIR
        OLD_I2CGPIO3VAL[i] = io_inpb(GPIO3_DATA) & (0x03 << (i*2+4));  // backup GPIO3 VAL
        
        // set GPIO pins as INPUT state (equiv. to OUT 1 of I2C lines)
        io_outpb(GPIO3_DIR, io_inpb(GPIO3_DIR) & ~(0x03 << (i*2+4)));
    }

    return true;
}
示例#2
0
bool init() {
	int i;
	if(io_Init() == false) return false;

	//set corssbar Base Address
	sb_Write16(0x64,0x0A01);
	//printf("SB C0~C3 REG: 0x%08X\n", sb_Read(0xc0));
	sb_Write(0xc0, sb_Read(0xc0) | 0x8000C000L);
	//printf("SB C0~C3 REG: 0x%08X\n", sb_Read(0xc0));
	//set GPIO Base Address
	sb_Write16(0x62,0xf101);
	// GPIO enable
	io_outpdw(0xf100,0x00ff);
	//set GPIO P0~9 dircetion & data Address
	//io_outpdw(0xf100,0x03ff);
	for(i=0;i<8;i++) {
		io_outpdw(0xf100 + (i+1)*4,((0xf202 + i*4)<<16) + 0xf200 + i*4);
		//io_outpb((sb_Read16(0x64)&0xfffe)+i,0x00);
	}
	  
	//setADC Base Address
	sb_Write(0xbc, sb_Read(0xbc) & (~(1L<<28)));  // active adc
	sb1_Write16(0xde, sb1_Read16(0xde) | 0x02);   // not Available for 8051A Access ADC
	sb1_Write(0xe0, 0x0010fe00L); // baseaddr = 0xfe00, disable irq
	
	
	//CDC
	USBDEV = CreateUSBDevice();
    if(USBDEV == NULL)
    {
        printf("init error\n");
        return false;
    }
    usb_SetUSBPins(USBDEV, 7, 0, 7, 1);
    if(usb_Init(USBDEV) == false)
    {
        printf("init2 error\n");
        return false;
    }
	
	//io_Close();
	return true;
}
示例#3
0
bool init()
{
	if(io_Init() == false) return false;
	
	// set ADC Base Address
	sb_Write(0xBC, sb_Read(0xBC) & (~(1L<<28)));  // active adc
	sb1_Write16(0xDE, sb1_Read16(0xDE) | 0x02);   // not Available for 8051A Access ADC
	sb1_Write(0xE0, 0x00500000UL | ADC_BASEADDR); // baseaddr = 0xfe00, disable irq
	
	return true;
}
示例#4
0
bool cm_init(void)
{
  if (io_Init() == false)
    return false;
  sb_Write(0xc0, sb_Read(0xc0) & 0x7fffffffL | ((unsigned long)1UL << 31));
  io_Close();
  
  //com_SetUSBPins(2, 0, 2, 1);
  if ((Serial = com_Init(COM4)) == NULL)
    return false;
  com_SetTimeOut(Serial, 0);
  com_SetBPS(Serial, COM_UARTBAUD_1000000BPS);
  com_SetFormat(Serial, BYTESIZE8 + STOPBIT1 + NOPARITY);
  com_SetFlowControl(Serial, NO_CONTROL);
  com_EnableFIFO(Serial, FIFO_032);
  return true;
}
示例#5
0
DMPAPI(void) i2c_Close(void) {
    int i;
    
	if (I2C_ioSection == -1) return;

    for (i=0; i<2; i++) //restore GPIO3/I2C switch setting
    {
        if (I2C_action[i] == I2CACT_DISABLE) continue;

        io_outpb(GPIO3_DIR,  (io_inpb(GPIO3_DIR)  & (~(0x03 << (i*2+4)))) | OLD_I2CGPIO3DIR[i]); //restore GPIO3 DIR
        io_outpb(GPIO3_DATA, (io_inpb(GPIO3_DATA) & (~(0x03 << (i*2+4)))) | OLD_I2CGPIO3VAL[i]); //restore GPIO3 VAL
        sb_Write(SB_IPFCTRL3_REG, (sb_Read(SB_IPFCTRL3_REG) & (~OLD_I2CGPIO3MASK[i])) | OLD_I2CGPIO3FLAG[i]); //restore GPIO/I2C switch flag
        I2C_action[i] = I2CACT_DISABLE;
	}

	//io_Close(I2C_ioSection);
  io_Close();
	I2C_ioSection = -1;
}
示例#6
0
DMPAPI(bool) i2c_Init2(unsigned baseaddr, unsigned devs, int i2c0irq, int i2c1irq) {
    int  i;
    
    if (I2C_ioSection != -1)
	{
        err_print("I2C lib was already opened");
		return false;
	}
	if ((I2C_ioSection = io_Init()) == -1) return false;

	//NOTE: base address should be selected carefully to avoid conflicts with other devices!
	if (baseaddr != 0xffff)
	    i2c_SetBaseAddress(baseaddr);
	else
	{
        if (i2c_SetDefaultBaseAddress() == 0x0000) i2c_SetBaseAddress(0xfb00);
    }

    #ifdef ROBOIO
        switch (roboio_GetRBVer())
        {
            case RB_100b1:
            case RB_100b2:
            case RB_100b3:
            case RB_100:
            case RB_100RD:
            case RB_110:
            case RB_050:
                devs = devs & I2C_USEMODULE0;
                i2c1irq = I2CIRQ_DISABLE;
                break;
            default:
                devs = 0;
                i2c0irq = i2c1irq = I2CIRQ_DISABLE;
                break;
        }
    #endif
    i2c_SetIRQ(i2c0irq, i2c1irq);

    I2C_swMode[0] = I2C_swMode[1] = I2CSW_DISABLE;
    I2C_action[0] = I2C_action[1] = I2CACT_DISABLE;
    for (i=0; i<2; i++)
    {
        if ((i == 0) && ((devs & I2C_USEMODULE0) == 0)) continue;
        if ((i == 1) && ((devs & I2C_USEMODULE1) == 0)) continue;
        I2C_action[i] = I2CACT_IDLE;

        //switch GPIO/I2C pins into GPIO pins
        OLD_I2CGPIO3FLAG[i] = sb_Read(SB_IPFCTRL3_REG) & OLD_I2CGPIO3MASK[i]; //backup GPIO/I2C switch flag
        sb_Write(SB_IPFCTRL3_REG, sb_Read(SB_IPFCTRL3_REG) & (~OLD_I2CGPIO3MASK[i]));

        //send START & STOP signal to reset I2C devices
        OLD_I2CGPIO3DIR[i] = io_inpb(GPIO3_DIR)  & (0x03 << (i*2+4)); //backup GPIO3 DIR
        OLD_I2CGPIO3VAL[i] = io_inpb(GPIO3_DATA) & (0x03 << (i*2+4)); //backup GPIO3 VAL

        //set_pins(i, 1, 1); delay_ms(1); //SCL = 1, SDA = 1; START
        //set_pins(i, 1, 0); delay_ms(1); //SCL = 1, SDA = 0
        //set_pins(i, 0, 0); delay_ms(1); //SCL = 0, SDA = 0
        //Note: if we send the above START, some I2C sensors, such as ADI ADXL345, may fail to respond

        //set_pins(i, 0, 0); delay_ms(1); //SCL = 0, SDA = 0; STOP
        //Note: if we perform the line above, some I2C sensors, such as MEMSIC MXC6202, may fail to respond
        
        //set_pins(i, 1, 0); delay_ms(1); //SCL = 1, SDA = 0
        //set_pins(i, 1, 1); delay_ms(1); //SCL = 1, SDA = 1
        //Note: the above lines work for all sensors we tested, but we disable them to avoid unexpected sensor behaviors

        if (i2c_Reset(i) == false)  // assume the status of GPIO/I2C pins are GPIO "IN" or "OUT 1"
        {
            i2c_Close();
            err_print("can't reset the I2C modules");
		    return false;
        }

        i2c_DisableINT(i, I2CINT_ALL);
        i2c_ClearSTAT(i, I2CSTAT_ALL);

        //Remarks: for DX ver.2, we must disable the noise filter to ensure that 3.3Mbps works in high-speed mode
        i2c_DisableNoiseFilter(i);
        //i2c_EnableNoiseFilter(i);
        i2c_DisableStandardHSM(i); //SCL open-drain in high-speed mode
        //i2c_EnableStandardHSM(i);
    
        i2c_SetSpeed(i, I2CMODE_AUTO, 100000L); //default 100Kbps

        i2cslave_SetAddr(i, 0x7f); //set slave address 0x7F by default (change this if it collide with external I2C devices)
        i2cslave_EnableACK(i);

        //switch GPIO pins into I2C SCL,SDA pins
        //Remarks: Vortex86DX's H/W I2C has an issue here; if you call i2c_Reset() in case GPIO/SCL pin = GPIO out 0,
        //         then, whenever you switch GPIO/SCL pin to SCL pin, the SCL pin always first send the 10 reset dummy clocks
        sb_Write(SB_IPFCTRL3_REG, sb_Read(SB_IPFCTRL3_REG) | OLD_I2CGPIO3MASK[i]);
    }

    return true;
}
示例#7
0
文件: i2cex.cpp 项目: drbokko/86Duino
DMPAPI(void) i2c_SetIRQ(int i2c0irq, int i2c1irq) {
    sb_Write(SB_I2CCTRL_REG, (sb_Read(SB_I2CCTRL_REG) & 0xff00ffffL)
                                 + ((unsigned long)(i2c0irq & 0x000f) << 16)
                                 + ((unsigned long)(i2c1irq & 0x000f) << 20));
}
示例#8
0
文件: i2cex.cpp 项目: drbokko/86Duino
DMPAPI(unsigned) i2c_SetDefaultBaseAddress(void) {
    BaseAddress[0] = (unsigned)(sb_Read(SB_I2CCTRL_REG) & 0xfff0L);
    BaseAddress[1] = BaseAddress[0]+8;
    return BaseAddress[0];
}
示例#9
0
文件: i2cex.cpp 项目: drbokko/86Duino
DMPAPI(void) i2c_SetBaseAddress(unsigned baseaddr) {
    sb_Write(SB_I2CCTRL_REG,  //set base address with enabling I/O address decoding
                 ((sb_Read(SB_I2CCTRL_REG) & 0xffff0000L) | 0x80000000L) + (unsigned long)(baseaddr & 0xfff0));
    BaseAddress[0] = baseaddr;
    BaseAddress[1] = baseaddr+8;
}
示例#10
0
bool init() {
	int i, crossbarBase, gpioBase;
	if(io_Init() == false) return false;
    timer_NowTime(); // initialize timer
    CLOCKS_PER_MICROSEC = vx86_CpuCLK();
    VORTEX86EX_CLOCKS_PER_MS = CLOCKS_PER_MICROSEC*1000UL;
    
    // Set IRQ4 as level-trigger
    io_outpb(0x4D0, io_inpb(0x4D0) | 0x10);
    
	//set corssbar Base Address
	crossbarBase = sb_Read16(SB_CROSSBASE) & 0xfffe;
	if(crossbarBase == 0 || crossbarBase == 0xfffe)
		sb_Write16(SB_CROSSBASE, CROSSBARBASE | 0x01);
	
	// Force set HIGH speed ISA on SB
	sb_Write(SB_FCREG, sb_Read(SB_FCREG) | 0x8000C000L);
	
	//set SB GPIO Base Address
	gpioBase = sb_Read16(SB_GPIOBASE) & 0xfffe;
	if(gpioBase == 0 || gpioBase == 0xfffe)
	{
		sb_Write16(SB_GPIOBASE, GPIOCTRLBASE | 0x01);
		gpioBase = GPIOCTRLBASE;
	}
	
	// Enable GPIO 0 ~ 7 
	io_outpdw(gpioBase, 0x00ff);
	
	// set GPIO Port 0~7 dircetion & data Address
	for(i=0;i<8;i++)
		io_outpdw(gpioBase + (i+1)*4,((GPIODIRBASE + i*4)<<16) + GPIODATABASE + i*4);
	  
	// set ADC Base Address
	sb_Write(0xbc, sb_Read(0xbc) & (~(1L<<28)));  // active adc
	sb1_Write16(0xde, sb1_Read16(0xde) | 0x02);   // not Available for 8051A Access ADC
	sb1_Write(0xe0, 0x0050fe00L); // baseaddr = 0xfe00, disable irq
	
	// set MCM Base Address
	set_MMIO();
	mc_setbaseaddr();
	for(i=0; i<4; i++)
		mc_SetMode(i, MCMODE_PWM_SIFB);
	
	if(Global_irq_Init == false)
	{
		// set MCM IRQ
		if(irq_Init() == false) 
	    {
	        printf("MCM IRQ init fail\n"); return false;
	    }
	    
	    if(irq_Setting(GetMCIRQ(), IRQ_LEVEL_TRIGGER + IRQ_DISABLE_INTR) == false)
	    {
	        printf("MCM IRQ Setting fail\n"); return false;
	    }
	    Set_MCIRQ(GetMCIRQ());
	    Global_irq_Init = true;
	}
    
	//CDC
	USBDEV = CreateUSBDevice();
	if(USBDEV == NULL)
	{
		printf("init error\n");
		return false;
	}
    
	usb_SetUSBPins(USBDEV, 7, 0, 7, 1);
	usb_SetTimeOut(USBDEV, 0L, 500L); // USB RX timerout is 0ms and TX timeout is 500ms
	if(usb_Init(USBDEV) == false)
	{
		printf("init2 error\n");
		return false;
	}
    
	//io_Close();
	return true;
}