Alternative microcontroller to PIC

Thread Starter

AlbertHall

Joined Jun 4, 2014
12,651
I have attached a project which has the bare minimum including the array declarations.
I have added a switch so the code will either include or exclude eds attribute.
#define USE_EDS

If this line is uncommented the program compiles just fine. If it is commented out then you get a whole string of 'could not allocate...' messages. I still do not understand why this is so.
 

Attachments

nsaspook

Joined Aug 27, 2009
16,470
Default: without EDS
https://ww1.microchip.com/downloads/en/DeviceDoc/30009717b.pdf
The PIC24F core has a 16-bit wide data memory space, addressable as a single linear range.The data space is accessed using two Address Generation Units (AGUs), one each for read andwrite operations. The data space memory map is shown in Figure 2-1. All Effective Addresses (EAs) in the data memory space are 16 bits wide and point to bytes within the data space. This gives a data space address range of 64 Kbytes or 32K words. The lower32 Kbytes of the data memory space (that is, when EA<15> = 0) are used for implemented memory addresses, while the upper half (EA<15> = 1) is reserved for the Program Space Visibility(PSV) area.
In project properties:
enable xc16-gcc option: Place data into its own section
so you can see where data objects are being located.
xc16-ld 1.61 (B)

Default Code Model: Small
Default Data Model: Large
Default Scalar Model: Small

"program" Memory [Origin = 0x200, Length = 0x555ec]

section address length (PC units) length (bytes) (dec)
------- ------- ----------------- --------------------
.text 0x200 0x100 0x180 (384)
.dinit 0x300 0x5c 0x8a (138)
.text 0x35c 0x2 0x3 (3)

Total "program" memory used (bytes): 0x20d (525) <1%


"data" Memory [Origin = 0x1000, Length = 0xc000]

section address alignment gaps total length (dec)
------- ------- -------------- -------------------
.nbss.pathLength 0x1000 0 0x4 (4)
.nbss.pathLocation 0x1004 0 0x4 (4)
.nbss.pathBank 0x1008 0 0x4 (4)
.bss.Rdata 0x100c 0 0x1000 (4096)
.bss.Edata 0x200c 0 0x1000 (4096)
.bss.walkability 0x300c 0 0x598 (1432)
.Hcost 0x68c6 0 0xb32 (2866)
.Fcost 0x73f8 0 0xb32 (2866)
.openY 0x7f2a 0 0xb32 (2866)
.openX 0x8a5c 0 0xb32 (2866)
.openList 0x958e 0 0xb32 (2866)
.Gcost 0xa0c0 0 0xbd0 (3024)
.parentY 0xac90 0 0xbd0 (3024)
.parentX 0xb860 0 0xbd0 (3024)
.whichList 0xc430 0 0xbd0 (3024)

Total "data" memory used (bytes): 0x8cde (36062) 73%


Dynamic Memory Usage

region address maximum length (dec)
------ ------- ---------------------
heap 0 0 (0)
stack 0x35a4 0x3322 (13090)

Maximum dynamic memory (bytes): 0x3322 (13090)
With EDS
https://ww1.microchip.com/downloads/en/DeviceDoc/39733a.pdf
PIC24F Family Reference ManualDS39733A-page 45-2Advance Information© 2009 Microchip Technology Inc.45.1
INTRODUCTION
To cater to the need of large data memory for some applications, like USB and Graphics, the data address space of some of the PIC24F microcontrollers (MCUs) are extended. These PIC24FMCUs with Extended Data Space (EDS) can access up to 16 Mbytes of additional data memory,both internal and external.
...
The PIC24F core has a 16-bit wide data memory space, addressable as a single linear range.The data space is accessed using two Address Generation Units (AGUs), one each for read andwrite operations. The data space memory map is shown in Figure 45-1. The 16-bit wide data addresses in the data memory space point to bytes within the Data Space(DS). This gives a DS address range of 64 Kbytes or 32K words, including 2 Kbytes of SFRspace. The lower 32 Kbytes (0x0000 to 0x7FFF) of the DS are compatible with the PIC24F MCUs without EDS.The upper 32 Kbytes of data memory address space (0x8000-0xFFFF) are used as an EDS window. The EDS window is used to access all of the memory region that is implemented in EDS,as shown in Figure 45-2.The EDS includes any additional internal data memory not accessible by the lower 32 Kbytes ofdata address space and any external memory through Enhanced PMP. In PIC24F MCUs with EDS, the Program Memory (PM) can also be read from EDS. This is called Program SpaceVisibility (PSV).The EDS is organized as pages, with a single page called an EDS page that equals the EDSwindow (32 Kbytes). A particular EDS page is selected through the Data Space Read register(DSRPAG) or Data Space Write register (DSWPAG). For PSV, only the DSRPAG register is used.The combination of DSxPAG register value and the 16-bit wide data address forms a 24-bitEffective Address (EA). See Section 45.3.1 “Data Access from EDS” for details on how EAsare generated for EDS address space for accessing internal extended data memory, externaldata memory and PSV address space for reading data from PM.
The 32-Kbyte EDS window is enabled when bit 15 of the data space address, provided in one of
the working registers (Wn), is set and the DSRPAG/DSWPAG register holds a valid EDS page
address. Each 32-Kbyte EDS window maps to the corresponding address of the selected EDS
page. The EDS page can be programmed in the DSRPAG register while reading memory, or in
the DSWPAG register while writing to a memory location. In PIC24F MCUs with EDS, the page
registers do not update automatically while crossing a page boundary. While developing code in
assembly, care must be taken to update page registers while the data memory access crosses
the page boundary. The ‘C’ compiler keeps track of the addressing, and increments or
decrements the page registers accordingly, while accessing contiguous data memory locations.
https://microchipdeveloper.com/16bit:extending-data-memory-on-a-16-bit-pic-mcu
MPLAB XC16 compiler will create a 32-bit pointer when the __eds__ qualifier is used during a pointer's declaration. 32-bit EDS qualified pointers are capable of being loaded with the virtual address of any operand. For the PIC24FJ256DA210, the virtual address for memory ranges from 0x0800 to 0x178FE (with all addresses above 0x8000 located in EDS memory). When accessing any variable with through an __eds__ qualified pointer, the compiler will ensure the appropriate values are loaded into PSRPAG and PSWPAG.
eds-def.png
 
Last edited:

nsaspook

Joined Aug 27, 2009
16,470
I have attached a project which has the bare minimum including the array declarations.
I have added a switch so the code will either include or exclude eds attribute.
#define USE_EDS

If this line is uncommented the program compiles just fine. If it is commented out then you get a whole string of 'could not allocate...' messages. I still do not understand why this is so.
Do you understand now?
 

nsaspook

Joined Aug 27, 2009
16,470
I am still working on it. My brain is close to exploding.
The concept is interesting (to a person who has studied OS design) as it gives a limited demand paging capability to the chip using the C runtime (vs a demand paging OS) to manage the paging registers in a quasi 32-bit VM address. Obviously there is a runtime penalty for using this feature (as opposed to a real MMU with memory protection like in 32-bit chips) to access more than the normal linear memory address range but by wisely selecting what arrays go to 'normal' low memory for fast access and what goes to upper 'slower' memory should limit that performance hit in the application.
 

Thread Starter

AlbertHall

Joined Jun 4, 2014
12,651
I can create the arrays using EDS but it seems I cannot access them!
I have attached the complete, very short, project. When run in the simulator this hits the AddressError trap at line 51: openX[1] = 1;
Why, or more importantly, how do I get to access this array?
 

Attachments

nsaspook

Joined Aug 27, 2009
16,470
Qualifier order matters.
Added a __eds__ X pointer example to show alternate array mode addressing of the X pointer.

C:
__eds__ __attribute__ ((eds)) uint16_t openX[mapWidth*mapHeight+2] ; //1d array stores the x location of an item on the open list
__eds__ uint16_t *X;

int main ( void ) 
{
    X=&openX[0];
    X[1]=1;
    openX[1] = 1; 
    while(1);
}
 
Top