Click here to Skip to main content
15,887,485 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: volatile issue - repost Pin
leon de boer22-May-18 15:44
leon de boer22-May-18 15:44 
GeneralRe: volatile issue - repost Pin
Vaclav_22-May-18 17:44
Vaclav_22-May-18 17:44 
GeneralRe: volatile issue - repost Pin
leon de boer22-May-18 18:13
leon de boer22-May-18 18:13 
GeneralRe: volatile issue - repost SOLVED Pin
Vaclav_23-May-18 3:17
Vaclav_23-May-18 3:17 
QuestionRe: volatile issue - repost SOLVED Pin
CPallini23-May-18 3:28
mveCPallini23-May-18 3:28 
GeneralRe: volatile issue - repost SOLVED Pin
Richard MacCutchan23-May-18 3:32
mveRichard MacCutchan23-May-18 3:32 
GeneralRe: volatile issue - repost SOLVED Pin
Peter_in_278023-May-18 3:44
professionalPeter_in_278023-May-18 3:44 
GeneralRe: volatile issue - repost SOLVED Pin
leon de boer23-May-18 6:55
leon de boer23-May-18 6:55 
Quote:
If uint32 is 4 bytes wide - why did they name it "32"?

4 bytes each of 8 bits = 4 x 8 = 32 bits .. its unsigned and a type .... so uint32_t Smile | :)
8 bytes of 8 bits = 8 x 8 = 64 bits .... so uint64_t also means 8 bytes.
Unlike int, long etc the sizes in bits and bytes are fixed in stone on every C compiler that meets the standard.

So we can basically say uint32_t is always 4 bytes, uint64_t is always 8 bytes on any C/C++ compiler

Yes correct it adds by 4 and as EVERYTHING on the PI 1,2 or 3 is aligned to 4 bytes they are an ARM RISC processor
and unaligned access is less than desirable. It is actually illegal and not predictable on many earlier ARM CPU's.

On your Pi3 which is 4 x Cortexa53 cores unaligned access is generally configured to raise an error exception but
can handle it if required. Now here is the big but, there is a MASSIVE penalty for unaligned access not just from the
CPU but the caches don't work properly.

The bottom line however is every hardware register is aligned to 4 bytes (that is it's divisible by 4) and can only
be written with 4 bytes at once (even in 64 bit mode). So the behaviour of uint32_t pointer addition is desirable and
ideal.

There is one further thing we generally do to make it compatible to for 64bit code for the Pi3 which is we declare
the pointers and/or structs representing hardware as align 4 with a GCC attribute. A typical sample will look like
this
/*--------------------------------------------------------------------------}
{  RASPBERRY PI SYSTEM TIMER HARDWARE REGISTERS - BCM2835 Manual Section 12	}
{--------------------------------------------------------------------------*/
struct __attribute__((__packed__, aligned(4))) SystemTimerRegisters {
	uint32_t ControlStatus;											// 0x00
	uint32_t TimerLo;												// 0x04
	uint32_t TimerHi;												// 0x08
	uint32_t Compare0;												// 0x0C
	uint32_t Compare1;												// 0x10
	uint32_t Compare2;												// 0x14
	uint32_t Compare3;												// 0x18
};

The reason is that the cortexa53 in AARCH64 mode natively runs everything in 8 byte alignment which it calls a word. It does however
have the ability to do half word (4 byte writes) and the aligned(4) is the way to tell it to use half word access. The packed
attribute is because without that the struct will have uint32_t spaced every 8 bytes (so 4 bytes uint32_t then 4 byte gap)

A volatile pointer to a hardware register is similarly written with an aligned 4
#define GPIO ((volatile __attribute__((aligned(4))) uint32_t*)(uintptr_t)(RPi_IO_Base_Addr + 0x200000))

So things written in this way work with 32bit and 64bit compilers for the Pi3.
It's not important on 32bit compilers but 64 bit compilers produce invalid code without it.

I program mainly in baremetal on the Pi .. so no O/S at all we just put our files on the blank SD card
GitHub - LdB-ECM/Raspberry-Pi: My public Baremetal Raspberry Pi code[^]
In vino veritas


modified 23-May-18 13:36pm.

GeneralRe: volatile issue - repost SOLVED Pin
Vaclav_24-May-18 5:53
Vaclav_24-May-18 5:53 
GeneralRe: volatile issue - repost SOLVED Pin
supercat931-May-18 12:48
supercat931-May-18 12:48 
GeneralRe: volatile issue - repost SOLVED Pin
leon de boer4-Jun-18 21:05
leon de boer4-Jun-18 21:05 
GeneralRe: volatile issue - repost SOLVED Pin
supercat98-Jun-18 10:31
supercat98-Jun-18 10:31 
QuestionReturn a local 2d Array Pin
kinderu18-May-18 8:59
kinderu18-May-18 8:59 
AnswerRe: Return a local 2d Array Pin
Richard MacCutchan18-May-18 9:13
mveRichard MacCutchan18-May-18 9:13 
GeneralRe: Return a local 2d Array Pin
kinderu18-May-18 9:45
kinderu18-May-18 9:45 
GeneralRe: Return a local 2d Array Pin
leon de boer18-May-18 16:34
leon de boer18-May-18 16:34 
GeneralRe: Return a local 2d Array Pin
Richard MacCutchan18-May-18 20:46
mveRichard MacCutchan18-May-18 20:46 
AnswerRe: Return a local 2d Array Pin
jfbode102930-May-18 4:46
jfbode102930-May-18 4:46 
QuestionCan someone show me an example of including a DLL or function in a C program ? Pin
m3mb3r17-May-18 10:41
m3mb3r17-May-18 10:41 
SuggestionRe: Can someone show me an example of including a DLL or function in a C program ? Pin
Randor 17-May-18 11:52
professional Randor 17-May-18 11:52 
AnswerRe: Can someone show me an example of including a DLL or function in a C program ? Pin
Richard MacCutchan17-May-18 21:40
mveRichard MacCutchan17-May-18 21:40 
AnswerRe: Can someone show me an example of including a DLL or function in a C program ? Pin
leon de boer18-May-18 8:58
leon de boer18-May-18 8:58 
Questionvolatile misbehaves Pin
Vaclav_17-May-18 3:19
Vaclav_17-May-18 3:19 
AnswerRe: volatile misbehaves Pin
Richard MacCutchan17-May-18 4:04
mveRichard MacCutchan17-May-18 4:04 
GeneralRe: volatile misbehaves Pin
Vaclav_17-May-18 4:26
Vaclav_17-May-18 4:26 

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.