コード例 #1
0
ファイル: skynet_cdc.c プロジェクト: i7sid/SkyNet-Dongle
int skynet_cdc_init(void) {
	USBD_API_INIT_PARAM_T usb_param;
	USB_CORE_DESCS_T desc;
	ErrorCode_t ret = LPC_OK;

	RingBuffer_Init(&usb_tx_ringbuf, usb_tx_buf, sizeof(uint8_t), USB_TX_FIFO_QUEUE_SIZE);
	RingBuffer_Flush(&usb_tx_ringbuf);

	Chip_USB_Init();

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

	/* initialize call back structures */
	memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
	usb_param.usb_reg_base = LPC_USB_BASE + 0x200;
	usb_param.max_num_ep = 3;
	usb_param.mem_base = USB_STACK_MEM_BASE;
	usb_param.mem_size = USB_STACK_MEM_SIZE;

	/* Set the USB descriptors */
	desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0];
	desc.string_desc = (uint8_t *) &USB_StringDescriptor[0];
	/* Note, to pass USBCV test full-speed only devices should have both
	   descriptor arrays point to same location and device_qualifier set to 0.
	 */
	desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.device_qualifier = 0;

	/* USB Initialization */
	ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
	if (ret == LPC_OK) {

		/* Init VCOM interface */
		ret = vcom_init(g_hUsb, &desc, &usb_param);
		if (ret == LPC_OK) {
			/*  enable USB interrupts */
			NVIC_EnableIRQ(USB_IRQn);

			// first disable to simulate re-plug
			skynet_cdc_disconnect();

			msDelay(100);

			// and now enable connection
			skynet_cdc_connect();

			return 1;
		}
	}

	//char* welcome_msg = "# This is skynet dongle.\n";
	//vcom_write(welcome_msg, strlen(welcome_msg));
	return 0;
}
コード例 #2
0
void USBInit(SemaphoreHandle_t usb_uart_connected_sem)
{
	USBD_API_INIT_PARAM_T usb_param;
	USB_CORE_DESCS_T desc;
	ErrorCode_t ret = LPC_OK;

	/* Initialize board and chip */
	SystemCoreClockUpdate();
	Board_Init();

	StopWatch_Init();

	/* enable clocks and pinmux */
	usb_pin_clk_init();

	/* initialize call back structures */
	memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
	usb_param.usb_reg_base = LPC_USB_BASE + 0x200;
	usb_param.max_num_ep = 3;
	usb_param.mem_base = USB_STACK_MEM_BASE;
	usb_param.mem_size = USB_STACK_MEM_SIZE;

	/* Set the USB descriptors */
	desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0];
	desc.string_desc = (uint8_t *) &USB_StringDescriptor[0];
	/* Note, to pass USBCV test full-speed only devices should have both
	   descriptor arrays point to same location and device_qualifier set to 0. */
	desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.device_qualifier = 0;

	/* USB Initialization */
	ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
	if (ret == LPC_OK)
	{
		/* Init VCOM interface */
		ret = vcom_init(g_hUsb, &desc, &usb_param);
		if (ret == LPC_OK)
		{
			/*  enable USB interrupts */
			NVIC_EnableIRQ(USB_IRQn);
			/* now connect */
			USBD_API->hw->Connect(g_hUsb, 1);
		}
	}

	/* Check if host has connected and opened the VCOM port */
	while(!vcom_connected())
		;

	xSemaphoreGive(usb_uart_connected_sem);
}
コード例 #3
0
ファイル: main.c プロジェクト: ppejic/temperatura
void USB_Periph_Init(void)
{
	USBD_API_INIT_PARAM_T usb_param;
	USB_CORE_DESCS_T desc;
	ErrorCode_t ret = LPC_OK;
	
	/* enable clocks and pinmux */
	usb_pin_clk_init();

	/* initilize call back structures */
	memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
	usb_param.usb_reg_base = LPC_USB0_BASE;
	usb_param.max_num_ep = 3;
	usb_param.mem_base = USB_STACK_MEM_BASE;
	usb_param.mem_size = USB_STACK_MEM_SIZE;

	/* Set the USB descriptors */
	desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0];
	desc.string_desc = (uint8_t *) &USB_StringDescriptor[0];
	/* Note, to pass USBCV test full-speed only devices should have both
	   descriptor arrays point to same location and device_qualifier set to 0.
	 */
	desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.device_qualifier = 0;

	/* USB Initialization */
	ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
	if (ret == LPC_OK) {
		/* Init VCOM interface */
		ret = vcom_init(g_hUsb, &desc, &usb_param);
		if (ret == LPC_OK) {
			/*  enable USB interrrupts */
			NVIC_EnableIRQ(USB0_IRQn);
			/* now connect */
			USBD_API->hw->Connect(g_hUsb, 1);
		}
	}
}
コード例 #4
0
/**
 * @brief	main routine for blinky example
 * @return	Function should not exit.
 */
int main(void)
{
	USBD_API_INIT_PARAM_T usb_param;
	USB_CORE_DESCS_T desc;
	ErrorCode_t ret = LPC_OK;
	uint32_t prompt = 0, rdCnt = 0;

	SystemCoreClockUpdate();
	/* Initialize board and chip */
	Board_Init();

	/* enable clocks */
	Chip_USB_Init();

	/* initialize USBD ROM API pointer. */
	g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->pUSBD;

	/* initialize call back structures */
	memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
	usb_param.usb_reg_base = LPC_USB0_BASE;
	/*	WORKAROUND for artf44835 ROM driver BUG:
	    Code clearing STALL bits in endpoint reset routine corrupts memory area
	    next to the endpoint control data. For example When EP0, EP1_IN, EP1_OUT,
	    EP2_IN are used we need to specify 3 here. But as a workaround for this
	    issue specify 4. So that extra EPs control structure acts as padding buffer
	    to avoid data corruption. Corruption of padding memory doesn’t affect the
	    stack/program behaviour.
	 */
	usb_param.max_num_ep = 3 + 1;
	usb_param.mem_base = USB_STACK_MEM_BASE;
	usb_param.mem_size = USB_STACK_MEM_SIZE;

	/* Set the USB descriptors */
	desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0];
	desc.string_desc = (uint8_t *) &USB_StringDescriptor[0];
	/* Note, to pass USBCV test full-speed only devices should have both
	   descriptor arrays point to same location and device_qualifier set to 0.
	 */
	desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.device_qualifier = 0;

	/* USB Initialization */
	ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
	if (ret == LPC_OK) {

		/* Init VCOM interface */
		ret = vcom_init(g_hUsb, &desc, &usb_param);
		if (ret == LPC_OK) {
			/*  enable USB interrupts */
			NVIC_EnableIRQ(USB0_IRQn);
			/* now connect */
			USBD_API->hw->Connect(g_hUsb, 1);
		}

	}

	DEBUGSTR("USB CDC class based virtual Comm port example!\r\n");

	while (1) {
		/* Check if host has connected and opened the VCOM port */
		if ((vcom_connected() != 0) && (prompt == 0)) {
			vcom_write("Hello World!!\r\n", 15);
			prompt = 1;
		}
		/* If VCOM port is opened echo whatever we receive back to host. */
		if (prompt) {
			rdCnt = vcom_bread(&g_rxBuff[0], 256);
			if (rdCnt) {
				vcom_write(&g_rxBuff[0], rdCnt);
			}
		}
		/* Sleep until next IRQ happens */
		__WFI();
	}
}
コード例 #5
0
ファイル: usb_serial.cpp プロジェクト: Xenon-Photon/arm-1
void setup() {
  // TODO(zapta): which ones can be non static?

   static USBD_API_INIT_PARAM_T usb_param;
   static USB_CORE_DESCS_T desc;

   ErrorCode_t ret = LPC_OK;

   /* enable clocks and pinmux */
   usb_pin_clk_init();

   // Get pointer to the base of the USB ROM struct.
   g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->usbdApiBase;

   /* initialize call back structures */
   memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
   usb_param.usb_reg_base = LPC_USB0_BASE;
   /*  WORKAROUND for artf44835 ROM driver BUG:
    Code clearing STALL bits in endpoint reset routine corrupts memory area
    next to the endpoint control data. For example When EP0, EP1_IN, EP1_OUT,
    EP2_IN are used we need to specify 3 here. But as a workaround for this
    issue specify 4. So that extra EPs control structure acts as padding buffer
    to avoid data corruption. Corruption of padding memory doesn’t affect the
    stack/program behaviour.
    */
   usb_param.max_num_ep = 3 + 1;
   usb_param.mem_base = USB_STACK_MEM_BASE;
   usb_param.mem_size = USB_STACK_MEM_SIZE;

   /* Set the USB descriptors */
   desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0];
   desc.string_desc = (uint8_t *) &USB_StringDescriptor[0];
   /* Note, to pass USBCV test full-speed only devices should have both
    descriptor arrays point to same location and device_qualifier set to 0.
    */
   desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
   desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
   desc.device_qualifier = 0;

   /* USB Initialization */
   ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
   if (ret == LPC_OK) {

     /*  WORKAROUND for artf32219 ROM driver BUG:
      The mem_base parameter part of USB_param structure returned
      by Init() routine is not accurate causing memory allocation issues for
      further components.
      */
     usb_param.mem_base = USB_STACK_MEM_BASE
         + (USB_STACK_MEM_SIZE - usb_param.mem_size);

     /* Init VCOM interface */
     ret = vcom_init(g_hUsb, &desc, &usb_param);
     if (ret == LPC_OK) {
       /*  enable USB interrupts */
       NVIC_EnableIRQ(USB0_IRQn);
       /* now connect */
       USBD_API->hw->Connect(g_hUsb, 1);
     }

   }
}
コード例 #6
0
/**
 * @brief	main routine for blinky example
 * @return	Function should not exit.
 */
int main(void) {
	USBD_API_INIT_PARAM_T usb_param;
	USB_CORE_DESCS_T desc;
	ErrorCode_t ret = LPC_OK;
	uint32_t prompt = 0;

	SystemCoreClockUpdate();
	/* Initialize board and chip */
	Board_Init();
	Board_ADC_Init();

	/* Initialize PWM Units */
	handle0 = Chip_PWM_Init(0, 18, 100);
	handle1 = Chip_PWM_Init(0, 13, 100);

	/* enable clocks and pinmux */
	Chip_USB_Init();

	/* initialize USBD ROM API pointer. */
	g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->usbdApiBase;

	/* initialize call back structures */
	memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
	usb_param.usb_reg_base = LPC_USB0_BASE;
	/*	WORKAROUND for artf44835 ROM driver BUG:
	 Code clearing STALL bits in endpoint reset routine corrupts memory area
	 next to the endpoint control data. For example When EP0, EP1_IN, EP1_OUT,
	 EP2_IN are used we need to specify 3 here. But as a workaround for this
	 issue specify 4. So that extra EPs control structure acts as padding buffer
	 to avoid data corruption. Corruption of padding memory doesn’t affect the
	 stack/program behaviour.
	 */
	usb_param.max_num_ep = 3 + 1;
	usb_param.mem_base = USB_STACK_MEM_BASE;
	usb_param.mem_size = USB_STACK_MEM_SIZE;

	/* Set the USB descriptors */
	desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0];
	desc.string_desc = (uint8_t *) &USB_StringDescriptor[0];
	/* Note, to pass USBCV test full-speed only devices should have both
	 descriptor arrays point to same location and device_qualifier set to 0.
	 */
	desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.device_qualifier = 0;

	/* USB Initialization */
	ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
	if (ret == LPC_OK) {

		/*	WORKAROUND for artf32219 ROM driver BUG:
		 The mem_base parameter part of USB_param structure returned
		 by Init() routine is not accurate causing memory allocation issues for
		 further components.
		 */
		usb_param.mem_base = USB_STACK_MEM_BASE
				+ (USB_STACK_MEM_SIZE - usb_param.mem_size);

		/*
		 Initialize ADC
		 */
		Chip_ADC_Init(_LPC_ADC_ID, &ADCSetup);
		Chip_ADC_EnableChannel(_LPC_ADC_ID, ADC_CH0, ENABLE);
		Chip_ADC_Int_SetChannelCmd(_LPC_ADC_ID, ADC_CH0, ENABLE);
		NVIC_SetPriority(_LPC_ADC_IRQ, 1);
		NVIC_EnableIRQ(_LPC_ADC_IRQ);

		/* Init VCOM interface */
		ret = vcom_init(g_hUsb, &desc, &usb_param);
		if (ret == LPC_OK) {
			/*  enable USB interrupts */
			NVIC_SetPriority(USB0_IRQn, 1);
			NVIC_EnableIRQ(USB0_IRQn);
			/* now connect */
			USBD_API->hw->Connect(g_hUsb, 1);
		}

	}

	DEBUGSTR("USB CDC class based virtual Comm port example!\r\n");

	/* Start BURST Mode (Continuously Convert and Interrupt) */
	Chip_ADC_SetBurstCmd(_LPC_ADC_ID, ENABLE);
	Chip_RIT_Init(LPC_RITIMER);
	Chip_RIT_SetTimerInterval(LPC_RITIMER, CONTROL_INTERVAL);

	NVIC_EnableIRQ(RIT_IRQn);

	int read_mode = WAITING_HEADER;

	while (1) {

		/* Check if host has connected and opened the VCOM port */

		if ((vcom_connected() != 0) && (prompt == 0)) {
			//vcom_write("Hello World!!\r\n", 15);
			prompt = 1;
		}

		if (prompt) {

			unsigned char c;
			if (vcom_bread(&c, 1) != 0) {
				switch (read_mode) {
				case WAITING_HEADER:
					if (c == PACKET_HEADER) {
						g_buffCounter = 0;
						read_mode = WAITING_FOOTER;
					}
					break;
				case WAITING_FOOTER:
					if (c == PACKET_FOOTER) {
						onReceivePacket();
						read_mode = WAITING_HEADER;
					} else {
						g_rxBuff[g_buffCounter] = c;
						g_buffCounter++;
					}
					break;
				default:
					break;
				}
			}
		}
		/* Sleep until next IRQ happens */
		//__WFI();

	}
}