Keil Logo

C166: Share Interrupt Vector With Bootloader


Information in this article applies to:

  • C166 Version, 5.04

QUESTION

I have implemented a bootloader that contains an interrupt handler for the vector address 0x20. However, the downloaded application also needs an interrupt service routine for the vector address 0x20.

How can I share interrupt vectors so that I have a separate interrupt function in the bootloader and in the downloaded application?

ANSWER

The following assembler program allows you to redirect an interrupt vector. When the bit boot is set, the interrupt function irq (which is part of your boot loader) is executed. When a boot is clear, the interrupt vector is redirected to 0x20020. All other interrupt vectors are redirected to a vector table at address 0x20000.

$segmented
$case   ; case sensitive symbols

VEC_SEG  EQU 2
VEC_OFF  EQU 0H

; The RESET vector is used by the boot application
VECT_TAB SECTION CODE AT 4
VEC_PROC PROC
  JMPS VEC_SEG,VEC_OFF+004H
  JMPS VEC_SEG,VEC_OFF+008H
  JMPS VEC_SEG,VEC_OFF+00CH
  JMPS VEC_SEG,VEC_OFF+010H
  JMPS VEC_SEG,VEC_OFF+014H
  JMPS VEC_SEG,VEC_OFF+018H
  JMPS VEC_SEG,VEC_OFF+01CH
  JMP  irq8                                      ; irq8
  JMPS VEC_SEG,VEC_OFF+024H
  JMPS VEC_SEG,VEC_OFF+028H
  JMPS VEC_SEG,VEC_OFF+02CH
  :
  :
VEC_PROC ENDP
VECT_TAB ENDS

extrn boot:bit
extrn irq:near

?PR?irq8 section code
irq8 proc near
  JB   boot,irq8_boot
  JMPS VEC_SEG,VEC_OFF+20H
irq8_boot:
  JMP  irq
irq8 endp
?PR?irq8 ends

  end

The bootloader may be implemented in C. Here is an example:

void irq (void) interrupt irq=CACHED  {
   ;                          // code of your interrupt function
}

bit boot;

void bootloader ()  {
  ;
}

void main (void)  {
  boot = 1;                       // use local irq in bootloader
  bootloader ();

  boot = 0;                       // use irq function in user app
  ((void (far *) (void)) 0x200000) ();  // start user app

  while (1);
}

Note: You need to use the C166 Compiler Version 5.04 since it allows using the CACHED attribute even for non XC16x targets. The CACHED attribute disables the generation of an interrupt vector which is supplied in this example by an assembler module.

You may download a complete application example from the attachment to this Knowledgebase Article.

SEE ALSO


ATTACHED FILES

Request the files attached to this knowledgebase article.

Last Reviewed: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.