简体   繁体   中英

Processor word size? 8bit processor = 8 bit word?

I thought if I had an AVR 8 bit microcontroller the wordsize is 8 bits/1 byte? But in the datasheet it states that most AVR processors have a 16bit word. But it does not say that the specific processor has that. Weird to state something generally in a specific datasheet.

But what is the 8-bit, 32-bit MCU about if that is not the word size?

If wordsize = 2 byte then this is atomic in C right: U16 Position;

Position = 1000;

But if the word is 1 byte I should disable interrupts (the interrupt uses this variable) when writing to this variable? How slow is it to disable interrupts?

The traditional AVR family (ie ATtiny, ATmega, ATxmega, not the AVR32) are 8-bit MCUs working on 8-bit registers/accumulators, though there are a few 16-bit instructions such as when dealing with pointers through address pairs.

Unfortunately there is no universally accepted definition of what a "word" is. In this context I suspect that the author is simply referring to a 16-bit value as a word, as oppose to an 8-bit byte or a 32-bit double-word.

So, no, you cannot count on a 16-bit variable being accessed atomically. Thankfully some of the most important I/O registers, such as timers, where this matters have internal latches to hide the fact but you do need to be careful with RAM variables shared with interrupts.

Temporarily disabling interrupts is quite fast, a cycle each for the CLI/SEI instructions. One gotcha with certain compilers (ImageCraft comes to mind) is that using inline assembly like this in a function may disable optimizations so the actual cost can be somewhat higher. Consider disabling only the contentious interrupt in question to avoid this issue and to reduce latency.

Beware that unlike some other MCUs atomic bit access is normally restricted to a small subset of registers in the lowest I/O port range, typically a few PORTs and general-purpose registers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM