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

Bootloader: Questions about Ckielstra's bootloader

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



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

Bootloader: Questions about Ckielstra's bootloader
PostPosted: Mon Mar 12, 2007 5:44 am     Reply with quote

Hi;

I've studied Ckielstra's Bootloader and took it as reference for my Bootlader. This bootloader is mentioned in 3 topics, as:

http://www.ccsinfo.com/forum/viewtopic.php?t=20971
http://www.ccsinfo.com/forum/viewtopic.php?t=27019
http://www.ccsinfo.com/forum/viewtopic.php?t=27387


But none of them includes my questions. Because I'm a newbie in bootloading concept. I've read lots of topics but have to make sure something.

Let me paste my code here:

Bootloader.h
Code:

#include <18F4620.h>      
#device *=16 ADC=10      
#device CCS4 WRITE_EEPROM=ASYNC         


#fuses INTRC_IO            
#fuses NOIESO            
#fuses NOWDT            
#fuses NOPROTECT         
#fuses BROWNOUT_NOSL      
#fuses BORV43            
#fuses NOLVP            
#fuses NOPUT            
#fuses NOMCLR            
#fuses NOLPT1OSC         
#fuses NOPBADEN            
#fuses NOXINST            
#fuses NODEBUG            

#use delay(clock=4000000)      

#ifdef __PCH__
#else
#error Invalid Compiler Version
#endif


#define RESET_VECTOR            0x0000      // Defined by hardware
#define HIGH_INT_VECTOR         0x0008      // Defined by hardware
#define NORMAL_INT_VECTOR       0x0018      // Defined by hardware
#define INTERRUPT_REMAP_END     HIGH_INT_VECTOR + 0x1B // End of the remap code

#define LOADER_START            INTERRUPT_REMAP_END+1
#define LOADER_END              0x07FF        // Defined by size of the bootloader code and/or protection fuses
#define LOADER_RESET            RESET_VECTOR
#define LOADER_HIGH_INT         LOADER_START
#define LOADER_NORMAL_INT       LOADER_HIGH_INT + 0x10

#define APPLICATION_START       LOADER_END + 2
#define APPLICATION_RESET       APPLICATION_START + RESET_VECTOR
#define APPLICATION_HIGH_INT    APPLICATION_START + HIGH_INT_VECTOR
#define APPLICATION_NORMAL_INT  APPLICATION_START + NORMAL_INT_VECTOR


#define BUFFER_LEN_LOD 64         /// Seems 32 can be used

#define ACKLOD 0x06
#define XON    0x11
#define XOFF   0x13


// A global flag indicating the bootloader is active or not.
// This flag must be present in both the bootloader and application at the same
// address, that's why we place it here in the bootloader.h with a #locate
// instruction to fixed address 0x10. Address 0x10 was choosen arbitrarily in
// the start of memory above the CCS scratch register area (0x00 to 0x??).
int8 BootloaderActive;
#locate BootloaderActive=10

/// Prototypes
void LoadApplication(void);
#separate
unsigned int atoi_b16(char *s);




Bootloader.c
Code:

#include "SmartLoader.h"

#build(reset=LOADER_RESET, interrupt=LOADER_HIGH_INT)       

#use RS232 (BAUD=9600, STREAM=CPORT, XMIT=PIN_C6, RCV=PIN_C7, PARITY=N, BITS=8, ERRORS)


int  buffidx;
char buffer[BUFFER_LEN_LOD];

////////////////////////////////////////////////////////////////////////////////
// Relocate the interrupt vectors.
// Depending on whether the bootloader or application is active
// different interrupt dispatchers are called.

#include "LoadFunctions.c"

#org HIGH_INT_VECTOR, INTERRUPT_REMAP_END
void isr_relocate(void)
{
   #asm
     // Address 0x0008 is the hardware High priority interrupt
     TSTFSZ BootloaderActive       // if bootloader active
     GOTO  LOADER_HIGH_INT         // then jump to bootloader ISR
     GOTO  APPLICATION_HIGH_INT    // else jump to application ISR

   NOP                           // Just filling memory
     NOP
     NOP

     // Address 0x0018 is the hardware Low priority interrupt
     TSTFSZ BootloaderActive       // if bootloader active
     GOTO   LOADER_NORMAL_INT      // then jump to bootloader ISR
     GOTO   APPLICATION_NORMAL_INT // else jump to application ISR
   #endasm
}


void main()
{
   short LoadCondition = 1;      /// Just making it get "Load" command

   fprintf(CPORT,"BootLoader started");
   
   if(LoadCondition)
   {
      fprintf(CPORT,"Loader ready to bootload");
      
      LoadApllication();         /// Has an unknown size      
   }
   
   goto_address(APPLICATION_START);
   
}



My Questions are:
- Is there any obvious problem in this code.
- How can I get the program size "exactly", to be sure about bootloader size
- I can see lots of "Interrupt area" variable in Symbol Table in the application program, but with this code I can't see anything about Interrupts. is it normal?
- Do I have to use this section:
Code:
#int_global
void isr(void) {
   jump_to_isr(LOADER_END+10);
}


- is there any detailed help file/topics about *.sym files?
- what is low memory and high memory areas? I'm a bit confused the ROM mapping about the programs.

I appreciate your kind help.
_________________
/// KMT
/// www.muratursavas.com
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

PostPosted: Tue Mar 13, 2007 4:14 am     Reply with quote

I'm digging the problem while waiting for answers. And still confused Confused

We have values as :

Code:
#define RESET_VECTOR            0x0000      // Defined by hardware
#define HIGH_INT_VECTOR         0x0008      // Defined by hardware
#define NORMAL_INT_VECTOR       0x0018      // Defined by hardware
#define INTERRUPT_REMAP_END     HIGH_INT_VECTOR + 0x1B // End of the remap code

#define LOADER_START            INTERRUPT_REMAP_END+1
#define LOADER_END              0x03FF        // Defined by size of the bootloader code and/or protection fuses
#define LOADER_RESET            RESET_VECTOR
#define LOADER_HIGH_INT         LOADER_START
#define LOADER_NORMAL_INT       LOADER_HIGH_INT + 0x10

#define APPLICATION_START       LOADER_END + 2
#define APPLICATION_RESET       APPLICATION_START + RESET_VECTOR
#define APPLICATION_HIGH_INT    APPLICATION_START + HIGH_INT_VECTOR
#define APPLICATION_NORMAL_INT  APPLICATION_START + NORMAL_INT_VECTOR


As you can notice I've modified bootloader size because actual size is just 0x3BF. The actual values are 8according to this)

Code:
RESET_VECTOR             0x00
HIGH_INT_VECTOR          0x08
NORMAL_INT_VECTOR        0x18
INTERRUPT_REMAP_END      0x23
   
LOADER_START             0x24
LOADER_END               0x3FF
LOADER_RESET             0x00
LOADER_HIGH_INT          0x24
LOADER_NORMAL_INT        0x34
   
APPLICATION_START        0x401
APPLICATION_RESET        0x401
APPLICATION_HIGH_INT     0x409
APPLICATION_NORMAL_INT   0x419


This table means the application interrupts should start at 0x409 and end at 0x424 right?

If I want to change HIGH_INT_VECTOR to 0x05 (for matching to symbol table, it gives "Invalid ORG range" error. OK 0x08 is no problem. But why not calling interrupts? I'm trying to get whole HW concept not just copy paste...
_________________
/// KMT
/// www.muratursavas.com
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

PostPosted: Tue Mar 13, 2007 7:21 am     Reply with quote

I've solved the situation...

There is a statement in definitions written as

Code:
#define APPLICATION_START       LOADER_END + 2


I switched 2 with 1. Disassembly was showing jump to 408, but +2 was meaning 409.

Also I've removed the additional lines for bootloader interrupts. I don't need them. Write as:
Code:
#org HIGH_INT_VECTOR, INTERRUPT_REMAP_END
void isr_relocate(void)
{
   #asm
     GOTO  APPLICATION_HIGH_INT    // else jump to application ISR

   NOP                           // Just filling memory
     NOP
     NOP
     NOP
     NOP
     NOP

     GOTO   APPLICATION_NORMAL_INT // else jump to application ISR
   #endasm
   
}



This topic seems like just "loud thinking" but I hope it would help the others. All the credits are going to _of course_ ckielstra... Thank you...
_________________
/// KMT
/// www.muratursavas.com
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Mar 20, 2007 1:34 pm     Reply with quote

I didn't publish a complete bootloader, all I did was showing an extension to the CCS bootloader example so it supports interrupts. I understand this is a feature you don't need.

Why do you want to create your own bootloader? There are many difficult and compiler specific issues to take care of, not very interesting to design but a pain in the *ss to get right. Please choose one of the existing bootloaders that is close to your requirements and start from there.

A good starting point is the CCS supplied bootloader example ex_bootloader.c
Or if your memory requirements are very tight you can have a look at the Tiny PIC bootloader.
More bootloader references can be found searching this forum.
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

PostPosted: Wed Mar 21, 2007 12:45 am     Reply with quote

Hi Ckielstra,

I was finished my bootloader based on your idea at my last post. And started to use the interrupt feature again. It's not from scratch. I modified the ccs bootloader example with your idea and some additional ideas. Now I'm very happy with it. I can program the PIC much faster than buggy PICStart Plus.

Thanks for your interest.
_________________
/// KMT
/// www.muratursavas.com
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