DEFINE RESET_ORG and DT Instant Interrupt


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    81

    Default DEFINE RESET_ORG and DT Instant Interrupt

    Hi all,
    anybody can understand why the below code works only commenting the first line ?
    If I use DEFINE RESET_ORG the program hangs and does nothing.

    Code:
    '    DEFINE RESET_ORG 3000h
    
        include "declare.inc"
        INCLUDE "DT_INTS-18.bas"       ; Base Interrupt System
        INCLUDE "ReEnterPBP-18.bas"    ; Include if using PBP interrupts
    
    ASM              
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _Timer1_250mS_INT,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
        @    INT_ENABLE  TMR1_INT         ; enable Timer1 interrupts
    
        OSCCON        =%100000            ; Primary oscillator, internal 8MHz
        OSCCON2.0    =1
        OSCTUNE.7    =1
        T1CON        =%110111            ; Timer1, 1:8 prescaler, 262mS Interrupt
    
        INTCON.7=1                        ; global int
        INTCON.6=1                        ; peripheral int
    
    MyLoop:
        Hserout2["Hello ... ",#x,13,10]
        x=x+1
        pause 500
        goto MyLoop
        
    Timer1_250mS_INT:
        toggle led 
        @ INT_RETURN

  2. #2
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: DEFINE RESET_ORG and DT Instant Interrupt

    Because, you need to reroute reset interrupt vectors.
    PIC always jump to 04 and 08 on hi/lo int.
    And you don't have anything there.
    Generally that is bad idea, because you hijack interrupts from main code.
    And that reroute you cant do in PBP, nor ASM at compile time. So you need to do it manually. Then you can reroute int vectors in main program, to some other location.
    And all that is just bad.

    What exactly you are trying to do. I know you are building bootloader, I have posted few on this forum.
    It should be very easy, straight forward code... Not sure why you need interrupts.

  3. #3
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: DEFINE RESET_ORG and DT Instant Interrupt

    Hi Pedja,
    this is a sample program that runs ok without the DEFINE RESET_ORG.
    What I'm trying to do is move it from org 0 to create place for my bootloader.
    My real program needs interrupt.

    I think I have read that interrupt vector are moved automatically when you use DEFINE RESET_ORG, you say not ?
    Can you drive me how to remap int vector ?

  4. #4
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: DEFINE RESET_ORG and DT Instant Interrupt

    I describe my idea.

    1) Write a bootloader program at ORG 0 that get an HEX file and write memory starting at 3000h
    2) export code, manipulate to obtain something like below and put it in a file "bootloader.inc"

    Code:
    ASM
    	dw 0x0EF5B, 0x0F002, 0x0FFFF, 0x0FFFF, 0x0EFAA, 0x0F003, 0x0FFFF, 0x0FFFF, 0x0FFFF, 0x0FFFF, 0x0FFFF, 0x0FFFF
    	dw 0x0E00B, 0x00606, 0x0C004, 0x0FFE9, 0x0C005, 0x0FFEA, 0x050EE, 0x0CFE9, 0x0F004, 0x0CFEA, 0x0F005, 
    	dw 0x00004, 0x0A89E, 0x0D7FD, 0x06EAD, 0x080D8, 0x0EF58, 0x0F002, 0x050E9, 0x0010F, 0x00004, 0x0A8A4, 
    ENDASM
    3) Take my main program and add DEFINE RESET_ORG 3000h
    4) at the end of the program add

    Code:
    @ ORG 0h
    BootLoader:
    	include "BootLoader.inc"
    Then I can call the bootloader with a GOTO @0.

    Of course it doesn't work .....

  5. #5
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: DEFINE RESET_ORG and DT Instant Interrupt

    If in the main program (with DEFINE RESET_ORG 3000h) I add this

    Code:
    @ ORG 0
    	@ GOTO 3000h
    @ ORG 8
    	@ GOTO 3008h
    @ ORG 4
    	@ GOTO 3004h
    It works....
    But when I want to jump to bootloader I need the vector remapped to 4 and 8....

    Maybe I can use WRITECODE to overwrite the INT vector before jumping to bootloader and then again WRITECODE before exit from bootloader ?

  6. #6
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: DEFINE RESET_ORG and DT Instant Interrupt

    Now I got it.
    I have done bootloaders on top of main program. At address 64000. So in main program i call bootloader with @ GOTO 64000. No need to remap anything.


    When you use reset org 3000h, PBP expect int vectors on 3008h, but CPU will jump at 08h.

    So in your bootloader you need to have
    Code:
    @ ORG 8
    	@ GOTO 3008h
    @ ORG 4
    	@ GOTO 3004h
    Then CPU will jump to 08h, then jump to 3008h, then jump to ISR. Lot of jumping...
    Also, when you power PIC it will enter to bootloader first, so you need exit from bootloader
    eg
    Code:
     @ GOTO 03000h
    But this
    Code:
    @ ORG 8
    	@ GOTO 3008h
    @ ORG 4
    	@ GOTO 3004h
    will generate warning in ASM, overwriting prev address, or something like that. Then it depends, what was last, so it may assemble correctly, maybe not.
    EDIT:
    You could try something like this in bootloader:
    Code:
    Reset org 10h
    @ ORG 0
    	@ GOTO 10h
    @ ORG 8
    	@ GOTO 3008h
    @ ORG 4
    	@ GOTO 3004h
    Last edited by pedja089; - 3rd February 2021 at 14:19.

  7. #7
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: DEFINE RESET_ORG and DT Instant Interrupt

    Hi Pedja, thanks for your confirmation.
    Yes, I was trying as you say placing the bootloader in the high memory, but then I faced with a "limit" of PBP that requires the library routines (assembly language for high-level commands like HSEROUT) be in memory below 64K.

    Here I was asking help to Melabs http://support.melabs.com/forum/picb...modifier-issue

    It can works if the code is very basilar, but not for instructions like Hserout, ArrayRead etc (and I need them).

  8. #8
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: DEFINE RESET_ORG and DT Instant Interrupt

    I'm experimenting this method:

    Bootloader code uses DEFINE RESET_ORG 80h and Main program uses DEFINE RESET_ORG 3000h

    When the main app need to call bootloader, I disable Interrupt, then remap vectrors, then @ RESET:

    Code:
    	Madr=$EF40: WriteCode 0,Madr		' --> GoTo $80 at address 0	
    	Madr=$F000: WriteCode 2,Madr		
    	Madr=$EF42: WriteCode 4,Madr		' --> GoTo $84 at address 4
    	Madr=$F000: WriteCode 6,Madr		
    	Madr=$EF44: WriteCode 8,Madr		' --> GoTo $88 at address 8
    	Madr=$F000: WriteCode 10,Madr
    	For Madr=12 to 126 step 2			' fill 128 bytes block for PIC18 to complete WriteCode
    		WriteCode Madr,$FF
    	Next Madr
    When the bootloader has finished, same logic above to restore vector at 3000, 3004, 3008, then @ RESET

    Not sure if it is a smart solution, but in my mind it should works .....

  9. #9
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: DEFINE RESET_ORG and DT Instant Interrupt

    Code for bootloader, generally need to be very basic. Then there is little space to make mistake.
    My biggest bootloader is around 1,2K, smalest 278B.
    I usually use 64K+ to store received HEX. So when I verify download in main code, check checksum, etc. Then I call bootloader, just to copy from 64K+ to 0-64K.
    I also used I2C, and SPI flash to store hex.
    Comm is handled by main code, sometimes I download hex from FTP, sometimes is over serial, or bluetooth(same as serial)...

  10. #10
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: DEFINE RESET_ORG and DT Instant Interrupt

    Not good solution at all. Because you need to erase FLASH before writing.
    That code need to be in bootloader, as I explained in few post above.
    GOTO need to be placed in while assembling, not at runtime.
    EDIT:
    Try this in bootloader
    Code:
    DEFINE RESET_ORG 80h
    @ ORG 0
    	@ GOTO 80h
    @ ORG 8
    	@ GOTO 3008h
    @ ORG 4
    	@ GOTO 3004h
    Last edited by pedja089; - 3rd February 2021 at 15:05.

  11. #11
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: DEFINE RESET_ORG and DT Instant Interrupt

    Yes, I have to erase just a 128 byte block before.
    Well, you are right, but I have not enough resources to use your method. My main program is around 80K, I have not enough space in the external EEprom so I have to manage FTP communication to download the new HEX in the bootloader code. Get a block, flash, Get a block, flash .... no crc controll at all.
    I agree there is much risk something goes wrong this way, but if it works I can try remotely update a firmware without having the device back to my lab from the customer as I'm doing now.

    Anyway I have space in the GSM module to save a copy of the actual firmware before starting update and manage a restore if some check fails during the update process. It is a heavy bootloader, I know.....

Similar Threads

  1. DEFINE RESET_ORG and DEC modifier issue
    By Marcick in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 5th February 2021, 08:21
  2. DT Instant Interrupt and Bootloader
    By mikebar in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd September 2014, 09:26
  3. Define Interrupt Label Problem
    By Junkman55 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 14th June 2011, 18:41
  4. Instant Interrupt and USART
    By sirvo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 23rd July 2008, 04:08
  5. DT Instant Interrupt counting
    By jderson in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 9th March 2008, 23:47

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts