aesd-char-driver/aesd-circular-buffer.c
void aesd_circular_buffer_add_entry(struct aesd_circular_buffer *buffer, const struct aesd_buffer_entry *add_entry)
{

	
	if(buffer->in_offs == AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED)  // check for  10 entries
	{
		
		printk("\n Buffer is full \n");
		buffer->in_offs = 0;
		buffer->out_offs = 0;
		buffer->full = true; //set full flag 
	}

	// if(buffer->out_offs == AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED)
	// {
	// 	buffer->out_offs = 0;
	// }
	
	buffer->entry[buffer->in_offs].size = add_entry->size;
	buffer->entry[buffer->in_offs].buffptr = add_entry->buffptr;
	
	
	
	if(buffer->full == true)
	{	
		buffer->out_offs++; // increment out_offs
		buffer->full = false;
		buffer->in_offs ++;
				
	}
	else
	{
	#ifdef __KERNEL__
	printk("The contents of buffer is : %s \n ", buffer->entry[buffer->in_offs].buffptr);
	#else
	printf("The contents of buffer is : %s \n ", buffer->entry[buffer->in_offs].buffptr);
	#endif
	buffer->in_offs++; // increment in_offs	
	}

int k = 0;
for(k=0;k<10;k++)
{
	printk("The contents of buffer is : %s at position %d \n ",buffer->entry[k].buffptr,k);	
}

}
/**
* Adds entry @param add_entry to @param buffer in the location specified in buffer->in_offs.
* If the buffer was already full, overwrites the oldest entry and advances buffer->out_offs to the
* new start location.
* Any necessary locking must be handled by the caller
* Any memory referenced in @param add_entry must be allocated by and/or must have a lifetime managed by the caller.
*/
Adds entry @param add_entry to @param buffer in the location specified in buffer->in_offs.
If the buffer was already full, overwrites the oldest entry and advances buffer->out_offs to the
new start location.
Any necessary locking must be handled by the caller
Any memory referenced in @param add_entry must be allocated by and/or must have a lifetime managed by the caller.
Adds entry @param add_entry to @param buffer in the location specified in buffer - > in_offs . If the buffer was already full overwrites the oldest entry and advances buffer - > out_offs to the new start location . Any necessary locking must be handled by the caller Any memory referenced in @param add_entry must be allocated by and / or must have a lifetime managed by the caller .
void aesd_circular_buffer_add_entry(struct aesd_circular_buffer *buffer, const struct aesd_buffer_entry *add_entry)
{
	if(buffer->in_offs == AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED)  
	{
		printk("\n Buffer is full \n");
		buffer->in_offs = 0;
		buffer->out_offs = 0;
		buffer->full = true; 
	}
	buffer->entry[buffer->in_offs].size = add_entry->size;
	buffer->entry[buffer->in_offs].buffptr = add_entry->buffptr;
	if(buffer->full == true)
	{	
		buffer->out_offs++; 
		buffer->full = false;
		buffer->in_offs ++;
	}
	else
	{
	#ifdef __KERNEL__
	printk("The contents of buffer is : %s \n ", buffer->entry[buffer->in_offs].buffptr);
	#else
	printf("The contents of buffer is : %s \n ", buffer->entry[buffer->in_offs].buffptr);
	#endif
	buffer->in_offs++; 
	}
int k = 0;
for(k=0;k<10;k++)
{
	printk("The contents of buffer is : %s at position %d \n ",buffer->entry[k].buffptr,k);	
}
}
void aesd_circular_buffer_add_entry ( struct aesd_circular_buffer * buffer , const struct aesd_buffer_entry * add_entry ) { if ( buffer -> in_offs == AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED ) { printk ( " \n \n " ) ; buffer -> in_offs = 0 ; buffer -> out_offs = 0 ; buffer -> full = true ; } buffer -> entry [ buffer -> in_offs ] . size = add_entry -> size ; buffer -> entry [ buffer -> in_offs ] . buffptr = add_entry -> buffptr ; if ( buffer -> full == true ) { buffer -> out_offs ++ ; buffer -> full = false ; buffer -> in_offs ++ ; } else { #ifdef __KERNEL__ printk ( " \n " , buffer -> entry [ buffer -> in_offs ] . buffptr ) ; #else printf ( " \n " , buffer -> entry [ buffer -> in_offs ] . buffptr ) ; #endif buffer -> in_offs ++ ; } int k = 0 ; for ( k = 0 ; k < 10 ; k ++ ) { printk ( " \n " , buffer -> entry [ k ] . buffptr , k ) ; } }
Adds entry @param add_entry to @param buffer in the location specified in buffer->in_offs.
Adds entry @param add_entry to @param buffer in the location specified in buffer - > in_offs .
// check for  10 entries //set full flag  // if(buffer->out_offs == AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED) // { // 	buffer->out_offs = 0; // } // increment out_offs // increment in_offs	