Fix iomem

fix_cache
xiangbingj 2019-10-23 13:58:51 +08:00
parent cc71e9e673
commit 20bdb540bc
8 changed files with 42 additions and 73 deletions

View File

@ -36,7 +36,7 @@ class k_dmac_driver : public dmac_driver, public static_object, public free_obje
{
public:
k_dmac_driver(uintptr_t base_addr)
: dmac_(*reinterpret_cast<volatile dmac_t *>(base_addr)), axi_master1_use_(0), axi_master2_use_(0)
: dmac_(*reinterpret_cast<volatile dmac_t *>(base_addr))
{
}
@ -81,31 +81,6 @@ public:
writeq(dmac_cfg.data, &dmac_.cfg);
}
uint32_t add_lru_axi_master()
{
uint32_t axi1 = atomic_read(&axi_master1_use_);
uint32_t axi2 = atomic_read(&axi_master2_use_);
if (axi1 < axi2)
{
atomic_add(&axi_master1_use_, 1);
return 0;
}
else
{
atomic_add(&axi_master2_use_, 1);
return 1;
}
}
void release_axi_master(uint32_t axi)
{
if (axi == 0)
atomic_add(&axi_master1_use_, -1);
else
atomic_add(&axi_master2_use_, -1);
}
volatile dmac_t &dmac()
{
return dmac_;
@ -113,8 +88,6 @@ public:
private:
volatile dmac_t &dmac_;
int32_t axi_master1_use_;
int32_t axi_master2_use_;
};
static k_dmac_driver dev0_driver(DMAC_BASE_ADDR);
@ -412,9 +385,6 @@ public:
ctl_u.ch_ctl.dst_tr_width = tr_width;
ctl_u.ch_ctl.dst_msize = msize;
uint32_t axi_master = dmac_.add_lru_axi_master();
session_.axi_master = axi_master;
ctl_u.ch_ctl.sms = DMAC_MASTER1;
ctl_u.ch_ctl.dms = DMAC_MASTER2;
@ -544,9 +514,6 @@ public:
ctl_u.ch_ctl.dst_tr_width = tr_width;
ctl_u.ch_ctl.dst_msize = msize;
uint32_t axi_master = dmac_.add_lru_axi_master();
session_.axi_master = axi_master;
ctl_u.ch_ctl.sms = DMAC_MASTER1;
ctl_u.ch_ctl.dms = DMAC_MASTER2;
@ -587,7 +554,6 @@ private:
{
if (atomic_read(driver.session_.stop_signal))
{
driver.dmac_.release_axi_master(driver.session_.axi_master);
if (driver.session_.stage_completion_handler)
driver.session_.stage_completion_handler(driver.session_.stage_completion_handler_data);
xSemaphoreGiveFromISR(driver.session_.completion_event, &xHigherPriorityTaskWoken);
@ -613,8 +579,6 @@ private:
}
else
{
driver.dmac_.release_axi_master(driver.session_.axi_master);
if (driver.session_.flow_control != DMAC_MEM2MEM_DMA && driver.session_.element_size < 4)
{
if (driver.session_.flow_control == DMAC_PRF2MEM_DMA)
@ -670,15 +634,6 @@ private:
driver.session_.ctx->flag ++;
xSemaphoreGiveFromISR(driver.session_.completion_event, &xHigherPriorityTaskWoken);
driver.session_.ctx->flag ++;
//driver.session_.completion_event = NULL;
//driver.session_.axi_master = 0;
//driver.session_.is_loop = 0;
//driver.session_.flow_control = DMAC_MEM2MEM_DMA;
//driver.session_.element_size = 0;
//driver.session_.count = 0;
//driver.session_.alloc_mem = NULL;
//driver.session_.dest = NULL;
}
if (xHigherPriorityTaskWoken)
@ -702,7 +657,6 @@ private:
struct
{
SemaphoreHandle_t completion_event;
uint32_t axi_master;
int is_loop;
union {
struct

View File

@ -137,7 +137,9 @@ public:
virtual void set_output_attributes(uint32_t index, video_format_t format, void *output_buffer) override
{
configASSERT(index < 2);
#if FIX_CACHE
configASSERT(!is_memory_cache((uintptr_t)output_buffer));
#endif
if (index == 0)
{
configASSERT(format == VIDEO_FMT_RGB24_PLANAR);

View File

@ -176,6 +176,11 @@ public:
{
if(xSemaphoreTake(completion_event_, 200) == pdTRUE)
{
if(mem_out_flag_)
{
memcpy(dest_kpu_, dest_io_, dest_len_);
mem_out_flag_ = 0;
}
if (ctx_.current_layer != ctx_.layers_length)
{
while(ai_step() == 1)
@ -808,7 +813,7 @@ private:
if (arg->flags & KLF_MAIN_MEM_OUT)
{
uint8_t *dest = ctx_.main_buffer + arg->main_mem_out_address;
mem_out_flag_ = 1;
kpu_.interrupt_clear.reg = 0b111;
kpu_.interrupt_mask.reg = 0b111;
layer.dma_parameter.data.send_data_out = 1;
@ -819,9 +824,17 @@ private:
printk("kpu output: dma=%d \n", context_.channel);
#endif
//int len = (layer.dma_parameter.data.dma_total_byte + 8) / 8 * sizeof(uint64_t);
//uint8_t *dest_io = (uint8_t *)iomem_malloc(len);
dma_transmit_async(dma_ch_, (void *)(&kpu_.fifo_data_out), (void *)dest, 0, 1, sizeof(uint64_t), (layer.dma_parameter.data.dma_total_byte + 8) / 8, 8, completion_event_);
dest_len_ = (layer.dma_parameter.data.dma_total_byte + 8) / 8 * sizeof(uint64_t);
dest_kpu_ = ctx_.main_buffer + arg->main_mem_out_address;
if(dest_len_ > max_len_)
{
max_len_ = dest_len_;
iomem_free(dest_io_);
dest_io_ = (uint8_t *)iomem_malloc(dest_len_);
}
dma_transmit_async(dma_ch_, (void *)(&kpu_.fifo_data_out), (void *)dest_io_, 0, 1, sizeof(uint64_t), (layer.dma_parameter.data.dma_total_byte + 8) / 8, 8, completion_event_);
}
else
{
@ -937,7 +950,6 @@ private:
kpu_.interrupt_clear.reg = 0b111;
kpu_.interrupt_mask.reg = 0b111;
#if KPU_DEBUG
uint32_t cnt_layer_id = ctx_.current_layer - 1;
gettimeofday(&time_, NULL);
@ -1057,6 +1069,11 @@ private:
uint8_t done_flag_ = 0;
kpu_model_context_t ctx_;
test_context_t context_;
uint8_t *dest_kpu_;
uint8_t *dest_io_;
size_t dest_len_;
size_t max_len_;
uint8_t mem_out_flag_;
#if KPU_DEBUG
struct timeval time_;
struct timeval last_time_;

View File

@ -103,20 +103,21 @@ static uint32_t k_malloc(uint32_t size)
for(offset=malloc_cortol.memtblsize-1; offset>=0; offset--)
{
if(!malloc_cortol.memmap[offset])
{
kmemb++;
}
else
{
offset = offset - malloc_cortol.memmap[offset] + 1;
kmemb=0;
}
if(kmemb==xmemb)
{
for(i=0; i<xmemb; i++)
{
malloc_cortol.memmap[offset+i] = xmemb;
}
malloc_cortol.memmap[offset] = xmemb;
malloc_cortol.memmap[offset+xmemb-1] = xmemb;
return (offset * IOMEM_BLOCK_SIZE);
}
}
return 0XFFFFFFFF;
}
@ -127,22 +128,19 @@ static uint8_t k_free(uint32_t offset)
{
malloc_cortol.init();
return 1;
}
}
if(offset < malloc_cortol.memsize)
{
{
int index=offset / IOMEM_BLOCK_SIZE;
int nmemb=malloc_cortol.memmap[index];
for(i=0; i<nmemb; i++)
{
malloc_cortol.memmap[index+i] = 0;
}
malloc_cortol.memmap[index] = 0;
malloc_cortol.memmap[index+nmemb-1] = 0;
if((uintptr_t)_ioheap_line == (uintptr_t)malloc_cortol.membase + offset)
{
_ioheap_line = (char *)((uintptr_t)_ioheap_line + nmemb * IOMEM_BLOCK_SIZE);
}
return 0;
}
else

View File

@ -647,7 +647,6 @@ static void uart_putf(void* unused, char c)
int printk(const char* format, ...)
{
portENTER_CRITICAL();
va_list ap;
va_start(ap, format);
@ -657,7 +656,6 @@ int printk(const char* format, ...)
/* End protected code */
corelock_unlock(&lock);
va_end(ap);
portEXIT_CRITICAL();
return 0;
}

Binary file not shown.

View File

@ -290,9 +290,9 @@ void detect()
face_detect_rl.input = output;
region_layer_run(&face_detect_rl, &face_detect_info);
//for (uint32_t face_cnt = 0; face_cnt < face_detect_info.obj_number; face_cnt++) {
// draw_edge(lcd_gram, &face_detect_info, face_cnt, RED);
//}
for (uint32_t face_cnt = 0; face_cnt < face_detect_info.obj_number; face_cnt++) {
draw_edge(lcd_gram, &face_detect_info, face_cnt, RED);
}
#endif
if(face_detect_info.obj_number)
{