Beispiel #1
0
static void ifx_spi_setup_transmission(struct ifx_spi_data *spi_data)
{
	IFX_SPI_DEBUG("sender buf=%d, reciver buf=%d", spi_data->ifx_sender_buf_size, spi_data->ifx_receiver_buf_size);

	if( (spi_data->ifx_sender_buf_size != 0) || (spi_data->ifx_receiver_buf_size != 0) )
	{
		if(spi_data->ifx_sender_buf_size > spi_data->ifx_receiver_buf_size)
		{
			spi_data->ifx_current_frame_size = spi_data->ifx_sender_buf_size;
		}
		else
		{ 
			spi_data->ifx_current_frame_size = spi_data->ifx_receiver_buf_size;    
		}
		
		if(spi_data->ifx_spi_count > 0)
		{
			if(spi_data->ifx_spi_count > spi_data->ifx_current_frame_size)
			{
				spi_data->ifx_valid_frame_size = spi_data->ifx_current_frame_size;
				spi_data->ifx_spi_count = spi_data->ifx_spi_count - spi_data->ifx_current_frame_size;
			}
			else
			{
				spi_data->ifx_valid_frame_size = spi_data->ifx_spi_count;
				spi_data->ifx_spi_count = 0;
			}
                }
		else
		{
			spi_data->ifx_valid_frame_size = 0;
			spi_data->ifx_sender_buf_size = 0;
		}

		spi_data->ifx_sender_buf_size = ifx_spi_get_next_frame_size(spi_data->ifx_spi_count);
		IFX_SPI_DEBUG("reciver buf=%d",spi_data->ifx_sender_buf_size);

		/* memset buffers to 0 */
		memset(spi_data->ifx_tx_buffer,0,IFX_SPI_MAX_BUF_SIZE+IFX_SPI_HEADER_SIZE);
		memset(spi_data->ifx_rx_buffer,0,IFX_SPI_MAX_BUF_SIZE+IFX_SPI_HEADER_SIZE);

		/* Set header information */
		ifx_spi_set_header_info(spi_data->ifx_tx_buffer, spi_data->ifx_valid_frame_size, spi_data->ifx_sender_buf_size);
		if( spi_data->ifx_valid_frame_size > 0 )
		{      
			memcpy(spi_data->ifx_tx_buffer+IFX_SPI_HEADER_SIZE, spi_data->ifx_spi_buf, spi_data->ifx_valid_frame_size);
			spi_data->ifx_spi_buf = spi_data->ifx_spi_buf + spi_data->ifx_valid_frame_size;
		}

	}
}
Beispiel #2
0
/*
 * Function to setup transmission and reception. It implements a logic to find out the ifx_current_frame_size,
 * valid_frame_size and sender_next_frame_size to set in SPI header frame. Copys the data to be transferred from 
 * user space to TX buffer and set MRDY signal to HIGH to indicate Master is ready to transfer data.
 */
static void 
ifx_spi_setup_transmission(void)
{

	//printk("[e] ifx_spi_setup_transmission\n");

	if( (ifx_sender_buf_size != 0) || (ifx_receiver_buf_size != 0) ){
		if(ifx_sender_buf_size > ifx_receiver_buf_size){
			ifx_current_frame_size = ifx_sender_buf_size;
		}
		else{ 
			ifx_current_frame_size = ifx_receiver_buf_size;    
		}
		if(ifx_spi_count > 0){
			if(ifx_spi_count > ifx_current_frame_size){
				ifx_valid_frame_size = ifx_current_frame_size;
				ifx_spi_count = ifx_spi_count - ifx_current_frame_size;
			}
			else{
				ifx_valid_frame_size = ifx_spi_count;
				ifx_spi_count = 0;
			}
                }
		else{
			ifx_valid_frame_size = 0;
			ifx_sender_buf_size = 0;
		}
		ifx_sender_buf_size = ifx_spi_get_next_frame_size(ifx_spi_count);

		/* memset buffers to 0 */
		memset(ifx_tx_buffer,0,IFX_SPI_MAX_BUF_SIZE+IFX_SPI_HEADER_SIZE);
		memset(ifx_rx_buffer,0,IFX_SPI_MAX_BUF_SIZE+IFX_SPI_HEADER_SIZE);

		/* Set header information */
		ifx_spi_set_header_info(ifx_tx_buffer, ifx_valid_frame_size, ifx_sender_buf_size);
		if( ifx_valid_frame_size > 0 ){      
			memcpy(ifx_tx_buffer+IFX_SPI_HEADER_SIZE, ifx_spi_buf, ifx_valid_frame_size);
			ifx_spi_buf = ifx_spi_buf + ifx_valid_frame_size;
		}
	}
}