--- pigpio/pigpio.c 2019-02-27 20:24:18.389655115 +0100 +++ pigpio-v68/pigpio.c 2019-02-27 20:19:07.712302977 +0100 @@ -1511,6 +1511,47 @@ return valid; } + + +static unsigned get_dt_ranges(const char *filename, unsigned offset) +{ + unsigned address = ~0; + FILE *fp = fopen(filename, "rb"); + if (fp) + { + unsigned char buf[4]; + fseek(fp, offset, SEEK_SET); + if (fread(buf, 1, sizeof buf, fp) == sizeof buf) + address = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0; + fclose(fp); + } + return address; +} + +unsigned bcm_host_get_peripheral_address(void) +{ + unsigned address = get_dt_ranges("/proc/device-tree/soc/ranges", 4); + return address == ~0 ? 0x20000000 : address; +} + +unsigned bcm_host_get_peripheral_size(void) +{ + unsigned address = get_dt_ranges("/proc/device-tree/soc/ranges", 8); + return address == ~0 ? 0x01000000 : address; +} + +unsigned bcm_host_get_sdram_address(void) +{ + unsigned address = get_dt_ranges("/proc/device-tree/axi/vc_mem/reg", 8); + return address == ~0 ? 0x40000000 : address; +} + + + + + + + /* ----------------------------------------------------------------------- */ static char * myTimeStamp() @@ -13338,6 +13379,54 @@ } fclose(filp); + + + if ( piCores == 0) + { + if ( !strncasecmp("processor\t: 0", buf, 10) ) + { + piCores=1; + piCores = 1; + pi_peri_phys = 0x20000000; + pi_dram_bus = 0x40000000; + pi_mem_flag = 0x0C; + } + + else if ( strncasecmp( "processor\t: 3", buf, 10) ) + { + piCores=4; + pi_peri_phys = bcm_host_get_peripheral_address(); + pi_dram_bus = bcm_host_get_sdram_address(); + pi_mem_flag = 0x04; + } + } + +printf("peripheral address %x\n", pi_peri_phys); +printf("sdram_address %x\n", pi_dram_bus); + printf("piCores: %d\n", piCores); + + if ( rev == 0 ) + { + filp = fopen( "/proc/device-tree/system/linux,revision", "r" ); + if (filp != NULL) + { + while (fgets(buf, sizeof(buf), filp) != NULL) + { + rev = (unsigned)buf[0]; + rev <<= 8; + rev |= (unsigned)buf[1]; + rev <<= 8; + rev |= (unsigned)buf[2]; + rev <<= 8; + rev |= (unsigned)buf[3]; + } + } + fclose( filp ); + } + + printf("revision: %8x\n", rev ); + + } return rev; }