Exemplo n.º 1
0
/***********************************************************************************************************************
* Function Name: r_tau0_channel3_interrupt
* Description  : This function is INTTM03 interrupt service routine.
* Arguments    : None
* Return Value : None
***********************************************************************************************************************/
__interrupt static void r_tau0_channel3_interrupt(void)
{
	static uint8_t start = 1;	/* changed to 0 after first cycle */
	static uint8_t isReceiving = 0;	/* have we received a partial packet */
	int i;				/* index for iterating through buffere elements */
	long packetStemIn;		/* first 4 bytes of packet received */
	
    /* Start user code. Do not edit comment generated here */
    	/* if this is the first cycle, start uart receive */
    	if (start == 1)
	{
		R_UART2_Receive(bufferIn, 5); 
		start = 0;
	}
    
	/* if timeout timer is running... */
	if (isReceiving == 1)
	{
		/* if we get our full packet, stop timer */
		if (g_uart2_rx_count == 5)
			isReceiving = 0;
		/* if a ms passes since countdown timer started, clear buffer */
		else 
		{
			R_UART2_Receive(bufferIn, 5);
			isReceiving = 0;
		}
	}
	
	/* if we just got our first byte(s) start timeout timer */
	else if (g_uart2_rx_count > 0 && g_uart2_rx_count < 5)
		isReceiving = 1;

	    
	/* if we just received a full packet... */
	if (g_uart2_rx_count == 5)
	{
		packetStemIn = (((long)bufferIn[0]) << 24) +
		(((long)bufferIn[1]) << 16) +
		(((long)bufferIn[2]) << 8) +
		((long) bufferIn[3]);
		
		/* if crc byte is correct, make master packet buffer packet */
		if ((long)bufferIn[4] == crc(packetStemIn))
		{
			for (i = 0; i<5; i++)
				masterPacket[i] = bufferIn[i];
			countLast = count;
			firstCall = 1;
		}
		
		/* clear buffer for future packets */
		R_UART2_Receive(bufferIn, 5);	
	}	
	
	/* get current angle and process current master packet */
	count = TRG;
	packet_process();
    /* End user code. Do not edit comment generated here */
}
Exemplo n.º 2
0
/***********************************************************************************************************************
* Function Name: main
* Description  : This function implements main function.
* Arguments    : None
* Return Value : None
***********************************************************************************************************************/
void main(void)
{
    R_MAIN_UserInit();
    /* Start user code. Do not edit comment generated here */

    int transmit_count = 0;
	R_UART2_Create();
	R_UART2_Start();
	uart2Status = R_UART2_Receive(&uart2RxBuf[0],1);	// Prime UART2 Rx

	R_TAU0_Create();
	R_TAU0_Channel0_Start();

	R_PORT_Create();

	R_ADC_Create();

	while (1U)
	{
		if(oneSec)
		{
			if(transmit)
				uart2Status = R_UART2_Send(uart2TxBuf, 1);

			counter++;
			oneSec = !oneSec;
		}

		if(uart2RxFlag)
		{
			uart2RxFlag = 0U;

			if(uart2RxBuf[0] == 'b')
			{
				uart2TxBuf[0] = counter;
				transmit_count = convertToNum(uart2TxBuf); //convert the ASCII symbols to integers instead.
				uart2Status = R_UART2_Send(uart2TxBuf, transmit_count);
			}
			else
			if(uart2RxBuf[0] == 'l')
				P7_bit.no7 = !P7_bit.no7;
			else
			if(uart2RxBuf[0] == 'a')
			{
				uint8_t adcvalue = 0;
				R_ADC_Start();
				while(!adc_done_flag); //wait for interrupt
				adc_done_flag = 0;
				R_ADC_Get_Result_8bit(&adcvalue);
				uart2TxBuf[0] = adcvalue;
				transmit_count = convertToNum(uart2TxBuf); //convert the ASCII symbols to integers instead.
				R_ADC_Stop();
				uart2Status = R_UART2_Send(uart2TxBuf, transmit_count);
			}
			else
			if(uart2RxBuf[0] == 't')
				transmit = !transmit;
			else
				uart2TxBuf[0] = uart2RxBuf[0];

			// Prime UART2 Rx
			uart2Status = R_UART2_Receive(uart2RxBuf, 1);
		}

		//If a character has been transmitted
		if (uart2TxFlag)
		{
			// End of UART2 transmit
			uart2TxFlag = 0U;   // clear tx flag
		}
	}

	R_UART2_Stop();
	R_TAU0_Channel0_Stop();
	//R_ADC_Stop();
	/* End user code. Do not edit comment generated here */
}