📄 example_x_space_modulo_buffer.c
字号:
/* Example illustrating how to create and incrementing modulo buffer
in X Data Space. The example also shows how to create an
decrementing modulo buffer in Y Data Space */
/***********************************************************************
* An incrementing modulo buffer for use in assembly language can be *
* easily defined in C. In this example, the macro _XBSS is used to *
* define an array whose memory alignment is the smallest power of *
* two that is greater than or equal to its size. _XBSS is defined in *
* the processor header file, which in this example is p30f6014.h. *
* *
* A decrementing modulo buffer for use in assembly language can be *
* easily defined in C. In this case, the ending address +1 of the *
* array must be aligned. There is not a suitable predefined macro *
* in the processor header files for this purpose, so variable *
* attributes are specified directly. The far attribute is recommended *
* because Y memory does not fall within the near space on all devices,*
* and the compiler uses a small-data memory model by default. *
* *
* You can view the results of the printf statements by enabling the *
* MPLAB SIM tool then enabling the UART1 I/O with Output set to *
* Window. The printf results are then displayed in the output window. *
* *
* A defined heap size is required since we are using a standard I/O *
* function. *
* *
* For additional information about dsPIC architecture and language *
* tools, refer to the following documents: *
* *
* MPLAB C30 Compiler User's Guide : DS51284 *
* dsPIC 30F MPLAB ASM30, MPLAB LINK30 and Utilities *
* User's Guide : DS51317 *
* Getting Started with dsPIC DSC Language Tools : DS51316 *
* dsPIC 30F Language Tools Quick Reference Card : DS51322 *
* dsPIC 30F 16-bit MCU Family Reference Manual : DS70046 *
* dsPIC 30F Programmer's Reference Manual : DS70030 *
* *
* Example file has been compiled with MPLAB C30 v1.30.00 *
* *
************************************************************************
* *
* Author: *
* Company: *
* Filename: Ex_X_Space_Modulo_Buffer.c *
* Date: 02/01/2005 *
* File Version: 1.00 *
* Other Files Required: p30f6014.gld *
* Tools Used: MPLAB IDE -> 7.01.00 *
* Compiler -> 1.30.00 *
* Assembler -> 1.30.00 *
* Linker -> 1.30.00 *
* *
***********************************************************************/
/* Include the appropriate header (.h) file, depending on device used */
/* Example (for dsPIC30F5013): #include <p30f5013.h> */
/* Alternatively include the generic header file, p30fxxxx.h, as shown
below. */
/* load SFR definitions and macros */
#include "p30fxxxx.h"
#include "stdio.h"
/* define/declare array aligned in X Data Space */
int _XBSS(128) xbuf[50];
/* define/declare array aligned in Y Data Space */
int __attribute__((space(ymemory), far, reverse(128))) ybuf[50];
int main( void )
{
printf("Should be zero: %x\n", (int) &xbuf % 128);
printf("Should be zero: %x\n", ((int) &ybuf + sizeof(ybuf)) % 128);
while( 1 );
}
/*
// CREATING AN INCREMENTING MODULO BUFFER IN X MEMORY
The equivalent definition in assembly language appears below. The
section alignment could have specified with a separate .align
directive. By using * as a section name, the linker is afforded
maximum flexibility to allocate memory.
.global _xbuf
.section *,xmemory,bss,align(128)
_xbuf: .space 100
// CREATING AN DECREMENTING MODULO BUFFER IN Y MEMORY
The equivalent definition in assembly language appears below.
Reverse section alignment can only be specified as an argument
to the .section directive.
.global _ybuf
.section *,ymemory,reverse(128)
_ybuf: .space 100
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -