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

loader

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



Joined: 16 Sep 2003
Posts: 21

View user's profile Send private message

loader
PostPosted: Sun Sep 10, 2006 4:23 pm     Reply with quote

Another tiresome loader question I'm sure.
PIC18F252 or 2520
My Loader located above 0x7B00


Quits at l_addr 0x1540. No evidence that it even exits the while(!done) loop.

A smaller program uploaded using the loader - will work fine but several that have program memory addresses > 0x1530 - it just quits.
I have a printf for the address just before the write_program_memory.

is there some table boundary at this point?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 10, 2006 5:19 pm     Reply with quote

Is this a loader that you wrote, or are you using the CCS examples
and drivers ? If it's CCS, please list the files that you're using.
eric



Joined: 16 Sep 2003
Posts: 21

View user's profile Send private message

using CCS loader.c
PostPosted: Mon Sep 11, 2006 8:42 am     Reply with quote

I am using loader.c - this works fine for small programs with addresses < ~0x1500, and has worked fine for any size program in the past. The acctual program is less than 0x7000

I've enlarged the loader size it a bit to account for the printf statements

#define LOADER_END 0x7FE0
#define LOADER_SIZE 0x6FF
#define LOADER_ADDR LOADER_END-LOADER_SIZE

//loader.c code here

delay_ms(20);
printf("Line %lu addr %lx\n\r",myline++,l_addr); <-- added this line
write_program_memory(addr, data, count);



If I comment out the write_program_memory the two different terminal programs I've used manage to complete download to the end of the hex file - so it does not appear to be on that side.

the terminal sees the address printed and line number. When it gets to
0x15b0 it fails.

Line 341 addr 1550
Line 342 addr 1560
Line 343 addr 1570
Line 344 addr 1580
Line 345 addr 1590
Line 346 addr 15a0
Line 347 addr 15b0



<loader.c>
#define LOADER_END 0x7FE0
#define LOADER_SIZE 0x6FF
#define LOADER_ADDR LOADER_END-LOADER_SIZE


#define BUFFER_LEN_LOD 64

int buffidx;
char buffer[BUFFER_LEN_LOD];
char bufferRead[BUFFER_LEN_LOD];
#define ACKLOD 0x06
#define XON 0x11
#define XOFF 0x13

#SEPARATE
unsigned int atoi_b16(char *s);

#ORG LOADER_ADDR+10, LOADER_END auto=0 default
void real_load_program (void)
{
int1 do_ACKLOD, done=FALSE;
int8 checksum, line_type;
int16 l_addr,h_addr=0;
int16 l_addr2,h_addr2=0;
int32 addr;
int n;
#if getenv("FLASH_ERASE_SIZE")>2
int32 next_addr;
#endif
int8 dataidx, i, count;
int8 data[32];
long MyLine=0;

printf("Loader Entered "); /added

disable_interrupts(global);
while (!done) // Loop until the entire program is downloaded
{
buffidx = 0; // Read into the buffer until 0x0D ('\r') is received or the buffer is full
do {
buffer[buffidx] = getc();
} while ( (buffer[buffidx++] != 0x0D) && (buffidx <= BUFFER_LEN_LOD) );

putchar (XOFF); // Suspend sender

do_ACKLOD = TRUE;
// Only process data blocks that start with ':'
if (buffer[0] == ':') {
count = atoi_b16 (&buffer[1]); // Get the number of bytes from the buffer

// Get the lower 16 bits of address
l_addr = make16(atoi_b16(&buffer[3]),atoi_b16(&buffer[5]));

line_type = atoi_b16 (&buffer[7]);

addr = make32(h_addr,l_addr);


// If the line type is 1, then data is done being sent
if (line_type == 1) {
done = TRUE;
} else if ((addr <LOADER_ADDR> LOADER_END) && addr < 0x300000){

checksum = 0; // Sum the bytes to find the check sum value
for (i=1; i<(buffidx-3); i+=2)
checksum += atoi_b16 (&buffer[i]);
checksum = 0xFF - checksum + 1;

if (checksum != atoi_b16 (&buffer[buffidx-3])){
do_ACKLOD = FALSE;
printf("ch \n\b");
}
else {
if (line_type == 0) {
// Loops through all of the data and stores it in data
// The last 2 bytes are the check sum, hence buffidx-3
for (i = 9,dataidx=0; i < buffidx-3; i += 2)
data[dataidx++]=atoi_b16(&buffer[i]);


if ((addr!=next_addr)&&(addr&(getenv("FLASH_ERASE_SIZE")/2-1)!=0)){
erase_program_eeprom(addr);
}

next_addr = addr + 1;
delay_ms(20); //added
printf("Line %lu addr %lx\n\r",myline++,l_addr); /added

write_program_memory(addr, data, count);

}
else if (line_type == 4)
h_addr = make16(atoi_b16(&buffer[9]), atoi_b16(&buffer[11]));
}
}
}

if (do_ACKLOD)
putchar (ACKLOD);

putchar(XON);
}

putchar (ACKLOD);
putchar(XON);

printf("loader done"); //added
reset_cpu();

}

unsigned int atoi_b16(char *s) { // Convert two hex characters to a int8
unsigned int result = 0;
int i;

for (i=0; i<2>= 'A')
result = 16*result + (*s) - 'A' + 10;
else
result = 16*result + (*s) - '0';
}

return(result);
}

#ORG default


#ORG LOADER_ADDR, LOADER_ADDR+5
void load_program(void)
{
real_load_program();
}
eric



Joined: 16 Sep 2003
Posts: 21

View user's profile Send private message

minor success
PostPosted: Mon Sep 11, 2006 9:27 am     Reply with quote

WHile I have yet to solve the problem....

I made a smaller program using EX_Load to get the loader installed. This does not lockup when I upload the larger program. Once the larger program is loaded the loader still functions happily and I can reload the large program w/o a lock up.

I will have to look into why when, loader is instaled with the larger program (max address 0x6690 ) that there is a problem in the loader.
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