Пример #1
0
/*!
    \brief attempts to write up to len bytes to the SPI channel

	\param	 		fd			-	file descriptor of an opened SPI channel

	\param			pBuff		- 	points to first location to start getting the data from

	\param			len			-	number of bytes to write to the SPI channel

	\return			upon successful completion, the function shall return 0.
					Otherwise, -1 shall be returned

    \sa             spi_Open , spi_Read
	\note			This function could be implemented as zero copy and return only upon successful completion
					of writing the whole buffer, but in cases that memory allocation is not too tight, the
					function could copy the data to internal buffer, return back and complete the write in
					parallel to other activities as long as the other SPI activities would be blocked untill
					the entire buffer write would be completed
    \warning
*/
int spi_Write(Fd_t fd, unsigned char *pBuff, int len)
{
    int write_size = 0;

    if(fd!=1 || g_SpiFd!=1)
        return -1;

	if(len>DMA_BUFF_SIZE_MIN && g_ucDMAEnabled)
	{
#if defined(SL_PLATFORM_MULTI_THREADED)
        char temp[4];
#endif
	    SetupDMASend(pBuff,len);
	    SPICSEnable(LSPI_BASE);
#if defined(SL_PLATFORM_MULTI_THREADED)
	    osi_MsgQRead(&DMAMsgQ,temp,OSI_WAIT_FOREVER);
#else
	    while(g_cDummy != 0x1);
	    g_cDummy = 0x0;
#endif
            write_size += len;
	}

	else
	{
		write_size += spi_Write_CPU(pBuff,len);
	}
    return write_size;
}
Пример #2
0
/*!
    \brief attempts to write up to len bytes to the SPI channel

	\param	 		fd			-	file descriptor of an opened SPI channel

	\param			pBuff		- 	points to first location to start getting the data from

	\param			len			-	number of bytes to write to the SPI channel

	\return			upon successful completion, the function shall return 0.
					Otherwise, -1 shall be returned

    \sa             spi_Open , spi_Read
	\note			This function could be implemented as zero copy and return only upon successful completion
					of writing the whole buffer, but in cases that memory allocation is not too tight, the
					function could copy the data to internal buffer, return back and complete the write in
					parallel to other activities as long as the other SPI activities would be blocked untill
					the entire buffer write would be completed
    \warning
*/
int spi_Write(Fd_t fd, unsigned char *pBuff, int len)
{
    if (fd != 1 || g_SpiFd != 1) {
        return -1;
    }

    return spi_Write_CPU(pBuff,len);
}