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

C / C++ / MFC

 
GeneralRe: volatile misbehaves Pin
Vaclav_17-May-18 5:39
Vaclav_17-May-18 5:39 
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 
OK, the "base" comes from this mess.
I am including it all, including my debugging stuff.

So no peanut gallery comments, just the facts ma'm.

First obstacle in the code is the funky (debug) - it "defaults to zero but I have not found where. Also gpiomem has to be passed as zero (?).

The " BMC2835_RPI2_DT_FILENAME "

#define BMC2835_RPI2_DT_FILENAME "/proc/device-tree/soc/ranges"

is a "device-tree structure (?) " of RPi 3 and up(?) _ - and its access "returns " bcm2835_peripherals_base (pointer) and bcm2835_peripherals_size.
Neither use "volatile" keyword.

And I have to ask - why not start with volatile at the base?

Now gpiomem must have something to do with identifying the actual gpio " tree branch" or what does it do?

To be continued.


<pre lang="c++">
#define DEBUG_bcm2835_init

int C_BCM2835_SPI_TFT::bcm2835_init(int gpiomem) {

int memfd;
int ok;
FILE *fp;

if (debug) {
bcm2835_peripherals = (uint32_t*) BCM2835_PERI_BASE;

bcm2835_pads = bcm2835_peripherals + BCM2835_GPIO_PADS / 4;
bcm2835_clk = bcm2835_peripherals + BCM2835_CLOCK_BASE / 4;
bcm2835_gpio = bcm2835_peripherals + BCM2835_GPIO_BASE / 4;
bcm2835_pwm = bcm2835_peripherals + BCM2835_GPIO_PWM / 4;
bcm2835_spi0 = bcm2835_peripherals + BCM2835_SPI0_BASE / 4;
bcm2835_bsc0 = bcm2835_peripherals + BCM2835_BSC0_BASE / 4;
bcm2835_bsc1 = bcm2835_peripherals + BCM2835_BSC1_BASE / 4;
bcm2835_st = bcm2835_peripherals + BCM2835_ST_BASE / 4;

#ifdef DEBUG_bcm2835_init
cout << "\033[1;32m VERIFY TRACE ENTRY \033[0m\n";
cout << "*** TRACE file " << __FILE__ << endl;
cout << " function " << __FUNCTION__ << endl;
cout << " line " << __LINE__ << endl;
exit(1);
#endif

return 1; /* Success */
}

/* Figure out the base and size of the peripheral address block
// using the device-tree. Required for RPi2, optional for RPi 1
* Or actually needed on RPi3 or Zero
*/
if ((fp = fopen(BMC2835_RPI2_DT_FILENAME, "rb"))) {
unsigned char buf[4];
fseek(fp, BMC2835_RPI2_DT_PERI_BASE_ADDRESS_OFFSET, SEEK_SET);
if (fread(buf, 1, sizeof(buf), fp) == sizeof(buf))
bcm2835_peripherals_base = (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))
bcm2835_peripherals_size = (buf[0] << 24 | buf[1] << 16
| buf[2] << 8 | buf[3] << 0);

#ifdef DEBUG_bcm2835_init
cout << "\033[1;31mTRACE \033[0m\n";
cout << "*** TRACE file " << __FILE__ << endl;
cout << " function " << __FUNCTION__ << endl;
cout << " line " << __LINE__ << endl;
cout << " device tree " << BMC2835_RPI2_DT_FILENAME << endl;
cout << " bcm2835_peripherals_base " << bcm2835_peripherals_base
<< endl;
cout << " bcm2835_peripherals_size " << hex << bcm2835_peripherals_size
<< dec << endl;
//exit(1);
#endif

fclose(fp);
}

/*
* either use tree
* or "hardwired defaults" ?
*
*
*
*/

/* else we are prob on RPi 1 with BCM2835, and use the hardwired defaults */
// so what is this for (?)
/* Now get ready to map the peripherals block */
memfd = -1;
ok = 0;
/* Open the master /dev/memory device */
if (gpiomem) {
// clear bcm2835_peripherals_base (?)
bcm2835_peripherals_base = 0;
if ((memfd = open("/dev/gpiomem", O_RDWR | O_SYNC)) < 0) {
// failed to open , exiting
#ifdef DEBUG_bcm2835_init
perror("Result /dev/gpiomem ");
fprintf(stderr, "bcm2835_init: Unable to open /dev/gpiomem: %s\n",
strerror(errno));
cout << "\033[1;32m TRACE ENTRY \033[0m\n";
cout << "*** TRACE file " << __FILE__ << endl;
cout << " function " << __FUNCTION__ << endl;
cout << " line " << __LINE__ << endl;
//exit(1);
#endif
#ifdef DEBUG_bcm2835_init
cout << "\033[1;32m VERIFY TRACE ENTRY \033[0m\n";
cout << "*** TRACE file " << __FILE__ << endl;
cout << " function " << __FUNCTION__ << endl;
cout << " line " << __LINE__ << endl;
exit(1);
#endif

return -1;
}
} else {
if ((memfd = open("/dev/mem", O_RDWR | O_SYNC)) < 0) {

#ifdef DEBUG_bcm2835_init
perror("Result /dev/mem ");
fprintf(stderr, "bcm2835_init: Unable to open /dev/mem: %s\n",
strerror(errno));
cout << "\033[1;32m TRACE ENTRY \033[0m\n";
cout << "*** TRACE file " << __FILE__ << endl;
cout << " function " << __FUNCTION__ << endl;
cout << " line " << __LINE__ << endl;
exit(1);
#endif
#ifdef DEBUG_bcm2835_init
cout << "\033[1;32m VERIFY TRACE ENTRY \033[0m\n";
cout << "*** TRACE file " << __FILE__ << endl;
cout << " function " << __FUNCTION__ << endl;
cout << " line " << __LINE__ << endl;
exit(1);
#endif

return -1;
}

#ifdef DEBUG_bcm2835_init
cout << "\033[1;32m VERIFY memfd = open \033[0m\n";
cout << "*** TRACE file " << __FILE__ << endl;
cout << " function " << __FUNCTION__ << endl;
cout << " line " << __LINE__ << endl;
cout << "memfd " << memfd << endl;
//exit(1);
#endif

}

// 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);

#ifdef DEBUG_bcm2835_init
perror("Result bcm2835_peripherals ");
cout << "\033[1;32m TRACE ENTRY \033[0m\n";
cout << "*** TRACE file " << __FILE__ << endl;
cout << " function " << __FUNCTION__ << endl;
cout << " line " << __LINE__ << endl;
cout << " bcm2835_peripherals " << +bcm2835_peripherals << endl;
//exit(1);
#endif
// check validity
if (bcm2835_peripherals == MAP_FAILED) {

#ifdef DEBUG_bcm2835_init
perror("Result bcm2835_peripherals ");
cout << "\033[1;32m TRACE ENTRY \033[0m\n";
cout << "*** TRACE file " << __FILE__ << endl;
cout << " function " << __FUNCTION__ << endl;
cout << " line " << __LINE__ << endl;
cout << " bcm2835_peripherals " << bcm2835_peripherals << endl;
// exit(1);
#endif

return -1;
}

/* Now compute the base addresses of various peripherals,
// which are at fixed offsets within the mapped peripherals block
// Caution: bcm2835_peripherals is uint32_t*, so divide offsets by 4
*/
if (gpiomem) {
// checkin what (?)
bcm2835_gpio = bcm2835_peripherals;
} else {

bcm2835_gpio = (uint32_t*) bcm2835_peripherals +
BCM2835_GPIO_BASE / 4;
perror("Result bcm2835_gpio ");
#ifdef BYPASS
/*
bcm2835_gpio = bcm2835_peripherals +
BCM2835_GPIO_BASE / 4;
*/
cout << "bcm2835_peripherals " << bcm2835_peripherals << endl;
cout << "BCM2835_GPIO_BASE / 4 " << hex << BCM2835_GPIO_BASE / 4
<< endl;

cout << "bcm2835_gpio " << bcm2835_gpio << endl;
cout << " function " << __FUNCTION__ << endl;
cout << " line " << __LINE__ << endl;
exit(1);
#endif
bcm2835_pwm = bcm2835_peripherals + BCM2835_GPIO_PWM / 4;

bcm2835_clk = bcm2835_peripherals + BCM2835_CLOCK_BASE / 4;
bcm2835_pads = bcm2835_peripherals + BCM2835_GPIO_PADS / 4;
bcm2835_spi0 = bcm2835_peripherals + BCM2835_SPI0_BASE / 4;
bcm2835_bsc0 = bcm2835_peripherals + BCM2835_BSC0_BASE / 4; /* I2C */
bcm2835_bsc1 = bcm2835_peripherals + BCM2835_BSC1_BASE / 4; /* I2C */
bcm2835_st = bcm2835_peripherals + BCM2835_ST_BASE / 4;
}

ok = 1;

exit: if (memfd >= 0)
close(memfd);

if (!ok)
bcm2835_close(); // TODO not checked
// returns 1 on success !
// shoulds return 0 as every other function
// forced to 0 on sucess
#ifdef DEBUG_bcm2835_init
perror("Result bcm2835_peripherals ");
cout << "\033[1;32m TRACE ENTRY \033[0m\n";
cout << "*** TRACE file " << __FILE__ << endl;
cout << " function " << __FUNCTION__ << endl;
cout << " line " << __LINE__ << endl;
cout << " bcm2835_peripherals " << bcm2835_peripherals << endl;
//exit(1);
#endif

return 0;
}


</pre>
GeneralRe: volatile misbehaves Pin
leon de boer20-May-18 4:41
leon de boer20-May-18 4:41 
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 

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.