Data Memory with EDS management

From openPicus Wiki
Jump to: navigation, search

Contents

What you are going to learn

This tutorial shows you how to manage the internal Data Memory with Extended Data Space (EDS).

Extended Data Space

The FlyportPRO has an internal RAM greater (96 Kbytes) than the normal Flyport.
It is divided in 4 pages in total:
1 page with 30 KB (Data RAM Space);
2 pages with 32 KB each (EDS);
1 page with 2 KB (EDS).
This partition is due to the fact that a single pointer (16 bits) would not be able to scan the entire memory.

How to use it

To use the EDS Space is very simple.
There are two way to initialize a variable in this space:
1) Out the Task

__eds__ int longArray[16000] __attribute__((eds));

2) In the Task

__eds__ static int longArray[16000] __attribute__((eds));


The biggest array, which is possible declared, is 32 KB. It depends on data type and length of the array, their multiplication must not exceed 32 Kbytes.
Example:

__eds__ int longArray[16000] __attribute__((eds));    //32 kB
 
---
 
__eds__ BYTE longArray[16000] __attribute__((eds));   //16 kB
 
---
 
__eds__ DWORD longArray[8000] __attribute__((eds));   //32 kB


N.B. The sum of all variable in the firmware must be 96 KB. The user space is approximately 88 Kilobytes.

If you want to create a pointer, it must be created in this way:

__eds__ int* pointer;

Code example

#include "taskFlyport.h"
 
//	Declaring a var in this way to use the extended PIC memory
__eds__ int longArray[16000] __attribute__((eds));
 
void FlyportTask()
{
	int i, a = 1;
	char buff[30];
	//	Static array declared inside Flyport task assigned in extended memory
	__eds__ static int longArray2[16000] __attribute__((eds));
 
	vTaskDelay(25);
	UARTWrite(1,"EDS memory example\r\n\r\n");
 
	//	Initializing the array's element with numbers from 0 to 16000 + 1
	for (i=0; i<16000; i++)
		longArray[i] = i + a;
 
	//	Three elements of the array are printed on serial just to show that the array is correctly
	sprintf(buff,"longArray[500]: %d\r\n", longArray[500]);
	UARTWrite(1, buff);
	sprintf(buff,"longArray[12367]: %d\r\n", longArray[12367]);
	UARTWrite(1, buff);
	sprintf(buff,"longArray[14590]: %d\r\n\r\n", longArray[14590]);
	UARTWrite(1, buff);
 
	//	----- longArray2 usage + pointer example -----
	//	Initializing the array's element with numbers from 0 to 16000 + 2
	for (i=0; i<16000; i++)
		longArray2[i] = i + 2;
 
	//	Here a pointer to an __eds__ int is declared (no __attribute__((eds))) is needed, it is placed in standard memory)
	//	now the pointer can point to longArray2, and we can use it in the sprintf, try to remove the __eds__ tag in the following
	//	declaration and the compiler will return error, since you are using an int* pointer to point an __eds__ int var.
	__eds__ int* pointer;
	pointer = longArray2;
	//	Three elements of the array are printed on serial just to show that the array is correctly
	sprintf(buff,"longArray2[500]: %d\r\n", *(pointer + 500));
	UARTWrite(1, buff);
	sprintf(buff,"longArray2[12367]: %d\r\n", *(pointer + 12367));
	UARTWrite(1, buff);
	sprintf(buff,"longArray2[14590]: %d\r\n", *(pointer + 14590));
	UARTWrite(1, buff);
	while(1)
	{
		//	Main user's firmware loop
	}
}
Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox