void usb_msc_start (void) {

    debug("Initialising USB stack");

    // initialise stack
    USBInit();

    // enable bulk-in interrupts on NAKs
    // these are required to get the BOT protocol going again after a STALL
    USBHwNakIntEnable(INACK_BI);

    // register descriptors
    USBRegisterDescriptors(abDescriptors);

    // register class request handler
    USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);

    // register endpoint handlers
    USBHwRegisterEPIntHandler(MSC_BULK_IN_EP, MSCBotBulkIn);
    USBHwRegisterEPIntHandler(MSC_BULK_OUT_EP, MSCBotBulkOut);

    debug("Starting USB communication");

    // connect to bus
    USBHwConnect(true);

    // call USB interrupt handler continuously
    while (1) {
        USBHwISR();
    }
}
Exemplo n.º 2
0
int ubertooth_usb_init(VendorRequestHandler *vendor_req_handler)
{
	// initialise stack
	USBInit();
	
	// register device descriptors
	USBRegisterDescriptors(abDescriptors);

	// Request handler 
	v_req_handler = vendor_req_handler;

	// override standard request handler
	USBRegisterRequestHandler(REQTYPE_TYPE_VENDOR, usb_vendor_request_handler, abVendorReqData);

	// register endpoints
	//USBHwRegisterEPIntHandler(BULK_IN_EP, usb_bulk_in_handler);
	//USBHwRegisterEPIntHandler(BULK_OUT_EP, usb_bulk_out_handler);

	// enable USB interrupts
	//ISER0 = ISER0_ISE_USB;

	// connect to bus
	USBHwConnect(TRUE);

	return 0;
}
Exemplo n.º 3
0
void USBSerial_Init(void)
{
  // initialise stack
  USBInit();
	LPC_GPIO1->FIODIR |= 1 << 23; // P1.29 connected to LED


  // register descriptors
  USBRegisterDescriptors(abDescriptors);

  // register class request handler
  USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);

  // register endpoint handlers
  USBHwRegisterEPIntHandler(INT_IN_EP, NULL);
  USBHwRegisterEPIntHandler(BULK_IN_EP, BulkIn);
  USBHwRegisterEPIntHandler(BULK_OUT_EP, BulkOut);

  // register frame handler
  USBHwRegisterFrameHandler(USBFrameHandler);

  // enable bulk-in interrupts on NAKs
  USBHwNakIntEnable(INACK_BI);

  // initialise VCOM
  fifo_init(&rxfifo, rxbuf);
  fifo_init(&txfifo, txbuf);

  NVIC_EnableIRQ(USB_IRQn);

  // connect to bus
  USBHwConnect(TRUE);
}
Exemplo n.º 4
0
void init_usb_msc_device(void)
{
	DBG("Initialising USB stack\n");

	// initialise stack
	USBInit();

	// enable bulk-in interrupts on NAKs
	// these are required to get the BOT protocol going again after a STALL
	USBHwNakIntEnable(INACK_BI);

	// register descriptors
	USBRegisterDescriptors(abDescriptors);

	// register class request handler
	USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);

	// register endpoint handlers
	USBHwRegisterEPIntHandler(MSC_BULK_IN_EP, MSCBotBulkIn);
	USBHwRegisterEPIntHandler(MSC_BULK_OUT_EP, MSCBotBulkOut);

	DBG("Starting USB communication\n");

	// connect to bus
	USBHwConnect(TRUE);
}
Exemplo n.º 5
0
void USBSerial_Init(void)
{
    char serialnumber[10] = {0};
    char *pmem117;

    pmem117 = SECTOR_14_START;
    int serialnumber_present = 0;
    for (int i = 0; i < 10; i++) {
        serialnumber[9 - i] = *pmem117;
        pmem117++;
        if(*pmem117 != 0xFF)
            serialnumber_present = 1;
    }
    if(serialnumber_present == 1){
        /*
         * abDescriptors[112+i] -> 112 is the position where the Serial Number string is located in the USB Descriptor
         */
        abDescriptors[SERIAL_ADD] = serialnumber[0];
        abDescriptors[SERIAL_ADD+2] = serialnumber[1];
        abDescriptors[SERIAL_ADD+4] = serialnumber[2];
        abDescriptors[SERIAL_ADD+6] = serialnumber[3];
        abDescriptors[SERIAL_ADD+8] = serialnumber[4];
        abDescriptors[SERIAL_ADD+10] = serialnumber[5];
        abDescriptors[SERIAL_ADD+12] = serialnumber[6];
        abDescriptors[SERIAL_ADD+14] = serialnumber[7];
        abDescriptors[SERIAL_ADD+16] = serialnumber[8];
        abDescriptors[SERIAL_ADD+18] = serialnumber[9];
    }

    // initialise stack
    USBInit();

    // register descriptors
    USBRegisterDescriptors(abDescriptors);

    // register endpoint handlers
    USBHwRegisterEPIntHandler(BULK_IN_EP, BulkIn);
    USBHwRegisterEPIntHandler(BULK_OUT_EP, BulkOut);

    // register frame handler
    USBHwRegisterFrameHandler(USBFrameHandler);

    // enable bulk-in interrupts on NAKs
    USBHwNakIntEnable(INACK_BI); // é gerada uma interrupção sempre que o host tenta ler do EP IN mas este está vazio.

    // initialise VCOM
    fifo_init(&rxfifo, rxbuf);
    fifo_init(&txfifo, txbuf);

    NVIC_EnableIRQ(USB_IRQn);

    // connect to bus
    USBHwConnect(TRUE);
}
Exemplo n.º 6
0
/*
 * main
 */
int main(void) {

    FIO_ENABLE;
    pllstart_seventytwomhz() ;
    mam_enable();
    uart0_init_115200() ;

    DBG(UART0,"Initialising USB stack\n");

    // initialise stack
    USBInit();

    // register descriptors
    USBRegisterDescriptors(abDescriptors);

    // register class request handler
    USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);

    // register endpoint handlers
    USBHwRegisterEPIntHandler(INT_IN_EP, NULL);

    // register frame handler
    USBHwRegisterFrameHandler(USBFrameHandler);

    // register device event handler
    USBHwRegisterDevIntHandler(USBDevIntHandler);

    inputIsocDataBuffer[0] = 0;

    DBG(UART0,"Starting USB isoc datatpath test\n");

    VICVectPriority22 = 0x01;
    VICVectAddr22     = (int) USBIntHandler;

    // set up USB interrupt
    VICIntSelect      &= ~(1<<22);     // select IRQ for USB
    VICIntEnable      |= (1<<22);

    vic_enableIRQ();

    // connect to bus
    USBHwConnect(TRUE);

    stream_task();

    return 0;
}
Exemplo n.º 7
0
/*************************************************************************
	main
	====
**************************************************************************/
int main(void)
{
	// PLL and MAM
	Initialize();

	// init DBG
	ConsoleInit(60000000 / (16 * BAUD_RATE));

	// initialise the SD card
	BlockDevInit();

	DBG("Initialising USB stack\n");

	// initialise stack
	USBInit();
	
	// enable bulk-in interrupts on NAKs
	// these are required to get the BOT protocol going again after a STALL
	USBHwNakIntEnable(INACK_BI);

	// register descriptors
	USBRegisterDescriptors(abDescriptors);

	// register class request handler
	USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);
	
	// register endpoint handlers
	USBHwRegisterEPIntHandler(MSC_BULK_IN_EP, MSCBotBulkIn);
	USBHwRegisterEPIntHandler(MSC_BULK_OUT_EP, MSCBotBulkOut);

	DBG("Starting USB communication\n");

	// connect to bus
	USBHwConnect(TRUE);

	// call USB interrupt handler continuously
	while (1) {
		USBHwISR();
	}
	
	return 0;
}
Exemplo n.º 8
0
/*************************************************************************
  main
  ====
**************************************************************************/
int main_mass_storage(void)
{
  unsigned cpsr;

  // disable global interrupts, do it polling
  cpsr = disableIRQ();

  // initialise the SD card
  BlockDevInit();

  // initialise stack
  USBInit();

  // enable bulk-in interrupts on NAKs
  // these are required to get the BOT protocol going again after a STALL
  USBHwNakIntEnable(INACK_BI);

  // register descriptors
  USBRegisterDescriptors(abDescriptors);

  // register class request handler
  USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);

  // register endpoint handlers
  USBHwRegisterEPIntHandler(MSC_BULK_IN_EP, MSCBotBulkIn);
  USBHwRegisterEPIntHandler(MSC_BULK_OUT_EP, MSCBotBulkOut);

  // connect to bus
  USBHwConnect(TRUE);

  // call USB interrupt handler continuously
  while (1) {
    USBHwISR();
  }

  // possibly restore global interrupts (never happens)
  restoreIRQ(cpsr);

  return 0;
}
Exemplo n.º 9
0
void usbConnect(uint8_t con) {
	USBHwConnect(con);

#ifdef USB_CONNECT_PORT
#ifndef USB_CONNECT_INVERT
	if(con) {
		USB_CONNECT_PORT->FIOSET |= 1 << USB_CONNECT_PIN;
	} else {
		USB_CONNECT_PORT->FIOCLR |= 1 << USB_CONNECT_PIN;
	}
#else
	if(con) {
		USB_CONNECT_PORT->FIOCLR |= 1 << USB_CONNECT_PIN;
	} else {
		USB_CONNECT_PORT->FIOSET |= 1 << USB_CONNECT_PIN;
	}
#endif

#endif


}
Exemplo n.º 10
0
void platform_setup_usb_cdc(void)
{
	int c;

	printf("Initialising USB stack\n");

	// initialise stack
	USBInit();

	// register descriptors
	USBRegisterDescriptors(abDescriptors);

	// register class request handler
	USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);

	// register endpoint handlers
	USBHwRegisterEPIntHandler(INT_IN_EP, NULL);
	USBHwRegisterEPIntHandler(BULK_IN_EP, BulkIn);
	USBHwRegisterEPIntHandler(BULK_OUT_EP, BulkOut);

	// register frame handler
	USBHwRegisterFrameHandler(USBFrameHandler);

	// enable bulk-in interrupts on NAKs
	USBHwNakIntEnable(INACK_BI);

	// initialise VCOM
	VCOM_init();
	printf("Starting USB communication\n");

	// enable IRQ
	NVIC_EnableIRQ(USB_IRQn);

	// connect to bus

	printf("Connecting to USB bus\n");
	USBHwConnect(TRUE);
}
Exemplo n.º 11
0
USBSerialStream::USBSerialStream(Stream *echoStream) :  m_infifo(512), m_outfifo(512), m_bTransferInProgress(false), m_bDontStartNew(false),
	m_bConnected(false)
{

	// initialise stack
	USBInit();

	// register descriptors
	USBRegisterDescriptors(abDescriptors);

	// register class request handler
	USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);

	// register endpoint handlers
	USBHwRegisterEPIntHandler(INT_IN_EP, NULL);
	USBHwRegisterEPIntHandler(BULK_IN_EP, BulkIn);
	USBHwRegisterEPIntHandler(BULK_OUT_EP, BulkOut);

	USBHwRegisterDevIntHandler(DevIntHandler);
	USBHwRegisterFrameHandler(FrameHandler);

	// enable bulk-in interrupts on NAKs
	//USBHwNakIntEnable(INACK_BI);

	// set up USB interrupt
	VICIntSelect &= ~(1<<22);               // select IRQ for USB
	VICIntEnable |= (1<<22);

	(*(&VICVectCntl0+INT_VECT_NUM)) = 0x20 | 22; // choose highest priority ISR slot 	
	(*(&VICVectAddr0+INT_VECT_NUM)) = (int)USBHandlerSerial;

	UART_puts("Connecting USB\n\r");

	// connect to bus
	USBHwConnect(TRUE);

}
Exemplo n.º 12
0
void vUSBTask( void *pvParameters )
{
    int c;

    /* Just to prevent compiler warnings about the unused parameter. */
    ( void ) pvParameters;
    DBG("Initialising USB stack\n");

    xRxedChars = xQueueCreate( usbBUFFER_LEN, sizeof( char ) );
    xCharsForTx = xQueueCreate( usbBUFFER_LEN, sizeof( char ) );

    if( ( xRxedChars == NULL ) || ( xCharsForTx == NULL ) )
    {
        /* Not enough heap available to create the buffer queues, can't do
        anything so just delete ourselves. */
        vTaskDelete( NULL );
    }


    // initialise stack
    USBInit();

    // register descriptors
    USBRegisterDescriptors(abDescriptors);

    // register class request handler
    USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);

    // register endpoint handlers
    USBHwRegisterEPIntHandler(INT_IN_EP, NULL);
    USBHwRegisterEPIntHandler(BULK_IN_EP, BulkIn);
    USBHwRegisterEPIntHandler(BULK_OUT_EP, BulkOut);

    // register frame handler
    USBHwRegisterFrameHandler(USBFrameHandler);

    // enable bulk-in interrupts on NAKs
    USBHwNakIntEnable(INACK_BI);

    DBG("Starting USB communication\n");

    NVIC_SetPriority( USB_IRQn, configUSB_INTERRUPT_PRIORITY );
    NVIC_EnableIRQ( USB_IRQn );

    // connect to bus

    DBG("Connecting to USB bus\n");
    USBHwConnect(TRUE);

    // echo any character received (do USB stuff in interrupt)
    for( ;; )
    {
        c = VCOM_getchar();
        if (c != EOF)
        {
            // Echo character back with INCREMENT_ECHO_BY offset, so for example if
            // INCREMENT_ECHO_BY is 1 and 'A' is received, 'B' will be echoed back.
            VCOM_putchar(c + INCREMENT_ECHO_BY );
        }
    }
}
/*************************************************************************
	main
	====
**************************************************************************/
int main(void)
{
	int c, i;
	
	IODIR0 |= (1<<10);
	
	
	// PLL and MAM
	HalSysInit();

#ifdef LPC214x
	// init DBG
	ConsoleInit(60000000 / (16 * BAUD_RATE));
#else
	// init DBG
	ConsoleInit(72000000 / (16 * BAUD_RATE));
#endif

	DBG("Initialising USB stack\n");

	// initialise stack
	USBInit();

	configureADCPort(AD0_3);
	
	// register descriptors
	USBRegisterDescriptors(abDescriptors);

	// register class request handler
	USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);

	// register endpoint handlers
	USBHwRegisterEPIntHandler(INT_IN_EP, NULL);
		
	// register frame handler
	USBHwRegisterFrameHandler(USBFrameHandler);
	
	// register device event handler
	USBHwRegisterDevIntHandler(USBDevIntHandler);
	
	
	char ch = 'a';
	for (i = 0; i < BYTES_PER_ISOC_FRAME; i++) {
		inputIsocDataBuffer[i] = ch;
		ch = (ch == 'z' ? 'a' : (ch + 1));
	}
	
	DBG("Starting USB communication\n");

#ifdef LPC214x
	(*(&VICVectCntl0+INT_VECT_NUM)) = 0x20 | 22; // choose highest priority ISR slot 	
	(*(&VICVectAddr0+INT_VECT_NUM)) = (int)USBIntHandler;
#else
  VICVectCntl22 = 0x01;
  VICVectAddr22 = (int)USBIntHandler;
#endif
  
	// set up USB interrupt
	VICIntSelect &= ~(1<<22);               // select IRQ for USB
	VICIntEnable |= (1<<22);
	
	enableIRQ();

	// connect to bus
	USBHwConnect(TRUE);
	
	int x = 0;
		
	const int interval = 100000;
	// echo any character received (do USB stuff in interrupt)
	
	for(;;) {
		x++;
		U32 temp = cADC_Result(AD0_3);
		if( temp >= 0 && temp <= 1024 )
			inputIsocDataBuffer[ADC_INPUT_INDEX] = temp;
		
		
		inputIsocDataBuffer[BUTTON1_INPUT_INDEX] = ((IOPIN0 & (1<<15)) ? 1 : 0);
		inputIsocDataBuffer[BUTTON2_INPUT_INDEX] = ((IOPIN0 & (1<<16)) ? 1 : 0);
		
		if (x == interval) {
			
			IOSET0 = (1<<11);
			//turn on led	
		    
		} else if (x >= (interval*2)) {
			IOCLR0 = (1<<11);
			//turn off led
			x = 0;
		}
	}

	return 0;
}
Exemplo n.º 14
0
/*************************************************************************
	main
	====
**************************************************************************/
int main(void)
{
    int x = 0;

    const int interval = 200000;

    FIO_ENABLE;

    vic_disableIRQ();

    pllstart_seventytwomhz() ;
    // pllstart_sixtymhz() ;
    //   pllstart_fourtyeightmhz() ;

    mam_enable();

    info_init();

    uart0_init_115200() ;

    uart0_putstring("\n***Starting gfe color led test***\n\n");
    uart0_putstring("\n***Board is defined as: ");

    uart0_putstring( infoquery_gfe_boardtag() );

    uart0_putstring(" ***\n");

    init_color_led();

    RED_LED_OFF;
    BLUE_LED_OFF;
    GREEN_LED_OFF;

    printf_lpc(UART0,"5 FAST flashes...red, blue then green\n");
    color_led_flash(5, RED_LED, FLASH_FAST ) ;
    RED_LED_OFF;
    color_led_flash(5, BLUE_LED,  FLASH_FAST ) ;
    BLUE_LED_OFF;
    color_led_flash(5, GREEN_LED, FLASH_FAST ) ;
    GREEN_LED_OFF;
    uart0_putstring(" ** END OF TEST ""\n");

    printf_lpc(UART0, "Initialising USB stack\n");

    // initialize stack
    USBInit();

    // register descriptors
    USBRegisterDescriptors(abDescriptors);

    // register class request handler
    USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);

    // register endpoint handlers
    USBHwRegisterEPIntHandler(INT_IN_EP, NULL);

    // register frame handler
    USBHwRegisterFrameHandler(USBFrameHandler);

    // register device event handler
    USBHwRegisterDevIntHandler(USBDevIntHandler);

    inputIsocDataBuffer[0] = 0;

    printf_lpc(UART0, "Starting USB communication\n");

    VICVectPriority22  = 0x01;         // 0x0 is highest priority, 0xF is lowest
    VICVectAddr22      = (unsigned int)USBIntHandler;
    VICAddress         = 0x0;

    printf_lpc(UART0, "addresses entered\n");

    ENABLE_USB_IRQ;

    printf_lpc(UART0, "USB IRQ Enabled\n");

    vic_enableIRQ();

    printf_lpc(UART0, "vic_enable\n");

    ENABLE_USB_INT;

    printf_lpc(UART0, "USB INT Enabled\n");



    //printf_lpc(UART0, "connect to bus\n");
//
//	// connect to bus
    USBHwConnect(TRUE);
//

    for(;;) {
        x++;

        if (x == interval) {
            RED_LED_ON;
        } else if (x >= (interval*2)) {
            x = 0;
            RED_LED_OFF;
        }
    }

    return 0;
}
Exemplo n.º 15
0
/*************************************************************************
	main
	====
**************************************************************************/
int main(void)
{
	int c, i;
	
	// PLL and MAM
	HalSysInit();

#ifdef LPC214x
	// init DBG
	ConsoleInit(60000000 / (16 * BAUD_RATE));
#else
	// init DBG
	ConsoleInit(72000000 / (16 * BAUD_RATE));
#endif

	configureADCPort(AD0_3);

	
	DBG("Initialising USB stack\n");

	// initialise stack
	USBInit();

	// register descriptors
	USBRegisterDescriptors(abDescriptors);

	// register class request handler
	USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);

	// register endpoint handlers
	USBHwRegisterEPIntHandler(INT_IN_EP, NULL);
		
	// register frame handler
	USBHwRegisterFrameHandler(USBFrameHandler);
	
	// register device event handler
	USBHwRegisterDevIntHandler(USBDevIntHandler);
	
	USBInitializeUSBDMA(udcaHeadArray);
	USBEnableDMAForEndpoint(ISOC_IN_EP);
	
	DBG("Starting USB communication\n");

#ifdef LPC214x
	(*(&VICVectCntl0+INT_VECT_NUM)) = 0x20 | 22; // choose highest priority ISR slot 	
	(*(&VICVectAddr0+INT_VECT_NUM)) = (int)USBIntHandler;
#else
  VICVectCntl22 = 0x01;
  VICVectAddr22 = (int)USBIntHandler;
#endif
  
	// set up USB interrupt
	VICIntSelect &= ~(1<<22);               // select IRQ for USB
	VICIntEnable |= (1<<22);
	
	enableIRQ();

	// connect to bus
	USBHwConnect(TRUE);
	
	int x = 0;
	c = EOF;
	
	
	//populate source data with all 'B's
	for(i = 0; i < ISOC_INPUT_DATA_BUFFER_SIZE; i++ ) {
		inputIsocDataBuffer[i] = 'B';
	}

	
	int cnt = 0;
	const int interval = 100000;
	// echo any character received (do USB stuff in interrupt)
	
	for(;;) {
		x++;
		U32 temp = cADC_Result(AD0_3);
		if( temp >= 0 && temp <= 1024 )
			currentADCReadValue = temp;
		
		if (x == interval) {
			qq++;
			
			IOSET0 = (1<<11);
			//turn on led	
		    
		} else if (x >= (interval*2)) {
			IOCLR0 = (1<<11);
			//turn off led
			x = 0;
		}
	}

	return 0;
}
Exemplo n.º 16
0
/*************************************************************************
	main
	====
**************************************************************************/
int main(void)
{
	// USB: Init
	// CAS -> Initialization of KbdInputReport to initial values (0,0,0,0,..)
	HIDDKbdInputReport_Initialize (&KbdInputReport);

	// CAS -> Variable used to simulate the pressing of Letter A (0x04)
	int i;

	DBG("Initialising USB stack\n");
	
	// CAS -> Variable used to simulate the pressing of Letter A (0x04)
	// 	USBInit()
	//		USBHwInit()										HW Init
	//			-> Set Pins for USB, AHBClock, ACK generate interrupts
	//		USBHwRegisterDevIntHandler(HandleUsbReset)
	//			-> Define un handler (HandleUsbReset).
	//
	// initialize stack
	USBInit();
	
	// register device descriptors
	USBRegisterDescriptors(abDescriptors);

	// register HID standard request handler
	USBRegisterCustomReqHandler(HIDHandleStdReq);

	// register class request handler
	USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);

	// register endpoint (2?). Interrupt In Endpoint
	USBHwRegisterEPIntHandler(INTR_IN_EP, NULL);

	// register frame handler
	USBHwRegisterFrameHandler(HandleFrame);
	
	DBG("Starting USB communication\n");


	// connect to bus
	USBHwConnect(TRUE);

	//RC5: Init
	GPIO_SetDir(0,1<<4,1);
	GPIO_SetDir(0,1<<5,1);

	GPIO_SetValue(0,1<<5);
	GPIO_SetValue(0,1<<4);


	RC5_Init();

	// main() Loop:


	// call USB interrupt handler continuously
	
	// CodeRed - either read mouse, or provide "fake mouse readings"
	while (1)
	{

		for (i=0; i<10;  i++) {


			// RC5
		    if (RC5_flag)                      // wait for RC5 code
		    	    {

		      if((RC5_System==0)&&(RC5_Command==1)){
		      GPIO_ClearValue(0,1<<4);
		      for(i=0;i<1000000;i++);
		      GPIO_SetValue(0,1<<4);
		      for(i=0;i<1000000;i++);
		      }

		      if((RC5_System==0)&&(RC5_Command==5)){
		      GPIO_ClearValue(0,1<<5);
		      for(i=0;i<1000000;i++);
		      GPIO_SetValue(0,1<<5);
		      for(i=0;i<1000000;i++);
		      }

		      RC5_flag = 0;
		      printf( "RC5 =  %d   %d\n", RC5_System, RC5_Command);
		    }
		    // RC5

		  USBHwISR();
		  if (i < 5) {
			  KbdInputReport.Key_1 = 0x04;
		  }
		  else {
			  KbdInputReport.Key_1 = 0x00;
		  }
		}
		
	}
	
	return 0;
}
Exemplo n.º 17
0
/*************************************************************************
	main
	====
**************************************************************************/
bool  USBStart(void)
{
	int c;
	


	// initialise stack
	USBInit();

	// register descriptors
	USBRegisterDescriptors(abDescriptors);

	// register class request handler
	USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);

	// register endpoint handlers
	USBHwRegisterEPIntHandler(INT_IN_EP, NULL);
	USBHwRegisterEPIntHandler(BULK_IN_EP, BulkIn);
	USBHwRegisterEPIntHandler(BULK_OUT_EP, BulkOut);
	
	// register frame handler
	USBHwRegisterFrameHandler(USBFrameHandler);
	
	// register device event handler
	USBHwRegisterDevIntHandler(USBDevIntHandler);

	// initialise VCOM
	VCOM_init();



      VICVectCntl22 = 0x01;
      VICVectAddr22 = (int)USBIntHandler;

  
	// set up USB interrupt
	VICIntSelect &= ~(1<<22);               // select IRQ for USB
	VICIntEnable |= (1<<22);
	

	// connect to bus
	USBHwConnect(TRUE);

#if TCM
	// echo any character received (do USB stuff in interrupt)
	while (1) {
		c = VCOM_getchar();
		if (c != EOF) {
			// show on console
			if ((c == 9) || (c == 10) || (c == 13) || ((c >= 32) && (c <= 126))) {
				DBG("%c", c);
			}
			else {
				DBG(".");
			}
			VCOM_putchar(c);
		}
	}

	return 0;
#endif
 return true;
}
Exemplo n.º 18
0
/*************************************************************************
        main
        ====
**************************************************************************/
int main(void)
{

    ///////////////////////////////////////////////////
    // PRELUDE
    ///////////////////////////////////////////////////
        
    // PLL and MAM
    HalSysInit();

#ifdef LPC214x
    // init DBG
    ConsoleInit(60000000 / (16 * BAUD_RATE));
#else
    // init DBG
    ConsoleInit(72000000 / (16 * BAUD_RATE));
#endif

    DBG("Initialising USB stack\n");

    // initialise stack
    USBInit();

    // enable bulk-in interrupts on NAKs
    USBHwNakIntEnable(INACK_BI);
    
    // register descriptors
    USBRegisterDescriptors(isoDescriptors);
    
	//USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);


    // register endpoint handlers
    USBHwRegisterEPIntHandler(INT_IN_EP, NULL);
    USBHwRegisterEPIntHandler(BULK_IN_EP, BulkIn);
    USBHwRegisterEPIntHandler(BULK_OUT_EP, BulkOut);

    // USBHwRegisterEPIntHandler(ISOC_OUT_EP, IsocOut);
                
    // register frame handler
    //USBHwRegisterFrameHandler(USBFrameHandler);
        
    // register device event handler
    USBHwRegisterDevIntHandler(USBDevIntHandler);
    bulk_init();
    
    DBG("Starting USB communication\n");

#ifdef LPC214x
    (*(&VICVectCntl0+INT_VECT_NUM)) = 0x20 | 22; // choose highest priority ISR slot        
    (*(&VICVectAddr0+INT_VECT_NUM)) = (int)USBIntHandler;
#else
    VICVectCntl22 = 0x01;
    VICVectAddr22 = (int)USBIntHandler;
#endif
  
    // set up USB interrupt
    VICIntSelect &= ~(1<<22);               // select IRQ for USB
    VICIntEnable |= (1<<22);
        
    enableIRQ();
        
    // connect to bus
    USBHwConnect(TRUE);


    /////////////////////////////////////////////
    // FUNCTION
    /////////////////////////////////////////////

    // int

    // bulk   - echo




    // isoc A - regular - Broadcast numbers

    // isoc B - dma -echo

    // isoc C - dma
    


    //////////////////////////////////////////
    // DEBUG LIGHTS
    //////////////////////////////////////////

    int c;
    int x = 0;
    int ch  ='a';
    c = EOF;
        
    // echo any character received (do USB stuff in interrupt)
    while (1) {

            
        // Turn light on and off.
                
        x++;
        if (x == 400000) {
                        
            IOSET0 = (1<<11);
            //turn on led
                        
            if( ch > 'z' ) {
                ch = 'a';
            }

            ch++;
                    
        } else if (x >= 800000) {
            IOCLR0 = (1<<11);
            //turn off led
            x = 0;
        }

    }

    return 0;
}
Exemplo n.º 19
0
Arquivo: main.c Projeto: lwalkera/R2C2
int main() {
	// DeInit NVIC and SCBNVIC
	NVIC_DeInit();
	NVIC_SCBDeInit();

	/* Configure the NVIC Preemption Priority Bits:
	 * two (2) bits of preemption priority, six (6) bits of sub-priority.
	 * Since the Number of Bits used for Priority Levels is five (5), so the
	 * actual bit number of sub-priority is three (3)
	 */
	NVIC_SetPriorityGrouping(0x05);

	NVIC_SetVTOR(0x00000000);

	#ifdef	UARTDEBUG
		uart_init();
	#endif

	BlockDevInit();

#ifdef	UARTDEBUG
	if (1) {
		U32 size;
		BlockDevGetSize(&size);
		DBG("Found SD card of size %d", size);
		BlockDevGetBlockLength(&size);
		DBG("block length %d", size);
	}
#endif

	if (bootloader_button_pressed() || (user_code_present() == 0)) {
		DBG("entering bootloader");
		init_usb_msc_device();

		for (;usb_msc_not_ejected();)
			USBHwISR();

		DBG("usb ejected, rebooting");

		USBHwConnect(FALSE);
		spi_close();
	}
	else {
		if ((r = f_mount(0, &fatfs)) == FR_OK) {
			if ((r = f_open(&f, "/firmware.bin", FA_READ | FA_OPEN_EXISTING)) == FR_OK) {
				unsigned int fs = f_size(&f);
				DBG("found firmware.bin with %u bytes", fs);
				if ((fs > 0) && (fs <= USER_FLASH_SIZE)) {
					U8 buffer[FLASH_BUF_SIZE];
					for (unsigned int i = 0; i < fs; i += FLASH_BUF_SIZE) {
						unsigned int j = FLASH_BUF_SIZE;
						if (i + j > fs)
							j = fs - i;
						DBG("writing %d-%d", i, i+j);
						if ((r = f_read(&f, buffer, j, &j)) == FR_OK) {
							// pad last block to a full sector size
							while (j < FLASH_BUF_SIZE) {
								buffer[j++] = 0xFF;
							}
							write_flash((unsigned int *) (USER_FLASH_START + i), (char *) &buffer, j);
						}
						else {
							DBG("read failed: %d", r);
							i = fs;
						}
					}
					r = f_close(&f);
					r = f_unlink("/firmware.bck");
					r = f_rename("/firmware.bin", "/firmware.bck");
				}
			}
			else {
				DBG("open \"/firmware.bin\" failed: %d", r);
			}
			#ifdef	GENERATE_FIRMWARE_CUR
				if (f_open(&f, "/firmware.bck", FA_READ | FA_OPEN_EXISTING)) {
					f_close(&f);
				}
				else {
					// no firmware.bck, generate one!
					if (f_open(&f, "/firmware.bck", FA_WRITE | FA_CREATE_NEW) == FR_OK) {
						U8 *flash = (U8 *) USER_FLASH_START;

						f_close(&f);
					}
				}
			#endif
			// elm-chan's fatfs doesn't have an unmount function
			// f_umount(&fatfs);
		}
		else {
			DBG("mount failed: %d", r);
		}
		spi_close();

		if (user_code_present()) {
			DBG("starting user code...");
			execute_user_code();
		}
		else {
			DBG("user code invalid, rebooting");
		}
	}
	NVIC_SystemReset();
}
Exemplo n.º 20
0
/*************************************************************************
    main
    ====
**************************************************************************/
int main(void)
{
    GO go_entry;

    // PLL and MAM
    Initialize();

    // init DBG
    ConsoleInit(CCLK / (16 * BAUD_RATE));

    DBG("Initialising USB stack\n");

    write_ram_len=0;
    read_mem_len=0;
    unlocked=0;
    bEcho=1;

    // initialise stack
    USBInit();

    // register descriptors
    USBRegisterDescriptors(abDescriptors);

    // register vendor request handler
    USBRegisterRequestHandler(REQTYPE_TYPE_VENDOR, HandleVendorRequest);

    // register pre request handler
    USBRegisterPreRequestHandler(PreHandleRequest);

    DBG("Starting USB communication\n");

    // connect to bus
    USBHwConnect(TRUE);

    start_app = 0;

    // call USB interrupt handler continuously
    while (1)
    {
        USBHwISR();

        if (start_app == 1)
        {
            volatile unsigned int count;

            // wait some time until response is sent
            for (count=0;count<10000;count++) USBHwISR();

            // disconnect from bus
            USBHwConnect(FALSE);

            // wait some ms so that called app might safely re-connect usb
            for (count=0;count<300000;count++) count=count;

            go_entry = (GO) (start_adr);
            go_entry();
        }
    }

    return 0;
}
Exemplo n.º 21
0
/*************************************************************************
	main
	====
**************************************************************************/
int main(void)
{
    IODIR0 |= (1<<10);//Debug LED on the olimex 2148 dev board set to output mode
    IODIR0 |= (1<<11);//Debug LED on the olimex 2148 dev board set to output mode

    // PLL and MAM
    HalSysInit();

#ifdef LPC214x
    // init DBG
    ConsoleInit(60000000 / (16 * BAUD_RATE));
#else
    // init DBG
    ConsoleInit(72000000 / (16 * BAUD_RATE));
#endif

    DBG("Initialising USB stack\n");

    // initialise stack
    USBInit();

    // register descriptors
    USBRegisterDescriptors(abDescriptors);

    // register class request handler
    USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);

    // register endpoint handlers
    USBHwRegisterEPIntHandler(INT_IN_EP, NULL);

    // register frame handler
    USBHwRegisterFrameHandler(USBFrameHandler);

    // register device event handler
    USBHwRegisterDevIntHandler(USBDevIntHandler);

    inputIsocDataBuffer[0] = 0;

    USBInitializeUSBDMA(udcaHeadArray);
    USBEnableDMAForEndpoint(ISOC_IN_EP);

    DBG("Starting USB communication\n");

#ifdef LPC214x
    (*(&VICVectCntl0+INT_VECT_NUM)) = 0x20 | 22; // choose highest priority ISR slot
    (*(&VICVectAddr0+INT_VECT_NUM)) = (int)USBIntHandler;
#else
    VICVectCntl22 = 0x01;
    VICVectAddr22 = (int)USBIntHandler;
#endif

    // set up USB interrupt
    VICIntSelect &= ~(1<<22);               // select IRQ for USB
    VICIntEnable |= (1<<22);

    enableIRQ();

    // connect to bus
    USBHwConnect(TRUE);

    int x = 0;

    const int interval = 200000;
    // echo any character received (do USB stuff in interrupt)

    for(;;) {
        x++;

        if (x == interval) {
            IOSET0 = (1<<11);//turn on led on olimex dev board
        } else if (x >= (interval*2)) {
            IOCLR0 = (1<<11);//turn off led on olimex dev board
            x = 0;
        }
    }

    return 0;
}