Click here to Skip to main content
15,886,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: volatile misbehaves Pin
supercat930-May-18 12:20
supercat930-May-18 12:20 
AnswerRe: volatile misbehaves Pin
Joe Woodbury17-May-18 5:48
professionalJoe Woodbury17-May-18 5:48 
GeneralRe: volatile misbehaves Pin
Vaclav_17-May-18 6:04
Vaclav_17-May-18 6:04 
GeneralRe: volatile misbehaves Pin
Vaclav_17-May-18 7:24
Vaclav_17-May-18 7:24 
AnswerRe: volatile misbehaves Pin
leon de boer18-May-18 8:16
leon de boer18-May-18 8:16 
GeneralRe: volatile misbehaves Pin
Vaclav_19-May-18 14:02
Vaclav_19-May-18 14:02 
GeneralRe: volatile misbehaves Pin
Vaclav_19-May-18 14:36
Vaclav_19-May-18 14:36 
GeneralRe: volatile misbehaves Pin
leon de boer20-May-18 4:41
leon de boer20-May-18 4:41 
Haha that is the longest winded writing of these dozen lines of code for the Pi3 .. gpio is the volatile address you use
static volatile uint32_t *gpio;
int fd ;
// Try Obtain handle to physical memory
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC) ) < 0) {
    if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC) ) < 0){    
       printf("Unable to open physical memory handle: %s\n", strerror(errno));      
       return -1;
    }
}

//map a page of memory to gpio at offset 0x3F200000 which is where GPIO goodness starts on a Pi3
gpio = (uint32_t *)mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x3F200000);

if ((int32_t)gpio < 0){
  printf("Mmap failed: %s\n", strerror(errno));
  return -1;
}

/* Now you have gpio use and abuse it */


So looking at the code GPIOmem is an entry value >>>> you provide to the function <<<<.

If you provide 0 it basically means Autodetect the base address
If you provide any number it will use that number as the base address ignoring all the autodetection routines.

Okay this pile of rubbish is just reading the device table file (hence the DT). Its just returning a number from a file it's not volatile and this junk should be a function so I would make it one. It will return 0 if it can't find the entry in the DT file and the address if it find it.

I am going to dump all the long winded debug code, it's just making a mess of what is actually happening so here is your function
uint32_t BaseAddressFromDTFile (void) 
{
   uint32_t base_addr = 0;
   FILE *fp;
   if ((fp = fopen(BMC2835_RPI2_DT_FILENAME, "rb"))) {
     uint32_t base_size;
     unsigned char buf[4];
     fseek(fp, BMC2835_RPI2_DT_PERI_BASE_ADDRESS_OFFSET, SEEK_SET);
     if (fread(buf, 1, sizeof(buf), fp) == sizeof(buf))
     base_addr = (uint32_t *) (buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0);
     fseek(fp, BMC2835_RPI2_DT_PERI_SIZE_OFFSET, SEEK_SET);
     if (fread(buf, 1, sizeof(buf), fp) == sizeof(buf))
         base_size = (buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0);
     fclose(fp);
   }
   return (base_addr);
}

If that returns 0 it looks like it assumes it's a Pi1

Next it just tries to Obtain handle to physical memory which the reduce form is above in my code
Then if you set GPIOMem to zero it will use that address found otherwise it use the GPIOMem address to map the page.

Then it does the page map with
// use memory file descriptor
/* Base of the peripherals block is mapped to VM */
bcm2835_peripherals = (uint32_t*) mapmem("gpio", bcm2835_peripherals_size,
memfd, (uint32_t) bcm2835_peripherals_base);

We don't have the definition of bcm2835_peripherals but that is the thing that should be volatile like my code above it is their version of gpio.
In vino veritas


modified 20-May-18 10:48am.

GeneralRe: volatile misbehaves Pin
Vaclav_20-May-18 5:44
Vaclav_20-May-18 5:44 
GeneralRe: volatile misbehaves Pin
leon de boer20-May-18 20:35
leon de boer20-May-18 20:35 
GeneralRe: volatile misbehaves Pin
Vaclav_21-May-18 3:18
Vaclav_21-May-18 3:18 
GeneralRe: volatile misbehaves Pin
leon de boer21-May-18 4:33
leon de boer21-May-18 4:33 
Question__sync_synchronize stops processor ? Pin
Vaclav_16-May-18 10:31
Vaclav_16-May-18 10:31 
AnswerRe: __sync_synchronize stops processor ? Pin
Randor 16-May-18 12:15
professional Randor 16-May-18 12:15 
GeneralRe: __sync_synchronize stops processor ? Pin
Vaclav_16-May-18 13:15
Vaclav_16-May-18 13:15 
GeneralRe: __sync_synchronize stops processor ? Pin
Randor 16-May-18 14:10
professional Randor 16-May-18 14:10 
GeneralRe: __sync_synchronize stops processor ? Pin
Vaclav_17-May-18 3:22
Vaclav_17-May-18 3:22 
QuestionTo install Visual Studio(2008 Pro,2010 Express and 2013 Express) in the same machine Pin
manoharbalu14-May-18 19:30
manoharbalu14-May-18 19:30 
AnswerRe: To install Visual Studio(2008 Pro,2010 Express and 2013 Express) in the same machine Pin
Victor Nijegorodov14-May-18 20:24
Victor Nijegorodov14-May-18 20:24 
GeneralRe: To install Visual Studio(2008 Pro,2010 Express and 2013 Express) in the same machine Pin
manoharbalu14-May-18 20:50
manoharbalu14-May-18 20:50 
GeneralRe: To install Visual Studio(2008 Pro,2010 Express and 2013 Express) in the same machine Pin
Victor Nijegorodov14-May-18 22:56
Victor Nijegorodov14-May-18 22:56 
GeneralRe: To install Visual Studio(2008 Pro,2010 Express and 2013 Express) in the same machine Pin
manoharbalu15-May-18 3:10
manoharbalu15-May-18 3:10 
GeneralRe: To install Visual Studio(2008 Pro,2010 Express and 2013 Express) in the same machine Pin
Victor Nijegorodov15-May-18 3:40
Victor Nijegorodov15-May-18 3:40 
GeneralRe: To install Visual Studio(2008 Pro,2010 Express and 2013 Express) in the same machine Pin
manoharbalu15-May-18 3:48
manoharbalu15-May-18 3:48 
GeneralRe: To install Visual Studio(2008 Pro,2010 Express and 2013 Express) in the same machine Pin
leon de boer15-May-18 5:50
leon de boer15-May-18 5:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.