gpt4 book ai didi

c - 程序存储器中的 Hitech C 数据缓冲区

转载 作者:行者123 更新时间:2023-11-30 14:22:51 25 4
gpt4 key购买 nike

C18 编译器允许在具有 ROM 限定符的程序存储器中使用变量,但 Hi-Tech C 似乎不太愿意充分利用 Havard 架构。那么有没有办法用高科技C编译器在程序存储器中创建数据缓冲区(我准备牺牲访问速度)。

我已经看到 psect 的可能性,但没有任何有效的实现。

最佳答案

HI-TECH PICC18 编译器默认将声明为 const 的对象放入程序空间。不需要像 C18 的 RAM/ROM 这样的特殊限定符:

3.5.3 Objects in Program Space

const objects are usually placed in program space. On the PIC18 devices, the program space is byte-wide, the compiler stores one character per byte location and values are read using the table read instructions. All const-qualified data objects and string literals are placed in the const psect. The const psect is placed at an address above the upper limit of RAM since RAM and const pointers use this address to determine if an access to ROM or RAM is required.

请注意,将频繁更新的数据放入微 Controller 的闪存中可能不是一个好主意,因为闪存的编程/删除周期数量有限。

far 指针可用于取消引用程序内存:

3.4.12.2 Const and Far Pointers

const and far pointers can either be 16 or 24 bits wide. Their size can be toggled with the --CP=24 or --CP=16 command line option. The code used to dereference them also changes with their size. The same pointer size must be used for all modules in a project. A pointer to far is identical to a pointer to const, except that pointers to far may be used to write to the address they hold. A pointer to const objects cannot be used to write as the const qualifier imposes that the object is read-only. const and far pointers which are 16 bits wide can access all RAM areas and most of the program space. At runtime when dereferenced, the contents of the pointer are examined. For addresses above the upper limit of RAM the program space is accessed using table read or table write instructions. Addresses below the upper limit of RAM access the data space. Even if the address held by a pointer to const is in RAM, the RAM location may not be changed. The default linker options always place const data at addresses above the upper limit of the data space so that the correct memory space is accessed when dereferencing with pointers. If the target device selected has more than 64k bytes of program space memory, then only the lower 64k bytes may be accessed with 16-bit wide pointers. Provided that all program space objects that need to be dereferenced are in the lower 64k bytes, 16-bit pointers to const and far objects may still be used. The smaller pointer size results in less RAM required and less code produced and so should be used whenever possible. const and far pointers which are 24 bits wide can access all RAM areas and all of the program space. At runtime when dereferenced, the contents of the pointer are examined. If bit number 21 in the address is set, the address is assumed to be a RAM address. Bit number 21 of the address is then ignored. If Bit number 21 is clear, then the address is assumed to be of an object in the program space and the access is performed using table read or table write instructions. Again, no writes to objects are permitted using a pointer to const. Note that when dereferencing a 24-bit pointer, the most significant implemented bit (bit number 21) of the TBLPTRU register may be overwritten. This bit may be used to enable access to the configuration area of the PIC18 device. If loading the table pointer registers from hand-written assembler code, make no assumptions about the state of bit number 21 prior to executing table read or write instructions.

引用自HI-TECH PICC18 v9.51手册。

关于c - 程序存储器中的 Hitech C 数据缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13430970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com