Пример #1
0
/**
    Local function to handle outgoing bulk data

    @param [in] bEP
    @param [in] bEPStatus
 */
static void BulkIn(U8 bEP, U8 bEPStatus)
{
  int i, iLen;

  if (_fifo_avail(&txfifo) == 0)
  {
    // no more data, disable further NAK interrupts until next USB frame
    USBHwNakIntEnable(0);
    return;
  }

  // get bytes from transmit FIFO into intermediate buffer
  for (i = 0; i < MAX_PACKET_SIZE; i++)
  {
    if (!_fifo_get(&txfifo, &abBulkBuf[i]))
    {
      break;
    }
  }
  iLen = i;

  // send over USB
  if (iLen > 0)
  {
    USBHwEPWrite(bEP, abBulkBuf, iLen);
  }
}
Пример #2
0
/**
    Local function to handle outgoing bulk data

    @param [in] bEP
    @param [in] bEPStatus
 */
static void BulkIn(U8 bEP, U8 bEPStatus)
{
  int i, iLen;

  // Verifica se não há data para enviar ao PC
  if (_fifo_avail(&txfifo) == 0)
  {
    // no more data, disable further NAK interrupts until next USB frame
    USBHwNakIntEnable(0); // não é gerada nenhuma interrupção sempre que o host tenta ler/escrever nos EPs mas este estão cheios/vazios.
    return;
  }

  // get bytes from transmit FIFO into intermediate buffer
  for (i = 0; i < MAX_PACKET_SIZE; i++)
  {
    if (!_fifo_get(&txfifo, &abBulkBuf[i]))
    {
      break; // sai do ciclo quando o fifo fica vazio, terminando a transferência de informação do &txfifo para &abBulkBuf[].
    }
  }
  iLen = i;

  // send over USB
  if (iLen > 0)
  {
    USBHwEPWrite(bEP, abBulkBuf, iLen);
  }
}
Пример #3
0
static void USBFrameHandler(u16 wFrame)
{
	if (fifo_avail(&txfifo) > 0) {
		// data available, enable NAK interrupt on bulk in
		USBHwNakIntEnable(INACK_BI);
	}
}
Пример #4
0
void USBSerial_Init(void)
{
  // 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
  serial_init();

  NVIC_EnableIRQ(USB_IRQn);

  // connect to bus
  USBHwConnect(TRUE);
}
Пример #5
0
/**
	Local function to handle outgoing bulk data

	@param [in] bEP
	@param [in] bEPStatus
 */
static void BulkIn(unsigned char bEP, unsigned char bEPStatus)
{
    int i, iLen;
    long lHigherPriorityTaskWoken = pdFALSE;

    ( void ) bEPStatus;

    if (uxQueueMessagesWaitingFromISR( xCharsForTx ) == 0) {
        // no more data, disable further NAK interrupts until next USB frame
        USBHwNakIntEnable(0);
        return;
    }

    // get bytes from transmit FIFO into intermediate buffer
    for (i = 0; i < MAX_PACKET_SIZE; i++) {
        if( xQueueReceiveFromISR( xCharsForTx, ( &abBulkBuf[i] ), &lHigherPriorityTaskWoken ) != pdPASS )
        {
            break;
        }
    }
    iLen = i;

    // send over USB
    if (iLen > 0) {
        USBHwEPWrite(bEP, abBulkBuf, iLen);
    }

    portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );
}
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();
    }
}
Пример #7
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);
}
Пример #8
0
static void USBFrameHandler(U16 wFrame __attribute__((unused)))
{
	if (fifo_avail(&txfifo) > 0) {
		// data available, enable NAK interrupt on bulk in
		USBHwNakIntEnable(INACK_BI);
	}
}
Пример #9
0
static void USBFrameHandler(unsigned short wFrame)
{
    ( void ) wFrame;

    if( uxQueueMessagesWaitingFromISR( xCharsForTx ) > 0 )
    {
        // data available, enable NAK interrupt on bulk in
        USBHwNakIntEnable(INACK_BI);
    }
}
Пример #10
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);
}
Пример #11
0
static void USBFrameHandler(U16 wFrame)
{
  if (_fifo_avail(&txfifo) > 0) // Se há data no fifo de tx...
  {
    // data available, enable NAK interrupt on bulk in
    //
    // Caso esta interrupção não seja ligada, não há transmissão de dados, uma vez que a interrupão sobre o EP IN só
    // acontece após transferência com sucesso. É necessário activar esta interrupção para que seja chamada a BulkIn()
    // e acontecer a transferência.
    // Caso haja um RTOS, uma task pode ver regularmente quando o EP IN está vazio e fazer a transferência, em vez de
    // este USBFrame Interrupt.
    USBHwNakIntEnable(INACK_BI);
  }
}
Пример #12
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;
}
Пример #13
0
/**
	Initialises the USB hardware

	This function assumes that the hardware is connected as shown in
	section 10.1 of the LPC2148 data sheet:
	* P0.31 controls a switch to connect a 1.5k pull-up to D+ if low.
	* P0.23 is connected to USB VCC.

	Embedded artists board: make sure to disconnect P0.23 LED as it
	acts as a pull-up and so prevents detection of USB disconnect.

	@return TRUE if the hardware was successfully initialised
 */
BOOL USBHwInit(void)
{
	// configure P0.23 for Vbus sense
	PINSEL1 = (PINSEL1 & ~(3 << 14)) | (1 << 14);	// P0.23
	IODIR0 &= ~(1 << 23);
	// configure P0.31 for CONNECT
	PINSEL1 = (PINSEL1 & ~(3 << 30)) | (2 << 30);	// P0.31

	// enable PUSB
	PCONP |= (1 << 31);

	// initialise PLL
	PLL1CON = 1;			// enable PLL
	PLL1CFG = (1 << 5) | 3; // P = 2, M = 4
	PLL1FEED = 0xAA;
	PLL1FEED = 0x55;
	while ((PLL1STAT & (1 << 10)) == 0);

	PLL1CON = 3;			// enable and connect
	PLL1FEED = 0xAA;
	PLL1FEED = 0x55;

	// disable/clear all interrupts for now
	USBDevIntEn = 0;
	USBDevIntClr = 0xFFFFFFFF;
	USBDevIntPri = 0;

	USBEpIntEn = 0;
	USBEpIntClr = 0xFFFFFFFF;
	USBEpIntPri = 0;

	// by default, only ACKs generate interrupts
	USBHwNakIntEnable(0);

	// init debug leds
	DEBUG_LED_INIT(8);
	DEBUG_LED_INIT(9);
	DEBUG_LED_INIT(10);

	return TRUE;
}
Пример #14
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;
}
Пример #15
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);
}
Пример #16
0
/**
	Initialises the USB hardware
		
		
	@return TRUE if the hardware was successfully initialised
 */
int USBHwInit(void)
{
	// P2.9 -> USB_CONNECT - this is MDIO pin on the LPC1758
	#if defined(_LPC_SERIES_176x_)
	LPC_PINCON->PINSEL4 &= ~0x000C0000;
	LPC_PINCON->PINSEL4 |= 0x00040000;
	#endif

	// P1.18 -> USB_UP_LED
	// P1.30 -> VBUS
	LPC_PINCON->PINSEL3 &= ~0x30000030;
	LPC_PINCON->PINSEL3 |= 0x20000010;

	// P0.29 -> USB_D+
	// P0.30 -> USB_D-
	LPC_PINCON->PINSEL1 &= ~0x3C000000;
	LPC_PINCON->PINSEL1 |= 0x14000000;	

	// enable PUSB
	LPC_SC->PCONP |= (1 << 31);

	LPC_USB->OTGClkCtrl = 0x12;	                  /* Dev clock, AHB clock enable  */
	while ((LPC_USB->OTGClkSt & 0x12) != 0x12);
	
	// disable/clear all interrupts for now
	LPC_USB->USBDevIntEn = 0;
	LPC_USB->USBDevIntClr = 0xFFFFFFFF;
	LPC_USB->USBDevIntPri = 0;

	LPC_USB->USBEpIntEn = 0;
	LPC_USB->USBEpIntClr = 0xFFFFFFFF;
	LPC_USB->USBEpIntPri = 0;

	// by default, only ACKs generate interrupts
	USBHwNakIntEnable(0);

	return TRUE;
}
Пример #17
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 );
        }
    }
}
Пример #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;
}
Пример #19
0
int main (void)
{
    OS_ERR   os_err;
#if (CPU_CFG_NAME_EN == DEF_ENABLED)
    CPU_ERR  cpu_err;
#endif

    BSP_PreInit();                                 /* initialize basic board support routines */

#if (CPU_CFG_NAME_EN == DEF_ENABLED)
    CPU_NameSet((CPU_CHAR *)CSP_DEV_NAME,
                (CPU_ERR  *)&cpu_err);
#endif

    Mem_Init();                                       /* Initialize memory management  module */

    OSInit(&os_err);                                                        /* Init uC/OS-III */

//    Debug_printf(Debug_Level_1, "Starting init");
#if 0
    /* Enable Timer0 Interrupt.*/
    CSP_IntVectReg((CSP_DEV_NBR   )CSP_INT_CTRL_NBR_MAIN,
                   (CSP_DEV_NBR   )CSP_INT_SRC_NBR_TMR_00,
                   (CPU_FNCT_PTR  )App_TMR0_IntHandler,
                   (void         *)0);
    CSP_IntEn(CSP_INT_CTRL_NBR_MAIN, CSP_INT_SRC_NBR_TMR_00);

    /* Enable Timer1 Interrupt.*/
    CSP_IntVectReg((CSP_DEV_NBR   )CSP_INT_CTRL_NBR_MAIN,
                   (CSP_DEV_NBR   )CSP_INT_SRC_NBR_TMR_01,
                   (CPU_FNCT_PTR  )App_TMR1_IntHandler,
                   (void         *)0);
    CSP_IntEn(CSP_INT_CTRL_NBR_MAIN, CSP_INT_SRC_NBR_TMR_01);

    /* Enable Timer2 Interrupt.*/
    CSP_IntVectReg((CSP_DEV_NBR   )CSP_INT_CTRL_NBR_MAIN,
                   (CSP_DEV_NBR   )CSP_INT_SRC_NBR_TMR_02,
                   (CPU_FNCT_PTR  )App_TMR2_IntHandler,
                   (void         *)0);
    CSP_IntEn(CSP_INT_CTRL_NBR_MAIN, CSP_INT_SRC_NBR_TMR_02);
    
    CSP_TmrInit();
    CSP_TmrCfg (CSP_TMR_NBR_00,TIMER_FREQ);
    CSP_TmrCfg (CSP_TMR_NBR_01,TIMER_FREQ);
    CSP_TmrCfg (CSP_TMR_NBR_02,TIMER_FREQ);
#endif

#if 0
    // Init the Ethernet PHY
    EMAC_PinCfg();
    emacConfigStruct.Mode = EMAC_MODE_100M_FULL;
    emacConfigStruct.pbEMAC_Addr = EthernetLinkLayer_macAddress();
    OS_EMAC_Init(EthernetLinkLayer_rxSemaphore());
    EMAC_Init(&emacConfigStruct);
    EMAC_SetFilterMode(EMAC_RFC_UCAST_EN, ENABLE);
    EMAC_SetFilterMode(EMAC_RFC_BCAST_EN, ENABLE);
    EMAC_SetFilterMode(EMAC_RFC_MCAST_EN, ENABLE);
    EMAC_SetFilterMode(EMAC_RFC_PERFECT_EN, ENABLE);
    EMAC_SetFilterMode(EMAC_RFC_MAGP_WOL_EN, DISABLE);
    EMAC_SetFilterMode(EMAC_RFC_PFILT_WOL_EN, DISABLE);
    
    // Init the Ethernt interrupt vecotrs
    CSP_IntVectReg((CSP_DEV_NBR   )CSP_INT_CTRL_NBR_MAIN,
                   (CSP_DEV_NBR   )CSP_INT_SRC_NBR_ETHER_00,
                   (CPU_FNCT_PTR  )CSP_IntETH_Handler,
                   (void         *)0);
    CSP_IntEn(CSP_INT_CTRL_NBR_MAIN, CSP_INT_SRC_NBR_ETHER_00);
    
    EthernetLinkLayer_setMacAddress(macAddress);
    Ip_initialize();
    Ip_setIPv4Address(ipv4Address);
#endif

#if 0
    USBInit();                                               /* USB Initialization */
    /* register descriptors */
    USBRegisterDescriptors(abDescriptors);                   /* USB Descriptor Initialization */

    /* register endpoint handlers */
    USBHwRegisterEPIntHandler(BULK_IN_EP, BulkIn);           /* register BulkIn Handler for EP */
    USBHwRegisterEPIntHandler(BULK_OUT_EP, BulkOut);         /* register BulkOut Handler for EP */
    USBHwRegisterEPIntHandler(INT_IN_EP, NULL);

    USBHwEPConfig(BULK_IN_EP, MAX_PACKET_SIZE);   /* Configure Packet Size for outgoing Transfer */
    USBHwEPConfig(BULK_OUT_EP, MAX_PACKET_SIZE);  /* Configure Packet Size for incoming Transfer */

    /* enable bulk-in interrupts on NAKs */
    USBHwNakIntEnable(INACK_BI);
#endif
    //Cb_initialize(&cncQueueBuffer, CNC_QUEUE_BUFFER_SIZE, sizeof(QueueItem), (void*)&cncQueueBufferData);
    
//    Debug_printf(Debug_Level_1, "Init finished");

    if(os_err != OS_ERR_NONE)
        for(;;);

    OSTaskCreate((OS_TCB      *)&App_TaskStartTCB,                  /* Create the Start Task */
                 (CPU_CHAR    *)"Start",
                 (OS_TASK_PTR  )App_TaskStart,
                 (void        *)0,
                 (OS_PRIO      )4,
                 (CPU_STK     *)App_TaskStartStk,
                 (CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE_LIMIT,
                 (CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE,
                 (OS_MSG_QTY   )0u,
                 (OS_TICK      )0u,
                 (void        *)0,
                 (OS_OPT       )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR      *)&os_err);

    OSStart(&os_err);                                                   /* Start Multitasking */
    if(os_err != OS_ERR_NONE)                                         /* shall never get here */
        for(;;);
    return (0);
}
Пример #20
0
/**
	Initialises the USB hardware
		
	This function assumes that the hardware is connected as shown in
	section 10.1 of the LPC2148 data sheet:
	* P0.31 controls a switch to connect a 1.5k pull-up to D+ if low.
	* P0.23 is connected to USB VCC.
	
	Embedded artists board: make sure to disconnect P0.23 LED as it
	acts as a pull-up and so prevents detection of USB disconnect.
		
	@return TRUE if the hardware was successfully initialised
 */
BOOL USBHwInit(void)
{
/*	CodeRed - comment out original code
 * 
	// configure P0.23 for Vbus sense
	PINSEL1 = (PINSEL1 & ~(3 << 14)) | (1 << 14);	// P0.23
	// configure P0.31 for CONNECT
	PINSEL1 = (PINSEL1 & ~(3 << 30)) | (2 << 30);	// P0.31
*/
	
	// CodeRed - set up USB pins
	
	// P2.9 -> USB_CONNECT
	LPC_PINCON->PINSEL4 &= ~0x000C0000;
	LPC_PINCON->PINSEL4 |= 0x00040000;

	// P1.18 -> USB_UP_LED
	// P1.30 -> VBUS
	LPC_PINCON->PINSEL3 &= ~0x30000030;
	LPC_PINCON->PINSEL3 |= 0x20000010;

	// P0.29 -> USB_D+
	// P0.30 -> USB_D-
	LPC_PINCON->PINSEL1 &= ~0x3C000000;
	LPC_PINCON->PINSEL1 |= 0x14000000;	

	
	// enable PUSB
	LPC_SC->PCONP |= (1 << 31);

/*  CodeRed - Comment out original PLL code
 *  PLL now set up by NXP code in target.c within example projects
 * 
	// initialise PLL
	PLL1CON = 1;			// enable PLL
	PLL1CFG = (1 << 5) | 3; // P = 2, M = 4
	PLL1FEED = 0xAA;
	PLL1FEED = 0x55;
	while ((PLL1STAT & (1 << 10)) == 0);

	PLL1CON = 3;			// enable and connect
	PLL1FEED = 0xAA;
	PLL1FEED = 0x55;	
	
*/
	

// AWB added USB clock enable
// These are actually the USBClkCtrl and USBClkSt registers
//	  OTG_CLK_CTRL = 0x12;	                  /* Dev clock, AHB clock enable  */
//	  while ((OTG_CLK_STAT & 0x12) != 0x12);

	  LPC_USB->USBClkCtrl = 0x1A;	                  /* Dev clock, AHB clock enable  */
	  while ((LPC_USB->USBClkSt & 0x1A) != 0x1A);

	  
	// disable/clear all interrupts for now
	LPC_USB->USBDevIntEn = 0;
	LPC_USB->USBDevIntClr = 0xFFFFFFFF;
	LPC_USB->USBDevIntPri = 0;

	LPC_USB->USBEpIntEn = 0;
	LPC_USB->USBEpIntClr = 0xFFFFFFFF;
	LPC_USB->USBEpIntPri = 0;

	// by default, only ACKs generate interrupts
	USBHwNakIntEnable(0);

	// CodeRed - commented out LEDs - not used by current port
	// init debug leds
    /*
	DEBUG_LED_INIT(5);
	DEBUG_LED_INIT(6);
	DEBUG_LED_INIT(7);
	*/
	
	return TRUE;
}