parent
adaced954a
commit
d09cb323cd
@ -24,14 +24,27 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdatomic.h>
|
||||
#include <pthread.h>
|
||||
#include "ucp_utility.h"
|
||||
#include "ucp_printf.h"
|
||||
#include "drv_init.h"
|
||||
|
||||
//#include "ospShell.h"
|
||||
|
||||
uint8_t* virMemAddr = NULL;
|
||||
uint32_t gTagStatus = 0;
|
||||
pthread_spinlock_t gLockArmCsu;
|
||||
#if 0
|
||||
void arm_csu_show()
|
||||
{
|
||||
USHELL_PRINT("%d", gTagStatus);
|
||||
}
|
||||
#endif
|
||||
|
||||
int arm_csu_init()
|
||||
{
|
||||
pthread_spin_init((pthread_spinlock_t *)&gLockArmCsu,PTHREAD_PROCESS_PRIVATE);//PTHREAD_PROCESS_SHARED
|
||||
|
||||
if (-1 == g_drv_mem_fd0)
|
||||
{
|
||||
// printf("open dev mem. \r\n");
|
||||
@ -73,6 +86,8 @@ int arm_csu_init()
|
||||
*((volatile uint32_t*)(virMemAddr+AP_CSU_TAGMASK2)) = 0xFFFFFFFF;
|
||||
*((volatile uint32_t*)(virMemAddr+AP_CSU_TAGMASK3)) = 0xFFFFFFFF;
|
||||
|
||||
//osp_insert_cmd("sc", (OSP_FUNCPTR)arm_csu_show, "arm insert test", 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -100,24 +115,27 @@ int arm_csu_wait_done(uint8_t tag)
|
||||
while (1)
|
||||
{
|
||||
status = VIR_ADDR_VAL(virMemAddr, AP_CSU_DMASTATUS);
|
||||
// printf("tag = %d, dmastatus = 0x%x. \r\n", tag, status);
|
||||
if (0 != (status&(1<<tag)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
// while (0 == (VIR_ADDR_VAL(virMemAddr, AP_CSU_DMASTATUS) & (1<<tag)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int arm_csu_wait_all_done(void)
|
||||
{
|
||||
#if 0
|
||||
for (int i = 0; i < 32; i++)
|
||||
volatile uint32_t status = 0;
|
||||
while (1)
|
||||
{
|
||||
arm_csu_wait_done(i);
|
||||
status = VIR_ADDR_VAL(virMemAddr, AP_CSU_DMASTATUS);
|
||||
if (0xFFFFFFFF == status)
|
||||
{
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#if 0
|
||||
while (1)
|
||||
{
|
||||
int cmdNum = 0;
|
||||
@ -125,11 +143,12 @@ int arm_csu_wait_all_done(void)
|
||||
{
|
||||
cmdNum += VIR_ADDR_VAL(virMemAddr, AP_CSU_CMDFIFO0_NUM+(i<<2));
|
||||
}
|
||||
if (0 == cmdNum)
|
||||
if (0 == cmdNum) // 命令字个数为0,也说明搬完了
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -176,33 +195,36 @@ int get_free_reg_group(uint8_t tag)
|
||||
|
||||
int get_free_channel()
|
||||
{
|
||||
pthread_spin_lock((pthread_spinlock_t *)&gLockArmCsu);
|
||||
while (1)
|
||||
{
|
||||
for (int tag = 0; tag < 32; tag++)
|
||||
for(int tag = 0; tag < 8; tag++)
|
||||
{
|
||||
if (0 == (VIR_ADDR_VAL(virMemAddr, AP_CSU_DMASTATUS) & (1<<tag)))
|
||||
if((1 << tag) == (VIR_ADDR_VAL(virMemAddr, AP_CSU_DMASTATUS) & (1 << tag)))
|
||||
{
|
||||
if((1 << tag) & gTagStatus)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t temp = get_free_reg_group(tag);
|
||||
if (-1 == temp)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t regGroup = temp & 0xFF;
|
||||
uint8_t fifoNum = (temp>>16) & 0xFF;
|
||||
gTagStatus |= (1 << tag) ; //置上tag使用中
|
||||
uint8_t regGroup = tag;
|
||||
uint8_t fifoNum = tag & 0x3;
|
||||
int ret = regGroup | (fifoNum<<8) | (tag<<16);
|
||||
pthread_spin_unlock((pthread_spinlock_t *)&gLockArmCsu);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int arm_csu_dma_1D_transfer(uint64_t addrSrc, uint64_t addrDst, uint32_t dataLen)
|
||||
{
|
||||
uint8_t regGroup = 0;
|
||||
@ -234,8 +256,12 @@ int arm_csu_dma_1D_transfer(uint64_t addrSrc, uint64_t addrDst, uint32_t dataLen
|
||||
//(uint32_t)(VIR_ADDR_VAL(virMemAddr, AP_CSU_CMDFIFO0+(fifoNum<<2))) = (uint32_t)(*((uint32_t*)(&dmaCmdL)));
|
||||
memcpy((uint32_t*)(virMemAddr+AP_CSU_CMDFIFO0+(fifoNum<<2)), (uint32_t*)(&dmaCmdL), 4);
|
||||
|
||||
//atomic_fetch_and(&gTagStatus, (~(1<<tag)));
|
||||
pthread_spin_lock((pthread_spinlock_t *)&gLockArmCsu);
|
||||
gTagStatus &= (~(1<<tag));
|
||||
pthread_spin_unlock((pthread_spinlock_t *)&gLockArmCsu);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user