/* RTlab-3.c - FYS4220 2011 */ /* B. Skaali copyright */ #define VXWORKS #define M5000 #include #include #include #include #include #include #include #include #include #include #include "stdio.h" void uniImageShow(); /* Pci slave image 1 default mapping */ UINT32 pciBase1d = 0xD1000000, vmeBase1d = 0x00000000, size1d = 0x01000000, pciAddrSpace1d = UNI_PCI_MEMORY_SPACE, vmeAmCode1d = VME_AM_STD_SUP_DATA, vmeDataWidth1d = UNI_VMEBUS_DATAWIDTH_32; BOOL postedWrites1d = TRUE; typedef struct VME_PCISLAVE_INFO { UINT pci_base_adr; UINT vme_base_adr; UINT vme_size; UINT pci_addr_space; UINT vme_am_code; UINT vme_data_width; BOOL posted_writes; } VME_PCISLAVE_INFO; /* some handy routines */ UINT32 swapendian (UINT32 val) { return (((0xff000000 & val)>>24) + ((0x00ff0000 & val)>>8) + ((0x0000ff00 & val)<<8) + ((0x000000ff & val)<<24)); } UINT32 bitfield (UINT32 val, UINT32 mask, int shift) { return ((swapendian(val) & mask) >> shift); } /* PciSlave stuff */ STATUS PciSlaveImage1Set( VME_PCISLAVE_INFO *info) { int image = 1; if (uniPciSlaveImageSet (image, info->pci_base_adr, info->vme_base_adr, info->vme_size, info->pci_addr_space, info->vme_am_code, info->vme_data_width, info->posted_writes) == ERROR) return ERROR; return OK; } STATUS PciSlaveImage1Default() { int image = 1; if (uniPciSlaveImageSet (image, pciBase1d, vmeBase1d, size1d, pciAddrSpace1d, vmeAmCode1d, vmeDataWidth1d, postedWrites1d) == ERROR) return ERROR; return OK; } /* TSVME module base addresses for RAM, ROM and jumper setting */ #define TSVME_RAM 0x8000; #define TSVME_ROM 0xC000; #define TSVME_BADR 0x00F00000; UINT32 TSVMEadroffRAM = TSVME_RAM; UINT32 TSVMEadroffROM = TSVME_ROM; STATUS tsvme() { uint32_t vmePtr; uint32_t vmeAdr; int off; /* set up PCI Slave image for the TSVME module */ VME_PCISLAVE_INFO pci_slave_image; VME_PCISLAVE_INFO *pinfo = &pci_slave_image; pci_slave_image.pci_base_adr = 0xD1000000; pci_slave_image.vme_base_adr = 0x00000000; pci_slave_image.vme_size = 0x01000000; pci_slave_image.pci_addr_space = UNI_PCI_MEMORY_SPACE; pci_slave_image.vme_am_code = VME_AM_STD_SUP_DATA; /* 0x3d */ pci_slave_image.vme_data_width = UNI_VMEBUS_DATAWIDTH_8; pci_slave_image.posted_writes = TRUE; /* show PciSlave mapping before and after setup */ printf("===>uniImageShow before remapping\n"), uniImageShow(); printf("\n"); if (PciSlaveImage1Set(pinfo) == ERROR) return ERROR; printf("===> uniImageShow after re-mapping of PciSlave 1\n"); uniImageShow(); printf("\n"); /* map from TSVME A24 jumper base address with pointer arithmetic for RAM/ROM acccess */ vmeAdr = TSVME_BADR; if (sysBusToLocalAdrs(VME_AM_STD_SUP_DATA, (char*)vmeAdr, (void**)&vmePtr) == ERROR) { printf("TSVME: could not translate the VME address, check AM value\n"); PciSlaveImage1Default(); return ERROR; } printf("TSVME base address 0x%x is mapped to local BSP address 0x%x\n", vmeAdr, vmePtr); printf("\nDumping start of TSVME ROM\n"); for(off=0; off<0x40; ++off) { if (off%16 == 0) printf("0x%6x", vmeAdr + TSVMEadroffROM + off); printf(" %02x", *((unsigned char*)vmePtr + TSVMEadroffROM + off)); if (off%16==15) printf("\n"); } printf("\nWriting to TSVME RAM with readback\n"); /* ----- insert the missing code here, please! ----- */ /* --- don't worry about the compiler type / format warnings --- */ /* set PciSlaveImage 1 back to default setting */ if (PciSlaveImage1Default() == ERROR) return ERROR; printf("\n"); return OK; }