📄 testdma.c
字号:
/************************************************************************** * * Copyright (c) 2005 Curtiss-Wright Controls, Inc. All rights * reserved. This Source Code is the Property of Curtiss-Wright * Controls, Inc. and can only be used in accordance with Source * Code License Agreement(s) of Curtiss-Wright Controls, Inc. or any * of its subsidiaries. * **************************************************************************//*FILE HEADER************************************************************** * Product Name: 182/3 BSP * * Header %name: testdma.c % * Instance: kanata_1 * * Description: 182 test for dma * * %created_by: tissa % * %date_created: Tue Jan 30 17:42:59 2006 % * * Notes: * * History: * 02b, 30jan06, tis changed local buffer address for VME-183 boards. * 02a, 20oct05, rsr CR3191: Added bsp.h to includes * *END FILE HEADER*********************************************************//* ------------------------------------------------------------------------ *\** universeDmaVme.c - Tundra UNIVERSE II PCI-VME DMA interface library **** ------------------------------------------------------------------------ **** **** DY 4 Universe II VxWorks demonstration DMA driver for SVME-18x **** **** Copyright (C) 1998 **** DY 4 Systems, Inc. **** **** Project: EB955 **** **** ------------------------------------------------------------------------ **** **** Prepared by Applied Microelectronics Incorporated **** **** ------------------------------------------------------------------------ **** **** DESCRIPTION **** This library contains routines which relate to the VMEbus functions of **** the Universe VMEbus chip. **** **** The functions addressed here include: **** **** - VME DMA functions: **** - copy blocks via DMA **** - lock DMA operation **** - initialize DMA **** - set/get DMA parameters **** **** ------------------------------------------------------------------------ **** **** Author: Neil.Hamilton@appliedmicro.ns.ca **** **** Language: C **** **\* ------------------------------------------------------------------------ *//* ------------------------------------------------------------------------ *\ Filename: $Source: D:\tornadoppc\target\config\svme181\src\drv\vme\testdma.c Current Revision: $Revision: 1.9 $ Last Updated: $Date: 1999/06/28 10:51:34 $ Last Modified by: $Author: DUD Informission $ Currently Locked by: $Locker: $ Change History: $Log: testdma.c,v $ Revision 1.10 1999/07/10 ELP - Change include paths to be relative rather than specific Revision 1.9 1999/06/28 10:51:34 DUD Informission - Remove offset for address calculation for universe chip to adapt the code for SVME179. Revision 1.8 1999/01/28 15:05:51 Neil.Hamilton - Added test which exercises the example ISR in the universeDma.c file. Revision 1.7 1999/01/27 15:50:24 Neil.Hamilton - Removed call to (now defunct) sysVmeDmaReleaseMutex() as this operation is now handled within the sysVmeDmaIsAsyncDone() function. Revision 1.6 1999/01/26 19:00:59 Neil.Hamilton - Added tests for both blocking and non-blocking DMA functions. Revision 1.5 1999/01/21 12:02:14 Neil.Hamilton - As delivered to DY4 15Jan1999. Revision 1.4 1999/01/12 22:25:27 Neil.Hamilton - Modified PPC and Universe relative addresses to be correct. Revision 1.3 1999/01/12 20:20:35 Neil.Hamilton - Fixed typos. Revision 1.2 1999/01/12 20:08:50 Neil.Hamilton - Added some test functions to find VME stuff. Revision 1.1 1999/01/11 15:04:01 Neil.Hamilton Initial revision\* ------------------------------------------------------------------------ */#define MAX_WAIT 60#define DEFAULT_DEBUG_STATE TRUE#undef CHANGE_DEBUG_STATE/**********************************************************************//*#define CHANGE_DEBUG_STATE*//**********************************************************************/#undef DEBUG_LOCK#undef INT_HANDLER_MSG#define DO_NOT_FORCE_UNLOCK FALSE#define FORCE_UNLOCK TRUE#define DO_VERIFIY TRUE#define DO_NOT_VERIFY FALSE#define LOCK_TIMEOUT 100 /* x100ms */#define ASYNC_DELAY 10#define SYNC_DELAY 2/* System Include Files */#include <vxWorks.h>#include <errnoLib.h>#include <intLib.h>#include <iv.h>#include <iosLib.h>#include <semLib.h>#include <stdio.h>#include <stdlib.h>#include <sysLib.h>#include <taskLib.h>#include <logLib.h>#include <usrLib.h>#include "h/drv/dy4/boardName.h"#include "bsp.h"/* DY4 standard include files */#define __DY4_CADDR_T#define __DY4_PTRDIFF_T/* Local include files */#ifdef VME_182#include "dy4182.h"#endif#ifdef VME_183#include "cwv183.h"#endif/*#include "../config/svme181/h/drv/intrCtl/i82371Mx.h"*/#include "h/drv/vme/universe_dy4.h"#include "h/drv/vme/universe2_dy4.h"#include "vme.h"#include "h/drv/vme/universeDmaVme_dy4.h"/* Macros and constant definitions *//* Struct to set/get DMA mode types. */typedef struct{ STATUS type; /* sysVmeDma{S|G}et types */ char name[40]; /* Text string description of type. */} SYS_VME_DMA_GET_SET_TYPE;SYS_VME_DMA_GET_SET_TYPE sysVmeDmaGetSetType[] = { { UNIVERSE_VME_DMA_DCAP, "DCAP mode" }, { UNIVERSE_VME_DMA_ACAP, "ACAP mode" }, { UNIVERSE_VME_DMA_UCAP, "UCAP mode" }, { UNIVERSE_VME_DMA_PCAP, "PCAP mode" }, { UNIVERSE_VME_DMA_BSIZE, "BSIZE" }, { UNIVERSE_VME_DMA_DELAY, "Delay" }, { 0xff, "Deliberate Invalid type" } };/* Types of DMA data patterns. */#if 0enum DMA_PATTERN_TYPES{ DMA_PAT_ALL_ZEROS, DMA_PAT_ALL_ONES, DMA_PAT_55, DMA_PAT_AA, DMA_PAT_INC, DMA_PAT_DEC, DMA_PAT_RANDOM};#else#define DMA_PAT_ALL_ZEROS 0#define DMA_PAT_ALL_ONES 1#define DMA_PAT_55 2#define DMA_PAT_AA 3#define DMA_PAT_INC 4#define DMA_PAT_DEC 5#define DMA_PAT_RANDOM 6#endiftypedef struct{ /*DMA_PATTERN_TYPES*/ int pattern; char name[40];} SYS_VME_DMA_PATTERN_TYPE;SYS_VME_DMA_PATTERN_TYPE sys_vme_dma_pattern_type[] = { { DMA_PAT_ALL_ZEROS, "All zeros" }, { DMA_PAT_ALL_ONES, "All ones" }, { DMA_PAT_55, "All 0x55" }, { DMA_PAT_AA, "All 0xAA" }, { DMA_PAT_INC, "Incremental" }, { DMA_PAT_DEC, "Decremental" }, { DMA_PAT_RANDOM, "Random" } };/* The following offsets are used to calculate the Universe addresses for * both the local (PCI master) and VME address relative to the Universe's * point of view. For example, an address seen by the PowerPC at location * X would be seen by the Universe DMA engine's PCI master at X+0x80000000. These offset are not applicable on SVME-181 * A VME address seen by the PowerPC at Y would be seen by Universe DMA * engine's VME master at Y+0x50000000. Note that since the 2nd VME card is * seen by the PowerPC at address 0x48000000, the addition of 0x50000000 * will cause a rollover, resulting in the correct address of 0x48000000. *#define UNIVERSE_LOCAL_ADDR_OFFSET 0x80000000#define UNIVERSE_VME_ADDR_OFFSET 0x70000000*/#ifdef VME_183#define LOCAL_BUFFER_ADDR 0x00180000#else#define LOCAL_BUFFER_ADDR 0x00080000#endif#ifdef SVME178 /* D8000000 changed to 48000000 on SVME-181 */#define VME_BUFFER_ADDR (0xD8000000+LOCAL_BUFFER_ADDR)#else#define VME_BUFFER_ADDR (0x48000000+LOCAL_BUFFER_ADDR)#endif#if 0/* These offsets need not to be used on SVME-181 */#define UNIVERSE_PCI_ADDR (LOCAL_BUFFER_ADDR + UNIVERSE_LOCAL_ADDR_OFFSET)#define UNIVERSE_VME_ADDR (VME_BUFFER_ADDR + UNIVERSE_VME_ADDR_OFFSET)#endif/* Declarations */IMPORT UINT32 sysGetUniverseIoBaseAdrs(void);char * my_local_addr = (char *)LOCAL_BUFFER_ADDR;char * my_vme_addr = (char *)VME_BUFFER_ADDR;#if 0 /* use this if you want to hard code pci/vme addresses */char * my_univ_local_addr = (char *)UNIVERSE_PCI_ADDR;char * my_univ_vme_addr = (char *)UNIVERSE_VME_ADDR;#endifBOOL my_to_vme = TRUE;UINT32 my_size = 0x10000;/*DMA_PATTERN_TYPES*/int my_pattern_type = DMA_PAT_DEC;BOOL my_do_verify = TRUE;/* Function prototypes */void testDmaInit( void );void testDmaCopy( char * local_addr, /* relative to PPC */ char * vme_addr, /* relative to PPC */ UINT32 size, BOOL to_vme, int pattern_type, /*DMA_PATTERN_TYPE*/ BOOL do_verify );void testDmaGet( void );void testDmaSet( void );STATUS createDmaPattern( char * addr, /* relative to PPC */ UINT32 size, int pattern_type ); /*DMA_PATTERN_TYPE*/STATUS clearTargetRam( char * addr, UINT32 size );STATUS verifyDmaPattern( char * pattern_addr, /* relative to PPC */ char * dest_addr, /* relative to PPC */ UINT32 size );void testSync( void );void testVarsShow( void );void TimeDelay( UINT32 tenths_of_seconds );void testAsync2( void ); /* Prototype needed *//* Functions *//*HEADER***************************************************/void testDmaInit( void )/* Description : * Attempts to initialize the DMA driver. Attempts a second * time to see that the driver still reacts correctly. (Driver * should report it is already installed.) * * Return Value : * None. * * Comments: * **END HEADER**********************************************/{ STATUS ret_val; BOOL originalDebugState; fprintf(stdout, "Test Initialization of DMA device driver\n" ); /* Get original state of debug value and set state of debug value * to TRUE to get display out of this function. */ originalDebugState = sysVmeDmaGetDebugState ();#ifdef CHANGE_DEBUG_STATE sysVmeDmaSetDebugState( DEFAULT_DEBUG_STATE );#endif /* Initialize driver 1st time. */ fprintf(stdout, "Attempting 1st initialization of device driver\n" ); if( (ret_val = sysVmeDmaInit () ) == OK ) fprintf(stdout, "Driver initialized OK\n" ); else fprintf(stdout, "Driver initialization FAILED\n" ); /* Initialize driver 2nd time. */ fprintf(stdout, "Attempting 2nd initialization of device driver...\n" ); fprintf(stdout, "...driver should warn it is already initialized\n" ); if( (ret_val = sysVmeDmaInit () ) == OK ) fprintf(stdout, "Driver initialized OK\n" ); else fprintf(stdout, "Driver initialization FAILED\n" ); /* Restore original state of debug value. */ sysVmeDmaSetDebugState( originalDebugState );}/*HEADER***************************************************/void testDmaCopy( char * local_addr, /* relative to PPC */ char * vme_addr, /* relative to PPC */ UINT32 size, BOOL to_vme, int pattern_type, BOOL do_verify )/* Description : * Attempts to create and copy a block of memory to/from * VME over the DMA. The target block is then verified * against original pattern. * * Return Value : * None. * * Comments: * Function will fail if twice the memory required by * the size parameter can be allocated. * **END HEADER**********************************************/{ BOOL originalDebugState; char *pattern_addr, *dest_addr;#if 0 /* Change for SVME-18x */ char *universe_local_addr = local_addr+UNIVERSE_LOCAL_ADDR_OFFSET, *universe_vme_addr = vme_addr+UNIVERSE_VME_ADDR_OFFSET;#endif char *universe_local_addr = local_addr; char *universe_vme_addr = vme_addr; fprintf(stdout, "++++++++++++++++++++++++++++++++\n" ); fprintf(stdout, "Test DMA copy function\n" ); /* Get original state of debug value and set state of debug value * to TRUE to get display out of this function. */ originalDebugState = sysVmeDmaGetDebugState ();#ifdef CHANGE_DEBUG_STATE sysVmeDmaSetDebugState( DEFAULT_DEBUG_STATE );#endif /* Display the DMA copy we are starting. */ fprintf(stdout, "================================\n" ); fprintf(stdout, "Local address : 0x%08X (local_addr)\n", (UINT32)local_addr ); fprintf(stdout, "Universe local addr : 0x%08X\n", (UINT32)universe_local_addr ); fprintf(stdout, "Local VME address : 0x%08X (vme_addr)\n", (UINT32)vme_addr ); fprintf(stdout, "Universe VME addr : 0x%08X\n", (UINT32)universe_vme_addr ); fprintf(stdout, "Transfer size : 0x%08X (%0d)\n", size, size ); if( to_vme ) fprintf(stdout, "Direction (to VME) : TRUE\n" ); else fprintf(stdout, "Direction (to VME) : FALSE\n" ); fprintf(stdout, "Pattern type : %s (%0d)\n", sys_vme_dma_pattern_type[pattern_type].name, pattern_type ); if( do_verify ) fprintf(stdout, "Verify result : TRUE\n" ); else fprintf(stdout, "Verify result : FALSE\n" ); /* Set the pattern location according to the to_vme flag. */ if( to_vme ) { pattern_addr = local_addr; dest_addr = vme_addr; } else { pattern_addr = vme_addr; dest_addr = local_addr; } /* Clear the RAM on the target to ensure that the DMA copy is real. */ clearTargetRam( dest_addr, size ); /* Create the pattern. */ if( createDmaPattern( pattern_addr, size, pattern_type ) != OK ) fprintf(stdout, "Unable to create pattern: FAILED\n" ); else { fprintf(stdout, "Pattern created OK\n" ); /* Set up the copy routine and call it. *//* fprintf(stdout, "universe_local_addr = 0x%08x\n", universe_local_addr ); fprintf(stdout, "universe_vme_addr = 0x%08x\n", universe_vme_addr ); fprintf(stdout, "size = 0x%08x\n", size ); fprintf(stdout, "to_vme = 0x%08x\n", to_vme );*/ if( sysVmeDmaCopy( universe_local_addr, universe_vme_addr, size, to_vme ) != OK ) fprintf(stdout, "DMA copy failed: ERROR.\n" ); else { fprintf(stdout, "DMA copy returned OK.\n" ); /* Wait about one second more for good measure. */ taskDelay(sysClkRateGet()); /* Verify the pattern if requested. */ if( do_verify )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -