Пример #1
0
/** End using the Serial port and close it
*
* This function ends using the serial port.
*/
void clixxIOSerial::end()
{
    softuart_turn_rx_off();

    C_iotclose(pMainClass);

    return;
}
Пример #2
0
void hibernate(void)
{
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    sleep_bod_disable();
    softuart_turn_rx_off();
    TIMSK = 0;
    sei();                      // Enable global interrupts 
    sleep_mode();
    sleep_disable();
    setup();
}
Пример #3
0
/***********************************************************************
 * Name: get_ant_msg
 * 
 * Description: wait and recieve a message from the nRF24AP2
 * 
 * Author(s): Charles Wolf
 * 
 * @param: 
 * 		int	max_wait -> timeout in 1mSec increments
 * 		UCHAR *MSG 	-> pointer to the message array
 * @return:
 * 		int -> 	0 = message timeout
 * 				1 = message recieved
 * Comments:
 * 		ANT Message Structure
 * 			SYNC (0xA4)		1 Byte
 * 			length			1 Byte
 * 			message ID		1 Byte
 * 			Data 			length
 * 			CheckSum		1 Byte
 * 			
 * ********************************************************************/
int get_ant_msg(int max_wait, UCHAR *MSG)
{	
	int count = 0;
	int i = 0;
	int outcome = 0;
	int length = 0;
	int checksum = 0;
	
	softuart_turn_rx_on();	
	softuart_flush_input_buffer();
	
	while((count < max_wait) && (outcome != 1))
	{
		//wait for data
		while((softuart_kbhit() < 1) && (count < max_wait))
		{
			_delay_us(100); // 1bit = 208.333uSec
			count++;
		}
		if ( softuart_kbhit() > 0 )
		{
			outcome = 2; //no sync
			//check for sync
			MSG[0] = softuart_getchar();
			//softuart_getchar() is a possible place to get stuck waiting
			if(MSG[0] == MESG_TX_SYNC) 
			{
				MSG[1] = softuart_getchar(); //length
				length = MSG[1]+2;
				if(length > 17) length = 17; //protect length
				for (i = 0; i < length; i++)
				{
					MSG[i+2] = softuart_getchar();
				}
				checksum = checkSum(&MSG[0], length+3);
				if (checksum != MSG[length+4])
				{
					outcome = 3; //bad checksum
				}
				else
				{
					outcome = 1; //message recieved	
				}
			}
		}
	}
	softuart_turn_rx_off();
	return outcome;
}