//frame=START_BYTE + CMD_ID + LENGTH_BYTE + payload (LSB first)
void UartRFIntHandler()
{
	static uint8_t msgRF[20];
	static uint32_t msgRFLen=0;
	static uint32_t numBytes=0;
	uint32_t status = ROM_UARTIntStatus(UART_RF,true);
	ROM_UARTIntClear(UART_RF,status);
	while (ROM_UARTCharsAvail(UART_RF))
	{
		char temp=ROM_UARTCharGetNonBlocking(UART_RF);
		if (numBytes==0)
		{
			if (temp==START_BYTE)
			{
				msgRF[numBytes++]=temp;
			}
			continue;
		}
		msgRF[numBytes++]=temp;
		if (numBytes==3)
			msgRFLen = msgRF[2] + 3;
		if ((numBytes==msgRFLen) && (msgRFLen!=0))
		{
			processRFMsg(msgRF);
			numBytes=0;
			msgRFLen=0;
		}
	}
}
Example #2
0
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void
UARTIntHandler(void)
{
    uint32_t ui32Status;

    //
    // Get the interrrupt status.
    //
    ui32Status = ROM_UARTIntStatus(UART0_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    ROM_UARTIntClear(UART0_BASE, ui32Status);

    //
    // Loop while there are characters in the receive FIFO.
    //
    while(ROM_UARTCharsAvail(UART0_BASE))
    {
        //
        // Read the next character from the UART and write it back to the UART.
        //
        ROM_UARTCharPutNonBlocking(UART0_BASE,
                                   ROM_UARTCharGetNonBlocking(UART0_BASE));
    }
}
Example #3
0
/*
 * UART3 is used to communicate with the Optode.  Set UART3
 * to 9600 baud, 8, N, 1.  Also, set up and enable the RX FIFO interrupt
 * to receive data.
 */
void UART3Init(void)
{
	// set up UART3 to the optode
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);
	ROM_GPIOPinConfigure(GPIO_PC6_U3RX);              //set up the pins
	ROM_GPIOPinConfigure(GPIO_PC7_U3TX);
	ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);

	//9600 baud, 8, N, 1
	ROM_UARTConfigSetExpClk(UART3_BASE, ROM_SysCtlClockGet(), 9600,
			(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
					UART_CONFIG_PAR_NONE));

	// Enable the UART.
	ROM_UARTEnable(UART3_BASE);


	//RX interrupt will occur when FIFO is 1/8 full
	ROM_UARTFIFOLevelSet(UART3_BASE, UART_FIFO_TX7_8, UART_FIFO_RX1_8);

	//enable the interrupt
	ROM_IntEnable(INT_UART3);

	//flush the RX fifo before enabling the RX interrupt to get rid of residual data
	while(ROM_UARTCharsAvail(UART3_BASE))
	{
		ROM_UARTCharGetNonBlocking(UART3_BASE);
	}


	//Enable the UART peripheral interrupt...receive
	ROM_UARTIntEnable(UART3_BASE, UART_INT_RX);
}
// Receive data from the UART
void
UART4Receive(uint8_t *pui8Buffer, uint32_t ui32Count)
{
	int i = 0;
	int j = 0;
    //
    // Loop while there are more data expected.
    //
    while(ui32Count)
    {
        //
        // Read the next character from the UART and write it back to the UART.
        //
    	if (ROM_UARTCharsAvail(UART4_BASE)) {
    		pui8Buffer[i++] = ROM_UARTCharGetNonBlocking(UART4_BASE);
        	ui32Count--;
        	j = 0;
    	}

    	j++;
    	if (j > RETRY_NUM) {
    		break;
    	}
    }
}
Example #5
0
File: uart.c Project: daniel-k/RIOT
/**
 * The UART interrupt handler.
 */
void isr_uart0(void)
{
    unsigned long ulStatus;

    ulStatus = ROM_UARTIntStatus(UART0_BASE, true);
    ROM_UARTIntClear(UART0_BASE, ulStatus);

    /* Are we interrupted due to TX done */
    if(ulStatus & UART_INT_TX)
    {
        if (config[UART_0].tx_cb(config[UART_0].arg) == 0){
            UART0_IM_R &= ~UART_IM_TXIM;
        }
    }

    /* Are we interrupted due to a recieved character */
    if(ulStatus & (UART_INT_RX | UART_INT_RT))
    {
        while(ROM_UARTCharsAvail(UART0_BASE))
        {
            char cChar;
            long lChar;
            lChar = ROM_UARTCharGetNonBlocking(UART0_BASE);
            cChar = (unsigned char)(lChar & 0xFF);
            config[UART_0].rx_cb(config[UART_0].arg, cChar);
        }
    }
    if (sched_context_switch_request) {
        thread_yield();
    }
}
Example #6
0
void UART1IntHandler(void)
{
    uint32_t 	ui32Status;
    //
    // Get the interrrupt status.
    //
    ui32Status = ROM_UARTIntStatus(UART1_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    ROM_UARTIntClear(UART1_BASE, ui32Status);
    PRINTF("INT:\n");
    //
    // Loop while there are characters in the receive FIFO.
    //
    while(ROM_UARTCharsAvail(UART1_BASE)) {
        //
        // Read the next character from the UART and write it back to the UART.
        //
        uart1buffer[RX_PTR1]=ROM_UARTCharGetNonBlocking(UART1_BASE);
        /// echo
        ROM_UARTCharPutNonBlocking(UART0_BASE, uart1buffer[RX_PTR1]);
        RX_PTR1++;
        RX_PTR1 &= DIM_READ_BUFF - 1;
        //UARTCharPutNonBlocking(UART1_BASE,
        //		dato);
    }
}
//*****************************************************************************
//
// Read as many characters from the UART FIFO as possible and move them into
// the CDC transmit buffer.
//
// \return Returns UART error flags read during data reception.
//
//*****************************************************************************
static long
ReadUARTData(void)
{
    long lChar, lErrors;
    unsigned char ucChar;
    unsigned long ulSpace;

    //
    // Clear the error indicator.
    //
    lErrors = 0;

    //
    // How much space is available in the buffer?
    //
    ulSpace = USBBufferSpaceAvailable(&g_sTxBuffer);

    //
    // Read data from the UART FIFO until there is none left or there is no
    // more space in the receive buffer.
    //
    while(ulSpace && ROM_UARTCharsAvail(UART0_BASE))
    {
        //
        // Read a character from the UART FIFO into the ring buffer if no
        // errors are reported.
        //
        lChar = ROM_UARTCharGetNonBlocking(UART0_BASE);

        //
        // If the character did not contain any error notifications,
        // copy it to the output buffer.
        //
        if(!(lChar & ~0xFF))
        {
            ucChar = (unsigned char)(lChar & 0xFF);
            USBBufferWrite(&g_sTxBuffer, &ucChar, 1);

            //
            // Decrement the number of bytes the buffer can accept.
            //
            ulSpace--;
        }
        else
        {
            //
            // Update the error accumulator.
            //
            lErrors |= lChar;
        }
    }

    //
    // Pass back the accumulated error indicators.
    //
    return(lErrors);
}
Example #8
0
void
UARTIntHandler(void) //This is triggered when the pc sends data - it is the virtual serial port interrupt.
{
    ROM_UARTIntClear(UART0_BASE, ROM_UARTIntStatus(UART0_BASE, true));

    while(ROM_UARTCharsAvail(UART0_BASE))
    {
        ROM_UARTCharPutNonBlocking(UART3_BASE,ROM_UARTCharGetNonBlocking(UART0_BASE));
    }
}
void HardwareSerial::UARTIntHandler(void){
    unsigned long ulInts;
    long lChar;
    // Get and clear the current interrupt source(s)
    //
    ulInts = ROM_UARTIntStatus(UART_BASE, true);
    ROM_UARTIntClear(UART_BASE, ulInts);

    // Are we being interrupted because the TX FIFO has space available?
    //
    if(ulInts & UART_INT_TX)
    {
        //
        // Move as many bytes as we can into the transmit FIFO.
        //
        primeTransmit(UART_BASE);

        //
        // If the output buffer is empty, turn off the transmit interrupt.
        //
        if(TX_BUFFER_EMPTY)
        {
            ROM_UARTIntDisable(UART_BASE, UART_INT_TX);
        }
    }
    if(ulInts & (UART_INT_RX | UART_INT_RT))
    {
        while(ROM_UARTCharsAvail(UART_BASE))
            {

            //
            // Read a character
            //
            lChar = ROM_UARTCharGetNonBlocking(UART_BASE);
            //
            // If there is space in the receive buffer, put the character
            // there, otherwise throw it away.
            //
            uint8_t volatile full = RX_BUFFER_FULL;
            if(full) break;

            rxBuffer[rxWriteIndex] =
                (unsigned char)(lChar & 0xFF);
            rxWriteIndex = ((rxWriteIndex) + 1) % rxBufferSize;

            //
            // If we wrote anything to the transmit buffer, make sure it actually
            // gets transmitted.
            //
        }
        primeTransmit(UART_BASE);
        ROM_UARTIntEnable(UART_BASE, UART_INT_TX);
    }
}
Example #10
0
void UARTIntHandler(void){
    uint32_t ui32Status;
    ui32Status = ROM_UARTIntStatus(UART0_BASE, true);
    ROM_UARTIntClear(UART0_BASE, ui32Status);
    while(ROM_UARTCharsAvail(UART0_BASE)){
        ROM_UARTCharPutNonBlocking(UART0_BASE, ROM_UARTCharGetNonBlocking(UART0_BASE));
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
        SysCtlDelay(SysCtlClockGet() / (1000 * 3));
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
    }
}
Example #11
0
/*---------------------------------------------------------------------------*/
void UART0IntHandler(void)
{
	unsigned long ulStatus;

	ulStatus = ROM_UARTIntStatus(UART0_BASE, true);
	ROM_UARTIntClear(UART0_BASE, ulStatus);

	while(ROM_UARTCharsAvail(UART0_BASE))
	{
		uart0_input_handler(ROM_UARTCharGetNonBlocking(UART0_BASE));
	}
}
Example #12
0
void
UART3IntHandler(void) //This is triggered when the UART3 gets data - PC6/7
{
    unsigned long ulStatus;
    char character;

    ulStatus = ROM_UARTIntStatus(UART3_BASE, true);

    ROM_UARTIntClear(UART3_BASE, ulStatus);

    while(ROM_UARTCharsAvail(UART3_BASE))
    {
        ROM_UARTCharPutNonBlocking(UART0_BASE,ROM_UARTCharGetNonBlocking(UART3_BASE));
    }
}
Example #13
0
/*
 * This is the UART3RX interrupt handler for the Optode
 * The handler simply writes characters out to the desktop.
 */
void UART3IntHandler(void)
{
	unsigned long ulStatus;

	// Get the interrupt status.
	ulStatus = ROM_UARTIntStatus(UART3_BASE, true);

	// Clear the asserted interrupts.
	ROM_UARTIntClear(UART3_BASE, ulStatus);


	// Loop while there are characters in the receive FIFO
	while(ROM_UARTCharsAvail(UART3_BASE))
	{
		// Read the next character from the UART and write it to desktop.
		ROM_UARTCharPutNonBlocking(UART1_BASE, ROM_UARTCharGetNonBlocking(UART3_BASE));
	}
}
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void
UARTIntHandler(void)
{
    uint32_t ui32Status;

    //
    // Get the interrrupt status.
    //
    ui32Status = ROM_UARTIntStatus(UART0_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    ROM_UARTIntClear(UART0_BASE, ui32Status);

    //
    // Loop while there are characters in the receive FIFO.
    //
    while(ROM_UARTCharsAvail(UART0_BASE))
    {
        //
        // Read the next character from the UART and write it back to the UART.
        //
        ROM_UARTCharPutNonBlocking(UART0_BASE,
                                   ROM_UARTCharGetNonBlocking(UART0_BASE));

        //
        // Blink the LED to show a character transfer is occuring.
        //
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

        //
        // Delay for 1 millisecond.  Each SysCtlDelay is about 3 clocks.
        //
        SysCtlDelay(SysCtlClockGet() / (1000 * 3));

        //
        // Turn off the LED
        //
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);

    }
}
void UartGPSIntHandler()
{
	uint32_t status = ROM_UARTIntStatus(UART_GPS,true);
	static uint32_t numBytes=0;
	ROM_UARTIntClear(UART_GPS,status);
	while (ROM_UARTCharsAvail(UART_GPS))
	{
		if ((MsgBuf[numBytes++]=ROM_UARTCharGetNonBlocking(UART_GPS))=='\n')
		{
			HandleGPSMsg(MsgBuf);
			flagNewGPSMsg=true;
			msgLen=numBytes;
			numBytes = 0;
		}
		if (numBytes==MAX_GPS_MSG_BYTE)
			numBytes=0;

	}
}
Example #16
0
/**
 * The UART interrupt handler.
 */
void isr_uart0(void)
{
    unsigned long ulStatus;

    ulStatus = ROM_UARTIntStatus(UART0_BASE, true);
    ROM_UARTIntClear(UART0_BASE, ulStatus);

    /* Are we interrupted due to a recieved character */
    if(ulStatus & (UART_INT_RX | UART_INT_RT))
    {
        while(ROM_UARTCharsAvail(UART0_BASE))
        {
            long lchar = ROM_UARTCharGetNonBlocking(UART0_BASE);
            config[UART_0].rx_cb(config[UART_0].arg, (uint8_t)lchar);
        }
    }
    if (sched_context_switch_request) {
        thread_yield();
    }
}
Example #17
0
void
UARTIntHandler(void)
{
    uint32_t ui32Status;

    ui32Status = ROM_UARTIntStatus(UART7_BASE, true);
    ROM_UARTIntClear(UART7_BASE, ui32Status);

    while(ROM_UARTCharsAvail(UART7_BASE))
    {
        // ROM_UARTCharPutNonBlocking(UART7_BASE,ROM_UARTCharGetNonBlocking(UART7_BASE));

		UARTLed(LED1);

		message[ptr] = ROM_UARTCharGetNonBlocking(UART7_BASE);

		if(message[ptr] == '\n')
		{
			  if(ptr == 32) /* hard coded message size ;-) */
			  {
				/* answer first, then display */
				transform_message(message);
				for(uint8_t i = 0; i < ptr; ++i)
				{
				  UARTSend(&message[i],1);
				}
				UARTSend((const uint8_t*) '\n',1);
			  }
			  ptr = 0;
		}
		else
		{
			  ++ptr;
			  
			  if(ptr >= 64)
			  {
				ptr = 0;
			  }
		}
    }
}
Example #18
0
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void UARTIntHandler(void)
{
    uint32_t ui32Status;
    char data;

    //
    // Get the interrrupt status.
    //
    ui32Status = ROM_UARTIntStatus(UART0_BASE, true);

	UARTIntClear(UART0_BASE, ui32Status);

    if ((ui32Status&UART_INT_RX) == UART_INT_RX)
    {
		//
		// Loop while there are characters in the receive FIFO.
		//
		while(ROM_UARTCharsAvail(UART0_BASE))
		{
			//
			// Read the next character from the UART and write it back to the UART.
			//
			data = (char)ROM_UARTCharGetNonBlocking(UART0_BASE);
			OSQueuePost(qUART, data);
		}
    }

    if ((ui32Status&UART_INT_TX) == UART_INT_TX)
    {
    	ROM_UARTIntDisable(UART0_BASE, UART_INT_TX);

    	// Call the keyboard analysis task
        OSSemPost(sUART);
    }

    // ************************
    // Interrupt Exit
    // ************************
    OS_INT_EXIT_EXT();
    // ************************
}
Example #19
0
//*****************************************************************************
// UART interrupt handler.
//*****************************************************************************
void UART0_IntHandler(void)
{
    uint32_t status = ROM_UARTIntStatus(UART0_BASE, true);
    ROM_UARTIntClear(UART0_BASE, status);
    
    // drain rx FIFO
    while(ROM_UARTCharsAvail(UART0_BASE))
    {
        char ch = ROM_UARTCharGetNonBlocking(UART0_BASE);
        
        if(inputRB.nbytes < DBG_IN_BUFFER_SIZE)
        {
            RB_Push(dbg_inputBuffer, inputRB, ch, DBG_IN_BUFFER_SIZE);
            if(ch == '\r')
                ++newlines;
        }
        else
        {
            // Attempt to report overflow and clear buffer
            // Must do this to avoid condition where buffer is full and code
            // is waiting for a newline that can not fit in the buffer.
            dbg_putstr_nb("\rRXOVF\r\n");
            RB_Clear(inputRB);
            newlines = 0;
        }
    }
    
    // feed tx FIFO
    // Echo received characters
    while(ROM_UARTSpaceAvail(UART0_BASE) && echoPtr != inputRB.wp)
    {
        ROM_UARTCharPutNonBlocking(UART0_BASE, dbg_inputBuffer[echoPtr]);
        echoPtr = (echoPtr + 1) % DBG_IN_BUFFER_SIZE;
    }
    // Write pending characters
    while(ROM_UARTSpaceAvail(UART0_BASE) && outputRB.nbytes > 0)
    {
        ROM_UARTCharPutNonBlocking(UART0_BASE, RB_Front(dbg_outputBuffer, outputRB));
        RB_Pop(outputRB, DBG_OUT_BUFFER_SIZE);
    }
} // UART0_IntHandler()
Example #20
0
//*****************************************************************************
//
// The UART1 interrupt handler.
// Get response from XBee (UART1), print to terminal (UART0)
//
//*****************************************************************************
void
UART1IntHandler(void)
{
	unsigned char x;
    uint32_t ui32Status;

    //
    // Get the interrrupt status.
    //
    ui32Status = ROM_UARTIntStatus(UART1_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    ROM_UARTIntClear(UART1_BASE, ui32Status);

	  UARTprintf("Response:'");
    //
    // Loop while there are characters in the receive FIFO.
    //
    while(ROM_UARTCharsAvail(UART1_BASE))
    {
        //
        // Read the next character from the UART and write it back to the UART.
        // if special character print out the integer for it
			  //
				x=ROM_UARTCharGetNonBlocking(UART1_BASE);
				if(x<' ' | x>'~')
				{
					UARTprintf("/%d",(int)x);
					//ROM_UARTCharPutNonBlocking(UART0_BASE,x);
				}
				else
				{
					ROM_UARTCharPutNonBlocking(UART0_BASE,x);
				}
					
    }
		UARTprintf("'\n");
}
Example #21
0
void
UARTBridge(uint32_t SOURCE, uint32_t DESTINATION)
{
	//
	// Loop while there are characters in the receive FIFO.
	//
	while(ROM_UARTCharsAvail(SOURCE))
	{
		//
		// Read the next character from the UART and write it back to the UART.
		//
		ROM_UARTCharPutNonBlocking(DESTINATION,
				ROM_UARTCharGetNonBlocking(SOURCE));
	}
	//
	// Blink the LED to show a character transfer is occuring.
	//
	if (SOURCE == UART0_BASE) 
		GPIOPinWrite(GPIO_PORTF_BASE, LED_BLUE, LED_BLUE);
	else 
		GPIOPinWrite(GPIO_PORTF_BASE, LED_GREEN, LED_GREEN);
	GPIOPinWrite(GPIO_PORTF_BASE, LED_BLUE|LED_GREEN, 0);
}
Example #22
0
static inline void irq_handler(uart_t uartnum, unsigned long ulBase, unsigned long ulRxInt)
{
    unsigned long ulStatus;

    ulStatus = ROM_UARTIntStatus(ulBase, true);
    ROM_UARTIntClear(ulBase, ulStatus);

    /* Are we interrupted due to a recieved character */
    if(ulStatus & (UART_INT_RX | UART_INT_RT))
    {
        while(ROM_UARTCharsAvail(ulBase))
        {
            char cChar;
            long lChar;
            lChar = ROM_UARTCharGetNonBlocking(ulBase);
            cChar = (unsigned char)(lChar & 0xFF);
            config[uartnum].rx_cb(config[uartnum].arg, cChar);
        }
    }
    if (sched_context_switch_request) {
        thread_yield();
    }
}
Example #23
0
void UpstreamUARTIntHandler(void) {
    uint32_t ui32Status;
    uint8_t data;
    static luxframe_t* lframe;
    static uint8_t lbuffer[LUX_MAX_FRAME_SIZE + 8];

    // Get the interrrupt status.
    ui32Status = ROM_UARTIntStatus(UART1_BASE, true);
    // Clear the asserted interrupts.
    ROM_UARTIntClear(UART1_BASE, ui32Status);
    // Loop while there are characters in the receive FIFO.
    while(ROM_UARTCharsAvail(UART1_BASE)){
        data = ROM_UARTCharGetNonBlocking(UART1_BASE);
        // Read the next character from the UART and write it back to the UART.
        //ROM_UARTCharPutNonBlocking(UART1_BASE, data);
        // Update lux framing
        lframe = lux_usart_poll(data);
        if(lframe){
            lux_calculate_crc(lframe);
            lux_serialize(lframe, lbuffer);
            //UARTSend(UART0_BASE, lbuffer, lframe->length + 6);
            //UARTSend(UART1_BASE, lbuffer, lframe->length + 6);
            //UARTSend(UART2_BASE, lbuffer, lframe->length + 6);
            //UARTSend(UART3_BASE, lbuffer, lframe->length + 6);
            //UARTSend(UART4_BASE, lbuffer, lframe->length + 6);
            UARTSend(UART5_BASE, lbuffer, lframe->length + 6);
            //UARTSend(UART6_BASE, lbuffer, lframe->length + 6);
            //UARTSend(UART7_BASE, lbuffer, lframe->length + 6);
        }
        // Blink the LED to show a character transfer is occuring.
        GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, GPIO_PIN_6);
        // Delay for 1 millisecond.  Each SysCtlDelay is about 3 clocks.
        SysCtlDelay(SysCtlClockGet() / (1000 * 3));
        // Turn off the LED
        GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, 0);
    }
}
Example #24
0
void UART3IntHandler(void)
{
	    ROM_UARTIntClear(UART3_BASE, ROM_UARTIntStatus(UART3_BASE, true));

	    while(ROM_UARTCharsAvail(UART3_BASE))
	    {
	    	char character;
	    	character = ROM_UARTCharGetNonBlocking(UART3_BASE);

			switch ( nmea_state )               // evaluate expression
			{
				case ( 1 ):                    // wait for 'G'
					if ( character == 0x47) nmea_state++;
					break;
				case ( 2 ):                    // wait for 'G'
					if ( character == 0x47)
						nmea_state++;
					else
						nmea_state=1;
					break;
				case ( 3 ):                    // wait for 'A'
					if ( character == 0x41)
						nmea_state++;
					else
						nmea_state=1;
					break;
				case ( 4 ):                    // wait for ',' //First comma
					if ( character == 0x2c) nmea_state++;
					break;
				case ( 5 ):                    // wait for ',' //comma after time
					if ( character == 0x2c) nmea_state++;
					break;
				case ( 6 ):
					if ( character == 0x2c) nmea_state=1; //don't have a fix
					else {nmea_state++; latitude[0] = character;}
					break;
				case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18:
					if (character == 0x2c) {nmea_state = 19;}
					else {latitude[nmea_state - 6] = character; nmea_state++;}
					break;
				case ( 19 ):
					if (character == 'S') {neglat=true;}
					nmea_state++;
					break;
				case ( 20 ):           //after latitude n/s
					if ( character == 0x2c) nmea_state++;
					break;
				case ( 21 ):
					nmea_state++;
					longitude[0] = character;
					break;
				case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31: case 32: case 33:
					if (character == 0x2c) {nmea_state = 34;}
					else {longitude[nmea_state - 21] = character; nmea_state++;}
					break;
				case 34:
					if (character == 'W') {neglong=true;}
					nmea_state++;
					break;
				case 35:
					haveFix= true;
					nmea_state=1;
					break;
				default:
					nmea_state = 1;  // we'll never and up here, but in case of a brownout make sure we start at the beginning
					break;
			}
		}
}
Example #25
0
//*****************************************************************************
//
// Read as many characters from the UART FIFO as we can and move them into
// the CDC transmit buffer.
//
// \return Returns UART error flags read during data reception.
//
//*****************************************************************************
static int32_t
ReadUARTData(void)
{
    int32_t i32Char, i32Errors;
    uint8_t ui8Char;
    uint32_t ui32Space;

    //
    // Clear our error indicator.
    //
    i32Errors = 0;

    //
    // How much space do we have in the buffer?
    //
    ui32Space = USBBufferSpaceAvailable((tUSBBuffer *)&g_sTxBuffer);

    //
    // Read data from the UART FIFO until there is none left or we run
    // out of space in our receive buffer.
    //
    while(ui32Space && ROM_UARTCharsAvail(USB_UART_BASE))
    {
        //
        // Read a character from the UART FIFO into the ring buffer if no
        // errors are reported.
        //
        i32Char = ROM_UARTCharGetNonBlocking(USB_UART_BASE);

        //
        // If the character did not contain any error notifications,
        // copy it to the output buffer.
        //
        if(!(i32Char & ~0xFF))
        {
            ui8Char = (uint8_t)(i32Char & 0xFF);
            USBBufferWrite((tUSBBuffer *)&g_sTxBuffer,
                           (uint8_t *)&ui8Char, 1);

            //
            // Decrement the number of bytes we know the buffer can accept.
            //
            ui32Space--;
        }
        else
        {
#ifdef DEBUG
            //
            // Increment our receive error counter.
            //
            g_ui32UARTRxErrors++;
#endif
            //
            // Update our error accumulator.
            //
            i32Errors |= i32Char;
        }

        //
        // Update our count of bytes received via the UART.
        //
        g_ui32UARTRxCount++;
    }

    //
    // Pass back the accumulated error indicators.
    //
    return(i32Errors);
}
Example #26
0
// main routine
int main(void) {

    // enable lazy stacking
    ROM_FPUEnable();
    ROM_FPULazyStackingEnable();

    // run from crystal, 80 MHz
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    // enable peripherals
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    // set UART pins
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    // init PORTB
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    GPIO_PORTB_DIR_R = 0x00;
    GPIO_PORTB_DEN_R = 0xff;

    // configure uart
    ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    // Enable interrupts to the processor. - not sure if this is needed...
    ROM_IntMasterEnable();

    // main loop
    while (1) {

        if (ROM_UARTCharsAvail(UART0_BASE)) {
            unsigned char cmd;
            cmd = ROM_UARTCharGetNonBlocking(UART0_BASE);

            switch (cmd) {
                case SUMP_RESET:
                    break;
                case SUMP_ARM:
                    doticksampling();
                    break;
                case SUMP_QUERY:
                    uart_puts("1ALS");
                    break;
                case SUMP_GET_METADATA:

                    // device name
                    uart_putch(0x01);
                    uart_puts(VERSION);
                    uart_putch(0x00);

                    // amount of sample memory available (bytes) 
                    sump_sendmeta_uint32(0x21, BUFFERSIZE);

                    // maximum sample rate (hz)
                    sump_sendmeta_uint32(0x23, MAX_SAMPLERATE);

                    // number of usable probes (short) 
                    sump_sendmeta_uint8(0x40, 0x08);

                    // protocol version (short)
                    sump_sendmeta_uint8(0x41, 0x02);

                    // end of meta data
                    uart_putch(0x00);

                    break;
                
                case SUMP_SET_DIVIDER: {
                  /*
                  Set Divider (80h)
                  When x is written, the sampling frequency is set to f = clock / (x + 1)
                  */
                  unsigned long clock = 100000000; //no idea where this comes from...
                  //these three bytes are our clock divider - lsb first
                  unsigned char b0 = ROM_UARTCharGet(UART0_BASE);
                  unsigned char b1 = ROM_UARTCharGet(UART0_BASE);
                  unsigned char b2 = ROM_UARTCharGet(UART0_BASE);
                  ROM_UARTCharGet(UART0_BASE); //eat last byte

                  unsigned long rate = b0 | (b1 << 8) | (b2 << 16);
                  rate = clock / (rate+1);

                  ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / rate);
                  break;
                }

                // long commands.. consume bytes from uart
                case 0xC0:
                case 0xC4:
                case 0xC8:
                case 0xCC:
                case 0xC1:
                case 0xC5:
                case 0xC9:
                case 0xCD:
                case 0xC2:
                case 0xC6:
                case 0xCA:
                case 0xCE:
                case 0x81:
                case 0x82:
                    ROM_UARTCharGet(UART0_BASE);
                    ROM_UARTCharGet(UART0_BASE);
                    ROM_UARTCharGet(UART0_BASE);
                    ROM_UARTCharGet(UART0_BASE);
                    break;
            }

        }

    }
}
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void
UARTIntHandler(void)
{
    uint32_t ui32Status;



    //
    // Get the interrrupt status.
    //
    ui32Status = ROM_UARTIntStatus(UART0_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    ROM_UARTIntClear(UART0_BASE, ui32Status);

    //
    // Loop while there are characters in the receive FIFO.
    //
    while(ROM_UARTCharsAvail(UART0_BASE))
    {
        //
        // Delay for 1 millisecond.  Each SysCtlDelay is about 3 clocks.
        //
        SysCtlDelay(g_ui32SysClock / (1000 * 3));



    	buffer[location] = ROM_UARTCharGetNonBlocking(UART0_BASE); //Place next character into the buffer array

    	if (location == 0 && (buffer[0] == 27 || buffer[0] == '\r')) //Check for the <ESC> or <ENTER> character
    	{
    		UARTPrompt(); //Prompt the user again
    	} else {
        	location = location + 1; //Increase the array index
        	ROM_UARTCharPut(UART0_BASE, buffer[location-1]); //Echo last character on screen
        	if (buffer[location - 1] == 27 || buffer[location - 1] == '\r') //Check for the <ESC> or <ENTER> character
        	{
        		buffer[location - 1] = '\0'; //Replace last character with a null char

        		UARTSend("\033[2J\033[12;30H", 12); //Clear screen and move cursor to middle-ish
        		UARTSend(buffer, location);         //Use UARTSend() to print contents of buffer
        		location = 0;                       //Reset array index
        	}
    	}

        //
        // Blink the LED to show a character transfer is occuring.
        //
        GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0);

        //
        // Delay for 1 millisecond.  Each SysCtlDelay is about 3 clocks.
        //
        SysCtlDelay(g_ui32SysClock / (1000 * 3));

        //
        // Turn off the LED
        //
        GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0);
    }

}
Example #28
0
//*****************************************************************************
//
// Set up the system, initialize the UART, Graphics, and CAN. Then poll the
// UART for data. If there is any data send it, if there is any thing received
// print it out to the UART. If there are errors call the error handling
// function.
//
//*****************************************************************************
int
main(void)
{
    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPULazyStackingEnable();

    //
    // Set the clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    //
    // Initialize the UART
    //
    ConfigureUART();

    //
    // Initialize the graphical display
    //
    InitGraphics();

    //
    // Initialize CAN0
    //
    InitCAN0();

    //
    // Print welcome message
    //
    UARTprintf("\nCAN Example App\n");
    UARTprintf("Type something to see it show up on the other terminal: \n\n");

    //
    // Poll UART for data, transmit across CAN when something is entered
    //
    while(1)
    {
        //
        // If the flag is set, that means that the RX interrupt occurred and
        // there is a message ready to be read from the CAN
        //
        if(g_bRXFlag)
        {
            //
            // Reuse the same message object that was used earlier to configure
            // the CAN for receiving messages.  A buffer for storing the
            // received data must also be provided, so set the buffer pointer
            // within the message object.
            //
            g_sCAN0RxMessage.pui8MsgData = (uint8_t *) &g_ui8RXMsgData;

            //
            // Read the message from the CAN.  Message object RXOBJECT is used
            // (which is not the same thing as CAN ID).  The interrupt clearing
            // flag is not set because this interrupt was already cleared in
            // the interrupt handler.
            //
            CANMessageGet(CAN0_BASE, RXOBJECT, &g_sCAN0RxMessage, 0);

            //
            // Clear the pending message flag so that the interrupt handler can
            // set it again when the next message arrives.
            //
            g_bRXFlag = 0;

            //
            // Check to see if there is an indication that some messages were
            // lost.
            //
            if(g_sCAN0RxMessage.ui32Flags & MSG_OBJ_DATA_LOST)
            {
                UARTprintf("\nCAN message loss detected\n");
            }

            //
            // Print the received character to the UART terminal
            //
            UARTprintf("%c", g_ui8RXMsgData);

            //
            // Print the received character to the display, 
            // clear line with spaces
            //
            GrStringDrawCentered(&g_sContext, "RX Data", -1,
                                 GrContextDpyWidthGet(&g_sContext) / 2,
                                 SCREENLINE2, 0);
            GrStringDrawCentered(&g_sContext, (const char *) &g_ui8RXMsgData,
                                 1, GrContextDpyWidthGet(&g_sContext) / 2,
                                 SCREENLINE3, true);
            GrFlush(&g_sContext);
        }
        else
        {
            //
            // Error Handling
            //
            if(g_ui32ErrFlag != 0)
            {
                CANErrorHandler();
            }

            //
            // See if there is something new to transmit
            //
            while(ROM_UARTCharsAvail(UART0_BASE))
            {
                //
                // Read the next character from the UART terminal
                //
                g_ui8TXMsgData = ROM_UARTCharGetNonBlocking(UART0_BASE);

                //
                // Write the character to the display
                // clear line with spaces
                //
                GrStringDrawCentered(&g_sContext, "TX Data", -1,
                                     GrContextDpyWidthGet(&g_sContext) / 2,
                                     SCREENLINE4, true);
                GrStringDrawCentered(&g_sContext,
                                     (const char *)&g_ui8TXMsgData, 1,
                                     GrContextDpyWidthGet(&g_sContext) / 2,
                                     SCREENLINE5, true);
                GrFlush(&g_sContext);

                //
                // Send the CAN message using object number TXOBJECT (not the
                // same thing as CAN ID, which is also TXOBJECT in this
                // example).  This function will cause the message to be
                // transmitted right away.
                //
                CANMessageSet(CAN0_BASE, TXOBJECT, &g_sCAN0TxMessage,
                              MSG_OBJ_TYPE_TX);
            }
        }
    }
}