Simple XGATE

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Simple XGATE

4,908 Views
isabelong
Contributor I
Im new to microcontrollers so i appologise in advance. I have a program that looks at times between events that cause an interupt in port P. I am having a lot of problems because the main processor doesnt have enough time to process the huge number of interupts as well as do its tasks. Therefore i would like to learn how to use the xgate. I have read the app notes on it and tried to adapt the SCI example. However i dont understand the SCI parts and cant get anything to work. Does anyone have a really simple ideot proof example of the xgate in operation? (I guess thats probably it)
 
How do you pass variables from the code on one processor to the other? The first thing i would like the Xgate to do is store the Timer value to a variable (LastIntTime = TCNT), which would then be used by the main processor.
 
Thanks
0 Kudos
11 Replies

900 Views
isabelong
Contributor I
Got that working nicely. I had copied bits and pieces from too many example and there was a bad link somewhere. My next step was get the timer overflow interupt back in.
 
interrupt 16 void TMOF() //TIMER OVERFLOW INTERRUPT
{
 SecondTimer++;
 TFLG2_TOF = 1;   //CLEAR INT FLAG
}
and
 TSCR1 = 0x80;    //ENABLE TIMER 
 TSCR2 = 0x84;    //PRESCALER SET TO 16     
 
Now  i get
 
L1907: Fixup overflow in vector_16, to TMOF type 1, at offset 0x0.
 
Why is this?
0 Kudos

900 Views
CrasyCat
Specialist III
Hello
 
You have to make sure the function TMOF is allocated in a __NEAR_CODE section.
 
ifndef __SMALL__
#pragma CODE_SEG __NEAR_SEG NON_BANKED
#endif
interrupt 16 void TMOF() { //TIMER OVERFLOW INTERRUPT
  // Code here
}
#pragma CODE_SEG DEFAUT
 
CrasyCat
0 Kudos

900 Views
isabelong
Contributor I
Its Working, I removed the following line, what does it do?
 
//#pragma CONST_SEG XGATE_VECTORS 
 
Again, thanks for all your help
0 Kudos

900 Views
Steve
NXP Employee
NXP Employee
That places the XGATE vector table at a specific place in memory. You need to check the linker file (.prm) to find out where that is - there may be a conflict which meant that XGATE did not fetch the correct vector.
If XGATE fails to execute properly then it sends an interrupt to the CPU (which could cause an illegal_BP if not set up).
0 Kudos

900 Views
isabelong
Contributor I
I have also used portB to trigger interupt and same problem.
0 Kudos

900 Views
isabelong
Contributor I
I have a switch to cause the interupt. The code runs ok until this interupt occurs.
 
Therefore I ran code, halted it, pressed the switch and then stepped it and nothing ever happens just carries on with main code. as soon as continue is hit, illegal_BP. How do I find the problem? I assume its with the xgate code since theres only a problem when an interupt occurs but i dont see anything happening with the xgate debugging windows. Should i not see the code get executed line by line when i step through.
0 Kudos

900 Views
isabelong
Contributor I
Thanks for help, so far i have the following but i have an Illegal_BP problem. I would just like to be able to see one of the counter going up.
 
0 Kudos

900 Views
Steve
NXP Employee
NXP Employee
I can't see any particular issues with your code. I recommend you track down the cause of the illegal breakpoint - this is usually caused by code runaway which may be due to an unexpected interrupt not being handled. Use the debugger to check that the XGATE code is being executed and try to see what happens just before the Illegal_BP. You may have to initialise all of the CPU vectors if an interrupt is the source of the problem.
0 Kudos

900 Views
Alban
Senior Contributor II
Good Afternoon Steve and Isabelong,
 
I just got an idea...
Isa, you say you use a switch to create the interrupt.
 
I'm thinking about rebounce and Spurious Interrupt.
 
Am I crazy (frog) or it fits the profile ? It just reminds me of an old story :smileywink:
 
Cheers,
Alban.
0 Kudos

900 Views
Steve
NXP Employee
NXP Employee
Can you let us know what toolchain you are using?
In principle sharing variables between the cores is no different to sharing variables between two different C files on the same CPU.
You declare a variable in one file (say main.c)
unsigned int LastIntTime;
Then access it in the other (say xgate.cxgate) with
extern unsigned int LastIntTime;
 
Now both cores can read and write the variable (but be careful that both don't write at the same time).
 
To make your interrupt run on XGATE you take three steps. I'll show you where this happens in the SCI example since I know you have it. (This is based on CodeWarrior)
1. Send the interrupt to the XGATE
This is done by the ROUTE_INTERRUPT macro at line 32 in main.c.
If you want XGATE to handle the interrupts from port P change this to
ROUTE_INTERRUPT(PORTP_VEC, 0x81);
and define PORTP_VEC as #define PORTP_VEC  0x8E /* vector address= $xx8E */
(You get the vector address from the vector table in the databook)
 
2. Write the XGATE thread
This is equivalent to the CPU interrupt service routine so you already have it. If it is in C then you should be able to reuse it completely unless you are accessing CPU specific features. Put it in an XGATE file (with .cxgate extension). You could put it in the xgate.cxgate file in the SCI project. Let's assume it is called
interrupt void PortH_thread()
 
3. Set up the XGATE vector
This is like setting up the CPU vector table. You need to add the name of your XGATE thread into the XGATE vector table in xgate.cxgate. In your case you put PortH_thread at channel 47 in the XGATE vector table. This is clearly marked in the file
 {PortH_thread, 0x47},  // Channel 47 - Port P Interrupt   

That's it. Now all the Port P interrupts will go to your XGATE thread. You should remove all the code for the SCI otherwise you will get the SCI interrupts as well.
 
To share the variable do as I suggested above and declare it in one file and access it as extern in the other.
 
I haven't tried this here but those are the three steps and it should work.
 
0 Kudos

900 Views
SteveRussell
Contributor III
One additional thing to do:
 
Make sure that all variables with shared access between interrupt code (either S12X or XGate )and non-interrupt code are declared "volatile".
 
Hardware IO registers should also be declared as "volatile".
 
The C documentation explains volatile.  What it does is make sure that the C compiler always gets the current value from the variable location, and doesn't assume that it can use an old value in a register from several statements ago.
 
Example
You declare a variable in one file (say main.c)
volatile unsigned int LastIntTime;
Then access it in the other (say xgate.cxgate) with
extern volatile unsigned int LastIntTime;
 
0 Kudos