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); }
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; }
void serial_irq_handler_UART0 (void) { serial_irq_handler(UART0_BASE, uart0_rx_handler, &uart0_tx_buffer); VICVectAddr = 0; // Acknowledge Interrupt }
/*---------------------------------------------------------------------------*/ 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); }
SerialBase::SerialBase(PinName tx, PinName rx) : #if DEVICE_SERIAL_ASYNCH _thunk_irq(this), _tx_usage(DMA_USAGE_NEVER), _rx_usage(DMA_USAGE_NEVER), #endif _serial(), _baud(9600) { serial_init(&_serial, tx, rx); serial_irq_handler(&_serial, SerialBase::_irq_handler, (uint32_t)this); }
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; }
void UARTClass::attach( uart_irq_handler handle ) { UARTName uart = UART_0; serial_t obj; obj.uart = (NRF_UART_Type *)uart; obj.index = 0; /* must be 0 */ if(handle == NULL) return; /* id : if 0, don't call handle */ serial_irq_handler(&obj, handle, 1); }
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); }
// ---------------------------------------------------------------------------- // for non-blocking IO void jshInit() { systemTimeWasHigh = false; systemTimeHigh = 0; systemTime.start(); int i; for (i=0;i<MBED_PINS;i++) { gpio_init(&mbedPins[i], (PinName)(P0_0+i), PIN_INPUT); } for (i=0;i<USARTS;i++) { serial_init(&mbedSerial[i], USBTX, USBRX); // FIXME Pin serial_irq_handler(&mbedSerial[i], &mbedSerialIRQ, i); // serial_irq_set(&mbedSerial[i], RxIrq, 1); // FIXME Rx IRQ just crashes when called } }
SerialBase::SerialBase(PinName tx, PinName rx) : #if DEVICE_SERIAL_ASYNCH _thunk_irq(this), _tx_usage(DMA_USAGE_NEVER), _rx_usage(DMA_USAGE_NEVER), #endif _serial(), _baud(9600) { // No lock needed in the constructor for (int i = 0; i < sizeof _irq / sizeof _irq[0]; i++) { _irq[i].attach(donothing); } serial_init(&_serial, tx, rx); serial_irq_handler(&_serial, SerialBase::_irq_handler, (uint32_t)this); }
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); }
// 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; }
Serial::Serial(PinName tx, PinName rx, const char *name) : Stream(name) { serial_init(&_serial, tx, rx); _baud = 9600; serial_irq_handler(&_serial, Serial::_irq_handler, (uint32_t)this); }