u32 bsp_om_send_coder_src(u8 *send_data_virt, u32 send_len) { SOCP_BUFFER_RW_STRU bd_buf = {0}; u32 ulBDNum; SOCP_BD_DATA_STRU *p_bd_data; u32 send_data_phy = 0; u32 ret; osl_sem_down(&socp_opt_sem); /* 将用户虚拟地址转换成物理地址*/ send_data_phy = bsp_om_virt_phy((u32)send_data_virt); bsp_socp_get_write_buff(g_bsp_om_socp_chan_info.en_src_chan_id, &bd_buf); /* 计算空闲BD的值 */ ulBDNum = (bd_buf.u32Size + bd_buf.u32RbSize) / sizeof(SOCP_BD_DATA_STRU); /* 判断是否还有空间 */ if (1 >= ulBDNum) { bsp_om_debug(BSP_LOG_LEVEL_ERROR," get BD fail,ulBDNum = %d\n",ulBDNum); ret = BSP_ERR_OMS_SOCP_GET_BD_NUM_ERR; goto fail; } /*SOCP给出是虚拟地址*/ if(NULL == bd_buf.pBuffer ) { bsp_om_debug(BSP_LOG_LEVEL_ERROR," get BD fail,pBuffer = NULL \n"); ret = BSP_ERR_OMS_SOCP_BD_ADDR_ERR; goto fail; } p_bd_data = (SOCP_BD_DATA_STRU *)(bd_buf.pBuffer); p_bd_data->pucData = send_data_phy; p_bd_data->usMsgLen = (BSP_U16)send_len; p_bd_data->enDataType = SOCP_BD_DATA; (void)cacheFlush(DATA_CACHE, bd_buf.pBuffer, sizeof(SOCP_BD_DATA_STRU)); ret = (u32)bsp_socp_write_done(g_bsp_om_socp_chan_info.en_src_chan_id, sizeof(SOCP_BD_DATA_STRU)) ; /* 当前数据写入完毕 */ if(ret != BSP_OK) { goto fail; } else { goto successful; } fail: osl_sem_up(&socp_opt_sem); return ret; successful: osl_sem_up(&socp_opt_sem); return BSP_OK; }
u32 bsp_om_socp_chan_init(void) { SOCP_CODER_SRC_CHAN_STRU channle_stu = {0}; /*编码源通道buf初始化*/ /* 申请BD空间 */ g_bsp_om_socp_chan_info.bd_buf = bsp_om_alloc(BSP_OM_CODER_SRC_BDSIZE,&(g_bsp_om_socp_chan_info.bd_buf_phy)); if(( 0== g_bsp_om_socp_chan_info.bd_buf)||(0 == g_bsp_om_socp_chan_info.bd_buf_phy )) { bsp_om_debug(BSP_LOG_LEVEL_ERROR," alloc BD fail\n"); return BSP_ERR_OMS_MALLOC_FAIL; } /* 申请RD空间 */ g_bsp_om_socp_chan_info.rd_buf = bsp_om_alloc(BSP_OM_CODER_SRC_RDSIZE,&(g_bsp_om_socp_chan_info.rd_buf_phy)); if(( 0== g_bsp_om_socp_chan_info.rd_buf)||(0 == g_bsp_om_socp_chan_info.rd_buf_phy )) { bsp_om_debug(BSP_LOG_LEVEL_ERROR," alloc RD fail\n"); return BSP_ERR_OMS_MALLOC_FAIL; } channle_stu.u32DestChanID = (u32)g_bsp_om_socp_chan_info.en_dst_chan_id; /* 目标通道ID */ channle_stu.eDataType = g_bsp_om_socp_chan_info.en_data_type; /* 数据类型,指明数据封装协议,用于复用多平台 */ channle_stu.eMode = g_bsp_om_socp_chan_info.en_chan_mode; /* 通道数据模式 */ channle_stu.ePriority = g_bsp_om_socp_chan_info.en_chan_level; /* 通道优先级 */ channle_stu.u32BypassEn = SOCP_HDLC_ENABLE; /* 通道bypass使能 */ channle_stu.eDataTypeEn = SOCP_DATA_TYPE_EN; /* 数据类型使能位 */ channle_stu.eDebugEn = SOCP_ENC_DEBUG_DIS; /* 调试位使能 */ channle_stu.sCoderSetSrcBuf.u32InputStart = (u32)g_bsp_om_socp_chan_info.bd_buf_phy; /* 输入通道起始地址 */ channle_stu.sCoderSetSrcBuf.u32InputEnd = (u32)((g_bsp_om_socp_chan_info.bd_buf_phy + g_bsp_om_socp_chan_info.bd_buf_len)-1); /* 输入通道结束地址 */ channle_stu.sCoderSetSrcBuf.u32RDStart = (u32)(g_bsp_om_socp_chan_info.rd_buf_phy); /* RD buffer起始地址 */ channle_stu.sCoderSetSrcBuf.u32RDEnd = (u32)((g_bsp_om_socp_chan_info.rd_buf_phy + g_bsp_om_socp_chan_info.rd_buf_len)-1); /* RD buffer结束地址 */ channle_stu.sCoderSetSrcBuf.u32RDThreshold = 0; /* RD buffer数据上报阈值 */ if (BSP_OK != bsp_socp_coder_set_src_chan(g_bsp_om_socp_chan_info.en_src_chan_id, &channle_stu)) { bsp_om_debug(BSP_LOG_LEVEL_ERROR,"DRV_SOCP_CORDER_SET_SRC_CHAN fail\n"); return BSP_ERR_OMS_SOCP_INIT_ERR; } /*初始化SOCP通道操作的信号量 */ osl_sem_init(SEM_FULL,&socp_opt_sem); /*通道使能操作在目的通道初始化完成之后进行*/ g_bsp_om_socp_chan_info.init_state= BSP_OM_SOCP_CHAN_INIT_SUCC; return BSP_OK; }
void bsp_sysview_debug_show(void) { bsp_om_debug(BSP_LOG_LEVEL_FATAL, "task_info_swt =%d\n",task_info_stru.report_swt); bsp_om_debug(BSP_LOG_LEVEL_FATAL, "task_cb_call_times =%d\n",g_sysview_debug[BSP_SYSVIEW_TASK_INFO].cb_call_times); bsp_om_debug(BSP_LOG_LEVEL_FATAL, "task_timeout_times =%d\n",g_sysview_debug[BSP_SYSVIEW_TASK_INFO].timeout_times); bsp_om_debug(BSP_LOG_LEVEL_FATAL, "task_info_send_times =%d\n",g_sysview_debug[BSP_SYSVIEW_TASK_INFO].info_send_times); bsp_om_debug(BSP_LOG_LEVEL_FATAL, "task_info_send_size = %d\n",g_sysview_debug[BSP_SYSVIEW_TASK_INFO].info_send_size); bsp_om_debug(BSP_LOG_LEVEL_FATAL, "intlock_info_swt =%d\n",int_lock_stru.report_swt); bsp_om_debug(BSP_LOG_LEVEL_FATAL, "intlock_cb_call_times =%d\n",g_sysview_debug[BSP_SYSVIEW_INT_LOCK_INFO].cb_call_times); bsp_om_debug(BSP_LOG_LEVEL_FATAL, "intlock_timeout_times =%d\n",g_sysview_debug[BSP_SYSVIEW_INT_LOCK_INFO].timeout_times); bsp_om_debug(BSP_LOG_LEVEL_FATAL, "intlock_info_send_times =%d\n",g_sysview_debug[BSP_SYSVIEW_INT_LOCK_INFO].info_send_times); bsp_om_debug(BSP_LOG_LEVEL_FATAL, "intlock_info_send_size =%d\n",g_sysview_debug[BSP_SYSVIEW_INT_LOCK_INFO].info_send_size); }
s32 bsp_om_server_init(void) { u32 ret = 0, taskid = 0; /* 初始化 BSP OM SOCP 源缓存buf*/ ret = bsp_om_buf_init(); if(BSP_OK != ret) { bsp_om_debug(BSP_LOG_LEVEL_ERROR, "&&&&&&&&bsp_om_buf_init error!!!ret = 0x%x\n",ret); return (s32)ret; } /* 初始化 BSP使用的SOCP源通道*/ ret = bsp_om_socp_chan_init(); if(BSP_OK !=ret ) { bsp_om_debug(BSP_LOG_LEVEL_ERROR, "bsp_om_server_init error!!!ret = 0x%x\n",ret); return (s32)ret; } /*初始化om模块全局信息*/ bsp_om_global_init(); /* 初始化log打印级别为default值*/ bsp_log_level_reset(); bsp_dump_init(); bsp_utrace_init(); #ifdef ENABLE_BUILD_SYSVIEW /* 初始化sysview全局数据*/ ret = sys_view_init(); if(BSP_OK != ret) { bsp_om_debug(BSP_LOG_LEVEL_ERROR, "&&&&&&&&&&&sys_view_init error!!!ret = 0x%x\n",ret); return (s32)ret; } #endif osl_task_init("tCcpuOmTask", 50, 0x2000, bsp_om_send_task, 0, &taskid); /*lint -save -e18*/ printf(" bsp om init ok\n"); /*lint -restore +e18*/ return BSP_OK; }
u32 bsp_sysview_swt_set(bsp_sysview_type_e set_type,u32 set_swt,u32 period) { u32 ret = BSP_OK; bsp_om_debug(BSP_LOG_LEVEL_DEBUG,"set_type = %d,set_swt = %d,period = %d\n",set_type,set_swt,period); switch(set_type) { case BSP_SYSVIEW_MEM_TRACE: ret = bsp_mem_swt_set(set_swt,period); break; case BSP_SYSVIEW_CPU_INFO: ret = bsp_cpu_swt_set(set_swt,period); break; case BSP_SYSVIEW_TASK_INFO: ret = bsp_task_swt_set(set_swt,period); break; case BSP_SYSVIEW_INT_LOCK_INFO: ret = bsp_int_lock_set(set_swt,period); break; default: ret = BSP_ERR_SYSVIEW_INVALID_PARAM; break; } return ret; }
/***************************************************************************** * 函 数 名 : bsp_om_server_init * * 功能描述 : om初始化总入口 * * 输入参数 :无 * * * 输出参数 :无 * * 返 回 值 :BSP_OK 初始化成功;其他 初始化失败 *****************************************************************************/ s32 bsp_om_server_init(void) { u32 ret ; spin_lock_init(&g_st_buf_lock); spin_lock_init(&g_st_control_lock); /* 初始化 BSP OM SOCP 源缓存buf*/ ret = bsp_om_buf_init(); if(BSP_OK != ret) { bsp_om_debug(BSP_LOG_LEVEL_ERROR, "&&&&&&&&bsp_om_buf_init error!!!ret = 0x%x\n",ret); return (s32)ret; } /* 初始化 BSP使用的SOCP源通道*/ ret = bsp_om_socp_chan_init(); if(BSP_OK !=ret ) { bsp_om_debug(BSP_LOG_LEVEL_ERROR, "bsp_om_server_init error!!!ret = 0x%x\n",ret); return (s32)ret; } /*初始化om模块全局信息*/ bsp_om_global_init(); /* 初始化log打印级别为default值*/ bsp_log_level_reset(); #ifdef ENABLE_BUILD_SYSVIEW /* 初始化sysview全局数据*/ ret = sys_view_init(); if(BSP_OK != ret) { bsp_om_debug(BSP_LOG_LEVEL_ERROR, "&&&&&&&&&sys_view_init error!!!ret = 0x%x\n",ret); return (s32)ret; } #endif kthread_run(bsp_om_send_task, NULL, "tAcpuOmTask"); bsp_om_debug(BSP_LOG_LEVEL_ERROR, "bsp om init ok\n"); return BSP_OK; }
u32 bsp_log_module_cfg_set(bsp_log_swt_cfg_s *log_swt_stru ,u32 data_len) { u32 mod_num = 0; u32 i; if((NULL == log_swt_stru )||( 0 == data_len)||((data_len % sizeof(bsp_log_swt_cfg_s) != 0))) { bsp_om_debug(BSP_LOG_LEVEL_ERROR," bsp_log_module_cfg_set error!! data_len = %d\n",data_len); return BSP_ERR_LOG_INVALID_PARAM; } mod_num = data_len / sizeof(bsp_log_swt_cfg_s); if(mod_num > BSP_MODU_MAX ) { bsp_om_debug(BSP_LOG_LEVEL_ERROR," bsp_log_module_cfg_set error!! mod_num = %d\n",mod_num); return BSP_ERR_LOG_INVALID_MODULE; } for(i = 0; i < mod_num; i++) { if(log_swt_stru[i].print_level <= BSP_LOG_LEVEL_MAX) { g_mod_peint_level_info[i].print_level = log_swt_stru[i].print_level; } else { bsp_om_debug(BSP_LOG_LEVEL_ERROR," bsp_log_module_cfg_set log_swt_stru[i].print_level = %d\n",log_swt_stru[i].print_level); return BSP_ERR_LOG_INVALID_LEVEL ; } } return BSP_OK; }
int bsp_om_stop_timer(struct softtimer_list *timer) { int ret = BSP_OK; if( timer->init_flags == TIMER_INIT_FLAG) { ret = bsp_softtimer_delete_sync(timer); if(ret < 0) { bsp_om_debug(BSP_LOG_LEVEL_ERROR, "bsp om stop timer fail \n"); return ret; } } return BSP_OK; }
* 函 数 名 : bsp_om_clean_rd * * 功能描述 :清理RD缓存和OM buf缓存 * * 输入参数 :无 * * * 输出参数 :无 * * 返 回 值 : BSP_OK 成功; 其他 失败 *****************************************************************************/ u32 bsp_om_clean_rd(void) { u32 i; u32 ret = BSP_OK; SOCP_BUFFER_RW_STRU rd_buf = {0}; SOCP_RD_DATA_STRU rd_data = {0}; ret = bsp_om_socp_clean_rd_buf(g_bsp_om_socp_chan_info.en_src_chan_id,&rd_buf); if((NULL != rd_buf.pBuffer)&&(ret == BSP_OK)) { bsp_om_buf_sem_take(); for(i = 0;i < (rd_buf.u32Size /sizeof(SOCP_RD_DATA_STRU));i++) { memcpy((void *)&rd_data,(void *)(rd_buf.pBuffer),sizeof(SOCP_RD_DATA_STRU)); rd_data.pucData = bsp_om_phy_virt((u32)(rd_data.pucData)); ret = bsp_om_free_buf((u32)(rd_data.pucData),(u32)(rd_data.usMsgLen)&0xffff); if(ret != BSP_OK) { bsp_om_debug(BSP_LOG_LEVEL_ERROR,"free om buf error, stop socp coder chan\n"); bsp_socp_stop(g_bsp_om_socp_chan_info.en_src_chan_id); bsp_om_buf_sem_give(); return ret; } rd_buf.pBuffer = rd_buf.pBuffer +sizeof(SOCP_RD_DATA_STRU); } bsp_om_buf_sem_give(); } else { return ret; } return BSP_OK; }
* 函 数 名 : bsp_om_free_buf * * 功能描述 :释放缓存buf * * 输入参数 :buf_addr :释放缓存地址 * len : 需要释放的地址 * * 输出参数 :无 * * 返 回 值 : BSP_OK 释放成功;其他 释放失败 *****************************************************************************/ u32 bsp_om_free_buf(u32 buf_addr,u32 len) { u32 buf_type = 0; u32 read_ptr ,write_ptr ,buf_len , start_ptr ,last_pading_len,end_ptr = 0; for(buf_type = 0;buf_type < BSP_OM_BUF_NUM;buf_type++) { if((buf_addr>= g_bsp_om_socp_buf_info[buf_type].start_ptr) &&( buf_addr < (g_bsp_om_socp_buf_info[buf_type].start_ptr + g_bsp_om_socp_buf_info[buf_type].buf_len))) { break; } } if(buf_type == BSP_OM_BUF_NUM) { return BSP_ERR_OMS_INVALID_PARAM; } /*LOG BUF 单独处理*/ if(buf_type == BSP_OM_LOG_BUF_TYPE) { return bsp_om_free_log_buf(buf_addr,len); } read_ptr = g_bsp_om_socp_buf_info[buf_type].read_ptr; write_ptr = g_bsp_om_socp_buf_info[buf_type].write_ptr; buf_len = g_bsp_om_socp_buf_info[buf_type].buf_len; start_ptr = g_bsp_om_socp_buf_info[buf_type].start_ptr; last_pading_len = g_bsp_om_socp_buf_info[buf_type].last_pading_len; end_ptr = start_ptr + buf_len; /*顺序申请和释放的情况*/ if((buf_addr == read_ptr )||( buf_addr == start_ptr)) { if((read_ptr + last_pading_len + len) < end_ptr) { g_bsp_om_socp_buf_info[buf_type].read_ptr = read_ptr + len; } else if((read_ptr + last_pading_len + len) >end_ptr) { g_bsp_om_socp_buf_info[buf_type].read_ptr = start_ptr + len; g_bsp_om_socp_buf_info[buf_type].last_pading_len = 0; } else { g_bsp_om_socp_buf_info[buf_type].read_ptr = start_ptr ; g_bsp_om_socp_buf_info[buf_type].last_pading_len = 0; } } /*申请之后组包发送错误,直接释放的情况*/ else if(buf_addr == (write_ptr- len)) { g_bsp_om_socp_buf_info[buf_type].write_ptr = buf_addr; g_bsp_om_socp_buf_info[buf_type].buf_size -= len; } else if(( buf_addr + last_pading_len + len) == end_ptr) { g_bsp_om_socp_buf_info[buf_type].write_ptr = buf_addr; g_bsp_om_socp_buf_info[buf_type].buf_size -= len; g_bsp_om_socp_buf_info[buf_type].last_pading_len = 0; } /*异常buf*/ else { bsp_om_debug(BSP_LOG_LEVEL_ERROR, " bsp om invalid buf 0x%x, read_ptr = 0x%x,write_ptr = 0x%x",buf_addr,read_ptr,write_ptr); } return BSP_OK; }
void show_list_debug(void) { bsp_om_debug(BSP_LOG_LEVEL_ERROR, " list_in = 0x%x\n",g_list_debug.list_in); bsp_om_debug(BSP_LOG_LEVEL_ERROR, " list_get = 0x%x\n",g_list_debug.list_get); bsp_om_debug(BSP_LOG_LEVEL_ERROR, " list_del = 0x%x\n",g_list_debug.list_del); }
/*lint -save -e830 -e525 -e539*/ u32 report_cpu_trace(void) { u32 task_num = 0; BSP_CPU_TRACE_STRU *p_cpu_trace_stru = NULL; BSP_TASK_CPU_TRACE_STRU *p_cpu_trace_data = NULL; u32 buf_len = 0; u32 task_slices = 0; buf_len = sizeof(BSP_CPU_TRACE_STRU) + sizeof(BSP_TASK_CPU_TRACE_STRU)*g_task_num; if(cpu_info_stru.report_swt == BSP_SYSVIEW_SWT_ON) { if(bsp_om_buf_sem_take()) { return BSP_ERR_SYSVIEW_FAIL; } p_cpu_trace_stru = (BSP_CPU_TRACE_STRU *)bsp_om_get_buf(BSP_OM_SOCP_BUF_TYPE,buf_len); if(NULL == p_cpu_trace_stru) { bsp_om_buf_sem_give(); return BSP_ERR_SYSVIEW_MALLOC_FAIL; } } else { p_cpu_trace_stru = (BSP_CPU_TRACE_STRU *)osl_malloc(buf_len); if(NULL == p_cpu_trace_stru) { return BSP_ERR_SYSVIEW_MALLOC_FAIL; } } #ifdef ENABLE_BUILD_SYSVIEW sysview_trace_packet((u8*)p_cpu_trace_stru,buf_len,BSP_SYSVIEW_CPU_INFO); #endif p_cpu_trace_data = p_cpu_trace_stru->cpu_info_stru; for(task_num =0;task_num < g_task_num; task_num++) { p_cpu_trace_data[task_num].task_id = (u32)vxworks_tid_list[task_num]; strncpy( (char *)(p_cpu_trace_data[task_num].task_name), (char *)(g_om_cpu_trace[task_num].task_name), BSP_SYSVIEW_TASK_NAME_LEN); p_cpu_trace_data[task_num].task_name[BSP_SYSVIEW_TASK_NAME_LEN-1] = '\0'; task_slices =g_om_cpu_trace[task_num].slices - g_om_cpu_trace[task_num].cmdslice; p_cpu_trace_data[task_num].interval_slice = task_slices; if(cpu_info_stru.report_swt == BSP_SYSVIEW_SWT_OFF) { if(task_slices != 0) { bsp_om_debug(BSP_LOG_LEVEL_INFO, "taskid:0x%x, %-11s, rate = %d% \n" ,p_cpu_trace_data[task_num].task_id,p_cpu_trace_data[task_num].task_name ,(task_slices *100)/g_cpu_task_taet); } } } if(cpu_info_stru.report_swt == BSP_SYSVIEW_SWT_ON) { if( BSP_OK != bsp_om_into_send_list((u32)p_cpu_trace_stru,buf_len)) { bsp_om_free_buf((u32)p_cpu_trace_stru,buf_len ); bsp_om_buf_sem_give(); return BSP_ERR_SYSVIEW_FAIL; } bsp_om_buf_sem_give(); } else { osl_free(p_cpu_trace_stru); } return BSP_OK; }
u32 bsp_om_send_coder_src(u8 *send_data_virt, u32 send_len) { SOCP_BUFFER_RW_STRU bd_buf = {0}; u32 ulBDNum; SOCP_BD_DATA_STRU bd_data = {0}; u32 send_data_phy = 0; u32 ret; osl_sem_down(&socp_opt_sem); /* 将用户虚拟地址转换成物理地址*/ send_data_phy = bsp_om_virt_phy((void *)send_data_virt); if(send_data_phy == 0) { ret = BSP_ERR_OMS_INVALID_PARAM; goto fail; } bsp_socp_get_write_buff(g_bsp_om_socp_chan_info.en_src_chan_id, &bd_buf); /* 计算空闲BD的值 */ ulBDNum = (bd_buf.u32Size + bd_buf.u32RbSize)/ sizeof(SOCP_BD_DATA_STRU); /* 判断是否还有空间 */ if (1 >= ulBDNum) { bsp_om_debug(BSP_LOG_LEVEL_ERROR," GET BD fail,ulBDNum = %d\n",ulBDNum); ret = BSP_ERR_OMS_SOCP_GET_BD_NUM_ERR; goto fail; } /*SOCP给出的是物理地址*/ if(NULL == bd_buf.pBuffer ) { bsp_om_debug(BSP_LOG_LEVEL_ERROR," GET BD fail,pBuffer = NULL \n"); ret = BSP_ERR_OMS_SOCP_BD_ADDR_ERR; goto fail; } bd_data.pucData = send_data_phy; bd_data.usMsgLen = (BSP_U16)send_len; bd_data.enDataType = SOCP_BD_DATA; memcpy((void *)bsp_om_phy_virt(((uintptr_t)bd_buf.pBuffer)),(void*)&bd_data,sizeof(SOCP_BD_DATA_STRU)); /*lint -save -e713*/ dma_map_single(NULL, (void*)bsp_om_phy_virt(((uintptr_t)bd_buf.pBuffer)), sizeof(SOCP_BD_DATA_STRU), DMA_TO_DEVICE); dma_map_single(NULL, (void *)(send_data_virt), send_len, DMA_TO_DEVICE); /*lint -restore*/ ret = (u32)bsp_socp_write_done(g_bsp_om_socp_chan_info.en_src_chan_id, sizeof(SOCP_BD_DATA_STRU)) ; /* 当前数据写入完毕 */ if(ret != BSP_OK) { goto fail; } else { ret = BSP_OK; goto successful; } fail: osl_sem_up(&socp_opt_sem); return ret; successful: osl_sem_up(&socp_opt_sem); return ret; }