/* M2M sync_trans. do not need isr_func. wait for semaphore of the edma completion ---in acore or async_trans. wait untill the channel is not busy --- in c core */ s32 edmac_test_channel(enum edma_req_id req, u32 direction) { s32 ret_id = 0; u32 bur_width = 2; u32 bur_len = 3; u32 byte_len = EDMA_M2M_TEST_LENGHT; char *temp = NULL; s32 count = 0; if((NULL == src_buf) || (NULL == des_buf)) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"-----------edma test not inited \n\n"); return EDMA_FAIL; } temp = src_buf; while (count < EDMA_M2M_TEST_LENGHT) { *temp++ = 'a' + count%20; ++count; } src_buf[EDMA_M2M_TEST_LENGHT - 1]='\0'; temp = des_buf; count = 0; while (count < EDMA_M2M_TEST_LENGHT) { *temp++ = 'b' + count%20; ++count; } des_buf[EDMA_M2M_TEST_LENGHT - 1]='\0'; hiedmac_trace(BSP_LOG_LEVEL_DEBUG,"---src_buf =%c%c%c%c%c%c%c\n", *((char*)src_buf + 0), *((char*)src_buf + 1), *((char*)src_buf + 2), *((char*)src_buf + 3), *((char*)src_buf + 4), *((char*)src_buf + 5), *((char*)src_buf + 6)); hiedmac_trace(BSP_LOG_LEVEL_DEBUG,"---des_buf =%c%c%c%c%c%c%c\n", *((char*)des_buf + 0), *((char*)des_buf + 1), *((char*)des_buf + 2), *((char*)des_buf + 3), *((char*)des_buf + 4), *((char*)des_buf + 5), *((char*)des_buf + 6)); ret_id = bsp_edma_channel_init(req, NULL, 0, 0); if (ret_id < 0) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"----------error ret_id = 0x%X\n\n",ret_id); return EDMA_CHANNEL_INVALID; } /* set config reg */ if (bsp_edma_channel_set_config((u32)ret_id, direction, bur_width, bur_len)) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"----------bsp_edma_channel_set_config failed!\n\n"); bsp_edma_channel_free((u32)ret_id); return EDMA_CONFIG_ERROR; } if (bsp_edma_channel_start((u32)ret_id, (u32)edma_src_addr, (u32)edma_des_addr , byte_len)) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"----------bsp_edma_channel_start FAILED!\n\n"); bsp_edma_channel_free((u32)ret_id); return EDMA_TRXFER_ERROR; } while(0==bsp_edma_channel_is_idle((u32) ret_id)) {printf("a");} printf("\n"); bsp_edma_channel_free((u32)ret_id); if(edmac_verify_data_blk(src_buf,des_buf)) { return EDMA_TRXFER_ERROR; } hiedmac_trace(BSP_LOG_LEVEL_CRIT,"=============== EDMA_CHANNEL_START_SUCCESS !\n"); return EDMA_SUCCESS; }
/*异步EDMA传输,上层模块查询EDMA传输是否结束*/ s32 edmac_test_channel_async(enum edma_req_id req, u32 direction) { s32 ret_id = 0; u32 bur_width = 2; u32 bur_len = 3; u32 ask_is_idle_loop = 0; u32 byte_len = EDMA_M2M_TEST_LENGHT; char *temp = NULL; s32 count = 0; if ((NULL == src_buf) || (NULL == des_buf)) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"-----------edma test not inited \n\n"); return EDMA_FAIL; } temp = src_buf; while (count < EDMA_M2M_TEST_LENGHT) { *temp++ = 'a' + count%20; ++count; } src_buf[EDMA_M2M_TEST_LENGHT - 1]='\0'; temp = des_buf; count = 0; while (count < EDMA_M2M_TEST_LENGHT) { *temp++ = 'c' + count%20; ++count; } des_buf[EDMA_M2M_TEST_LENGHT - 1]='\0'; hiedmac_trace(BSP_LOG_LEVEL_DEBUG,"---src_buf =%c%c%c%c%c%c%c\n", *((char*)src_buf + 0), *((char*)src_buf + 1), *((char*)src_buf + 2), *((char*)src_buf + 3), *((char*)src_buf + 4), *((char*)src_buf + 5), *((char*)src_buf + 6)); hiedmac_trace(BSP_LOG_LEVEL_DEBUG,"---des_buf =%c%c%c%c%c%c%c\n", *((char*)des_buf + 0), *((char*)des_buf + 1), *((char*)des_buf + 2), *((char*)des_buf + 3), *((char*)des_buf + 4), *((char*)des_buf + 5), *((char*)des_buf + 6)); ret_id = bsp_edma_channel_init(req, NULL, 0, 0); if (ret_id < 0) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"-----------ERROE ret_id = 0x%X\n\n",ret_id); return EDMA_CHANNEL_INVALID; } /* set config reg */ if (bsp_edma_channel_set_config((u32)ret_id, direction, bur_width, bur_len)) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"----------bsp_edma_channel_set_config FAILED!\n\n"); bsp_edma_channel_free((u32)ret_id); return EDMA_CONFIG_ERROR; } /* ** */ cacheClear( DATA_CACHE, (void*)edma_src_addr, EDMA_M2M_TEST_LENGHT * sizeof(char*)); cacheClear( DATA_CACHE, (void*)edma_des_addr, EDMA_M2M_TEST_LENGHT * sizeof(char*)); if (bsp_edma_channel_async_start((u32)ret_id, (u32)edma_src_addr, (u32)edma_des_addr, byte_len)) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"----------bsp_edma_channel_async_start FAILED!\n\n"); bsp_edma_channel_free((u32)ret_id); return EDMA_CONFIG_ERROR; } while(0==bsp_edma_channel_is_idle((u32) ret_id)) {printf("a");} printf("\n"); bsp_edma_channel_free((u32)ret_id); for (;;) { hiedmac_trace(BSP_LOG_LEVEL_DEBUG,"---------------pool channel async start!"); if (!bsp_edma_channel_is_idle((u32)ret_id)) { ask_is_idle_loop++; /*ssleep(2);*/ if (ask_is_idle_loop < 0x100000) { continue; } else { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"----------edma_trans_complete is TIMEOUT!"); return EDMA_TRXFER_ERROR; } } else { hiedmac_trace(BSP_LOG_LEVEL_DEBUG,"edma_trans_complete-----ask_is_idle_loop=0x%X!\n\n",ask_is_idle_loop); if (edmac_verify_data_blk(src_buf,des_buf)) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"----------EDMA_CHANNEL_ASYNC_TEST_FAILED! verify \n\n"); return EDMA_TRXFER_ERROR; } hiedmac_trace(BSP_LOG_LEVEL_CRIT,"===============EDMA_CHANNEL_ASYNC_TEST_SUCCESS!\n"); return EDMA_SUCCESS; } } }
/*异步EDMA传输,上层模块注册中断处理程序,处理EDMA传输完成事件*/ s32 edmac_test_channel_async_int(enum edma_req_id req, u32 direction) { s32 ret_id = 0; u32 bur_width = 2; u32 bur_len = 3; u32 byte_len = EDMA_M2M_TEST_LENGHT; char *temp = NULL; s32 count = 0; s32 isr_task_id = 0; g_edma_test_sema= semBCreate(SEM_Q_FIFO, (SEM_B_STATE)SEM_EMPTY); if(NULL==g_edma_test_sema) { hiedmac_trace(BSP_LOG_LEVEL_ERROR, "semBCreate FAILED!"); } isr_task_id=taskSpawn ("print_trans_complete", 50, 0, 20000, (FUNCPTR)data_trans_complete, 0, 0, 0, 0,0, 0, 0, 0, 0, 0); if (0==isr_task_id) { hiedmac_trace(BSP_LOG_LEVEL_ERROR, "taskSpawn FAILED! "); return EDMA_FAIL; } if ((NULL == src_buf) || (NULL == des_buf)) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"-----------edma test not inited \n\n"); return EDMA_FAIL; } temp = src_buf; while (count < EDMA_M2M_TEST_LENGHT) { *temp++ = 'a' + count%20; ++count; } src_buf[EDMA_M2M_TEST_LENGHT - 1]='\0'; temp = des_buf; count = 0; while (count < EDMA_M2M_TEST_LENGHT) { *temp++ = 'd' + count%20; ++count; } des_buf[EDMA_M2M_TEST_LENGHT - 1]='\0'; hiedmac_trace(BSP_LOG_LEVEL_DEBUG,"---src_buf =%c%c%c%c%c%c%c\n", *((char*)src_buf + 0), *((char*)src_buf + 1), *((char*)src_buf + 2), *((char*)src_buf + 3), *((char*)src_buf + 4), *((char*)src_buf + 5), *((char*)src_buf + 6)); hiedmac_trace(BSP_LOG_LEVEL_DEBUG,"---des_buf =%c%c%c%c%c%c%c\n", *((char*)des_buf + 0), *((char*)des_buf + 1), *((char*)des_buf + 2), *((char*)des_buf + 3), *((char*)des_buf + 4), *((char*)des_buf + 5), *((char*)des_buf + 6)); ret_id= bsp_edma_channel_init(req, (channel_isr)edma_isr_sema_give, 0, EDMA_INT_DONE); /*是否要初始化中断回调函数 */ if (ret_id < 0) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"-----------ERROR ret_id = 0x%X\n\n",ret_id); return EDMA_CHANNEL_INVALID; } /* set config reg */ if (bsp_edma_channel_set_config((u32)ret_id, direction, bur_width, bur_len)) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"---------EDMA_CHANNEL_ASYNC_TEST_FAILED! config \n\n"); bsp_edma_channel_free((u32)ret_id); return EDMA_CONFIG_ERROR; } if (bsp_edma_channel_async_start((u32)ret_id, (u32)edma_src_addr, (u32)edma_des_addr, byte_len)) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"---------EDMA_CHANNEL_ASYNC_TEST_FAILED! start \n\n"); bsp_edma_channel_free((u32)ret_id); return EDMA_TRXFER_ERROR; } taskDelay(sysClkRateGet()*200/1000+1); bsp_edma_channel_free((u32)ret_id); if (edmac_verify_data_blk(src_buf,des_buf)) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"----------EDMA_CHANNEL_ASYNC_TEST_FAILED! verify \n\n"); return EDMA_TRXFER_ERROR; } hiedmac_trace(BSP_LOG_LEVEL_CRIT,"===============EDMA_CHANNEL_ASYNC_INIT_TEST_SUCCESS!\n"); return EDMA_SUCCESS; }
/* async trans , users regist the int_handler */ s32 edmac_test_channel_async_int(enum edma_req_id req, u32 direction) { s32 ret_id = 0; u32 bur_width = 2; u32 bur_len = 3; u32 byte_len = EDMA_M2M_TEST_LENGHT; char *temp = NULL; s32 count = 0; if ((NULL == src_buf) || (NULL == des_buf)) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"-----------edma test not inited \n\n"); return EDMA_FAIL; } temp = src_buf; while (count < EDMA_M2M_TEST_LENGHT) { *temp++ = 'a' + count%20; ++count; } src_buf[EDMA_M2M_TEST_LENGHT - 1]='\0'; temp = des_buf; count = 0; while (count < EDMA_M2M_TEST_LENGHT) { *temp++ = 'd' + count%20; ++count; } des_buf[EDMA_M2M_TEST_LENGHT - 1]='\0'; hiedmac_trace(BSP_LOG_LEVEL_DEBUG,"---src_buf =%c%c%c%c%c%c%c\n", *((char*)src_buf + 0), *((char*)src_buf + 1), *((char*)src_buf + 2), *((char*)src_buf + 3), *((char*)src_buf + 4), *((char*)src_buf + 5), *((char*)src_buf + 6)); hiedmac_trace(BSP_LOG_LEVEL_DEBUG,"---des_buf =%c%c%c%c%c%c%c\n", *((char*)des_buf + 0), *((char*)des_buf + 1), *((char*)des_buf + 2), *((char*)des_buf + 3), *((char*)des_buf + 4), *((char*)des_buf + 5), *((char*)des_buf + 6)); ret_id= bsp_edma_channel_init(req, (channel_isr)data_trans_complete, 0, EDMA_INT_DONE); if (ret_id < 0) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"-----------ERROR ret_id = 0x%X\n\n",ret_id); return EDMA_CHANNEL_INVALID; } /* set config reg */ if (bsp_edma_channel_set_config((u32)ret_id, direction, bur_width, bur_len)) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"---------EDMA_CHANNEL_ASYNC_TEST_FAILED! config \n\n"); bsp_edma_channel_free((u32)ret_id); return EDMA_CONFIG_ERROR; } if (bsp_edma_channel_async_start((u32)ret_id, (u32)edma_src_addr, (u32)edma_des_addr, byte_len)) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"---------EDMA_CHANNEL_ASYNC_TEST_FAILED! start \n\n"); bsp_edma_channel_free((u32)ret_id); return EDMA_TRXFER_ERROR; } mdelay(200); bsp_edma_channel_free((u32)ret_id); if (edmac_verify_data_blk(src_buf,des_buf)) { hiedmac_trace(BSP_LOG_LEVEL_ERROR,"----------EDMA_CHANNEL_ASYNC_TEST_FAILED! verify \n\n"); return EDMA_TRXFER_ERROR; } hiedmac_trace(BSP_LOG_LEVEL_CRIT,"===============EDMA_CHANNEL_ASYNC_INIT_TEST_SUCCESS!\n"); return EDMA_SUCCESS; }