c_src/read_source/core1/Overlays/stream.cc
/*
* write using the circular buffer algorithm
* local copies and tail are refreshed on misses
* reducing the amount of reads from memory
*/
write using the circular buffer algorithm
local copies and tail are refreshed on misses
reducing the amount of reads from memory
write using the circular buffer algorithm local copies and tail are refreshed on misses reducing the amount of reads from memory
void pr_flow::stream::write( wide_t data )
{
	uint8_t debug_counter = 0;
	while(1)
	{
		 Not allowed to write when stream is full or the next update will collide
		 always leave 1 space
		if( ( (this->head + 1)  == this->tail) || (( (this->head +1) & this->buff_size) ==  this->tail ) )
		{
			this->tail = this->buff[TAIL_POINTER].lower_32;
#ifdef DEBUG_STREAMS
			debug_counter++;
			if(debug_counter == 128)
			{
				debug_counter =0;
				this->bsp_table->debug(this->axi_config,this->stream_id);
			}
#endif
        }
        else
        {
        	 write and update local pointer
        	this->buff[this->head].lower_32 = data.lower_32;
        	this->buff[this->head].mid_lo_32 = data.mid_lo_32;
        	this->buff[this->head].mid_hi_32 = data.mid_hi_32;
        	this->buff[this->head].upper_32 = data.upper_32;
			 ensures the data is written before the head pointer update is written to memory
        	dsb();
            this->head++;
            this->head = this->head & this->buff_size;
#ifdef DEBUG_STREAMS_PRINT
            printf("head: %d tail: %d \n",this->head,this->tail);
#endif
             update state
            this->buff[HEAD_POINTER].lower_32 = this->head;
#ifdef DEBUG_STREAMS_COUNT
            this->bytes_written++;
#endif
            break;
        }
	}
}
void pr_flow :: stream :: write ( wide_t data ) { uint8_t debug_counter = 0 ; while ( 1 ) { if ( ( ( this -> head + 1 ) == this -> tail ) || ( ( ( this -> head + 1 ) & this -> buff_size ) == this -> tail ) ) { this -> tail = this -> buff [ TAIL_POINTER ] . lower_32 ; #ifdef DEBUG_STREAMS debug_counter ++ ; if ( debug_counter == 128 ) { debug_counter = 0 ; this -> bsp_table -> debug ( this -> axi_config , this -> stream_id ) ; } #endif } else { this -> buff [ this -> head ] . lower_32 = data . lower_32 ; this -> buff [ this -> head ] . mid_lo_32 = data . mid_lo_32 ; this -> buff [ this -> head ] . mid_hi_32 = data . mid_hi_32 ; this -> buff [ this -> head ] . upper_32 = data . upper_32 ; dsb ( ) ; this -> head ++ ; this -> head = this -> head & this -> buff_size ; #ifdef DEBUG_STREAMS_PRINT printf ( " \n " , this -> head , this -> tail ) ; #endif this -> buff [ HEAD_POINTER ] . lower_32 = this -> head ; #ifdef DEBUG_STREAMS_COUNT this -> bytes_written ++ ; #endif break ; } } }
write using the circular buffer algorithm
local copies and tail are refreshed on misses
reducing the amount of reads from memory
write using the circular buffer algorithm local copies and tail are refreshed on misses reducing the amount of reads from memory
// // Not allowed to write when stream is full or the next update will collide // always leave 1 space // // // // write and update local pointer // ensures the data is written before the head pointer update is written to memory // // update state