void FillParamData() { int cnt, input; param->length = GetDec("Length: "); if (!param->length) return; input = GetDec("0=all 0, 1=all 0xff, 2=counter"); for (cnt=0; cnt<param->length; cnt++) { switch(input) { case 0: param->data[cnt] = 0; break; case 1: param->data[cnt] = 0xFFFFFFFF; break; case 2: param->data[cnt] = cnt; break; } } }
void StarGeneratorInterface::__IntegerValueUpdated( SpinBox& sender, int value ) { if ( sender == GUI->RAHours_SpinBox || sender == GUI->RAMins_SpinBox ) GetRA(); else if ( sender == GUI->DecDegs_SpinBox || sender == GUI->DecMins_SpinBox ) GetDec(); else if ( sender == GUI->EpochYear_SpinBox || sender == GUI->EpochMonth_SpinBox || sender == GUI->EpochDay_SpinBox ) GetEpoch(); }
/****************************************************************************** * int PrintEnumTypeValue(char *buf, char *pEnum, BYTE *pVar) ******************************************************************************* * * Since enums are a bit odd to decode (complex type yet simple integer), * this function prints the enum literal string from its numerical value. * * Where: * buf - the destination buffer * pVar - the address of the enum integer * * Returns: * Number of characters printed * ******************************************************************************/ static int PrintEnumTypeValue(char *buf, char *pEnum, BYTE *pVar) { int Value; // Enums are always ints char *p; // Walking pointer for the enum definition string UINT nNameLen; // Length of the name portion int written = 0; // Number of characters written // Walk the enum definition list and find the literal value that corresponds to the variable value if( GlobalReadDword(&Value, (DWORD) pVar) ) { // emon:1,tue:2,wed:3,thr:4,fri:5,sat:6,sun:7,; p = pEnum; // Start with the first name do { p = strchr(pEnum, ':'); // Find the colon if( p ) { nNameLen = p - pEnum; p = p+1; // Increment to the actual decimal value if( GetDec(&p)==Value ) { // Found the matching enum value - print it and return written = sprintf(buf, "%d <\"%s\">", Value, substr(pEnum, 0, nNameLen)); return( written ); } pEnum = p + 1; } else { // Could not find the colon, so the enum value does not match written = sprintf(buf, "%d", Value); return( written ); } } while( TRUE ); } else { // Could not read the value written = sprintf(buf, "<?>"); } return( written ); }
void StarGeneratorInterface::__RealValueUpdated( NumericEdit& sender, double value ) { if ( sender == GUI->RASecs_NumericEdit ) GetRA(); else if ( sender == GUI->DecSecs_NumericEdit ) GetDec(); else if ( sender == GUI->FocalLength_NumericEdit ) instance.focalLength = value; else if ( sender == GUI->PixelSize_NumericEdit ) instance.pixelSize = value; else if ( sender == GUI->SensorWidth_NumericEdit ) instance.sensorWidth = int32( value ); else if ( sender == GUI->SensorHeight_NumericEdit ) instance.sensorHeight = int32( value ); else if ( sender == GUI->LimitMagnitude_NumericEdit ) instance.limitMagnitude = value; else if ( sender == GUI->StarFWHM_NumericEdit ) instance.starFWHM = value; else if ( sender == GUI->TargetMinimumValue_NumericEdit ) instance.targetMinimumValue = value; }
/****************************************************************************** * * * UINT GetTypeSize(TSYMTYPEDEF1 *pType1) * * * ******************************************************************************* * * Returns the size (in bytes) of the type's memory footprint. The type can * be any kind of type. * * Where: * pType1 is the type descriptor to get the memory footprint * * Returns: * Type memory footprint in bytes * 0 if the type is invalid for some reasons * ******************************************************************************/ UINT GetTypeSize(TSYMTYPEDEF1 *pType1) { TSYMTYPEDEF1 Type1; // Local type storage UINT nSize = 0; // Size variable char *pDef; // Pointer to the type definition // Make sure the given type descriptor is valid if( pType1 ) { // Copy the input type into the local store so we may modify it memcpy(&Type1, pType1, sizeof(TSYMTYPEDEF1)); // Get the local type into the canonical form - this will modify it TypedefCanonical(&Type1); // Simple - if there is any pointer redirection level, the final size is just the pointer size if( Type1.maj ) return( sizeof(void *) ); // Depending on the base type, find the size - built in types: if( *pType1->pDef <= TYPEDEF__LAST ) return( nSimpleTypes[*(BYTE *)pType1->pDef] ); // Get the new type definition... pDef = Type1.pDef; // We know we have a terminal type here - one of the complex types: switch( *pDef ) { case 'u': // Unions always keep the size in bits case 's': // Structures always keep the size in bytes pDef++; nSize = GetDec(&pDef); break; case 'e': // Consider enum an integer size case 'r': // A type that is a subrange of itself - right now we assume "int" nSize = sizeof(int); break; case 'a': // Array is most complicated since we need the size of a child * the number of elements { int lower, upper; // Array bounds pDef = strchr(pDef, ';'); // Find the first ';' to get to the bounds scan2dec(pDef+1, &lower, &upper); // Scan 2 decimal numbers "%d,%d" pDef = strchr(pDef, '('); // Find the trailing '(' to get to the child element // This will call itself recursively to get the size of one array element pType1 = Type2Typedef(pDef, 0, Type1.file_id); nSize = (upper-lower+1) * GetTypeSize(pType1); } break; default: ; // We should not be here... break; } } return( nSize ); }
int main() { int err, cnt, offset, data, size_in_bytes; char input; /* struct timeval t0, t1; while(1) { gettimeofday(&t0, NULL); gettimeofday(&t1, NULL); RecordTime(&dma0Time, t0, t1); dma0Bytes += 1024; PrintSpeedStat(); } return 0; */ fd = open("/dev/tc_pcie_driver", O_RDWR); if (!fd) { printf("Failed to open device\n"); return -1; } param = (struct tc_ioc_data_struct *)malloc(sizeof(struct tc_ioc_data_struct) + TC_KMEM_LENGTH_BYTES); mem_info = (void **)malloc(sizeof (void*) * TC_KMEM_COUNT); err = ioctl(fd, TC_IOC_DRIVER_INFO, param); if (err) { printf("TC_IOC_DRIVER_INFO failed\n"); goto exit; } char_buffer = (char *)param; printf("%s : %s", (char *)char_buffer, (char *)&char_buffer[strlen(char_buffer)+1]); err = ioctl(fd, TC_IOC_KMEM_INFO, mem_info); if (err) { printf("TC_IOC_KMEM_INFO failed\n"); goto exit; } switch(sizeof(int)) { case 4: printf("\nOS=32bit\n"); break; case 8: printf("\nOS=64bit\n"); break; default: printf("unsupported OS; not 32 or 64 bits"); return; } // main loop while(1) { printf("\n"); printf(" 0. Exit\n"); printf(" 1. TC_IOC_DRIVER_INFO\n"); printf(" 2. TC_IOC_KMEM_INFO\n"); printf(" 3. TC_IOC_KMEM_WR\n"); printf(" 4. TC_IOC_KMEM_RD\n"); printf(" 5. TC_IOC_BAR0_WR\n"); printf(" 6. TC_IOC_BAR0_RD\n"); printf(" 7. Write to dev using app\n"); printf(" 8. Read from dev using app\n"); printf(" 9. DMAWriteReadCompare\n"); printf(" a. multiple DMAWriteReadCompare speed test\n"); printf("Hello darling! "); do { input = getchar(); } while (input == 13 || input == 10); printf("Thanks love.\n"); if (input == '0') break; switch(input) { case '1': // TC_IOC_DRIVER_INFO err = ioctl(fd, TC_IOC_DRIVER_INFO, param); if (err) { printf("TC_IOC_DRIVER_INFO failed\n"); break; } char_buffer = (char *)param; printf("%s : %s", char_buffer, &char_buffer[strlen(char_buffer)+1]); break; case '2': // TC_IOC_KMEM_INFO err = ioctl(fd, TC_IOC_KMEM_INFO, mem_info); if (err) { printf("TC_IOC_KMEM_INFO failed\n"); break; } for (cnt=0; cnt<TC_KMEM_COUNT; cnt++) printf("%d %16.16lx\n", cnt, (unsigned long)mem_info[cnt]); break; case '3': // TC_IOC_KMEM_WR param->index = GetDec("Index: "); param->offset = GetDec("Offset: "); FillParamData(); if (!param->length) break; err = ioctl(fd, TC_IOC_KMEM_WR, param); if (err) { printf("TC_IOC_KMEM_WR failed\n"); break; } break; case '4': // TC_IOC_KMEM_RD param->index = GetDec("Index: "); param->offset = GetDec("Offset: "); param->length = GetDec("Length: "); cnt=param->length; err = ioctl(fd, TC_IOC_KMEM_RD, param); if (err) { printf("TC_IOC_KMEM_RD failed\n"); break; } PrintParamData(cnt); break; case '5': // TC_IOC_BAR0_WR offset = GetDec("Offset: "); data = GetHex("Data 0x"); err = Bar0Write(offset, 1, &data); break; case '6': // TC_IOC_BAR0_RD err=Bar0Read(GetDec("Offset: "), 1, &cnt); if (!err) printf("0x%8.8x", cnt); break; case '7': // Write to dev using app FillParamData(); if (!param->length) break; DMAWriteToDev(param->length*4); break; case '8': // Read from dev using app err = DMAReadFromDev(&size_in_bytes); if (err) break; PrintParamData(size_in_bytes/4); break; case '9': // DMA write/read/compare size_in_bytes = GetDec("size_in_bytes: "); DMAWriteReadCompare(size_in_bytes); PrintParamData(size_in_bytes/4); break; case 'a': case 'A': // multiple dma write/read/compare and speed test data = GetDec("number of times to run: "); size_in_bytes = GetDec("size_in_bytes: "); if (!size_in_bytes) break; dma0Time.tv_sec = 0; dma0Time.tv_usec = 0; dma0Bytes = 0; dma1Time.tv_sec = 0; dma1Time.tv_usec = 0; dma1Bytes = 0; for(cnt=0; cnt<data; cnt++) { DMAWriteReadCompare(size_in_bytes); printf("%d: ", cnt); PrintSpeedStat(); } printf("\n"); break; default: printf("%c Unsupported\n", input); break; } } exit: free(param); free(mem_info); close(fd); return 0; }