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 problem if downloaded .hex has interrupt

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



Joined: 06 Oct 2008
Posts: 43

View user's profile Send private message

bootloader problem if downloaded .hex has interrupt
PostPosted: Tue Oct 02, 2012 7:26 am     Reply with quote

hi,
i have created a bootloader and it works fine if downloaded code doesnt have interrupt. however if it has an interrupt and it is triggered, the process suddenly becomes wierd. it resets for no reason. here is a sample code.

PCH v.4.124

main.c
Code:

#include <18F67K22.h>
#device PASS_STRINGS = IN_RAM

#FUSES NOWDT, INTRC_IO, NOPROTECT, NOIESO, BROWNOUT, PUT, NOCPD, STVREN, DEBUG, NOWRT, NOWRTD, NOEBTR, NOCPB, NOEBTRB, NOWRTC, NOWRTB, FCMEN, NOXINST, MCLR, RTCOSC_T1

#include "bootloader.h"
#use delay(clock=16000000)

#use rs232(baud=19200, xmit=PIN_G1, rcv=PIN_G2, stream=PC)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, stream=SERIAL_INT)

#define BUFFER_SIZE      255

#include <stdlib.h>
#include <string.h>
#include "interruptSerial.c"
#include "gsm.c"

int1 testGSM(void)
{
   strcpy(DESIRED_RESPONSE, "OK");
   clear_buffer();
   delay_ms(200);
   fprintf(SERIAL_INT, "AT\r");
   if(GetResponse())
   {
      fprintf(PC,"active\n");
      return TRUE;
   }
   else
      return FALSE;
}

void main(){
   delay_ms(2000);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   do{
      testGSM();
      delay_ms(1000);
   }while(1);
}

#int_rda
void rda_isr(void)
{

   INTSERIAL_FLAG = 1;
   RXD_DATA[WRITE_CNTR++]=fgetc(SERIAL_INT);

}


bootloader.h

Code:

#define LOADER_END 0x6FF
#define LOADER_SIZE 0x5FF
#define USE_STATEMENT_SIZE 0x100

#ifndef _bootloader

#build(reset=LOADER_END+1+USE_STATEMENT_SIZE, interrupt=LOADER_END+9+USE_STATEMENT_SIZE)
#org 0, LOADER_END+USE_STATEMENT_SIZE {}

#endif


on a side note:
if i remove the bootloader.h and run the code directly without using the bootloader, everything works great but if i place the bootloader.h, it resets if the interrupt is triggered.

please help. thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19396

View user's profile Send private message

PostPosted: Tue Oct 02, 2012 7:31 am     Reply with quote

The actual _bootloader_, needs to have the extra code present to re-vector the interrupt.
That is the section starting #int_global, in ex_bootloader.c, and also why the 'main' is located at address 0x20/0x40 (to leave space for this).

Best Wishes
overmindx



Joined: 06 Oct 2008
Posts: 43

View user's profile Send private message

PostPosted: Tue Oct 02, 2012 7:47 am     Reply with quote

hi,
thanks for the swift reply..

my bootloader gets the code from a flash memory chip via SPI. this works great for code without interrupts.

here is part of my bootloader code

Code:

#include <18F67K22.h>
#device adc=12
#device PASS_STRINGS = IN_RAM

#FUSES NOWDT, INTRC_IO, NOPROTECT, NOIESO, BROWNOUT, PUT, NOCPD, STVREN, DEBUG, NOWRT, NOWRTD, NOEBTR, NOCPB, NOEBTRB, NOWRTC, NOWRTB, FCMEN, NOXINST, MCLR, RTCOSC_T1

#use delay(clock=16000000)

#use rs232(force_sw,baud=19200, xmit=PIN_G1, rcv=PIN_G2, stream=PC)

#define _bootloader
#include <spi_lib.c>
#include "bootloader.h"
#include "loader.c"

#if defined(__PCM__)
 #org LOADER_END+1+USE_STATEMENT_SIZE,LOADER_END+10+USE_STATEMENT_SIZE
#elif defined(__PCH__)
 #org LOADER_END+2+USE_STATEMENT_SIZE,LOADER_END+20+USE_STATEMENT_SIZE
#endif

void application(void) {
  while(TRUE);
}

#if defined(__PCH__)
#org 0x40,0xFF
#else
#org 0x20,0x3F
#endif

void main(void) {
   if(input(PIN_B0))
   {
      delay_ms(500);
      setup_spi(SPI_MASTER|SPI_L_TO_H | SPI_XMIT_L_TO_H | SPI_CLK_DIV_64);
      DTFOpen();
      SetSizeFT();
     
      load_program();
   }
   application();
}

#ORG default

#int_global
void isr(void) {
   jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
}


is something wrong with my code?
please help..
Ttelmah



Joined: 11 Mar 2010
Posts: 19396

View user's profile Send private message

PostPosted: Tue Oct 02, 2012 8:08 am     Reply with quote

OK.
The vector used by the interrupt re-mapper, needs to be the same as the one used in the build statement. '9' is not going to be '5*bits per instruction'.....

Best Wishes
overmindx



Joined: 06 Oct 2008
Posts: 43

View user's profile Send private message

PostPosted: Tue Oct 02, 2012 8:28 am     Reply with quote

hi Ttelmah,
ok, i will try what you suggest tomorrow. since i dont have my board with me right now. thank you so much and will keep you posted as soon as i test it.

overmindx
overmindx



Joined: 06 Oct 2008
Posts: 43

View user's profile Send private message

PostPosted: Thu Oct 04, 2012 8:28 am     Reply with quote

hi Ttelmah,
it works! thanks for your help..

overmindx
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