Hello,
I might suggest the following code example.
interrupt void Bootload_ISR_01( void){ asm { ldhx #0xF9FC; // Vector location ldhx ,x // Fetch vector contents jsr ,x // Execute interrupt function }}
With the use of the interrupt function, the H-register should be automatically saved, and then restored immediately prior to the function exiting with a RTI instruction, where the other registers are also restored. To keep the stack balanced, the function vectored at 0xF9FC should be called as a normal function, rather than a direct jump. This should exit using a RTS instruction.
Regards,
Mac
Hello,
I tried using the above code, but still the same issue. Application stops at the point where Vector tables are concerned. Following is what I am using(I have two SEPERATE programs in Flash):
I have Bootloader.S19 which I load into Flash with programmer.
I have vector tables at default place ie FFC4.
I have Application.S19 which is loaded in the Flash through USB by my Bootloader code already present in the Flash.
I have relocated vector tables for my Application code ie at DFC4 (as 8k protected). However, as I can not write to NVOPT register therefore I need to manually redirect vector tables from FFC4 to DFC4.
**********************************************
In Bootloader code, in Vector.c I am doing:
interrupt void Bootload_ISR_1(void)
{
asm
{
ldhx #0xDFC4; // Vector location
ldhx ,x // Fetch vector contents
jsr ,x // Execute interrupt function
}
}
void (* near const _BOOT_vect[])(void) @0xFFC4 = { /* Interrupt vector table */
Bootload_ISR_1,
...........................
}
void (* near const _vectReset[])(void) @0xFFFE = { /* Interrupt vector table */
_EntryPoint /* Int.no. 0 Vreset (at FFFE) Reset vector */
};
**********************************************
In Application code for Interrupt functions:
instead of:
ISR(AS1_InterruptTx)
{
}
I am using:
void AS1_InterruptTx()
{
}
If I look at the dissassembly of the function:
interrupt void Bootload_ISR_1(void)
{
asm
{
ldhx #0xDFC4; // Vector location
ldhx ,x // Fetch vector contents
jsr ,x // Execute interrupt function
}
}
Looks like this:
[2] PSHH
266: asm
267: {
268: ldhx #0xDFD8; // Vector location
0001 45dfd8 [3] LDHX #-8232
269: ldhx ,x // Fetch vector contents
0004 9eae [5] LDHX ,X
270: jsr ,x // Execute interrupt function
0006 fd [5] JSR ,X
271: }
272: }
0007 8a [3] PULH
0008 80 [9] RTI
If you note the text in Red, instead of 57304 it shows "-8232"
Im not good in assembly please improve the code here.
Thanks
Hi Punit,
-8232 is equal to 57304. The former is simply the signed representation of the latter. So that is not the problem, although I don't know what is.
That ISR looks correct. Are you sure that location DFD8 is pointing correctly into your service routine?
Yes, I can confirmed this by looking into my application's S19 file and ROM in the debugger, values are same. Also, confirned with the map file.
However, what I found is that location DFD8 contains 8 - bit address(ex 24) and DFD9 contains another 8 bit address(ex 78) so altogether we need 16-bit address (ex 0x2478) to jump to. If this is the case can you please edit the assembly code you provided.
Hello
Yes, this is correct.
LDHX does a 16-bit fetch, the value at the specified address and the one 1 more than it. So it is doing what is expected here.
This 16-bit value in the H:X registers is then used as an offset from zero to JSR to.
OK.
Just to confirm here. My application code has vectors relocated at 0xDFC4 and the functions are not ISR functions but normal functions which are called from the ISRs in Bootloader.
Are there some other changes need to be done in the Application code as it is a seperate program. Will variable and other initializations happen automatically, as I am jumping to an address?
I found out that the Interrupt function in Application was still behaving as an Interrupt function although I changed the name from ISR(AS1_InterruptTx) to void AS1_InterruptTx(). So, I RENAMED it and declared in Vector.c. It worked then.
In this way, you only have one ISR (interrupt service rountine) that is located in unprotected flash, and two different vector tables will eventually points to same ISR function, don't you?
Hi shadoo, I am also in a similar trouble and found this solution of what I wanted to implement. I tried to implement the way stated, however, my application doesn't work. Once again seems to be an Interrupt vector issues. Would this solution also works for mc9s08jm60??