Пример #1
0
static rt_err_t ameba_uart_control (struct rt_serial_device *serial, int cmd, void *arg)
{
    struct device_uart * uart;

    uart = serial->parent.user_data;

    RT_ASSERT(uart != RT_NULL);

    switch (cmd)
    {
    case RT_DEVICE_CTRL_CLR_INT:
        /* Disable the UART Interrupt */
        serial_irq_set(&uart->serial, RxIrq, 0);
        serial_irq_handler(&uart->serial, RT_NULL, 0);
        break;

    case RT_DEVICE_CTRL_SET_INT:
        /* install interrupt */
        serial_irq_handler(&uart->serial, ameba_uart_irq, (uint32_t)serial);

        /* Enable the UART Interrupt */
        serial_irq_set(&uart->serial, RxIrq, 1);
        break;
    }

    return (RT_EOK);
}
Пример #2
0
int uartadapter_uart_open(char *uartname, ua_uart_set_str *puartpara)
{
	PinName uart_tx,uart_rx;

	if(!strcmp("uart0", uartname)){
		uart_tx = PA_7;
		uart_rx = PA_6;
		ua_uart_config[0].hal_uart_adp.BaudRate     = puartpara->BaudRate;
		ua_uart_config[0].hal_uart_adp.FlowControl  = puartpara->FlowControl;
		ua_uart_config[0].hal_uart_adp.WordLen      = puartpara->number;
		ua_uart_config[0].hal_uart_adp.Parity           = puartpara->parity;
		ua_uart_config[0].hal_uart_adp.StopBit         = puartpara->StopBits;
	}else{
		ua_printf(UA_ERROR, "please check uart name!");
		return RTW_ERROR;
	}

	/*initial uart */
	serial_init(&ua_sobj,uart_tx,uart_rx);
    	serial_baud(&ua_sobj,puartpara->BaudRate);
    	serial_format(&ua_sobj, puartpara->number, (SerialParity)puartpara->parity, puartpara->StopBits);
	
	/*uart irq handle*/
	serial_irq_handler(&ua_sobj, uartadapter_uart_irq, (uint32_t)&ua_sobj);
	serial_irq_set(&ua_sobj, RxIrq, 1);	
	serial_irq_set(&ua_sobj, TxIrq, 1);	

	return 0;
}
Пример #3
0
void Serial::attach(void (*fptr)(void), IrqType type) {
    if (fptr) {
        _irq[type].attach(fptr);
        serial_irq_set(&_serial, (SerialIrq)type, 1);
    } else {
        serial_irq_set(&_serial, (SerialIrq)type, 0);
    }
}
Пример #4
0
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;
}
Пример #5
0
void UARTClass1::begin( const uint32_t dwBaudRate )
{
	
	serial_init(&(this->sobj),UART1_TX,UART1_RX);

	serial_baud(&(this->sobj),dwBaudRate);
	serial_format(&(this->sobj), 8, ParityNone, 1);
	serial_set_pullNone();

    serial_irq_handler(&(this->sobj), uart_irq, (uint32_t)&(this->sobj));
    serial_irq_set(&(this->sobj), RxIrq, 1);
    serial_irq_set(&(this->sobj), TxIrq, 1);
}
Пример #6
0
void SerialBase::attach(Callback<void()> func, IrqType type) {
    lock();
    // Disable interrupts when attaching interrupt handler
    core_util_critical_section_enter();
    if (func) {
        _irq[type].attach(func);
        serial_irq_set(&_serial, (SerialIrq)type, 1);
    } else {
        _irq[type].attach(donothing);
        serial_irq_set(&_serial, (SerialIrq)type, 0);
    }
    core_util_critical_section_exit();
    unlock();
}
Пример #7
0
int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx_width, uint32_t handler, uint32_t event, DMAUsage hint)
{
    int i;
    buffer_t *buf = &obj->tx_buff;
    struct serial_global_data_s *data = uart_data + obj->serial.index;
    
    if (tx_length == 0) {
        return 0;
    }
    
    buf->buffer = (void *)tx;
    buf->length = tx_length * tx_width / 8;
    buf->pos = 0;
    buf->width = tx_width;
    data->tranferring_obj = obj;
    data->async_tx_callback = handler;
    serial_irq_set(obj, TxIrq, 1);
    
    while (!serial_writable(obj));
    i = buf->length;
    if (serial_available_buffer(obj) < i) {
        i = serial_available_buffer(obj);
    }
    do {
        uint8_t c = *(uint8_t *)buf->buffer;
        obj->tx_buff.buffer = (uint8_t *)obj->tx_buff.buffer + 1;
        ++buf->pos;
        obj->serial.uart->SCFTDR = c;
    } while (--i);
    serial_put_done(obj);
    
    return buf->length;
}
Пример #8
0
void config_uart()
{
	// setup uart
	serial_init(&mysobj, UART_TX, UART_RX);
	serial_baud(&mysobj, 38400);
	serial_format(&mysobj, 8, ParityNone, 1);

	serial_irq_handler(&mysobj, uart_irq_callback, (uint32_t)&mysobj);
	serial_irq_set(&mysobj, RxIrq, 1);
	serial_irq_set(&mysobj, TxIrq, 1);

	// config uart rx as gpio wakeup pin
	gpio_irq_t gpio_rx_wake;
	gpio_irq_init(&gpio_rx_wake, UART_RX, gpio_uart_rx_irq_callback, NULL);
	gpio_irq_set(&gpio_rx_wake, IRQ_FALL, 1);   // Falling Edge Trigger
	gpio_irq_enable(&gpio_rx_wake);
}
Пример #9
0
/** Kick a device into action (if required). For instance we may need
 * to set up interrupts */
void jshUSARTKick(IOEventFlags device) {
  int id = 0; // TODO: device
  int c = jshGetCharToTransmit(device);
  if (c >= 0) {
    serial_irq_set(&mbedSerial[id], TxIrq, 1);
    serial_putc(&mbedSerial[id], c);
  }
}
Пример #10
0
/*---------------------------------------------------------------------------*/
void
slip_arch_init(unsigned long ubr)
{
	serial_init(&_contiki_slip,USBTX,USBRX);
	serial_baud(&_contiki_slip,ubr);
	serial_irq_handler(&_contiki_slip,&slip_isr,1);
	serial_irq_set(&_contiki_slip,RxIrq,1);
}
Пример #11
0
// This function sets the current object as the "listening"
// one and returns true if it replaces another 
bool SoftwareSerial::listen()
{
    bool ret = false;

    serial_init((serial_t *)pUART, (PinName)g_APinDescription[transmitPin].pinname, (PinName)g_APinDescription[receivePin].pinname);
    serial_baud((serial_t *)pUART, speed);
    serial_format((serial_t *)pUART, data_bits, (SerialParity)parity, stop_bits);

    serial_irq_handler((serial_t *)pUART, (uart_irq_handler)handle_interrupt, (uint32_t)this);
    serial_irq_set((serial_t *)pUART, RxIrq, 1);
    serial_irq_set((serial_t *)pUART, TxIrq, 1);

    if (flowctrl) {
        serial_set_flow_control((serial_t *)pUART, FlowControlRTSCTS, (PinName)0, (PinName)0);
    }

    return ret;
}
Пример #12
0
// ---------------------------------------------------
void mbedSerialIRQ(uint32_t id, SerialIrq event) {
  IOEventFlags device = EV_SERIAL1;  // TODO: device

  if (event == RxIrq) {
    if (serial_readable(&mbedSerial[id]))
      jshPushIOCharEvent(device, (char)serial_getc(&mbedSerial[id]));
  }
  if (event == TxIrq) {
    int c = jshGetCharToTransmit(device);
    if (c >= 0) {
      serial_putc(&mbedSerial[id], c);
    } else
      serial_irq_set(&mbedSerial[id], TxIrq, 0);
  }
}
void UARTClass::begin(const uint32_t BaudRate, uint32_t rx_pin, uint32_t tx_pin)
{
	PinName	pin_rx, pin_tx;
	UARTName uart = UART_0;
	serial_t obj;
	
	pin_rx = Pin_nRF51822_to_Arduino(rx_pin);
	pin_tx = Pin_nRF51822_to_Arduino(tx_pin);
	
	obj.uart = (NRF_UART_Type *)uart;
	serial_init(&obj, pin_tx, pin_rx);
	serial_set_flow_control(&obj, FlowControlNone, (PinName)NC, (PinName)NC);
	serial_baud(&obj, BaudRate);
	/* TXIrq has a error, don't use it */
	serial_irq_set(&obj, RxIrq, 1);
	//serial_irq_set(&obj, TxIrq, 1);
}
Пример #14
0
void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_width, uint32_t handler, uint32_t event, uint8_t char_match, DMAUsage hint)
{
    buffer_t *buf = &obj->rx_buff;
    struct serial_global_data_s *data = uart_data + obj->serial.index;
    
    if (rx_length == 0) {
        return;
    }
    
    buf->buffer = rx;
    buf->length = rx_length * rx_width / 8;
    buf->pos = 0;
    buf->width = rx_width;
    obj->char_match = char_match;
    obj->char_found = 0;
    data->receiving_obj = obj;
    data->async_rx_callback = handler;
    data->event = 0;
    data->wanted_rx_events = event;
    
    serial_irq_set(obj, RxIrq, 1);
    serial_irq_err_set(obj, 1);
}