Exemple #1
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;
}
Exemple #2
0
void analogWrite(uint8_t pin, int val) {
	unsigned short crossbar_ioaddr = 0;
	
	if(pin >= PINS) return;
	
	if (val <= 0)
		digitalWrite(pin, LOW);
	else if (val >= 255)
		digitalWrite(pin, HIGH);
	else
	{
	    mc = arduino_to_mc_md[MCM_MC][pin];
	    md = arduino_to_mc_md[MCM_MD][pin];
	    
	    if(mc == NOPWM || md == NOPWM)
		{
			if (val < 128)
				digitalWrite(pin, LOW);
			else
				digitalWrite(pin, HIGH);
			return;				
	    }
	    
	    mc_setbaseaddr();
	    //Master_DX2();
	    crossbar_ioaddr = sb_Read16(0x64)&0xfffe;
	    
		if (pin <= 9)
			io_outpb(crossbar_ioaddr + 2, 0x01); // GPIO port2: 0A, 0B, 0C, 3A
		else if (pin > 28)
	    	io_outpb(crossbar_ioaddr, 0x03); // GPIO port0: 2A, 2B, 2C, 3C
		else
			io_outpb(crossbar_ioaddr + 3, 0x02); // GPIO port3: 1A, 1B, 1C, 3B
	    
	    // Init H/W PWM
	    if(mc_md_inuse[pin] == 0)
		{
			if (mc_SetMode(mc, MCMODE_PWM_SIFB) == false)
			{
			    printf("ERROR: fail to change MC mode!\n");
			    return;
			}
			
			mcpwm_SetOutMask(mc, md, MCPWM_HMASK_NONE + MCPWM_LMASK_NONE);
			mcpwm_SetOutPolarity(mc, md, MCPWM_HPOL_NORMAL + MCPWM_LPOL_NORMAL);
			mcpwm_SetDeadband(mc, md, 0L);
			mcpwm_ReloadOUT_Unsafe(mc, md, MCPWM_RELOAD_NOW);
			
			mcpwm_SetWaveform(mc, md, MCPWM_EDGE_A0I1);
			mcpwm_SetSamplCycle(mc, md, 1999L);   // sample cycle: 20ms
			
			mcpwm_SetOutPolarity(mc, md, MCPWM_HPOL_NORMAL + MCPWM_LPOL_NORMAL);
			mcpwm_SetDeadband(mc, md, 0L);
			mcpwm_ReloadOUT_Unsafe(mc, md, MCPWM_RELOAD_NOW);
			io_outpb(crossbar_ioaddr + 0x90 + pinMap[pin], 0x08);
	    }
	   
	    mcpwm_SetWidth(mc, md, 2040L*SYSCLK, (8*val*SYSCLK));  // period: 2.04ms, duty: 8us  resolution: 10ns
	    mcpwm_ReloadPWM(mc, md, MCPWM_RELOAD_PEREND);
	    
	    if(mc_md_inuse[pin] == 0)
		{
			mcpwm_Enable(mc, md);
			mc_md_inuse[pin] = 1;
	    }  
	}
}