pointers

Status
Not open for further replies.

aamirkhan

New Member
I wana get data from the serial buffer register and save the bytes in an array
i didnt know how many bytes i will recieve.how will i store the recieved data.i know that i can use use the pointer.any one tell me the method to write the code
 
I wana get data from the serial buffer register and save the bytes in an array
i didnt know how many bytes i will recieve.how will i store the recieved data.i know that i can use use the pointer.any one tell me the method to write the code

What language?

What architecture?

What OS, if any?

More information!


Torben
 
Here is some code from the serial ISR for an 8051 that puts incoming characters into a serial queue. SP_RX_SIZE must be a power of two.
Code:
  if(RI == 1)  /* Receiver Interrupt Flag -- SBUF has the character  */
  {
    RI = 0 ;   /* Clear the Receive Interrupt Flag                   */
    SDE = 0 ;  /* Clear the Error Flag                               */
    if(sp_nRx < SP_RX_SIZE)  /* Check to see if there is room        */
    {
      if(FE == 1)  /* Check for Framing Errors                       */
      {							
        FE = 0 ;  /* Clear the framing error bit                     */
        ++g_RxFramingError ;
        ACC = SBUF ;  /* Check for BREAK                             */
        if(ACC == 0)	BREAK = 1 ;
      }
      else
      {
        sp_RxBuffer[sp_RxPut] = SBUF ;
        sp_RxPut = (sp_RxPut + 1) & (SP_RX_SIZE - 1) ;
        ++sp_nRx ;
      }
    }
    else  /* One space remains	*/
    {
      if(FE == 1)
      {
        FE = 0 ;  /* Clear the framing error bit  */
        ++g_RxFramingError ;
        ACC = SBUF ;  /* Check for BREAK  */
        if(ACC == 0)	BREAK = 1 ;
      }
      else
      {	/* Continue to overwrite the last character
        ** Don't increment the pointer
        ** Don't increment the count of characters in the queue
        */
        sp_RxBuffer[sp_RxPut] = SBUF ;
        ++g_RxDataOverrun ;
        LSDE = SDE = 1 ;
      }
    }
  }
Of course there is an sp_RxGet index that is used to remove characters from the queue.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…