Ejemplo n.º 1
0
Archivo: uart.c Proyecto: MatKub/RIOT
void UART_2_ISR(void)
{
    /* Check for RX data valid interrupt */
    if(UART_2_DEV->STATUS & LEUART_STATUS_RXDATAV) {
        /* Copy data into RX Buffer */
        uint8_t rxData = LEUART_Rx(UART_2_DEV);

        irq_read(UART_2, rxData);
    }
    /* Check TX buffer level status */
    if(UART_2_DEV->IF & LEUART_IF_TXBL & UART_2_DEV->IEN) {
#if UART_2_ENABLE_BUF
        int data = ringbuffer_get_one(&rb_uart2);
        if(-1 != data) {
            /* Avoid deadlock if modifying the same register twice when freeze mode is */
            /* activated. */
            if(!(UART_2_DEV->FREEZE & LEUART_FREEZE_REGFREEZE)) {
                /* Wait for any pending previous write operation to have been completed */
                /* in low frequency domain */
                while(UART_2_DEV->SYNCBUSY & LEUART_SYNCBUSY_TXDATA)
                    ;;
            }
            /* Write data to TX register */
            UART_2_DEV->TXDATA = (uint32_t)data;
        } else {
            LEUART_IntDisable(UART_2_DEV, LEUART_IF_TXBL);
        }
#endif
    }

    if(sched_context_switch_request) {
        thread_yield();
    }
}
/*
 *Function name: LEUART0_IRQHandler
 *Description : Interrupt Service Routine for LEUART0.
 */
void LEUART0_IRQHandler(void)
{
	leuartif = LEUART_IntGet(LEUART0); 	// Store the interrupt flag

	LEUART_IntClear(LEUART0, leuartif); //Clear interrupts

	if (leuartif & LEUART_IF_SIGF)
	{
		int temp = 0, i = 0;
		char tempChar[7];						// To store the Value of Temperature in char to transmit
		char temp_string[TX_bufferSize];	// Concatenated string for Message and Temperature, this will be transfered
		char copyCmp[sizeof(commandString)/sizeof(char)];							// string to store the Received string from Buffer to compare

		// Stop the LEUART reception and DMA Transfers
		for (i = 0; i < (strlen(commandString)); i++)		// Run loop till the return message (RetTemp!) length and copy RX buffer to copyCmp for comparing

		{
			copyCmp[i] = RX_Buffer[i];
		}

		copyCmp[8]='\0';

    	/* To extract the digits of the temperature variable and put in tempChar. A basic digit extraction algorithm is used and then each digit is passed one by one. */
		if (!strcmp(commandString,copyCmp)) 			// If valid Command is Received ie RetTemp!
		{
			temp = temperature*10;
			tempChar[0] = (temp/100)+48;
			temp = temp%100;
			tempChar[1] = (temp/10)+48;
			temp  = temp%10;
			tempChar[2] = '.';
			tempChar[3] = (temp)+48;
			tempChar[4] = 'C';
			tempChar[5] = '\r';
			tempChar[6] = '\n';

			strcpy(temp_string,returnMsg);					//Copy the returnMsg message in the temporary string
			strcat(temp_string,tempChar);					// Concatenate with tempChar to get the final message to be transfered

			// Enable DMA wake-up from LEUART0 TX
			LEUART0->CTRL = LEUART_CTRL_TXDMAWU;				// Enable DMA wake up for LEUART TX in EM2
			// Activate DMA for LEUART TX transfers
			DMA_ActivateBasic(DMA_CHANNEL_TX, true, false, (void *)&(LEUART0->TXDATA), (void *)temp_string, strlen(temp_string)- 1);	// -1 for the Null character which we wont transmit
		}
		else
		{
			LEUART0->CTRL = LEUART_CTRL_TXDMAWU;				// Enable DMA wake up for LEUART0 TX in EM2
			// Activate DMA for LEUART TX transfers
			DMA_ActivateBasic(DMA_CHANNEL_TX, true, false, (void *)&(LEUART0->TXDATA), (void *)errorMsg, strlen(errorMsg)-2);	// -1 for the Null character which we wont transmit
		}
		LEUART_IntEnable(LEUART0, LEUART_IF_RXDATAV); //Enable RXDATA Interrupt to check for received characters
		DMA_ActivateBasic(DMA_CHANNEL_RX, true, false, NULL, NULL, LEUART0_BUFFER-1);
	}
	else if (leuartif & LEUART_IF_RXDATAV)
	{
		LEUART_IntDisable(LEUART0, LEUART_IF_RXDATAV);	// Disable after receiving
	}

}