/* ============================================================================= * EDMA/EMIF/other peripherial configuration. * This is on the top of the processing * Put the processing in it * ============================================================================= */ #include #include #include #include #include #include #include #pragma DATA_SECTION(Data_for_Processing,".MyDataMem"); #pragma DATA_SECTION(Data_Rand,".MyDataMem"); #pragma CODE_SECTION(Error_Count,".MyTestMem"); /* Intc declaration */ CSL_IntcContext intcContext; CSL_IntcEventHandlerRecord EventHandler[30]; CSL_IntcObj intcObjEdma; CSL_IntcObj intcObjEdma_1; CSL_IntcHandle hIntcEdma; CSL_IntcHandle hIntcEdma_1; CSL_IntcGlobalEnableState state; CSL_IntcEventHandlerRecord EventRecord; CSL_IntcParam vectId; CSL_IntcParam vectId_1; /* Globals */ Uint32 Data_for_Processing[8192]; Uint32 Data_Rand[8192]; volatile Uint32 intFlag = 0; volatile Uint32 count = 0; volatile Uint32 index = 0; volatile Uint32 Sys_Count = 0; volatile Uint32 aa = 0; /* Edma handle */ CSL_Edma3Handle hModule; /* Forward declaration */ void tcc1Fxn(void); void Error_Count(void); void main(void) { CSL_Edma3HwSetup hwSetup; CSL_Edma3Obj edmaObj; CSL_Edma3ParamHandle hParamBasic; CSL_Edma3ParamHandle hParamBasic1; CSL_Edma3ChannelObj chObj; CSL_Edma3CmdIntr regionIntr; CSL_Edma3CmdDrae regionAccess; CSL_Edma3ChannelHandle hChannel; CSL_Edma3ChannelHandle hChannel1; CSL_Edma3ParamSetup myParamSetup; CSL_Edma3Context context; CSL_Edma3ChannelAttr chAttr; CSL_Edma3ChannelAttr chAttr1; CSL_Status status; CSL_Edma3HwDmaChannelSetup dmahwSetup; Uint32 loopIndex; /////////////////////////////////////////////////////////////////////// *((volatile Uint32 *)McBSP_SPCR0) = 0x00000000; *((volatile Uint32 *)McBSP_PCR0) = 0x00003202; *((volatile Uint32 *)EMIF_CE4CFG) = 0x8000000e; /* GPIOÅäÖÃΪinput */ *((volatile Uint32 *)GPIO_BINTEN) = 0x00000001; *((volatile Uint32 *)GPIO_DIR) = 0x00000010; *((volatile Uint32 *)GPIO_SET_RIS_TRIG) = 0x00000010; /////////////////////////////////////////////////////////////////////// /* reset to FPGA */ *((volatile Uint32 *)McBSP_PCR0) = 0x00003200; //display:0 asm(" NOP "); asm(" NOP "); asm(" NOP "); asm(" NOP "); asm(" NOP "); *((volatile Uint32 *)McBSP_PCR0) = 0x00003202; //display:1 /* Initialize data buffers with random number */ srand(65533); for (loopIndex = 0; loopIndex < 8192; loopIndex++) { Data_Rand[loopIndex] = rand(); } /* for (loopIndex = 0; loopIndex < 8192; loopIndex++) { Data_Rand[loopIndex] = loopIndex; } */ /* Module initialization */ status = CSL_edma3Init(&context); if (status != CSL_SOK) { Sys_Count ++; return; } /* Intc module initialization */ intcContext.eventhandlerRecord = EventHandler; intcContext.numEvtEntries = 10; CSL_intcInit(&intcContext); /* Enable NMIs */ CSL_intcGlobalNmiEnable(); /* Enable global interrupts */ CSL_intcGlobalEnable(&state); /* Opening a intc handle for edma event */ vectId = CSL_INTC_VECTID_4; hIntcEdma = CSL_intcOpen (&intcObjEdma, CSL_INTC_EVENTID_EDMA3CC_INT0, \ &vectId , NULL); /* Edma module open */ hModule = CSL_edma3Open(&edmaObj,CSL_EDMA3,NULL,&status); if ( (hModule == NULL) || (status != CSL_SOK)) { Sys_Count ++; return; } *((volatile Uint32 *)0x02a00308) = 0xffffffff; // EMCR *((volatile Uint32 *)0x02a0030c) = 0xffffffff; // EMCRH while(intFlag == 0) { /* Edma module setup */ dmahwSetup.paramNum = 0; // Parameter set 0 dmahwSetup.que = CSL_EDMA3_QUE_0; // queue 0 hwSetup.dmaChaSetup = &dmahwSetup; hwSetup.qdmaChaSetup = NULL; status = CSL_edma3HwSetup(hModule,&hwSetup); if (status != CSL_SOK) { Sys_Count ++; CSL_edma3Close (hModule); return; } *((volatile Uint32 *)DCHMAP52) = 0x00000000; // DCHMAP52 *((volatile Uint32 *)0x02A01008) = 0xffffffff; // ECR *((volatile Uint32 *)0x02A0100C) = 0xffffffff; // ECRH /* Setup the DRAE masks */ regionAccess.region = CSL_EDMA3_REGION_0 ; regionAccess.drae = 0xffff ; regionAccess.draeh = 0xff0000 ; status = CSL_edma3HwControl(hModule,CSL_EDMA3_CMD_DMAREGION_ENABLE, \ ®ionAccess); if (status != CSL_SOK) { Sys_Count ++; return; } /* Channel 52 open */ chAttr.regionNum = CSL_EDMA3_REGION_0; chAttr.chaNum = 52; hChannel = CSL_edma3ChannelOpen(&chObj, CSL_EDMA3, &chAttr, &status); if ( (hChannel == NULL) || (status != CSL_SOK)) { Sys_Count ++; return; } *((volatile Uint32 *)0x02A01030) = 0x00000000; // EESR *((volatile Uint32 *)0x02A01034) = 0x00100000; // EESRH /* Get the parameter handle */ hParamBasic = CSL_edma3GetParamHandle(hChannel,0,&status); if (hParamBasic == NULL) { Sys_Count ++; return; } /* Edma parameter entry Setup */ myParamSetup.option = CSL_EDMA3_OPT_MAKE(CSL_EDMA3_ITCCH_DIS, \ CSL_EDMA3_TCCH_DIS, \ CSL_EDMA3_ITCINT_DIS, \ CSL_EDMA3_TCINT_EN,\ 52,CSL_EDMA3_TCC_NORMAL,\ CSL_EDMA3_FIFOWIDTH_NONE, \ CSL_EDMA3_STATIC_DIS, \ CSL_EDMA3_SYNC_A, \ CSL_EDMA3_ADDRMODE_INCR, \ CSL_EDMA3_ADDRMODE_INCR); myParamSetup.srcAddr = (Uint32)Data_Rand; // source address myParamSetup.aCntbCnt = CSL_EDMA3_CNT_MAKE(32768,1); // Acnt Bcnt myParamSetup.dstAddr = 0xc0000000; // destination address myParamSetup.srcDstBidx = CSL_EDMA3_BIDX_MAKE(0,0); // B src and dst index myParamSetup.linkBcntrld = CSL_EDMA3_LINKBCNTRLD_MAKE (CSL_EDMA3_LINK_NULL, 0); // link and Bcnt reload myParamSetup.srcDstCidx = CSL_EDMA3_CIDX_MAKE(0,0); // C src and dst index myParamSetup.cCnt = 1; // C cnt status = CSL_edma3ParamSetup(hParamBasic,&myParamSetup); if (status != CSL_SOK) { Sys_Count ++; return; } /* Association of an EDMA event handler with the INTC routine */ EventRecord.handler = &eventEdmaHandler; EventRecord.arg = (void*)(hModule); CSL_intcPlugEventHandler(hIntcEdma,&EventRecord); /* Enabling event edma */ CSL_intcHwControl(hIntcEdma,CSL_INTC_CMD_EVTENABLE,NULL); /* Hook up the EDMA event with an completion code function handler */ EdmaEventHook(52, tcc1Fxn); /* Enable interrupts */ regionIntr.region = CSL_EDMA3_REGION_0 ; regionIntr.intr = 0x0; regionIntr.intrh = 0x100000 ; status = CSL_edma3HwControl(hModule,CSL_EDMA3_CMD_INTR_ENABLE,®ionIntr); if (status != CSL_SOK) { Sys_Count ++; return; } *((volatile Uint32 *)0x02A01040) = 0xffffffff; // SECR *((volatile Uint32 *)0x02A01044) = 0xffffffff; // SECRH *((volatile Uint32 *)0x02A02070) = 0xffffffff; // ICR *((volatile Uint32 *)0x02A02074) = 0xffffffff; // ICRH /* GPIO4 come */ *((volatile Uint32 *)McBSP_PCR0) = 0x00003200; //display:0 asm(" NOP "); asm(" NOP "); asm(" NOP "); asm(" NOP "); asm(" NOP "); asm(" NOP "); *((volatile Uint32 *)McBSP_PCR0) = 0x00003202; //display:1 reset to FPGA /* Manually trigger the channel status = CSL_edma3HwChannelControl(hChannel,CSL_EDMA3_CMD_CHANNEL_SET,NULL); if (status != CSL_SOK) { Sys_Count ++; return; } */ /* Wait for completion */ while (!intFlag); intFlag = 0; count++; /* Disable the region 1 access */ regionAccess.region = CSL_EDMA3_REGION_0 ; regionAccess.drae = 0xffff ; regionAccess.draeh = 0xff0000 ; status = CSL_edma3HwControl(hModule,CSL_EDMA3_CMD_DMAREGION_DISABLE, \ ®ionAccess); /* Channel close */ status = CSL_edma3ChannelClose(hChannel); if (status != CSL_SOK) { Sys_Count ++; return; } /************************************************/ /* Data_Processing */ /************************************************/ /* clear the read_data buffer */ memset(Data_for_Processing, 0, 8192*sizeof(Uint32)); /************************************************/ /* channel 0 write */ /************************************************/ /* Edma module setup */ dmahwSetup.paramNum = 1; // Parameter set 1 dmahwSetup.que = CSL_EDMA3_QUE_0; // queue 0 hwSetup.dmaChaSetup = &dmahwSetup; hwSetup.qdmaChaSetup = NULL; status = CSL_edma3HwSetup(hModule,&hwSetup); if (status != CSL_SOK) { Sys_Count ++; CSL_edma3Close (hModule); return; } *((volatile Uint32 *)0x02A00100) = 0x00000020; // DCHMAP0 *((volatile Uint32 *)0x02A01008) = 0xffffffff; // ECR *((volatile Uint32 *)0x02A0100C) = 0xffffffff; // ECRH /* Setup the DRAE masks */ regionAccess.region = CSL_EDMA3_REGION_0 ; regionAccess.drae = 0xffff ; regionAccess.draeh = 0x0000 ; status = CSL_edma3HwControl(hModule,CSL_EDMA3_CMD_DMAREGION_ENABLE, \ ®ionAccess); if (status != CSL_SOK) { Sys_Count ++; return; } /* Channel 0 open */ chAttr1.regionNum = CSL_EDMA3_REGION_0; chAttr1.chaNum = 0; hChannel1 = CSL_edma3ChannelOpen(&chObj, CSL_EDMA3, &chAttr1, &status); if ( (hChannel == NULL) || (status != CSL_SOK)) { Sys_Count ++; return; } *((volatile Uint32 *)0x02A01030) = 0x00000001; // EESR *((volatile Uint32 *)0x02A01034) = 0x00000000; // EESRH /* Get the parameter handle */ hParamBasic1 = CSL_edma3GetParamHandle(hChannel1,1,&status); if (hParamBasic == NULL) { Sys_Count ++; return; } /* Edma parameter entry Setup */ myParamSetup.option = CSL_EDMA3_OPT_MAKE(CSL_EDMA3_ITCCH_DIS, \ CSL_EDMA3_TCCH_DIS, \ CSL_EDMA3_ITCINT_DIS, \ CSL_EDMA3_TCINT_EN,\ 0,\ CSL_EDMA3_TCC_NORMAL,\ CSL_EDMA3_FIFOWIDTH_NONE, \ CSL_EDMA3_STATIC_DIS, \ CSL_EDMA3_SYNC_A, \ CSL_EDMA3_ADDRMODE_INCR, \ CSL_EDMA3_ADDRMODE_INCR); myParamSetup.srcAddr = 0xc0000000; // source address myParamSetup.aCntbCnt = CSL_EDMA3_CNT_MAKE(32768,1); // Acnt Bcnt myParamSetup.dstAddr = (Uint32)Data_for_Processing; // destination address myParamSetup.srcDstBidx = CSL_EDMA3_BIDX_MAKE(0,0); // B src and dst index myParamSetup.linkBcntrld = CSL_EDMA3_LINKBCNTRLD_MAKE (CSL_EDMA3_LINK_NULL, 0); // link and Bcnt reload myParamSetup.srcDstCidx = CSL_EDMA3_CIDX_MAKE(0,0); // C src and dst index myParamSetup.cCnt = 1; // C cnt status = CSL_edma3ParamSetup(hParamBasic1,&myParamSetup); if (status != CSL_SOK) { Sys_Count ++; return; } /* Association of an EDMA event handler with the INTC routine EventRecord.handler = &eventEdmaHandler; EventRecord.arg = (void*)(hModule); CSL_intcPlugEventHandler(hIntcEdma,&EventRecord); */ /* Enabling event edma CSL_intcHwControl(hIntcEdma,CSL_INTC_CMD_EVTENABLE,NULL); */ /* Hook up the EDMA event with an completion code function handler */ EdmaEventHook(0, tcc1Fxn); /* Enable interrupts */ regionIntr.region = CSL_EDMA3_REGION_0 ; // ÉèÖÃIER regionIntr.intr = 0x1 ; regionIntr.intrh = 0x0 ; status = CSL_edma3HwControl(hModule,CSL_EDMA3_CMD_INTR_ENABLE,®ionIntr); if (status != CSL_SOK) { Sys_Count ++; return; } *((volatile Uint32 *)0x02A01040) = 0xffffffff; // SECR *((volatile Uint32 *)0x02A01044) = 0xffffffff; // SECRH *((volatile Uint32 *)0x02A02070) = 0xffffffff; // ICR *((volatile Uint32 *)0x02A02074) = 0xffffffff; // ICRH /* Manually trigger the channel */ status = CSL_edma3HwChannelControl(hChannel1,CSL_EDMA3_CMD_CHANNEL_SET,NULL); if (status != CSL_SOK) { Sys_Count ++; return; } /* Wait for completion */ while (!intFlag); intFlag = 0; /* Disable the region 0 access */ regionAccess.region = CSL_EDMA3_REGION_0 ; regionAccess.drae = 0xffff ; regionAccess.draeh = 0x0000 ; status = CSL_edma3HwControl(hModule,CSL_EDMA3_CMD_DMAREGION_DISABLE, \ ®ionAccess); /* error count */ Error_Count(); /* Channel 0 close */ status = CSL_edma3ChannelClose(hChannel1); if (status != CSL_SOK) { Sys_Count ++; return; } } /* Edma module close */ status = CSL_edma3Close(hModule); if (status != CSL_SOK) { Sys_Count ++; return; } return; } /* * ============================================================================= * @func tcc1Fxn * * @arg * NONE * * @desc * This is the interrupt service routine for edma interrupt * * @return * NONE * * ============================================================================= */ void tcc1Fxn(void) { intFlag = 1; } void Error_Count(void) { int temp, i; for (i = 2; i < 8190; i++) { temp = Data_Rand[i] - Data_for_Processing[i]; if (temp != 0){ index ++; printf("%d %d %d %d %d\n", aa, count, i, Data_Rand[i], Data_for_Processing[i]); } if (count == 10000) { aa++; count = 0; } if (aa == 100) { printf("%d over\n",index); exit(0); } } }