base/serial.c
void Synchronous_Transaction()
{
   UCHAR ucCheckSum;
   UCHAR ucMesgLen;
   UCHAR ucIndex;
   UCHAR ucByte;
   UCHAR* pucTxBuffer;  

   if (sqTxMessages.ucMessageCount > 0)    // if we have a message to send
   {  
      pucTxBuffer = sqTxMessages.aucMessages[sqTxMessages.ucTail].aucBuffer;
      SYNC_SMSGRDY_ASSERT();                          // notify the ANT device that the Host wishes to send a message

      // the following retry loop is a workaround to avoid a possible loss of the MSGRDY assertion edge with the  nRF24AP1
      {
         UCHAR ucSenTimeout = SEN_ASSERT_TIMEOUT;

         do                                              
         {
            if (!(ucSenTimeout--))                    // check the retry timeout
            {
               ucSenTimeout = SEN_ASSERT_TIMEOUT;     // Reset the timeout for the SEN response 

               SYNC_SMSGRDY_DEASSERT();               // Pulse MSGRDY again if SEN has not been asserted by the timeout
               Timer_DelayTime(1);                    // 10us
               SYNC_SMSGRDY_ASSERT();            
            }

            Timer_DelayTime(1);                       // wait 10us   
         }
         while (!IS_SEN_ASSERTED());                  // check if SEN is asserted
      }
   }            

   while (IS_SMSGRDY_ASSERTED() || IS_SEN_ASSERTED()) // while we have a message to send or a message to receive
   {   
      while (!IS_SEN_ASSERTED());                     // make sure SEN is asserted

      // Read the sync Byte 
      ucByte     = Synchronous_ReadByte();            // read the sync byte
      ucCheckSum = ucByte;                            // initialize the checksum

      if ((ucByte == MESG_RX_SYNC) && (sqTxMessages.ucMessageCount> 0))                     // ANT is ready to receive our message and we have a message to send
      {
         SYNC_SMSGRDY_DEASSERT();                     // clear the message ready signal

         ucMesgLen = pucTxBuffer[0] + MESG_SAVED_FRAME_SIZE; // read the message length of the message to send and adjust for frame size
         ucIndex   = 0;

         do
         {
            Synchronous_WriteByte(pucTxBuffer[ucIndex]);       // write out message byte
            ucCheckSum ^= pucTxBuffer[ucIndex];                // update the checksum

         } while (++ucIndex < ucMesgLen);                      // loop through message

         Synchronous_WriteByte(ucCheckSum);                    // write out the checksum byte

         while (IS_SEN_ASSERTED());                   // Wait until SEN goes HIGH
         sqTxMessages.ucTail = (sqTxMessages.ucTail + 1) & (SERIAL_QUEUE_TX_SIZE-1);    // Update queue
         sqTxMessages.ucMessageCount--;
      }
      else if (ucByte == MESG_TX_SYNC)                // ANT wants to send us a message
      {
         UCHAR* pucRxBuffer = NULL;

         // Check if there is room to receive message
         if(sqRxMessages.ucMessageCount < SERIAL_QUEUE_RX_SIZE)
         {
            pucRxBuffer = sqRxMessages.aucMessages[sqRxMessages.ucHead].aucBuffer;

            // Read the second byte which is the length of the message 
            ucByte    = Synchronous_ReadByte();
            ucMesgLen = ucByte + MESG_SAVED_FRAME_SIZE;  // save the message length and correct for the frame size
            ucIndex   = 0;

            do
            {
               pucRxBuffer[ucIndex] = ucByte;            // save it in the receive buffer            
               ucCheckSum ^= ucByte;                     // update the checksum
               ucByte      = Synchronous_ReadByte();     // read out the next byte

            } while (++ucIndex < ucMesgLen);           

            if (ucCheckSum == ucByte)                    // validate the checksum of the message
            {
               sqRxMessages.ucHead = ((sqRxMessages.ucHead + 1) & (SERIAL_QUEUE_RX_SIZE-1));
               sqRxMessages.ucMessageCount++;
            }
         }
         else //Buffer overflow
         {
            sqRxMessages.bQueueOverflow = TRUE;  //Set overflow flag
            // Read in the ANT message and discard it so as not to interrupt the serial line states
            // Read the second byte which is the length of the message
            ucByte    = Synchronous_ReadByte();
            ucMesgLen = ucByte + MESG_SAVED_FRAME_SIZE;  // save the message length and correct for the frame size
            ucIndex   = 0;

            do
            {
               ucByte      = Synchronous_ReadByte();     // read out the next byte

            } while (++ucIndex < ucMesgLen);
         }
      }
   } 
}
////////////////////////////////////////////////////////////////////////////
// Synchronous_Transaction
//
// If there is a message in the serial queue, send it.
// If ANT has a message to send to us, put it the recieve queue.
// 
////////////////////////////////////////////////////////////////////////////
Synchronous_Transaction
If there is a message in the serial queue, send it.
If ANT has a message to send to us, put it the recieve queue.
Synchronous_Transaction If there is a message in the serial queue send it . If ANT has a message to send to us put it the recieve queue .
void Synchronous_Transaction()
{
   UCHAR ucCheckSum;
   UCHAR ucMesgLen;
   UCHAR ucIndex;
   UCHAR ucByte;
   UCHAR* pucTxBuffer;  
   if (sqTxMessages.ucMessageCount > 0)    
   {  
      pucTxBuffer = sqTxMessages.aucMessages[sqTxMessages.ucTail].aucBuffer;
      SYNC_SMSGRDY_ASSERT();                          
      {
         UCHAR ucSenTimeout = SEN_ASSERT_TIMEOUT;
         do                                              
         {
            if (!(ucSenTimeout--))                    
            {
               ucSenTimeout = SEN_ASSERT_TIMEOUT;     
               SYNC_SMSGRDY_DEASSERT();               
               Timer_DelayTime(1);                    
               SYNC_SMSGRDY_ASSERT();            
            }
            Timer_DelayTime(1);                       
         }
         while (!IS_SEN_ASSERTED());                  
      }
   }            
   while (IS_SMSGRDY_ASSERTED() || IS_SEN_ASSERTED()) 
   {   
      while (!IS_SEN_ASSERTED());                     
      ucByte     = Synchronous_ReadByte();            
      ucCheckSum = ucByte;                            
      if ((ucByte == MESG_RX_SYNC) && (sqTxMessages.ucMessageCount> 0))                     
      {
         SYNC_SMSGRDY_DEASSERT();                     
         ucMesgLen = pucTxBuffer[0] + MESG_SAVED_FRAME_SIZE; 
         ucIndex   = 0;
         do
         {
            Synchronous_WriteByte(pucTxBuffer[ucIndex]);       
            ucCheckSum ^= pucTxBuffer[ucIndex];                
         } while (++ucIndex < ucMesgLen);                      
         Synchronous_WriteByte(ucCheckSum);                    
         while (IS_SEN_ASSERTED());                   
         sqTxMessages.ucTail = (sqTxMessages.ucTail + 1) & (SERIAL_QUEUE_TX_SIZE-1);    
         sqTxMessages.ucMessageCount--;
      }
      else if (ucByte == MESG_TX_SYNC)                
      {
         UCHAR* pucRxBuffer = NULL;
         if(sqRxMessages.ucMessageCount < SERIAL_QUEUE_RX_SIZE)
         {
            pucRxBuffer = sqRxMessages.aucMessages[sqRxMessages.ucHead].aucBuffer;
            ucByte    = Synchronous_ReadByte();
            ucMesgLen = ucByte + MESG_SAVED_FRAME_SIZE;  
            ucIndex   = 0;
            do
            {
               pucRxBuffer[ucIndex] = ucByte;            
               ucCheckSum ^= ucByte;                     
               ucByte      = Synchronous_ReadByte();     
            } while (++ucIndex < ucMesgLen);           
            if (ucCheckSum == ucByte)                    
            {
               sqRxMessages.ucHead = ((sqRxMessages.ucHead + 1) & (SERIAL_QUEUE_RX_SIZE-1));
               sqRxMessages.ucMessageCount++;
            }
         }
         else 
         {
            sqRxMessages.bQueueOverflow = TRUE;  
            ucByte    = Synchronous_ReadByte();
            ucMesgLen = ucByte + MESG_SAVED_FRAME_SIZE;  
            ucIndex   = 0;
            do
            {
               ucByte      = Synchronous_ReadByte();     
            } while (++ucIndex < ucMesgLen);
         }
      }
   } 
}
void Synchronous_Transaction ( ) { UCHAR ucCheckSum ; UCHAR ucMesgLen ; UCHAR ucIndex ; UCHAR ucByte ; UCHAR * pucTxBuffer ; if ( sqTxMessages . ucMessageCount > 0 ) { pucTxBuffer = sqTxMessages . aucMessages [ sqTxMessages . ucTail ] . aucBuffer ; SYNC_SMSGRDY_ASSERT ( ) ; { UCHAR ucSenTimeout = SEN_ASSERT_TIMEOUT ; do { if ( ! ( ucSenTimeout -- ) ) { ucSenTimeout = SEN_ASSERT_TIMEOUT ; SYNC_SMSGRDY_DEASSERT ( ) ; Timer_DelayTime ( 1 ) ; SYNC_SMSGRDY_ASSERT ( ) ; } Timer_DelayTime ( 1 ) ; } while ( ! IS_SEN_ASSERTED ( ) ) ; } } while ( IS_SMSGRDY_ASSERTED ( ) || IS_SEN_ASSERTED ( ) ) { while ( ! IS_SEN_ASSERTED ( ) ) ; ucByte = Synchronous_ReadByte ( ) ; ucCheckSum = ucByte ; if ( ( ucByte == MESG_RX_SYNC ) && ( sqTxMessages . ucMessageCount > 0 ) ) { SYNC_SMSGRDY_DEASSERT ( ) ; ucMesgLen = pucTxBuffer [ 0 ] + MESG_SAVED_FRAME_SIZE ; ucIndex = 0 ; do { Synchronous_WriteByte ( pucTxBuffer [ ucIndex ] ) ; ucCheckSum ^= pucTxBuffer [ ucIndex ] ; } while ( ++ ucIndex < ucMesgLen ) ; Synchronous_WriteByte ( ucCheckSum ) ; while ( IS_SEN_ASSERTED ( ) ) ; sqTxMessages . ucTail = ( sqTxMessages . ucTail + 1 ) & ( SERIAL_QUEUE_TX_SIZE - 1 ) ; sqTxMessages . ucMessageCount -- ; } else if ( ucByte == MESG_TX_SYNC ) { UCHAR * pucRxBuffer = NULL ; if ( sqRxMessages . ucMessageCount < SERIAL_QUEUE_RX_SIZE ) { pucRxBuffer = sqRxMessages . aucMessages [ sqRxMessages . ucHead ] . aucBuffer ; ucByte = Synchronous_ReadByte ( ) ; ucMesgLen = ucByte + MESG_SAVED_FRAME_SIZE ; ucIndex = 0 ; do { pucRxBuffer [ ucIndex ] = ucByte ; ucCheckSum ^= ucByte ; ucByte = Synchronous_ReadByte ( ) ; } while ( ++ ucIndex < ucMesgLen ) ; if ( ucCheckSum == ucByte ) { sqRxMessages . ucHead = ( ( sqRxMessages . ucHead + 1 ) & ( SERIAL_QUEUE_RX_SIZE - 1 ) ) ; sqRxMessages . ucMessageCount ++ ; } } else { sqRxMessages . bQueueOverflow = TRUE ; ucByte = Synchronous_ReadByte ( ) ; ucMesgLen = ucByte + MESG_SAVED_FRAME_SIZE ; ucIndex = 0 ; do { ucByte = Synchronous_ReadByte ( ) ; } while ( ++ ucIndex < ucMesgLen ) ; } } } }
Synchronous_Transaction
If there is a message in the serial queue, send it.
Synchronous_Transaction If there is a message in the serial queue send it .
// if we have a message to send // notify the ANT device that the Host wishes to send a message // the following retry loop is a workaround to avoid a possible loss of the MSGRDY assertion edge with the  nRF24AP1 // check the retry timeout // Reset the timeout for the SEN response  // Pulse MSGRDY again if SEN has not been asserted by the timeout // 10us // wait 10us    // check if SEN is asserted // while we have a message to send or a message to receive // make sure SEN is asserted // Read the sync Byte  // read the sync byte // initialize the checksum // ANT is ready to receive our message and we have a message to send // clear the message ready signal // read the message length of the message to send and adjust for frame size // write out message byte // update the checksum // loop through message // write out the checksum byte // Wait until SEN goes HIGH // Update queue // ANT wants to send us a message // Check if there is room to receive message // Read the second byte which is the length of the message  // save the message length and correct for the frame size // save it in the receive buffer             // update the checksum // read out the next byte // validate the checksum of the message //Buffer overflow //Set overflow flag // Read in the ANT message and discard it so as not to interrupt the serial line states // Read the second byte which is the length of the message // save the message length and correct for the frame size // read out the next byte