Subversion Repositories Projects

Compare Revisions

Regard whitespace Rev 684 → Rev 685

/C-OSD/trunk/usart1.c
97,40 → 97,45
ISR(SIG_USART1_DATA) {
}
 
/**
/*
* receive data through usart1
* portions taken and adapted from
* http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Fbranches%2FV0.72p+Code+Redesign+killagreg%2Fuart0.c
*/
ISR(SIG_USART1_RECV) {
uint8_t c;
// catch the received byte
c = UDR1;
if (rxd_buffer_locked) return; // if rxd buffer is locked immediately return
LED1_ON
static uint16_t crc;
static uint8_t ptr_rxd_buffer = 0;
static uint8_t c1 = 0;
static uint8_t c2 = 0;
static uint8_t usart_rx_ok = 0;
uint8_t crc1, crc2;
uint8_t c;
 
c = UDR1; // catch the received byte
 
// the rxd buffer is unlocked
if ((ptr_rxd_buffer == 0) && (c == '#')) // if rxd buffer is empty and syncronisation character is received
{
/*
// skip other datasets
if (ptr_rxd_buffer == 2 && rxd_buffer[ptr_rxd_buffer] != 'O') {
ptr_rxd_buffer = 0; // reset rxd buffer
rxd_buffer_locked = 0; // unlock rxd buffer
}*/
rxd_buffer[ptr_rxd_buffer++] = c; // copy 1st byte to buffer
crc = c; // init crc
} else if (ptr_rxd_buffer < RXD_BUFFER_LEN) // collect incomming bytes
{
if (c != '\r') // no termination character
{
if (usart_rx_ok == 0) {
if ((c2 == '#') && (c1 == 'b') && (c == 'D' || c == 'V' || c == 'O')) {
usart_rx_ok = 1;
rxd_buffer[ptr_rxd_buffer++] = c2;
crc = c2;
rxd_buffer[ptr_rxd_buffer++] = c1;
crc += c1;
rxd_buffer[ptr_rxd_buffer++] = c;
crc += c;
c2 = 0;
c1 = 0;
LED1_ON
LED2_OFF
} else {
c2 = c1;
c1 = c;
}
} else if (ptr_rxd_buffer < RXD_BUFFER_LEN) { // collect incomming bytes
if (c != '\r') { // no termination character
rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer
crc += c; // update crc
} else // termination character was received
{
} else { // termination character was received
// the last 2 bytes are no subject for checksum calculation
// they are the checksum itself
crc -= rxd_buffer[ptr_rxd_buffer - 2];
144,17 → 149,20
rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character
ReceivedBytes = ptr_rxd_buffer + 1; // store number of received bytes
rxd_buffer_locked = 1; // lock the rxd buffer
LED1_OFF
} else { // checksum invalid
rxd_buffer_locked = 0; // unlock rxd buffer
LED2_ON
}
ptr_rxd_buffer = 0; // reset rxd buffer pointer
usart_rx_ok = 0;
}
} else // rxd buffer overrun
{
} else { // rxd buffer overrun
ptr_rxd_buffer = 0; // reset rxd buffer
rxd_buffer_locked = 0; // unlock rxd buffer
usart_rx_ok = 0;
LED2_ON
}
LED1_OFF
}
 
/**