Esempio n. 1
0
void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
{
    IRQn_Type uart_irqs[] = UART_RX_TX_IRQS;
    uint32_t vector = 0;

    switch (obj->index) {
        case 0:
            vector = (uint32_t)&uart0_irq;
            break;
        case 1:
            vector = (uint32_t)&uart1_irq;
            break;
        case 2:
            vector = (uint32_t)&uart2_irq;
            break;
        default:
            break;
    }

    if (enable) {
        switch (irq) {
            case RxIrq:
                UART_EnableInterrupts(uart_addrs[obj->index], kUART_RxDataRegFullInterruptEnable);
                break;
            case TxIrq:
                UART_EnableInterrupts(uart_addrs[obj->index], kUART_TxDataRegEmptyInterruptEnable);
                break;
            default:
                break;
        }
        NVIC_SetVector(uart_irqs[obj->index], vector);
        NVIC_EnableIRQ(uart_irqs[obj->index]);

    } else { // disable
        int all_disabled = 0;
        SerialIrq other_irq = (irq == RxIrq) ? (TxIrq) : (RxIrq);
        switch (irq) {
            case RxIrq:
                UART_DisableInterrupts(uart_addrs[obj->index], kUART_RxDataRegFullInterruptEnable);
                break;
            case TxIrq:
                UART_DisableInterrupts(uart_addrs[obj->index], kUART_TxDataRegEmptyInterruptEnable);
                break;
            default:
                break;
        }
        switch (other_irq) {
            case RxIrq:
                all_disabled = ((UART_GetEnabledInterrupts(uart_addrs[obj->index]) & kUART_RxDataRegFullInterruptEnable) == 0);
                break;
            case TxIrq:
                all_disabled = ((UART_GetEnabledInterrupts(uart_addrs[obj->index]) & kUART_TxDataRegEmptyInterruptEnable) == 0);
                break;
            default:
                break;
        }
        if (all_disabled)
            NVIC_DisableIRQ(uart_irqs[obj->index]);
    }
}
Esempio n. 2
0
static void uart_mcux_irq_rx_enable(struct device *dev)
{
	const struct uart_mcux_config *config = dev->config->config_info;
	u32_t mask = kUART_RxDataRegFullInterruptEnable;

	UART_EnableInterrupts(config->base, mask);
}
Esempio n. 3
0
static void uart_mcux_irq_err_enable(struct device *dev)
{
	const struct uart_mcux_config *config = dev->config->config_info;
	u32_t mask = kUART_NoiseErrorInterruptEnable |
			kUART_FramingErrorInterruptEnable |
			kUART_ParityErrorInterruptEnable;

	UART_EnableInterrupts(config->base, mask);
}
/*!
 * @brief Main function
 */
int main(void)
{
    uart_config_t config;

    BOARD_InitPins();
    BOARD_BootClockRUN();

    /*
     * config.baudRate_Bps = 115200U;
     * config.parityMode = kUART_ParityDisabled;
     * config.stopBitCount = kUART_OneStopBit;
     * config.txFifoWatermark = 0;
     * config.rxFifoWatermark = 1;
     * config.enableTx = false;
     * config.enableRx = false;
     */
    UART_GetDefaultConfig(&config);
    config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
    config.enableTx = true;
    config.enableRx = true;

    UART_Init(DEMO_UART, &config, CLOCK_GetFreq(DEMO_UART_CLKSRC));

    /* Send g_tipString out. */
    UART_WriteBlocking(DEMO_UART, g_tipString, sizeof(g_tipString) / sizeof(g_tipString[0]));

    /* Enable RX interrupt. */
    UART_EnableInterrupts(DEMO_UART, kUART_RxDataRegFullInterruptEnable | kUART_RxOverrunInterruptEnable);
    EnableIRQ(DEMO_UART_IRQn);

    while (1)
    {
        /* Send data only when UART TX register is empty and ring buffer has data to send out. */
        while ((kUART_TxDataRegEmptyFlag & UART_GetStatusFlags(DEMO_UART)) && (rxIndex != txIndex))
        {
            UART_WriteByte(DEMO_UART, demoRingBuffer[txIndex]);
            txIndex++;
            txIndex %= DEMO_RING_BUFFER_SIZE;
        }
    }
}
Esempio n. 5
0
void gps_task(void *pArg)
{

	char rx_sentence[200];
	char *data_ptr;
	uint32_t len;
	uint32_t notificationValue;

	PRINTF("from gps task...\r\n");

	/* Use Task Notification to sychronize between UART Rx handler and GPS task */
	xGpsTaskHandle = xTaskGetCurrentTaskHandle();

	/* Initialize UART driver with given parameters */
	UART_Init(GPS_UART_BASE, &gps_uart_config, GPS_UART_SRCCLK);

	/* Initialize UART driver and install our own handler for UART Rx data, which is called by the ISR */
	UART_TransferCreateHandle(GPS_UART_BASE, &gps_uart_handle, gps_uart_rx_handler, NULL);

	/* Set receive buffer pointer explicitly for custom handling */
	gps_uart_handle.rxData = gps_rx_buf;
	gps_uart_handle.rxDataSize = 1;

	/* Enable RX interrupt (start reception of bytes from GPS module) */
	UART_EnableInterrupts(GPS_UART_BASE, kUART_RxDataRegFullInterruptEnable | kUART_RxOverrunInterruptEnable);

	/* Turn on RED LED */


	while (1) {

		/* Wait for notification from UART Rx handler */
		if((notificationValue = ulTaskNotifyTake(pdTRUE, portMAX_DELAY)) == 1) {
			/* Copy the received sentence */
			len = gps_rx_len;
			memcpy((void *) rx_sentence, (void *) gps_rx_sentence, len);

			/* Parse the received sentence to update gps_info structure */
			if (NULL != strstr(rx_sentence, "GPGGA")) {
				data_ptr = &rx_sentence[6];
				gps_parse_gga(data_ptr, &gps_info);
			}

			if ((NULL != strstr(rx_sentence, "GPRMC")) || (NULL != strstr(rx_sentence, "GNRMC"))) {
				data_ptr = &rx_sentence[6];
				gps_parse_rmc(data_ptr, &gps_info);
			}
		}

		/* Check for GPS Fix */
		if (NO_FIX != gps_info.fix) {
			/* Turn on GREEN LED */
			LED_GREEN_ON();
		}
		else {
			/* Turn off GREEN LED */
			LED_GREEN_OFF();
		}

	}

}
Esempio n. 6
0
int
hal_uart_config(int port, int32_t speed, uint8_t databits, uint8_t stopbits,
                enum hal_uart_parity parity, enum hal_uart_flow_ctl flow_ctl)
{
    struct hal_uart *u;
    uart_config_t uconfig;

    if (port >= FSL_FEATURE_SOC_UART_COUNT) {
        return -1;
    }
    u = &uarts[port];
    if (!u->u_configured || u->u_open) {
        return -1;
    }

    /* PIN config (all UARTs use kPORT_MuxAlt3) */
    CLOCK_EnableClock(u->p_clock);
    PORT_SetPinMux(u->p_base, u->u_pin_rx, kPORT_MuxAlt3);
    PORT_SetPinMux(u->p_base, u->u_pin_tx, kPORT_MuxAlt3);

    /* UART CONFIG */
    UART_GetDefaultConfig(&uconfig);
    uconfig.baudRate_Bps = speed;

    /* TODO: only handles 8 databits currently */

    switch (stopbits) {
    case 1:
        uconfig.stopBitCount = kUART_OneStopBit;
        break;
    case 2:
        uconfig.stopBitCount = kUART_TwoStopBit;
        break;
    default:
        return -1;
    }

    switch (parity) {
    case HAL_UART_PARITY_NONE:
        uconfig.parityMode = kUART_ParityDisabled;
        break;
    case HAL_UART_PARITY_ODD:
        uconfig.parityMode = kUART_ParityOdd;
        break;
    case HAL_UART_PARITY_EVEN:
        uconfig.parityMode = kUART_ParityEven;
        break;
    }

    /* TODO: HW flow control not supported */
    assert(flow_ctl == HAL_UART_FLOW_CTL_NONE);

    u->u_open = 1;
    u->u_tx_started = 0;

    NVIC_SetVector(u->u_irq, (uint32_t)s_uartirqs[port]);

    /* Initialize UART device */
    UART_Init(u->u_base, &uconfig, CLOCK_GetFreq(u->clk_src));
    UART_EnableTx(u->u_base, true);
    UART_EnableRx(u->u_base, true);
    UART_EnableInterrupts(u->u_base,
                          kUART_RxDataRegFullInterruptEnable |
                          kUART_RxOverrunInterruptEnable);
    EnableIRQ(u->u_irq);

    return 0;
}