📄 dma.c
字号:
#include "dma.h"#include "mem_map.h"void WAIT_RE32( Reg, ExpData, Timeout ) { tWORD tmp; tHALF index = 0; /* read the reg */ tmp = (volatile tWORD)(*(volatile tWORD *)(Reg)); /* test the reg */ while ( (( (volatile tWORD)(tmp) ) != ( (volatile tWORD)(ExpData) )) && ( (volatile tHALF) (index) < (volatile tHALF) (Timeout)) ) { tmp = (volatile tWORD)(*(volatile tWORD *)(Reg)); index++;#if 1 burst_writes(FLASH1_ADDRESS, 10);#endif } /* write the CPRINT */#if 1 ASSERT(index < Timeout);#else if (index >= Timeout) { printf("fail\n");//FAIL_4( (tWORD)( CPRINT_E_WAIT_RE32 ), (tWORD)( Reg ), (tWORD)( tmp ), (tWORD)( ExpData ), (tWORD)( Timeout ) ); } else { /* this means the test succeeded */ printf("success\n");//SUCCESS_4( (tWORD)( CPRINT_S_WAIT_RE32 ), (tWORD)( Reg ), (tWORD)( tmp ), (tWORD)( ExpData ), (tWORD)( Timeout ) ); } /* if test */ #endif}void WR32( Reg, WrData ) { tWORD tmp; /* write the reg */ *(volatile tWORD *)(Reg)=(tWORD)(WrData); /* read the reg */ tmp = (volatile tWORD)(*(volatile tWORD *)(Reg)); #if 1 ASSERT((tWORD)(tmp) == (tWORD)(WrData));#else if ( (tWORD)(tmp) != (tWORD)(WrData) ) { /* test failed */ printf("fail\n");//FAIL_3( (tWORD)( CPRINT_E_WR32 ), (tWORD)( Reg ), (tWORD)( WrData ), (tWORD)( tmp ) ); } else { printf("success\n");//SUCCESS_3( (tWORD)( CPRINT_S_WR32 ), (tWORD)( Reg ), (tWORD)( WrData ), (tWORD)( tmp ) ); }#endif}void WR8( Reg, WrData ) { tBYTE tmp; /* write the reg */ *(volatile tBYTE *)(Reg)=(tBYTE)(WrData); /* read the reg */ tmp = (volatile tBYTE)(*(volatile tBYTE *)(Reg)); #if 1 ASSERT((tBYTE)(tmp) == (tBYTE)(WrData));#else if ( (tBYTE)(tmp) != (tBYTE)(WrData) ) { /* test failed */ printf("fail\n");//FAIL_3( (tWORD)( CPRINT_E_WR8 ), (tWORD)( Reg ), (tWORD)( WrData ), (tWORD)( tmp ) ); } else { printf("success\n");//SUCCESS_3( (tWORD)( CPRINT_S_WR8 ), (tWORD)( Reg ), (tWORD)( WrData ), (tWORD)( tmp ) ); } #endif}void WR16( Reg, WrData ) { tHALF tmp; /* write the reg */ *(volatile tHALF *)(Reg)=(tHALF)(WrData); /* read the reg */ tmp = (volatile tHALF)(*(volatile tHALF *)(Reg)); #if 1 ASSERT((tHALF)(tmp) == (tHALF)(WrData));#else if ( (tHALF)(tmp) != (tHALF)(WrData) ) { /* test failed */ printf("fail\n");//FAIL_3( (tWORD)( CPRINT_E_WR16 ), (tWORD)( Reg ), (tWORD)( WrData ), (tWORD)( tmp ) ); } else { printf("success\n");//SUCCESS_3( (tWORD)( CPRINT_S_WR16 ), (tWORD)( Reg ), (tWORD)( WrData ), (tWORD)( tmp ) ); } #endif}void RE32( Reg , ExpData ) { tWORD tmp; tmp = (volatile tWORD)(*(volatile tWORD *)(Reg)); #if 1 ASSERT((tWORD)( tmp )==( (tWORD)(ExpData) ));#else if ((tWORD)( tmp )!=( (tWORD)(ExpData) )) { /* means the test failed */ printf("fail\n");//FAIL_3( (tWORD)( CPRINT_E_RE32 ), (tWORD)( Reg ), (tWORD)( tmp ), (tWORD)( ExpData ) ); } else { printf("success\n");//SUCCESS_3( (tWORD)( CPRINT_S_RE32 ), (tWORD)( Reg ), (tWORD)( tmp ), (tWORD)( ExpData ) ); }#endif}void RE16( Reg, ExpData ) { tHALF tmp; tmp = (volatile tHALF)(*(volatile tHALF *)(Reg)); #if 1 ASSERT((tHALF)( tmp )==( (tHALF)(ExpData) ));#else if ((tHALF)( tmp )!=( (tHALF)(ExpData) )) { /* means the test failed */ printf("Fail\n");//FAIL_3( (tWORD)( CPRINT_E_RE16 ), (tWORD)( Reg ), (tWORD)( tmp ), (tWORD)( ExpData ) ); } else { printf("Success\n");//SUCCESS_3( (tWORD)( CPRINT_S_RE16 ), (tWORD)( Reg ), (tWORD)( tmp ), (tWORD)( ExpData ) ); } #endif}void RE8( Reg, ExpData ) { tBYTE tmp; tmp = (volatile tBYTE)(*(volatile tBYTE *)(Reg)); #if 1 ASSERT((tBYTE)( tmp )==( (tBYTE)(ExpData) ));#else if ((tBYTE)( tmp )!=( (tBYTE)(ExpData) )) { /* means the test failed */ printf("Fail\n");//FAIL_3( (tWORD)( CPRINT_E_RE8 ), (tWORD)( Reg ), (tWORD)( tmp ), (tWORD)( ExpData ) ); } else { printf("Success\n");//SUCCESS_3( (tWORD)( CPRINT_S_RE8 ), (tWORD)( Reg ), (tWORD)( tmp ), (tWORD)( ExpData ) ); } #endif}void BCLR32(address, mask) { tWORD tmpi; tWORD tmpf; tmpi = (volatile tWORD)(*(volatile tWORD *)(address)); *(volatile tWORD *)(address) = tmpi & ~(volatile tWORD)( mask ); tmpf = (volatile tWORD)(*(volatile tWORD *)(address)); #if 0 printf("success\n");//SUCCESS_4( (tWORD)( CPRINT_BCLR32 ), (tWORD)( address ), (tWORD)( tmpi ), (tWORD)( mask ), (tWORD)( tmpf ) );#endif}void WAIT_REM32( Reg, ExpData, Mask, Timeout ) { tWORD tmp; tHALF index = 0; /* read the reg */ tmp = (volatile tWORD)(*(volatile tWORD *)(Reg)); /* test the reg */ while ( (( (volatile tWORD)(tmp) & (volatile tWORD)(Mask) ) != ( (volatile tWORD)(ExpData) & (volatile tWORD)(Mask) )) && ( (volatile tHALF) (index) < (volatile tHALF) (Timeout)) ) { tmp = (volatile tWORD)(*(volatile tWORD *)(Reg)); index++; } /* write the CPRINT */ #if 1 ASSERT(index < Timeout);#else if (index >= Timeout) { printf("fail\n");//FAIL_5( (tWORD)( CPRINT_E_WAIT_REM32 ), (tWORD)( Reg ), (tWORD)( tmp ), (tWORD)( ExpData ), (tWORD)( Mask ), (tWORD)( Timeout ) ); } else { /* this means the test succeeded */ printf("success\n");//SUCCESS_5( (tWORD)( CPRINT_S_WAIT_REM32 ), (tWORD)( Reg ), (tWORD)( tmp ), (tWORD)( ExpData ), (tWORD)( Mask ), (tWORD)( Timeout ) ); } /* if test */ #endif}void software_dma_transfer(channel, saddr, daddr, bytes, ssize, dsize){ tWORD ssize_enc, dsize_enc; tWORD sinc, dinc; channel = (channel << 5) + TCD00_W0; switch (ssize) { case 8: ssize_enc = 0x00000000; sinc = 0x00000001; break; case 16: ssize_enc = 0x01000000; sinc = 0x00000002; break; case 32: ssize_enc = 0x02000000; sinc = 0x00000004; break; case 128: ssize_enc = 0x04000000; sinc = 0x00000010; break; default: ;printf("Error: dma_transfer_start invalid source size\n");//ERROR("dma_transfer_start", "invalid source read size"); } switch (dsize) { case 8: dsize_enc = 0x00000000; dinc = 0x00000001; break; case 16: dsize_enc = 0x00010000; dinc = 0x00000002; break; case 32: dsize_enc = 0x00020000; dinc = 0x00000004; break; case 128: dsize_enc = 0x00040000; dinc = 0x00000010; break; default: ;printf("Error: dma_transfer_start invalid dest write size\n");//ERROR("dma_transfer_start", "invalid dest write size"); } // source address W32(channel+0x00, saddr); // read size, write size, source address increment W32(channel+0x04, ssize_enc | dsize_enc | sinc); // total bytes to transfer W32(channel+0x08, bytes); // add 0 to last source address W32(channel+0x0c, 0x00000000); // destination address W32(channel+0x10, daddr); // single transfer, destination address increment W32(channel+0x14, 0x00010000 | dinc); // single transfer, add 0 to last destination address W32(channel+0x18, 0x00010000); //printf("dma_transfer_start, TCD setup, initiating transfer\n");//INFO("dma_transfer_start", "TCD setup, initiating transfer"); W32(channel+0x1c, 0x00000001);}void dma_transfer_wait(tWORD channel, tWORD timeout){ channel = (channel << 5) + TCD00_W0; //printf("dma_transfer_wait wait for transfer to complete\n");//INFO("dma_transfer_wait", "wait for transfer to complete"); WAIT_REM32(channel+0x1c, 0x00000080, 0x00000080, timeout); BCLR32(channel+0x1c, 0x00000080); // verify that no errors occurred RE32(DMAES, 0x00000000);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -