> 1. No, different INTCn has different interrrupt source...
The level and priority only have to be unique on the one controller. We do that a lot as CAN and the TPU chew up a huge number of interrupts.
The clearing depends on the peripheral. But I would always recommend "clear at the start and then service". If you do the reverse you risk servicing an interrupt (say from a received character on a device), then having another character arrive when you're in the routine, then you clear the interrupt for THAT one and you've lost the interrupt. So you should always read the interrupt status register, clear all the interrupts set in that register (usually by reading the status, then writing that exact data back to the write-ones-to-clear register) and then service the interrupts indicated in the status value read at the top. Then exit. Any new interrupts that popped up while executing that code will be handled in the next interrupt.
You shouldn't have to touch the interrupt controller after it has been set up. All (most) interrupt handling happens by reading and writing the peripheral interrupt status and control registers. This is not a broken CPU chip like the ones that only have one interrupt request level, where you have to play the bolt-on interrupt controller to handle interrupts. This is a real hardware multi-level interrupt CPU.
> What happens if I clear the interrupt flag at the beginning of the ISR
When the CPU is interrupted at Level "N" the CPU is automatically set to priority level "N". Don't mess with it. Don't change the CPU priority level. While it is like that (in this ISR) it can't be interrupted by any level "N" interrupts (or lower) until it has finished and returned to the previous interrupt level. It can only be interrupted by higher level interrupts.
So if you're doing anything at all complicated, it is essential NOT to use any "interrupt enable" and "interrupt disable" functions. People usually write these to force the CPU IPL to "7" and "0" respectively. Then they call them from the middle of an interrupt service routine, the CPU gets dropped to Level 0 and the same interrupt hits again. Don't do that. If you must change the interrupt level, use functions that SAVE the previous level before changing it. Read the following for this:
https://community.nxp.com/message/316241#comment-316241
Concerning the TPU, is that a common service routine for multiple TPU channels? Have you got those TPU channels configured to interrupt at different LEVELS? That's likely as there are sixteen TPU interrupt sources and only 8 priorities, so you are forced to use two levels, Our code has the TPU interrupting on levels 3 and 4:
typedef struct
{
uint8_t controller;
uint8_t source;
uint8_t level;
uint8_t priority;
} INT_INFO;
static const INT_INFO int_etpu[ETPU_NUM_CHANNELS] =
{
{ 1, 27, 4, 7 }, { 1, 28, 4, 6 }, { 1, 29, 4, 5 }, { 1, 30, 4, 4 },
{ 1, 31, 4, 3 }, { 1, 32, 4, 2 }, { 1, 33, 4, 1 }, { 1, 34, 4, 0 },
{ 1, 35, 3, 7 }, { 1, 36, 3, 6 }, { 1, 37, 3, 5 }, { 1, 38, 3, 4 },
{ 1, 39, 3, 3 }, { 1, 40, 3, 2 }, { 1, 41, 3, 1 }, { 1, 42, 3, 0 },
};
You either have to have two separate service routines for the different levels, or on interrupt entry you have to force the interrupt level to the highest one being used to stop the other one from re-entering.
Tom