コード例 #1
0
ファイル: uart_socket.c プロジェクト: Lee1124Amy/HomeKit
uart_socket_t* uart_open(uart_set_str *puartpara)
{
	PinName uart_tx = PA_7;//PA_4; //PA_7
	PinName uart_rx = PA_6;//PA_0; //PA_6
	uart_socket_t *u;

	u = (uart_socket_t *)RtlZmalloc(sizeof(uart_socket_t));
	if(!u){
		uart_printf("%s(): Alloc memory for uart_socket failed!\n", __func__);
		return NULL;
	}
	
	/*initial uart */
	serial_init(&u->sobj, uart_tx,uart_rx);
	serial_baud(&u->sobj,puartpara->BaudRate);
	serial_format(&u->sobj, puartpara->number, (SerialParity)puartpara->parity, puartpara->StopBits);

	/*uart irq handle*/
	serial_irq_handler(&u->sobj, uart_irq, (int)u);
	serial_irq_set(&u->sobj, RxIrq, 1);
	serial_irq_set(&u->sobj, TxIrq, 1);

#if UART_SOCKET_USE_DMA_TX
   	serial_send_comp_handler(&u->sobj, (void*)uart_send_stream_done, (uint32_t)u);
#endif

	/*alloc a socket*/
 	u->fd = lwip_allocsocketsd();
	if(u->fd == -1){
		uart_printf("Failed to alloc uart socket!\n");
		goto Exit2;
	}
	/*init uart related semaphore*/
	RtlInitSema(&u->action_sema, 0);
	RtlInitSema(&u->tx_sema, 1);
	RtlInitSema(&u->dma_tx_sema, 1);
	
	/*create uart_thread to handle send&recv data*/
	{
#define	UART_ACTION_STACKSIZE 512
#define	UART_ACTION_PRIORITY	1
		if(xTaskCreate(uart_action_handler, ((const char*)"uart_action"), UART_ACTION_STACKSIZE, u, UART_ACTION_PRIORITY, NULL) != pdPASS){
			uart_printf("%s xTaskCreate(uart_action) failed", __FUNCTION__);
			goto Exit1;
		}
	}
	return u;
Exit1:
	/* Free uart related semaphore */
	RtlFreeSema(&u->action_sema);
	RtlFreeSema(&u->tx_sema);	
	RtlFreeSema(&u->dma_tx_sema);		
Exit2:
	RtlMfree((u8*)u, sizeof(uart_socket_t));
	return NULL;
}
コード例 #2
0
ファイル: example_uvc.c プロジェクト: alex1818/rtk-8711af
void example_uvc(void)
{
          /*init payload queue*/
        INIT_LIST_HEAD(&payload_queue.wait_queue);
        INIT_LIST_HEAD(&payload_queue.done_queue);
        RtlMutexInit(&payload_queue.wait_mutex);
        RtlMutexInit(&payload_queue.done_mutex);
        RtlInitSema(&payload_queue.wait_sema, 0);
        RtlInitSema(&payload_queue.done_sema, 0);
        payload_queue.flush_err = 0;
        uvc_stream_init();
}