예제 #1
0
파일: ISR.c 프로젝트: bif/SPARC-ISP1362
void usb_isr(void)
{
    ULONG   i_st;
    //IOWR(PIO_SEG7_B_BASE,0, 0xAAAAAAAA);
    disable();
    Hal4D13_LockDevice(0);
    bD13flags.bits.At_IRQL1 = 1;
    i_st = Hal4D13_ReadInterruptRegister();
 
    if(i_st != 0) 
    {
        //IOWR_ALTERA_AVALON_PIO_DATA(PIO_SEG7_A_BASE, i_st);
        //USB_ISR_DEBUG(("[ISR]i_st=%lX\r\n", i_st));
        if(i_st & D13REG_INTSRC_BUSRESET){  // 0x01
            USB_ISR_DEBUG(("[USB ISR] Bus Reset\r\n"));
            Isr_BusReset();
        }else if(i_st & D13REG_INTSRC_SUSPEND){  // 0x04
            USB_ISR_DEBUG(("[USB ISR] Suspend\r\n"));
            Isr_SuspendChange();
        }else if(i_st & D13REG_INTSRC_EOT){
            USB_ISR_DEBUG(("[USB ISR] EOT (End of Tx)\r\n"));
            Isr_DmaEot();
        }else if(i_st & (D13REG_INTSRC_SOF|D13REG_INTSRC_PSEUDO_SOF)){
            USB_ISR_DEBUG(("[USB ISR] SOF (start of frame)\r\n"));
            Isr_SOF();
        }else if(i_st & D13REG_INTSRC_SHORT_PACKET){
            USB_ISR_DEBUG(("[USB ISR] short packet\r\n"));
            Isr_SHORT_PACKET();
        }else if(i_st & D13REG_INTSRC_RESUME){
            USB_ISR_DEBUG(("[USB ISR] resume\n"));
            Hal4D13_LockDevice(0);
        }
        else 
        {
            USB_ISR_DEBUG(("[USB ISR] other, i_st = %lXh....resume\n", i_st));
            if(i_st & D13REG_INTSRC_EP0OUT)  
                Isr_Ep00RxDone();
            if(i_st & D13REG_INTSRC_EP0IN)
                Isr_Ep00TxDone();
            if(i_st & D13REG_INTSRC_EP01)
                Isr_Ep01Done();
            if(i_st & D13REG_INTSRC_EP02)
                Isr_Ep02Done();        
            if(i_st & D13REG_INTSRC_EP03)
                Isr_Ep03Done();
            if(i_st & D13REG_INTSRC_EP04)
                Isr_Ep04Done();
            if(i_st & D13REG_INTSRC_EP05)
                Isr_Ep05Done();
            if(i_st & D13REG_INTSRC_EP06)
                Isr_Ep06Done();
        }
    }

    enable();
    bD13flags.bits.At_IRQL1 = 0;
}
예제 #2
0
파일: ISR.c 프로젝트: bif/SPARC-ISP1362
// ************************************************************************
//  ISR Subroutine
// ************************************************************************
void fn_usb_isr(void)
{
    disable();
    Hal4D13_LockDevice(0);
  enable();
}
int main() {
	/* Local variables */
	HID_KEYS_REPORT old_report;

	BOOL bufferAvailable, readyToSend, watchdog_required;
	UCHAR gesture;
	UCHAR send_buffer[8];
	int i;

	/* Configure ISP1362 chip */
	disable_irq();
	disconnect_USB_controller();
	usleep(1000000);
	Hal4D13_ResetDevice(); //This is good because its a legit ISP1362 call
	//changed state settings to reset values -- If possible I would like to remove these.
	hid_settings.state = reset;
	watchdog_required = FALSE;
	bUSBCheck_Device_State.State_bits.DEVICE_DEFAULT_STATE = 1;
	bUSBCheck_Device_State.State_bits.DEVICE_ADDRESS_STATE = 0;
	bUSBCheck_Device_State.State_bits.DEVICE_CONFIGURATION_STATE = 0;
	bUSBCheck_Device_State.State_bits.RESET_BITS = 0;
	usleep(1000000);
	reconnect_USB_controller();
	CHECK_CHIP_ID(); //Checks chip ID and prints it to console. Is not actually required
	Hal4D13_AcquireD13(USB_0_BASE,(void*)usb_isr); //Registers main ISR. very important.
	enable_irq();

	/* Initialise HID report structures to zero */
	new_report.modifier = 0x00;
	new_report.reserved = 0x00;
	for(i=0; i<6; i++){
		new_report.keycode[i] = 0x00;
	}

	old_report.modifier = 0x00;
	old_report.reserved = 0x00;
	for(i=0; i<6; i++){
		old_report.keycode[i] = 0x00;
	}

	while(1) {

		/* Interrupt service routines modify state bits, calls handler based on state */
		if (bUSBCheck_Device_State.State_bits.RESET_BITS == 1) {
			disable_irq();
			break;
		}
		if (bD13flags.bits.suspend) {
			disable_irq();
			bD13flags.bits.suspend= 0;
			enable_irq();
			change_suspend_state();
		} // Suspend Change Handler
		if (bD13flags.bits.DCP_state == USBFSM4DCP_SETUPPROC) {
			disable_irq();
			SetupToken_Handler();
			enable_irq();
		} // Setup Token Handler
		if ((bD13flags.bits.DCP_state == USBFSM4DCP_REQUESTPROC) && !ControlData.Abort) {
			disable_irq();
			bD13flags.bits.DCP_state = 0x00;
			DeviceRequest_Handler();
			enable_irq();
		} // Device Request Handler

		//TODO: Revisit how toSend is decided. Now bufferAvailable
		if(bD13flags.bits.DCP_state == USBFSM4DCP_INTR1DONE) {
			bD13flags.bits.DCP_state = 0x00;
			if(Hal4D13_GetErrorCode(EPINDEX4EP01) & 0x01) {
				//I feel like I need to do something in here. We get interrupts from the other side when packet is received.
			}
		}

		UCHAR status = Hal4D13_GetEndpointStatusWOInteruptClear(EPINDEX4EP01);
		if(!(status & 0x60)) {
			bufferAvailable = TRUE;
		}
		printf("Status bits are  = %x\n", status);

		if(hid_settings.state == connected) {
			
			/* Check for gesture */
			disable_irq();
			gesture = readGesture();
			mapGestureToKeycodes(&new_report, gesture);
			enable_irq();

			/* See if we should send the next report */
			disable_irq();
			readyToSend = reportChanged(old_report, new_report) && bufferAvailable;
			if(readyToSend || watchdog_required) {
				send_buffer[0] =  new_report.modifier;
				send_buffer[1] =  new_report.reserved;
				send_buffer[2] =  new_report.keycode[0];
				send_buffer[3] =  new_report.keycode[1];
				send_buffer[4] =  new_report.keycode[2];
				send_buffer[5] =  new_report.keycode[3];
				send_buffer[6] =  new_report.keycode[4];
				send_buffer[7] =  new_report.keycode[5];

				Hal4D13_LockDevice(0);
				Hal4D13_WriteEndpoint(EPINDEX4EP01, send_buffer, 8);
				bufferAvailable = FALSE;
				readyToSend = FALSE;
				watchdog_required = FALSE;
			}
			enable_irq();

			/* Update old report */
			old_report.keycode[0] = new_report.keycode[0]; //We only use one key slot so only need to to update one
			old_report.modifier = new_report.modifier;

			if(new_report.keycode[0] != 0)
				IOWR(GREEN_LEDS_BASE, 0, new_report.keycode[0]);
		}

	} //End While(1)
	return 0;
 }//End Main