简体   繁体   English

处理器字大小? 8位处理器= 8位字?

[英]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? 我想如果我有一个AVR 8位微控制器,则字数为8位/ 1字节? But in the datasheet it states that most AVR processors have a 16bit word. 但在数据表中,它表​​明大多数AVR处理器都有16位字。 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? 但是什么是8位32位MCU,如果这不是字大小?

If wordsize = 2 byte then this is atomic in C right: U16 Position; 如果wordsize = 2个字节,那么这在C中是原子的:U16位置;

Position = 1000; 位置= 1000;

But if the word is 1 byte I should disable interrupts (the interrupt uses this variable) when writing to this variable? 但是,如果该字是1字节,我应该在写入此变量时禁用中断(中断使用此变量)? 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. 传统的AVR系列(即ATtiny,ATmega,ATxmega,而非AVR32)是8位MCU,用于8位寄存器/累加器,但有一些16位指令,例如通过地址对处理指针时。

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. 在这种情况下,我怀疑作者只是将16位值称为字,而不是8位字节或32位双字。

So, no, you cannot count on a 16-bit variable being accessed atomically. 所以,不,你不能指望以原子方式访问的16位变量。 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. 值得庆幸的是一些最重要的I / O寄存器,例如定时器,其中有重要的内部锁存器来隐藏事实,但你需要注意与中断共享的RAM变量。

Temporarily disabling interrupts is quite fast, a cycle each for the CLI/SEI instructions. 临时禁用中断非常快,每个都是CLI / SEI指令的循环。 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. 某些编译器的问题(ImageCraft浮现在脑海中)是在函数中使用这样的内联汇编可能会禁用优化,因此实际成本可能会更高一些。 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. 请注意,与其他一些MCU不同,原子位访问通常仅限于最低I / O端口范围内的一小部分寄存器,通常是几个PORT和通用寄存器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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