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 CCS Technical Support

Typemod using custom external ram functions

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



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

Typemod using custom external ram functions
PostPosted: Thu Apr 20, 2006 2:38 pm     Reply with quote

PCWH R3.249 I am seeing a typemod bug I can't explain.
I am using typemod for access to external memory as shown here.
http://www.ccsinfo.com/faq.php?page=addressmod
I made shell read and write functions.
The write function just prints the proposed data.
If I put in a line for "record2" I see expected data.
If I take that line out, I don't see the expected data.
Does anyone understand whats going on here?

Code:
#include <18F452.H>
#use delay(clock=40000000)
#fuses h4,nowdt,noprotect,nolvp
#use rs232(baud=19200,xmit=PIN_C0,invert,stream=DEBUG,disable_ints) // stderr(same as debug)
#case
#zero_ram
//---------------------------------------------
mr(int32 addr,int8 *data,int8 size);
mw(int32 addr,int8 *data,int8 size);
//---------------------------------------------
typemod <,mr,mw,0x0000,0xFFFF>RAM;//24 bit address ,16 bit range
//---------------------------------------------
struct  rec_struc //rec definition
{
  int16 pc;
  int16 ai;
  int8  tz;
}RAM record;
int16 RAM record2;
//====================================================================//
void main(void)
{
  setup_adc_ports(NO_ANALOGS);
  set_tris_a(0);set_tris_b(0);set_tris_c(0);set_tris_d(0);set_tris_e(0);
  printf("Start\n\r");
  record.pc=0x1122;
  record.ai=0x3344;
  record.tz=0x55;
  record2  =0x6677;  //<----------------Take out this line and it BLOWS up
  printf("DONE !\n\r");
  while(1)
  {
  }
}
//======================multi_write===========================//
mw(int32 addr,int8 *data,int8 size)
{
  int8 x;
  int32 start_size;
  start_size=size;
  fprintf(DEBUG,"write addr=%lu s=%u ",addr,size);
  for(x=0;x<size;x++,data++){
    fprintf(DEBUG,"0x%X,",*data);
  }
  fprintf(DEBUG,"\n\r");
  return(TRUE);
}
//======================multi_read===========================//
mr(int32 addr,int8 *data,int8 size){
}

Code:

//--BAD--
write addr=0 s=2 0x22,0x00,           
write addr=2 s=2 0x44,0x02,           
write addr=4 s=1 0x55,               

Code:

//--Good--
write addr=0 s=2 0x22,0x11,           
write addr=2 s=2 0x44,0x33,           
write addr=4 s=1 0x55,               
write addr=5 s=2 0x77,0x66,           


Last edited by treitmey on Thu Apr 20, 2006 3:46 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 20, 2006 3:34 pm     Reply with quote

Quote:
struct rec_struc //rec definition
{
int16 pc;
int16 ai;
int8 tz;
}RAM record;
int16 RAM record2;


One thing you might try is to take the "record" declaration out
of the structure and typdef the structure instead. Then use the
type to declare "record" on a separate line of code. I haven't
tested this but it's something to try. The way you describe the
problem implies that possibly CCS is looking for a typedef, and
they may have only tested it in that manner.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Thu Apr 20, 2006 3:50 pm     Reply with quote

Thanks
Seems to work. Doesn't give me a "warm fuzzy" feeling tho. Wink
Code:
#include <18F452.H>
#use delay(clock=40000000)
#fuses h4,nowdt,noprotect,nolvp
#use rs232(baud=19200,xmit=PIN_C0,invert,stream=DEBUG,disable_ints) // stderr(same as debug)
#case
#zero_ram
int8 ERRORS;
#define FRAM_CHIPS 4
//-------prototype-------------------------------
mr(int32 addr,int8 *data,int8 size);
mw(int32 addr,int8 *data,int8 size);
//---------------------------------------------
typemod <,mr,mw,0x0000,0xFFFF>RAM;//24 bit address ,16 bit range
//---------------------------------------------
struct  rec_struc //rec definition
{
  int16 pc;
  int16 ai;
  int8  tz;
};
//====================================================================//
void main(void)
{
struct rec_struc RAM record;
  setup_adc_ports(NO_ANALOGS);
  set_tris_a(0);set_tris_b(0);set_tris_c(0);set_tris_d(0);set_tris_e(0);
  printf("Start\n\r");
  record.pc=0xBBAA;
  record.ai=0xDDCC;
  record.tz=0xFF;
  printf("DONE !\n\r");
  while(1)
  {
  }
}
//======================multi_write===========================//
mw(int32 addr,int8 *data,int8 size)
{
  int8 x;
  int32 start_size;
  start_size=size;
  fprintf(DEBUG,"write addr=%lu s=%u ",addr,size);
  for(x=0;x<size;x++,data++){
    fprintf(DEBUG,"0x%X,",*data);
  }
  fprintf(DEBUG,"\n\r");
  return(TRUE);
}
//======================multi_read===========================//
mr(int32 addr,int8 *data,int8 size){
}

I responded so fast, cause I came to that same conclusion. Didn't know why it acted like that tho.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Thu Apr 20, 2006 4:08 pm     Reply with quote

BTW:
#byte and #locate will also screw up typemod variables
It looks like the compiler understands the use,.. but the second
byte of data transfered is corrupted again.
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