⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pros_edma3_drv_sample_cs.c

📁 vicp做为dm6446上的硬件加速器
💻 C
📖 第 1 页 / 共 2 页
字号:
 * For other cases, where buffer is NOT in DDR, user
 * may or may not require the below implementation and
 * should modify it according to her need.
 */
EDMA3_DRV_Result Edma3_CacheInvalidate(unsigned int mem_start_ptr,
                           unsigned int    num_bytes)
    {
    EDMA3_DRV_Result cacheInvResult = EDMA3_DRV_SOK;

    /* Verify whether the start address is cache aligned or not */
    if((mem_start_ptr & (EDMA3_CACHE_LINE_SIZE_IN_BYTES-1u))    !=    0)
        {
#ifdef DEBUG_CACHE
        kprintf("\r\n Cache : Memory is not %d bytes alinged\r\n",
                            EDMA3_CACHE_LINE_SIZE_IN_BYTES);
#endif
        cacheInvResult = EDMA3_NON_ALIGNED_BUFFERS_ERROR;
        }
    else
        {
    	while(num_bytes >0)
    	    {
    #ifndef USE_TI_TOOLS
    	  	__asm( " mcr     p15,    0,      mem_start_ptr,     c7,    c6,     1" );
    	  	__asm( " add mem_start_ptr, mem_start_ptr, #32");
    #else /* ifndef USE_TI_TOOLS */
            __asm(" mcr p15, #0, r1, c7, c6, #1" );
            __asm(" add r1, r1, #32");
    #endif  /* ifndef USE_TI_TOOLS */
    	  	if (num_bytes > EDMA3_CACHE_LINE_SIZE_IN_BYTES)
                {
    	  		num_bytes = num_bytes - EDMA3_CACHE_LINE_SIZE_IN_BYTES;
    		    }
            else
                {
    			num_bytes = 0;
    		    }
    	    }
        }

    return cacheInvResult;
    }



/**
 * \brief   EDMA3 Cache Flush
 *
 *  This function flushes (cleans) the Cache
 *
 *  \param  mem_start_ptr [IN]      Starting adress of memory.
 *                                  Please note that this should be
 *                                  aligned according to the cache line size.
 *  \param  num_bytes [IN]          length of buffer
 *  \return  EDMA3_DRV_SOK if success, else error code in case of error
 *          or non-alignment of buffers.
 *
 * Note: This function is required if the buffer is in DDR.
 * For other cases, where buffer is NOT in DDR, user
 * may or may not require the below implementation and
 * should modify it according to her need.
 */
EDMA3_DRV_Result Edma3_CacheFlush(unsigned int mem_start_ptr,
                                unsigned int num_bytes)
    {
    EDMA3_DRV_Result cacheFlushResult = EDMA3_DRV_SOK;

    /* Verify whether the start address is cache aligned or not */
    if((mem_start_ptr & (EDMA3_CACHE_LINE_SIZE_IN_BYTES-1u))    !=    0)
        {
#ifdef DEBUG_CACHE
	    kprintf("\r\n Cache : Memory is not %d bytes alinged\r\n",
                            EDMA3_CACHE_LINE_SIZE_IN_BYTES);
#endif
        cacheFlushResult = EDMA3_NON_ALIGNED_BUFFERS_ERROR;
        }
    else
        {
    	while(num_bytes>0)
    	    {
    #ifndef USE_TI_TOOLS
    	  	__asm( " mcr     p15,    0,      mem_start_ptr,     c7,    c10,     1" );
    	  	__asm( " add mem_start_ptr, mem_start_ptr, #32");
    #else /* #ifndef USE_TI_TOOLS */
            __asm(" mcr p15, #0, r1, c7, c10, #1" );
            __asm(" add r1, r1, #32");
    #endif /* #ifndef USE_TI_TOOLS */
    		if (num_bytes > EDMA3_CACHE_LINE_SIZE_IN_BYTES)
                {
    	  		num_bytes = num_bytes - EDMA3_CACHE_LINE_SIZE_IN_BYTES;
    		    }
            else
                {
    			num_bytes = 0;
    		    }
    	    }

    		/*Drain the write buffer before excuting any further*/
    #ifndef USE_TI_TOOLS
    	__asm(" mov     mem_start_ptr,     #0");
    	__asm( " mcr     p15,    0,      mem_start_ptr,     c7,    c10,     4" );
    #else /* #ifndef USE_TI_TOOLS */
    	__asm(" mov     r1,     #0");
    	__asm( " mcr     p15,    #0,      r1,     c7,    c10,     #4" );
    #endif /* #ifndef USE_TI_TOOLS */
        }

    return cacheFlushResult;
    }


/**
  * Counting Semaphore related functions (OS dependent) should be
  * called/implemented by the application. A handle to the semaphore
  * is required while opening the driver/resource manager instance.
  */

/**
 * \brief   EDMA3 OS Semaphore Create
 *
 *      This function creates a counting semaphore with specified
 *      attributes and initial value. It should be used to create a semaphore
 *      with initial value as '1'. The semaphore is then passed by the user
 *      to the EDMA3 driver/RM for proper sharing of resources.
 * \param   initVal [IN] is initial value for semaphore
 * \param   attrs [IN] is the semaphore attributes ex: Fifo type
 * \param   hSem [OUT] is location to recieve the handle to just created
 *      semaphore
 * \return  EDMA3_DRV_SOK if succesful, else a suitable error code.
 */
EDMA3_DRV_Result edma3OsSemCreate(int initVal,
                           const EDMA3_OS_SemAttrs *attrs,
                           EDMA3_OS_Sem_Handle *hSem)
    {
    EDMA3_DRV_Result semCreateResult = EDMA3_DRV_SOK;

    if((NULL == hSem) || (NULL == attrs))
        {
        semCreateResult = EDMA3_DRV_E_INVALID_PARAM;
        }
    else
        {
		*hSem = (EDMA3_OS_Sem_Handle) acre_sem((T_CSEM*)attrs);
        if ( (*hSem) == (EDMA3_OS_Sem_Handle) E_NOID )
            {
            semCreateResult = EDMA3_DRV_E_SEMAPHORE;
            }
        }

    return semCreateResult;
    }


/**
 * \brief   EDMA3 OS Semaphore Delete
 *
 *      This function deletes or removes the specified semaphore
 *      from the system. Associated dynamically allocated memory
 *      if any is also freed up.
 * \warning OsSEM services run in client context and not in a thread
 *      of their own. If there exist threads pended on a semaphore
 *      that is being deleted, results are undefined.
 * \param   hSem [IN] handle to the semaphore to be deleted
 * \return  EDMA3_DRV_SOK if succesful else a suitable error code
 */
EDMA3_DRV_Result edma3OsSemDelete(EDMA3_OS_Sem_Handle hSem)
    {
    EDMA3_DRV_Result semDeleteResult = EDMA3_DRV_SOK;

    if(NULL == hSem)
        {
        semDeleteResult = EDMA3_DRV_E_INVALID_PARAM;
        }
    else
        {
        semDeleteResult = (EDMA3_DRV_Result) del_sem((ID) hSem);
		if(semDeleteResult != (EDMA3_DRV_Result) E_OK)	{
				semDeleteResult = EDMA3_DRV_E_SEMAPHORE;
			}
        }

    return semDeleteResult;
    }


/**
 * \brief   EDMA3 OS Semaphore Take
 *
 *      This function takes a semaphore token if available.
 *      If a semaphore is unavailable, it blocks currently
 *      running thread in wait (for specified duration) for
 *      a free semaphore.
 * \param   hSem [IN] is the handle of the specified semaphore
 * \param   mSecTimeout [IN] is wait time in milliseconds
 * \return  EDMA3_DRV_Result if successful else a suitable error code
 */
EDMA3_DRV_Result edma3OsSemTake(EDMA3_OS_Sem_Handle hSem, int mSecTimeout)
    {
    EDMA3_DRV_Result semTakeResult = EDMA3_DRV_SOK;
    unsigned short semPendResult;

    if(NULL == hSem)
        {
        semTakeResult = EDMA3_DRV_E_INVALID_PARAM;
        }
    else
        {
		semPendResult = (EDMA3_DRV_Result) twai_sem((ID) hSem, mSecTimeout);
        if (semPendResult != (unsigned short) E_OK)
            {
            semTakeResult = EDMA3_DRV_E_SEMAPHORE;
            }
        }

    return semTakeResult;
    }


/**
 * \brief   EDMA3 OS Semaphore Give
 *
 *      This function gives or relinquishes an already
 *      acquired semaphore token
 * \param   hSem [IN] is the handle of the specified semaphore
 * \return  EDMA3_DRV_Result if successful else a suitable error code
 */
EDMA3_DRV_Result edma3OsSemGive(EDMA3_OS_Sem_Handle hSem)
    {
    EDMA3_DRV_Result semGiveResult = EDMA3_DRV_SOK;

    if(NULL == hSem)
        {
        semGiveResult = EDMA3_DRV_E_INVALID_PARAM;
        }
    else
        {
        semGiveResult = (EDMA3_DRV_Result) sig_sem((ID) hSem);
		if(semGiveResult != (EDMA3_DRV_Result) E_OK)
            {
			semGiveResult = EDMA3_DRV_E_SEMAPHORE;
			}
        }

    return semGiveResult;
    }





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -