Source file: /~heha/mb-iwp/Bergwerk/i2c-zero-tout.zip/i2c-zero-tout.cpp

#include <stdint.h>
#include <unistd.h>	// usleep(), execlp()
#include <fcntl.h>
#include <sys/mman.h>
#include <byteswap.h>
/*
 BSC[1]->TOUT=0 ausführen und beenden. Ohne busybox, ohne Python, ohne libbcm2835.
 Hoppla, ab BCM2837 wurde das Register TOUT in CLKT umbenannt, tut aber dasselbe.
 Hoppla, Broadcomm macht mit den genervten Anwendern ein Verwirrspiel:
 BCM2835	Pi1 A A+ B B+ Zero: Single-Core ARM1176
 BCM2836	Pi2 Pi3 A: Quad-Core ARMv7
 RP3A0		Pi2 Zero: BCM2710+BCM2837 1 GHz
 BCM2837	Pi3 B Compute3: ARMv8 (aka „ARM Cortex A53“) 1,2 GHz
 BCM2837B0	Pi3 A+ B+ Compute3+: 64 Bit, 1,4 GHz
 BCM2711	Pi4 B 400 Compute4 (Nummer wird plötzlich kleiner!): 1,5 GHz, bis 8 GByte RAM
 230510	erstellt
*/

int main() {
 int f=open("/proc/device-tree/soc/ranges",O_RDONLY);
 if (f<0) return 1;
 uint32_t mapdata[3];
 if (read(f,mapdata,sizeof mapdata)!=sizeof mapdata) return 2;
 close(f);
 uint32_t hBasis=bswap_32(mapdata[0]),
 	  vBasis=bswap_32(mapdata[1]),
           Länge=bswap_32(mapdata[2]);
 f=open("/dev/mem",O_RDWR|O_SYNC);
 if (f<0) return 3;
 volatile uint32_t*regs=(volatile uint32_t*)mmap(0,Länge,PROT_READ|PROT_WRITE,MAP_SHARED,f,vBasis);
 if (!regs) return 4;
// Aus dem Datenblatt (korrekter aus dem Device Tree)
 static const uint32_t i2cBasis[]={
	0x7E205000,	// BSC0
	0x7E804000,	// BSC1
	0x7E805000,	// BCM2835: BSC2, beim BCM2711: undokumentiert, für HDMI
	0x7E205600,	// BSC3 (dieses und fortfolgendes nur beim BCM2711)
	0x7E205800,	// BSC4
	0x7E205a80,	// BSC5
	0x7E205c00,	// BSC6
	0};		// BSC7: undokumentiert, für HDMI
 regs[(i2cBasis[1]-hBasis+0x1C)>>2]=0;
}
Detected encoding: UTF-80