/*
 *  ======== readIsrTextBlocking ========
 *  Function that is called by the ISR
 */
static bool readIsrTextBlocking(UART_Handle handle)
{
    int                       readIn;
    UARTMSP432_Object        *object = handle->object;
    UARTMSP432_HWAttrs const *hwAttrs = handle->hwAttrs;

    readIn = MAP_UART_receiveData(hwAttrs->baseAddr);

    if (readIn == '\r') {
        /* Echo character if enabled. */
        if (object->state.readEcho) {
            MAP_UART_transmitData(hwAttrs->baseAddr, '\r');
        }
        readIn = '\n';
    }

    if (RingBuf_put(&object->ringBuffer, (unsigned char) readIn) == -1) {
        DebugP_log1("UART:(%p) Ring buffer full!!", hwAttrs->baseAddr);
        return (false);
    }

    DebugP_log2("UART:(%p) buffered '0x%02x'", hwAttrs->baseAddr,
        (unsigned char) readIn);

    if (object->state.readEcho) {
        MAP_UART_transmitData(hwAttrs->baseAddr, (unsigned char) readIn);
    }
    if (object->state.callCallback) {
        object->state.callCallback = false;
        object->readCallback(handle, NULL, 0);
    }

    return (true);
}
/*
 *  ======== readIsrBinaryCallback ========
 */
static bool readIsrBinaryCallback(UART_Handle handle)
{
    int                       readIn;
    bool                      ret = true;
    UARTMSP432_Object        *object = handle->object;
    UARTMSP432_HWAttrs const *hwAttrs = handle->hwAttrs;

    readIn = MAP_UART_receiveData(hwAttrs->baseAddr);

    if (RingBuf_put(&object->ringBuffer, (unsigned char)readIn) == -1) {
        DebugP_log1("UART:(%p) Ring buffer full!!", hwAttrs->baseAddr);
        ret = false;
    }
    DebugP_log2("UART:(%p) buffered '0x%02x'", hwAttrs->baseAddr,
        (unsigned char) readIn);

    /*
     * Check and see if a UART_read in callback mode told use to continue
     * servicing the user buffer...
     */
    if (object->state.drainByISR) {
        readTaskCallback(handle);
    }

    return (ret);
}
Beispiel #3
0
void vUART_Handler( void )
{
uint8_t ucChar;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
uint_fast8_t xInterruptStatus;

	xInterruptStatus = MAP_UART_getEnabledInterruptStatus( EUSCI_A0_MODULE );

	if( ( xInterruptStatus & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG ) != 0x00 )
	{
		/* Obtain the character. */
		ucChar = MAP_UART_receiveData( EUSCI_A0_MODULE );

		/* Send the character to the queue.  Note the comments at the top of this
		file with regards to the inefficiency of this method for anything other than
		very low bandwidth communications.

		If writing to the queue unblocks a task, and the unblocked task	has a
		priority above the currently running task (the task that this interrupt
		interrupted), then xHigherPriorityTaskWoken will be set	to pdTRUE inside the
		xQueueSendFromISR() function.  xHigherPriorityTaskWoken is then passed to
		portYIELD_FROM_ISR() at	the end of this interrupt handler to request a
		context switch so the interrupt returns directly to the (higher priority)
		unblocked task. */
		xQueueSendFromISR( xRxQueue, &ucChar, &xHigherPriorityTaskWoken );
	}

	if( ( xInterruptStatus & EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG ) != 0x00 )
	{
		/* Are there more characters to transmit? */
		pcStringStart++;
		if( ( uint32_t ) pcStringStart < ( uint32_t ) pcStringEnd )
		{
			/* This is probably quite a heavy wait function just for writing to
			the Tx register.  An optimised design would probably replace this
			with a simple register write. */
			pxUARTA0->rTXBUF.r = ( uint_fast8_t ) *pcStringStart;
		}
		else
		{
			/* No more characters to send.  Disable the interrupt and notify the
			task, if the task is waiting. */
			MAP_UART_disableInterrupt( EUSCI_A0_MODULE, EUSCI_A_UART_TRANSMIT_INTERRUPT );
			if( xTransmittingTask != NULL )
			{
				vTaskNotifyGiveFromISR( xTransmittingTask, &xHigherPriorityTaskWoken );
				xTransmittingTask = NULL;
			}
		}
	}


	/* portYIELD_FROM_ISR() will request a context switch if executing this
	interrupt handler caused a task to leave the blocked state, and the task
	that left the blocked state has a higher priority than the currently running
	task (the task this interrupt interrupted).  See the comment above the calls
	to xSemaphoreGiveFromISR() and xQueueSendFromISR() within this function. */
	portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
/*
 *  ======== UARTMSP432_readPolling ========
 */
int UARTMSP432_readPolling(UART_Handle handle, void *buf, size_t size)
{
    int32_t                   count = 0;
    unsigned char            *buffer = (unsigned char *)buf;
    UARTMSP432_Object        *object = handle->object;
    UARTMSP432_HWAttrs const *hwAttrs = handle->hwAttrs;

    /* Read characters. */
    while (size) {
        /* Grab data from the RingBuf before getting it from the RX data reg */
        MAP_UART_disableInterrupt(hwAttrs->baseAddr,
            EUSCI_A_UART_RECEIVE_INTERRUPT);
        if (RingBuf_get(&object->ringBuffer, buffer) == -1) {
            /* RX interrupts are disabled; driverlib will poll for us */
            *buffer = MAP_UART_receiveData(hwAttrs->baseAddr);
        }
        if (object->state.rxEnabled) {
            MAP_UART_enableInterrupt(hwAttrs->baseAddr,
                EUSCI_A_UART_RECEIVE_INTERRUPT);
        }

        DebugP_log2("UART:(%p) Read character 0x%x", hwAttrs->baseAddr,
            *buffer);
        count++;
        size--;

        if (object->state.readDataMode == UART_DATA_TEXT && *buffer == '\r') {
            /* Echo character if enabled. */
            if (object->state.readEcho) {
                while (!MAP_UART_getInterruptStatus(hwAttrs->baseAddr,
                    EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG));
                MAP_UART_transmitData(hwAttrs->baseAddr,  '\r');
            }
            *buffer = '\n';
        }

        /* Echo character if enabled. */
        if (object->state.readDataMode == UART_DATA_TEXT &&
                object->state.readEcho) {
            while (!MAP_UART_getInterruptStatus(hwAttrs->baseAddr,
                EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG));
            MAP_UART_transmitData(hwAttrs->baseAddr,  *buffer);
        }

        /* If read return mode is newline, finish if a newline was received. */
        if (object->state.readDataMode == UART_DATA_TEXT &&
                object->state.readReturnMode == UART_RETURN_NEWLINE &&
                *buffer == '\n') {
            return (count);
        }

        buffer++;
    }

    DebugP_log2("UART:(%p) Read polling finished, %d bytes read",
        hwAttrs->baseAddr, count);

    return (count);
}
/* EUSCI A0 UART ISR - Echoes data back to PC host */
void euscia0_isr(void)
{
    uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_MODULE);

    MAP_UART_clearInterruptFlag(EUSCI_A0_MODULE, status);

    if(status & EUSCI_A_UART_RECEIVE_INTERRUPT)
    {
        MAP_UART_transmitData(EUSCI_A0_MODULE, MAP_UART_receiveData(EUSCI_A0_MODULE));
    }

}
/*
 *  ======== readIsrTextCallback ========
 */
static bool readIsrTextCallback(UART_Handle handle)
{
    int                       readIn;
    bool                      ret = true;
    UARTMSP432_Object        *object = handle->object;
    UARTMSP432_HWAttrs const *hwAttrs = handle->hwAttrs;

    readIn = MAP_UART_receiveData(hwAttrs->baseAddr);

    if (readIn == '\r') {
        /* Echo character if enabled. */
        if (object->state.readEcho) {
            /* Wait until TX is ready */
            while (!MAP_UART_getInterruptStatus(hwAttrs->baseAddr,
                EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG)) {}
            MAP_UART_transmitData(hwAttrs->baseAddr, '\r');
        }
        readIn = '\n';
    }
    if (RingBuf_put(&object->ringBuffer, (unsigned char) readIn) == -1) {
        DebugP_log1("UART:(%p) Ring buffer full!!", hwAttrs->baseAddr);
        ret = false;
    }
    DebugP_log2("UART:(%p) buffered '0x%02x'", hwAttrs->baseAddr,
        (unsigned char) readIn);

    if (object->state.readEcho) {
        /* Wait until TX is ready */
        while (!MAP_UART_getInterruptStatus(hwAttrs->baseAddr,
            EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG)) {}
        MAP_UART_transmitData(hwAttrs->baseAddr, (unsigned char)readIn);
    }

    /*
     * Check and see if a UART_read in callback mode told use to continue
     * servicing the user buffer...
     */
    if (object->state.drainByISR) {
        readTaskCallback(handle);
    }

    return (ret);
}
/* EUSCI A0 UART ISR - Echos data back to PC host */
void euscia0_isr(void)
{
    uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_MODULE);

    MAP_UART_clearInterruptFlag(EUSCI_A0_MODULE, status);

    if(status & EUSCI_A_UART_RECEIVE_INTERRUPT)
    {
        RXData = MAP_UART_receiveData(EUSCI_A0_MODULE);

        if(RXData != TXData)              // Check value
        {
            MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);
            while(1);                       // Trap CPU
        }
        TXData++;
        MAP_Interrupt_disableSleepOnIsrExit();
    }

}
/*
 *  ======== readIsrBinaryBlocking ========
 *  Function that is called by the ISR
 */
static bool readIsrBinaryBlocking(UART_Handle handle)
{
    int                       readIn;
    UARTMSP432_Object        *object = handle->object;
    UARTMSP432_HWAttrs const *hwAttrs = handle->hwAttrs;

    readIn = MAP_UART_receiveData(hwAttrs->baseAddr);

    if (RingBuf_put(&object->ringBuffer, (unsigned char) readIn) == -1) {
        DebugP_log1("UART:(%p) Ring buffer full!!", hwAttrs->baseAddr);
        return (false);
    }
    DebugP_log2("UART:(%p) buffered '0x%02x'", hwAttrs->baseAddr,
        (unsigned char) readIn);

    if (object->state.callCallback) {
        object->state.callCallback = false;
        object->readCallback(handle, NULL, 0);
    }
    return (true);
}