CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Assistance with AddressMod()

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
chargedneuron



Joined: 05 May 2007
Posts: 6
Location: Springfield, Oregon, USA

View user's profile Send private message Visit poster's website AIM Address

Assistance with AddressMod()
PostPosted: Wed Oct 10, 2007 1:18 am     Reply with quote

I am trying to create a LARGE data space in my external RAM. For the moment and the sake of simplicity I am using a 24FC1025, (1024K) Flash Chip connected to my PIC16F77 processor.

PIC16F77 @ 20MHz
24FC1025 1024KB Flash, (using 512K) over I2C at 1Mb.
RS232 @ 19200 for relaying debug data to the terminal.
Compiler version 4.056 via MPLab

I seem to be having an issue with AddressMod(); I have searched the forums looking for a bit more info then what is found in the manuals. So far the suggestions found in the few threads related to my issue have yielded very little improvements.

If I use the internal RAM of the processor everything seems to work just fine for a small array. I have also proven out my E2 routines.

I have attached a boiled down version of my program.

Code:

// Select Device type
#include <16F77.h>

// Set large pointers for optimized memory configuration
#device *=16

// Set the Device's Internal Configuration and Fuses
//   High Speed System Clock
//   No WatchDog Timer
//   No Code Protection
#fuses HS,NOWDT,NOPROTECT

// Specifiy the Device's Clock frequency
#use delay(clock=20000000)

// Set the Device's I/O Protocol
#use Fast_IO         // Set Port C to Fast I/O   ( Comms )

// Configure a UART Port for the Device
#use rs232 (baud=19200, xmit=PIN_C6, rcv=PIN_C7)

// Configure a I2C Port for the Device
#use i2c(master, scl=PIN_C1, sda=PIN_C2, Force_SW, Fast = 1000000 )

//   ***   Program Libraries   ***   ***   ***   ***   ***   ***   ***   ***   #include <stdlibm.h>                  // Attach the standard memory librarys
#include <e:\Color LCD Demo\Expanded_Ram_Flash.c>      // Attach Expanded Ram (Flash)

//   ---   Main Function     ---
void main()
{
//   Function Varibles
   int8   index;
   int16   *Pixel;

//   --- Setup Hardware ---
   Set_Tris_C( 0x80 );            // All Output 7 input

//   --- Setup drivers ---
   init_ext_eeprom();            // Initalize the Flash

//   --- Function body ---
   printf("\f\r\nStart\n\n");

//   --- Allocate required RAM ---   
   Pixel = malloc( sizeof(int16) * 20 );
      
//   --- Recall RAM to CLCD ---
   
   printf("\r\nAction");
   
   if( Pixel != NULL )
      printf("\r\n\nAllocated\r\n");
   else
   {
      printf("\r\n\nNOT ALLOCATED!\r\n");
      delay_ms(5000);
   }
   
   for( index = 0; index <= 20; index++ )
      Pixel[ index ] = index;

   for( index = 0; index <= 20; index++ )
      printf("\r\n Index %u   Element %LX", index, Pixel[ index ] );

   printf("\r\n\nDone\n\n\n");

   free( Pixel );


//   --- Endless Loop ---
   while( true );
   
}

With a result of
Code:

Start

Action

Allocated

 Index 0   Element 0000
 Index 1   Element 0001
 Index 2   Element 0002
 Index 3   Element 0003
 Index 4   Element 0004
 Index 5   Element 0005
 Index 6   Element 0006
 Index 7   Element 0007
 Index 8   Element 0008
 Index 9   Element 0009
 Index 10   Element 000A
 Index 11   Element 000B
 Index 12   Element 000C
 Index 13   Element 000D
 Index 14   Element 000E
 Index 15   Element 000F
 Index 16   Element 0010
 Index 17   Element 0011
 Index 18   Element 0012
 Index 19   Element 0013
 Index 20   Element 0014

Done


Next I change the location that 'Pixel' is stored from Internal to External RAM.

Replacing
Code:

   int16   *Pixel;

with
Code:

#Type default=EE_RAM
   int16   *Pixel;
#Type default=


and my result is now
Code:

Start

Action

NOT ALLOCATED!

 Index 0   Element 0900
 Index 1   Element 0902
 Index 2   Element 0904
 Index 3   Element 0906
 Index 4   Element 0908
 Index 5   Element 090A
 Index 6   Element 090C
 Index 7   Element 090E
 Index 8   Element 0910
 Index 9   Element 0912
 Index 10   Element 0914
 Index 11   Element 0900
 Index 12   Element 0900
 Index 13   Element 0900
 Index 14   Element 0900
 Index 15   Element 0900
 Index 16   Element 0900
 Index 17   Element 0900
 Index 18   Element 0900
 Index 19   Element 0900
 Index 20   Element 0900

Done


I don't understand where the 0x09** is coming from. Also the array no longer points to a 2 byte object. And it should have allocated the memory to the object...

The E2 code is below
Code:

#include <e:\Color LCD Demo\241025.c>   // Attach I2C FLASH functions

//   ---   Function Prototypes   ---   ---   ---   ---   ---
void   InitExpRam   ( void );
void   ReadExpRam   ( int32 Addr, int8 *Ram, int8 Bytes );
void   WriteExpRam   ( int32 Addr, int8 *Ram, int8 Bytes );


//   ===   Functions      ===   ===   ===   ===   ===

//   ---   Initalize external Ram   ---   ---   ---   ---   ---
void InitExpRam ( void )
{
   init_ext_eeprom();      // Initalize the Flash
}

//   ---   Read external Ram   ---   ---   ---   ---   ---
void ReadExpRam(  int32 Addr, int8 *Ram, int8 Bytes )
{
   int   index;
   
   for( index = 0; index < bytes; ++index )
      *Ram = read_ext_eeprom( Addr );
}

//   ---   Write external ram   ---   ---   ---   ---   ---
void WriteExpRam( int32 Addr, int8 *Ram, int8 Bytes )
{
   int   index;
   
   for( index = 0; index < bytes; ++index )
      write_ext_eeprom( Addr, *Ram );
}


//   ---   Apply Expanded RAM   ---   ---   ---   ---   ---
addressmod( EE_RAM, ReadExpRam, WriteExpRam, 0x0000, 0xFFFF );

_________________
"Trouble? I call it sport!" - Hyde - The League of Extraordinary Gentlemen



Last edited by chargedneuron on Wed Oct 10, 2007 6:45 pm; edited 1 time in total
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Wed Oct 10, 2007 11:44 am     Reply with quote

It looks like you are attempting to apply concepts that are good for a PC to an Embedded device. You can not dynamically allocate memory on a PIC. Thats not to say memory cant be recycled, it can between non recursive functions for local variables.

You can not really use a pointer to external memory in an EEPROM. The instruction set of the PIC does not support that kind of operation. You know what you want to accomplish. You have to think how is this going to actually work at a low level. I would suggest writing a function to load the indexed data from the EEPROM into LCD RAM. It doesn't have to actually reside in the PIC RAM more than a byte at a time.
chargedneuron



Joined: 05 May 2007
Posts: 6
Location: Springfield, Oregon, USA

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Wed Oct 10, 2007 7:01 pm     Reply with quote

Many thanks for your comments.

I must ask though, if it is not possible to dynamically allocate RAM using AddressMod() & malloc() then why are they included in the CCS compiler?

Obviously by my initial results show that the malloc() works because I managed to allocate 20 bytes, store and recall data from that array.

After applying AddressMod() I continue to see the data allocated but the data size seems corrupted. If I clear the FLASH prior to running this program, using the AddressMod(), The Flash shows that the data was written to the flash. However it seems that the data object sizes are all wrong.

Notice that the second version of the program shows that the array was initialized and written to. Index 0 to Index 10 seem to have the original data there, just a bit compressed and with a mysterious extra byte, (0x09).

For example;


    Index 0 Element 0900
    Index 1 Element 0902
    Index 2 Element 0904
    Index 3 Element 0906
    Index 4 Element 0908
    Index 5 Element 090A
    Index 6 Element 090C
    Index 7 Element 090E
    Index 8 Element 0910
    Index 9 Element 0912
    Index 10 Element 0914


Index 11 to Index 20 are actually pointing to Index 22 to Index 40.

The Flash shows that it was written to as a INT8 object size. If the program is rewritten with a INT8 object size the program works just fine.

Code:

Start


Action
 Clear Flash

NOT ALLOCATED!

 Index 0   Element 00
 Index 1   Element 01
 Index 2   Element 02
 Index 3   Element 03
 Index 4   Element 04
 Index 5   Element 05
 Index 6   Element 06
 Index 7   Element 07
 Index 8   Element 08
 Index 9   Element 09
 Index 10   Element 0A
 Index 11   Element 0B
 Index 12   Element 0C
 Index 13   Element 0D
 Index 14   Element 0E
 Index 15   Element 0F
 Index 16   Element 10
 Index 17   Element 11
 Index 18   Element 12
 Index 19   Element 13
 Index 20   Element 14

Done



  Flash Contents
 0000 --> 00
 0001 --> 01
 0002 --> 02
 0003 --> 03
 0004 --> 04
 0005 --> 05
 0006 --> 06
 0007 --> 07
 0008 --> 08
 0009 --> 09
 000A --> 0A
 000B --> 0B
 000C --> 0C
 000D --> 0D
 000E --> 0E
 000F --> 0F
 0010 --> 10
 0011 --> 11
 0012 --> 12
 0013 --> 13
 0014 --> 14



It is my guess that somewhere in AddressMod(), when it evaluates the object size and stores that in the variable 'byte' the object size is getting messed up. I would say that this could work if we can figure out where the object size is getting fouled up.

Many Thanks!
Cheers! - JMc
_________________
"Trouble? I call it sport!" - Hyde - The League of Extraordinary Gentlemen

Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group